29 #ifndef GUM_STRUCTURED_INFERENCE_H 30 #define GUM_STRUCTURED_INFERENCE_H 34 #include <agrum/tools/core/timer.h> 36 #include <agrum/BN/inference/variableElimination.h> 38 #include <agrum/tools/multidim/ICIModels/multiDimNoisyORCompound.h> 39 #include <agrum/tools/multidim/ICIModels/multiDimNoisyORNet.h> 40 #include <agrum/tools/multidim/implementations/multiDimSparse.h> 41 #include <agrum/tools/multidim/potential.h> 42 #include <agrum/tools/multidim/utils/operators/multiDimCombinationDefault.h> 43 #include <agrum/tools/multidim/utils/operators/projections4MultiDim.h> 45 #include <agrum/tools/graphs/algorithms/triangulations/partialOrderedTriangulation.h> 47 #include <agrum/PRM/PRM.h> 48 #include <agrum/PRM/inference/PRMInference.h> 49 #include <agrum/PRM/inference/gspan.h> 62 template <
typename GUM_SCALAR >
72 const PRMSystem< GUM_SCALAR >& system,
73 gspan::SearchStrategy< GUM_SCALAR >* strategy = 0);
93 virtual std::string
name()
const;
126 const std::vector<
typename PRMInference< GUM_SCALAR >::Chain >& queries,
127 Potential< GUM_SCALAR >& j);
228 CData(
const PRMClass< GUM_SCALAR >& c);
332 std::pair< Idx, std::string > attr);
368 std::string
str__(
const PRMInstance< GUM_SCALAR >* i,
369 const PRMAttribute< GUM_SCALAR >* a)
const;
370 std::string
str__(
const PRMInstance< GUM_SCALAR >* i,
371 const PRMAttribute< GUM_SCALAR >& a)
const;
372 std::string
str__(
const PRMInstance< GUM_SCALAR >* i,
373 const PRMSlotChain< GUM_SCALAR >& a)
const;
385 std::string
info()
const;
389 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 397 #include <agrum/PRM/inference/structuredInference_tpl.h> List< NodeSet > partial_order
The partial order used of variable elimination.
NodeProperty< Size > mods
The class variables modalities.
List< NodeSet > partial_order__
We'll use a PartialOrderedTriangulation with three sets: output, nodes and obs with children outside ...
UndiGraph reducedGraph
The reduced graph.
const List< NodeSet > * partial_order()
PData(const PData &source)
Copy constructor.
const GSpan< GUM_SCALAR > & gspan() const
Returns the instance of gspan used to search patterns.
PData(const gspan::Pattern &p, typename GSpan< GUM_SCALAR >::MatchedInstances &m)
Default constructor.
NodeSet & queries()
Returns the set of queried nodes given all the matches of pattern.
List< NodeSet > partial_order
Partial order used for triangulation, first is outputs nodes, second query nodes. ...
std::string str__(const PRMInstance< GUM_SCALAR > *i, const PRMSlotChain< GUM_SCALAR > &a) const
virtual void evidenceRemoved_(const typename PRMInference< GUM_SCALAR >::Chain &chain)
See PRMInference::evidenceRemoved_().
std::pair< Idx, std::string > query_data__
INLINE void emplace(Args &&... args)
UndiGraph moral_graph
The class moral graph. NodeId matches those in c.
void removeNode__(typename StructuredInference::PData &data, NodeId id, Set< Potential< GUM_SCALAR > * > &pool)
void reducePattern__(const gspan::Pattern *p)
Proceed with the elimination of all inner variables (observed or not) of all usable matches of Patter...
NodeSet & outputs()
Returns the set of outputs nodes given all the matches of pattern.
NodeProperty< std::pair< Idx, std::string > > map
To ease translating potentials from one match to another.
Set< const PRMInstance< GUM_SCALAR > *> instances
The Set of Instances reduces at class level.
Bijection< const DiscreteVariable *, NodeId > var2node
Mapping between DiscreteVariable and NodeId.
void insertNodeInElimLists__(typename StructuredInference::PData &data, const Sequence< PRMInstance< GUM_SCALAR > * > &match, PRMInstance< GUM_SCALAR > *inst, PRMAttribute< GUM_SCALAR > *attr, NodeId id, std::pair< Idx, std::string > &v)
GSpan< GUM_SCALAR > * gspan__
Pointer over th GSpan<GUM_SCALAR> instance used by this class.
UndiGraph graph
A yet to be triangulated undigraph.
bool allInstanceNoRefAttr__(typename StructuredInference::PData &data, std::pair< Idx, std::string > attr)
std::string dot__
Unreduce the match containing the query.
NodeSet & obs()
Returns the set of inner and observed nodes given all the matches of pattern.
NodeSet & outputs()
Returns the set of outputs nodes.
NodeSet & queries()
Returns the set of query nodes (which will not be eliminated).
StructuredInference & operator=(const StructuredInference &source)
Copy operator.
NodeProperty< Potential< GUM_SCALAR > *> pots
To handle barren nodes.
NodeSet & outputs()
Returns the set of outputs nodes (which will be eliminated).
virtual void posterior_(const typename PRMInference< GUM_SCALAR >::Chain &chain, Potential< GUM_SCALAR > &m)
See PRMInference::posterior_().
RGData()
Default constructor.
Bijection< NodeId, const DiscreteVariable *> vars
Bijection between graph's nodes and their corresponding DiscreteVariable, for inference purpose...
bool found_query__
Flag with an explicit name.
StructuredInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
virtual void joint_(const std::vector< typename PRMInference< GUM_SCALAR >::Chain > &queries, Potential< GUM_SCALAR > &j)
See PRMInference::joint_().
void reduceAloneInstances__(RGData &data)
Add the reduced potentials of instances not in any used patterns.
Set< NodeId > barren
Set of barren nodes.
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
virtual std::string name() const
Tells this algorithm to use pattern mining or not.
StructuredInference(const StructuredInference &source)
Copy constructor.
NodeSet & inners()
Returns the set of inner nodes.
void removeBarrenNodes__(typename StructuredInference::PData &data, Set< Potential< GUM_SCALAR > * > &pool)
void addEdgesInReducedGraph__(RGData &data)
Add the nodes in the reduced graph.
virtual void evidenceAdded_(const typename PRMInference< GUM_SCALAR >::Chain &chain)
See PRMInference::evidenceAdded_().
NodeProperty< Size > mod
The pattern's variables modalities.
NodeSet & aggregators()
Returns the set of aggregators and their parents.
std::vector< NodeId > & elim_order()
The elimination order for nodes of this class.
std::string str__(const PRMInstance< GUM_SCALAR > *i, const PRMAttribute< GUM_SCALAR > *a) const
List< NodeSet > * real_order__
A copy of partial_order__ without empty sets.
HashTable< const PRMClass< GUM_SCALAR > *, CData *> cdata_map__
Mapping between a Class<GUM_SCALAR> and data about instances reduced using only Class<GUM_SCALAR> lev...
std::vector< NodeId > elim_order__
virtual ~StructuredInference()
Destructor.
bool mining__
Flag which tells to use pattern mining or not.
Set< const PRMInstance< GUM_SCALAR > *> reducedInstances__
This keeps track of reduced instances.
CData(const PRMClass< GUM_SCALAR > &c)
Default constructor.
NodeSet & inners()
Returns the set of inner nodes.
void buildReduceGraph__(RGData &data)
This calls reducePattern__() over each pattern and then build the reduced graph which is used for inf...
GSpan< GUM_SCALAR > & gspan()
Returns the instance of gspan used to search patterns.
Bijection< NodeId, std::string > node2attr
A bijection to easily keep track between graph and attributes, its of the form instance_name DOT attr...
Set< Potential< GUM_SCALAR > *> pool
The pool of potentials matching the reduced graph.
void setPatternMining(bool b)
Tells this algorithm to use pattern mining or not.
Set< Potential< GUM_SCALAR > *> trash__
NodeProperty< Size > mods
Mapping between NodeId and modalities.
const PRMClass< GUM_SCALAR > & c
The class about what this data is about.
Set< Potential< GUM_SCALAR > *> * translatePotSet__(typename StructuredInference::PData &data, const Set< Potential< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match)
Translate a given Potential Set into one w.r.t. variables in match.
void buildPatternGraph__(PData &data, Set< Potential< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match)
Build the DAG corresponding to Pattern data.pattern, initialize pool with all the Potentials of all v...
PData * pdata__
The pattern data of the pattern which one of its matches contains the query.
void searchPatterns()
Search for patterns without doing any computations.