aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::prm::StructuredInference< GUM_SCALAR > Class Template Referenceabstract

<agrum/PRM/structuredInference.h> More...

#include <structuredInference.h>

Inheritance diagram for gum::prm::StructuredInference< GUM_SCALAR >:
Collaboration diagram for gum::prm::StructuredInference< GUM_SCALAR >:

Classes

struct  RGData
 Private structure to represent data about a reduced graph. More...
struct  PData
 Private structure to represent data about a pattern. More...
struct  CData
 Private structure to represent data about a Class<GUM_SCALAR>. More...

Public Types

using Chain = std::pair< const PRMInstance< GUM_SCALAR >*, const PRMAttribute< GUM_SCALAR >* >
 Code alias.
using EMap = NodeProperty< const Tensor< GUM_SCALAR >* >
 Code alias.
using EMapIterator = typename NodeProperty< const Tensor< GUM_SCALAR >* >::iterator_safe
 Code alias.
using EMapConstIterator
 Code alias.

Public Member Functions

std::string info () const
Constructor & destructor.
 StructuredInference (const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
 Default constructor.
 StructuredInference (const StructuredInference &source)
 Copy constructor.
virtual ~StructuredInference ()
 Destructor.
StructuredInferenceoperator= (const StructuredInference &source)
 Copy operator.
Getters and setters.
void setPatternMining (bool b)
 Tells this algorithm to use pattern mining or not.
virtual std::string name () const
 Tells this algorithm to use pattern mining or not.
GSpan< GUM_SCALAR > & gspan ()
 Returns the instance of gspan used to search patterns.
const GSpan< GUM_SCALAR > & gspan () const
 Returns the instance of gspan used to search patterns.
void searchPatterns ()
 Search for patterns without doing any computations.
Query methods.
void posterior (const Chain &chain, Tensor< GUM_SCALAR > &m)
 Compute the posterior of the formal attribute pointed by chain and stores it in m.
void joint (const std::vector< Chain > &chains, Tensor< GUM_SCALAR > &j)
 Compute the joint probability of the formals attributes pointed by chains and stores it in m.
Evidence handling.
EMapevidence (const PRMInstance< GUM_SCALAR > &i)
 Returns EMap of evidences over i.
EMapevidence (const PRMInstance< GUM_SCALAR > *i)
 Returns EMap of evidences over i.
const EMapevidence (const PRMInstance< GUM_SCALAR > &i) const
 Returns EMap of evidences over i.
const EMapevidence (const PRMInstance< GUM_SCALAR > *i) const
 Returns EMap of evidences over i.
bool hasEvidence (const PRMInstance< GUM_SCALAR > &i) const
 Returns true if i has evidence.
bool hasEvidence (const PRMInstance< GUM_SCALAR > *i) const
 Returns EMap of evidences over i.
bool hasEvidence (const Chain &chain) const
 Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
bool hasEvidence () const
 Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
void addEvidence (const Chain &chain, const Tensor< GUM_SCALAR > &p)
 Add an evidence to the given instance's elt.
void removeEvidence (const Chain &chain)
 Remove evidence on the given instance's elt.
void clearEvidence ()
 Remove all evidences.

Public Attributes

Timer timer
Timer plopTimer
double triang_time
double mining_time
double pattern_time
double inner_time
double obs_time
double full_time

Protected Member Functions

Protected members.
virtual void evidenceAdded_ (const typename PRMInference< GUM_SCALAR >::Chain &chain)
 See PRMInference::evidenceAdded_().
virtual void evidenceRemoved_ (const typename PRMInference< GUM_SCALAR >::Chain &chain)
 See PRMInference::evidenceRemoved_().
virtual void posterior_ (const typename PRMInference< GUM_SCALAR >::Chain &chain, Tensor< GUM_SCALAR > &m)
 See PRMInference::posterior_().
virtual void joint_ (const std::vector< typename PRMInference< GUM_SCALAR >::Chain > &queries, Tensor< GUM_SCALAR > &j)
 See PRMInference::joint_().

Private Member Functions

void _buildReduceGraph_ (RGData &data)
 This calls reducePattern() over each pattern and then build the reduced graph which is used for inference. The reduce graph is a triangulated instance graph.
void _addEdgesInReducedGraph_ (RGData &data)
 Add the nodes in the reduced graph.
void _removeNode_ (typename StructuredInference::PData &data, NodeId id, Set< Tensor< GUM_SCALAR > * > &pool)
void _reduceAloneInstances_ (RGData &data)
 Add the reduced tensors of instances not in any used patterns.
void _reducePattern_ (const gspan::Pattern *p)
 Proceed with the elimination of all inner variables (observed or not) of all usable matches of Pattern p. Inner variables which are part of the query are not eliminated.
void _buildPatternGraph_ (PData &data, Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match)
 Build the DAG corresponding to Pattern data.pattern, initialize pool with all the Tensors of all variables in data.pattern. The first match of data.pattern (aka data.match) is used.
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)
bool _allInstanceNoRefAttr_ (typename StructuredInference::PData &data, std::pair< Idx, std::string > attr)
void _removeBarrenNodes_ (typename StructuredInference::PData &data, Set< Tensor< GUM_SCALAR > * > &pool)
Set< Tensor< GUM_SCALAR > * > * _eliminateObservedNodes_ (typename StructuredInference::PData &data, const Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match, const std::vector< NodeId > &elim_order)
 Add in data.queries() any queried variable in one of data.pattern matches.
Set< Tensor< GUM_SCALAR > * > * _eliminateObservedNodesInSource_ (typename StructuredInference::PData &data, const Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match, const std::vector< NodeId > &elim_order)
Set< Tensor< GUM_SCALAR > * > * _translatePotSet_ (typename StructuredInference::PData &data, const Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match)
 Translate a given Tensor Set into one w.r.t. variables in match.
std::string _str_ (const PRMInstance< GUM_SCALAR > *i, const PRMAttribute< GUM_SCALAR > *a) const
std::string _str_ (const PRMInstance< GUM_SCALAR > *i, const PRMAttribute< GUM_SCALAR > &a) const
std::string _str_ (const PRMInstance< GUM_SCALAR > *i, const PRMSlotChain< GUM_SCALAR > &a) const

Private Attributes

GSpan< GUM_SCALAR > * _gspan_
 Pointer over th GSpan<GUM_SCALAR> instance used by this class.
HashTable< const Sequence< PRMInstance< GUM_SCALAR > * > *, Set< Tensor< GUM_SCALAR > * > * > _elim_map_
 Mapping between a Pattern's match and its tensor pool after inner variables were eliminated.
HashTable< const PRMClass< GUM_SCALAR > *, CData * > _cdata_map_
 Mapping between a Class<GUM_SCALAR> and data about instances reduced using only Class<GUM_SCALAR> level information.
Set< Tensor< GUM_SCALAR > * > _trash_
 Keeping track of create tensors to delete them after inference.
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > * > _outputs_
Set< const PRMInstance< GUM_SCALAR > * > _reducedInstances_
 This keeps track of reduced instances.
PRMInference< GUM_SCALAR >::Chain _query_
 The query.
PData_pdata_
 The pattern data of the pattern which one of its matches contains the query.
bool _mining_
 Flag which tells to use pattern mining or not.
bool _found_query_
 Flag with an explicit name.
std::pair< Idx, std::string > _query_data_
std::string _dot_
 Unreduce the match containing the query.

Private evidence handling methods and members.

HashTable< const PRMInstance< GUM_SCALAR > *, EMap * > _evidences_
 Mapping of evidence over PRMInstance<GUM_SCALAR>'s nodes.
EMap_EMap_ (const PRMInstance< GUM_SCALAR > *i)
 Private getter over evidences, if necessary creates an EMap for i.
using EvidenceIterator
 Code alias.
using EvidenceConstIterator
 Code alias.

Protected members.

virtual void evidenceAdded_ (const Chain &chain)=0
 This method is called whenever an evidence is added, but AFTER any processing made by PRMInference.
virtual void evidenceRemoved_ (const Chain &chain)=0
 This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference.
virtual void posterior_ (const Chain &chain, Tensor< GUM_SCALAR > &m)=0
 Generic method to compute the posterior of given element.
virtual void joint_ (const std::vector< Chain > &queries, Tensor< GUM_SCALAR > &j)=0
 Generic method to compute the posterior of given element.
PRM< GUM_SCALAR > const * prm_
 The PRM<GUM_SCALAR> on which inference is done.
PRMSystem< GUM_SCALAR > const * sys_
 The Model on which inference is done.

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::StructuredInference< GUM_SCALAR >

<agrum/PRM/structuredInference.h>

This PRM<GUM_SCALAR> inference algorithm exploits the GSpan<GUM_SCALAR> algorithm to discover new patters and exploit them in a structured way.

Definition at line 69 of file structuredInference.h.

Member Typedef Documentation

◆ Chain

template<typename GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::Chain = std::pair< const PRMInstance< GUM_SCALAR >*, const PRMAttribute< GUM_SCALAR >* >
inherited

Code alias.

Definition at line 71 of file PRMInference.h.

◆ EMap

template<typename GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::EMap = NodeProperty< const Tensor< GUM_SCALAR >* >
inherited

Code alias.

Definition at line 74 of file PRMInference.h.

◆ EMapConstIterator

template<typename GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::EMapConstIterator
inherited
Initial value:
typename NodeProperty< const Tensor< GUM_SCALAR >* >::const_iterator_safe
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.

Code alias.

Definition at line 80 of file PRMInference.h.

◆ EMapIterator

template<typename GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::EMapIterator = typename NodeProperty< const Tensor< GUM_SCALAR >* >::iterator_safe
inherited

Code alias.

Definition at line 77 of file PRMInference.h.

◆ EvidenceConstIterator

template<typename GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::EvidenceConstIterator
privateinherited
Initial value:
typename HashTable< const PRMInstance< GUM_SCALAR >*, EMap* >::const_iterator_safe
The class for generic Hash Tables.
Definition hashTable.h:637
NodeProperty< const Tensor< GUM_SCALAR > * > EMap
Code alias.

Code alias.

Definition at line 241 of file PRMInference.h.

◆ EvidenceIterator

template<typename GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::EvidenceIterator
privateinherited
Initial value:

Code alias.

Definition at line 238 of file PRMInference.h.

Constructor & Destructor Documentation

◆ StructuredInference() [1/2]

template<typename GUM_SCALAR>
gum::prm::StructuredInference< GUM_SCALAR >::StructuredInference ( const PRM< GUM_SCALAR > & prm,
const PRMSystem< GUM_SCALAR > & system,
gspan::SearchStrategy< GUM_SCALAR > * strategy = 0 )

Default constructor.

Definition at line 56 of file structuredInference_tpl.h.

59 :
61 _dot_(".") {
64 triang_time = 0.0;
65 mining_time = 0.0;
66 pattern_time = 0.0;
67 inner_time = 0.0;
68 obs_time = 0.0;
69 full_time = 0.0;
70 }
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
<agrum/PRM/structuredInference.h>
std::string _dot_
Unreduce the match containing the query.
PData * _pdata_
The pattern data of the pattern which one of its matches contains the query.
bool _mining_
Flag which tells to use pattern mining or not.
GSpan< GUM_SCALAR > * _gspan_
Pointer over th GSpan<GUM_SCALAR> instance used by this class.
StructuredInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.

References gum::prm::PRMInference< GUM_SCALAR >::PRMInference(), StructuredInference(), _dot_, _gspan_, _mining_, _pdata_, full_time, inner_time, mining_time, obs_time, pattern_time, and triang_time.

Referenced by StructuredInference(), StructuredInference(), ~StructuredInference(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StructuredInference() [2/2]

template<typename GUM_SCALAR>
gum::prm::StructuredInference< GUM_SCALAR >::StructuredInference ( const StructuredInference< GUM_SCALAR > & source)

Copy constructor.

Definition at line 73 of file structuredInference_tpl.h.

74 :
76 _found_query_(false), _dot_(".") {
78 _gspan_ = new GSpan< GUM_SCALAR >(*(this->prm_), *(this->sys_));
79 }
PRMSystem< GUM_SCALAR > const * sys_
The Model on which inference is done.
PRM< GUM_SCALAR > const * prm_
The PRM<GUM_SCALAR> on which inference is done.
bool _found_query_
Flag with an explicit name.

References gum::prm::PRMInference< GUM_SCALAR >::PRMInference(), StructuredInference(), _dot_, _found_query_, _gspan_, _mining_, _pdata_, gum::prm::PRMInference< GUM_SCALAR >::prm_, and gum::prm::PRMInference< GUM_SCALAR >::sys_.

Here is the call graph for this function:

◆ ~StructuredInference()

template<typename GUM_SCALAR>
gum::prm::StructuredInference< GUM_SCALAR >::~StructuredInference ( )
virtual

Destructor.

Definition at line 82 of file structuredInference_tpl.h.

82 {
84 delete this->_gspan_;
85
86 for (const auto& elt: _elim_map_)
87 delete elt.second;
88
89 for (const auto& elt: _cdata_map_)
90 delete elt.second;
91
92 for (const auto elt: _trash_)
93 delete (elt);
94
95 for (const auto& elt: _outputs_)
96 delete elt.second;
97
98 if (_pdata_) delete _pdata_;
99 }
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...
HashTable< const Sequence< PRMInstance< GUM_SCALAR > * > *, Set< Tensor< GUM_SCALAR > * > * > _elim_map_
Mapping between a Pattern's match and its tensor pool after inner variables were eliminated.
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > * > _outputs_
Set< Tensor< GUM_SCALAR > * > _trash_
Keeping track of create tensors to delete them after inference.

References StructuredInference(), _cdata_map_, _elim_map_, _gspan_, _outputs_, _pdata_, and _trash_.

Here is the call graph for this function:

Member Function Documentation

◆ _addEdgesInReducedGraph_()

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::_addEdgesInReducedGraph_ ( RGData & data)
private

Add the nodes in the reduced graph.

Add edges in the reduced graph.

Definition at line 709 of file structuredInference_tpl.h.

710 {
711 // We first add edges between variables already in pool (i.e. those of the
712 // reduced instances)
714
715 for (const auto pot: data.pool) {
716 const Sequence< const DiscreteVariable* >& vars = pot->variablesSequence();
717
718 for (Size var_1 = 0; var_1 < vars.size(); ++var_1) {
719 if (data.var2node.existsFirst(vars.atPos(var_1))) {
720 id_1 = data.var2node.second(vars.atPos(var_1));
721 } else {
722 id_1 = data.reducedGraph.addNode();
723 data.var2node.insert(vars.atPos(var_1), id_1);
724 data.mods.insert(id_1, vars.atPos(var_1)->domainSize());
725 data.outputs().insert(id_1);
726 }
727
728 for (Size var_2 = var_1 + 1; var_2 < vars.size(); ++var_2) {
729 if (data.var2node.existsFirst(vars.atPos(var_2))) {
730 id_2 = data.var2node.second(vars.atPos(var_2));
731 } else {
732 id_2 = data.reducedGraph.addNode();
733 data.var2node.insert(vars.atPos(var_2), id_2);
734 data.mods.insert(id_2, vars.atPos(var_2)->domainSize());
735 data.outputs().insert(id_2);
736 }
737
738 try {
739 data.reducedGraph.addEdge(id_1, id_2);
740 } catch (DuplicateElement const&) {}
741 }
742 }
743 }
744
745 // Adding tensors obtained from reduced patterns
746 for (const auto& elt: _elim_map_) {
747 // We add edges between variables in the same reduced patterns
748 for (const auto pot: *elt.second) {
749 data.pool.insert(pot);
750 const Sequence< const DiscreteVariable* >& vars = pot->variablesSequence();
751
752 for (Size var_1 = 0; var_1 < vars.size(); ++var_1) {
753 if (data.var2node.existsFirst(vars.atPos(var_1))) {
754 id_1 = data.var2node.second(vars.atPos(var_1));
755 } else {
756 id_1 = data.reducedGraph.addNode();
757 data.var2node.insert(vars.atPos(var_1), id_1);
758 data.mods.insert(id_1, vars.atPos(var_1)->domainSize());
759 data.outputs().insert(id_1);
760 }
761
762 for (Size var_2 = var_1 + 1; var_2 < vars.size(); ++var_2) {
763 if (data.var2node.existsFirst(vars.atPos(var_2))) {
764 id_2 = data.var2node.second(vars.atPos(var_2));
765 } else {
766 id_2 = data.reducedGraph.addNode();
767 data.var2node.insert(vars.atPos(var_2), id_2);
768 data.mods.insert(id_2, vars.atPos(var_2)->domainSize());
769 data.outputs().insert(id_2);
770 }
771
772 try {
773 data.reducedGraph.addEdge(id_1, id_2);
774 } catch (DuplicateElement const&) {}
775 }
776 }
777 }
778 }
779 }

References _elim_map_, gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNode(), gum::SequenceImplementation< Key, Gen >::atPos(), gum::Set< Key >::insert(), gum::prm::StructuredInference< GUM_SCALAR >::RGData::mods, gum::prm::StructuredInference< GUM_SCALAR >::RGData::outputs(), gum::prm::StructuredInference< GUM_SCALAR >::RGData::pool, gum::prm::StructuredInference< GUM_SCALAR >::RGData::reducedGraph, gum::SequenceImplementation< Key, Gen >::size(), and gum::prm::StructuredInference< GUM_SCALAR >::RGData::var2node.

Referenced by _buildReduceGraph_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _allInstanceNoRefAttr_()

template<typename GUM_SCALAR>
bool gum::prm::StructuredInference< GUM_SCALAR >::_allInstanceNoRefAttr_ ( typename StructuredInference< GUM_SCALAR >::PData & data,
std::pair< Idx, std::string > attr )
private

Definition at line 403 of file structuredInference_tpl.h.

405 {
406 for (const auto mat: data.matches)
407 if (mat->atPos(attr.first)->hasRefAttr(mat->atPos(attr.first)->get(attr.second).id()))
408 return false;
409
410 return true;
411 }

References gum::prm::StructuredInference< GUM_SCALAR >::PData::matches.

Referenced by _buildPatternGraph_().

Here is the caller graph for this function:

◆ _buildPatternGraph_()

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::_buildPatternGraph_ ( PData & data,
Set< Tensor< GUM_SCALAR > * > & pool,
const Sequence< PRMInstance< GUM_SCALAR > * > & match )
private

Build the DAG corresponding to Pattern data.pattern, initialize pool with all the Tensors of all variables in data.pattern. The first match of data.pattern (aka data.match) is used.

Definition at line 348 of file structuredInference_tpl.h.

351 {
354
355 for (const auto inst: match) {
356 for (const auto& elt: *inst) {
357 NodeId id = data.graph.addNode();
358 v = std::make_pair(match.pos(inst), elt.second->safeName());
359 data.map.insert(id, v);
360 data.node2attr.insert(id, _str_(inst, elt.second));
361 data.mod.insert(id, elt.second->type()->domainSize());
362 data.vars.insert(id, &(elt.second->type().variable()));
363 pool.insert(const_cast< Tensor< GUM_SCALAR >* >(&(elt.second->cpf())));
364 pot = &(const_cast< Tensor< GUM_SCALAR >& >(inst->get(v.second).cpf()));
365
366 for (const auto var: pot->variablesSequence()) {
367 try {
368 if (id != data.vars.first(var)) data.graph.addEdge(id, data.vars.first(var));
369 } catch (DuplicateElement const&) {
370 } catch (NotFound const&) {}
371 }
372
373 _insertNodeInElimLists_(data, match, inst, elt.second, id, v);
374
375 if (data.inners().exists(id)
376 && (inst->type().containerDag().children(elt.second->id()).size() == 0)
378 data.barren.insert(id);
379 }
380 }
381
382 if (!_found_query_) {
383 for (const auto mat: data.matches) {
384 if (mat->exists(const_cast< PRMInstance< GUM_SCALAR >* >(_query_.first))) {
385 Idx pos = mat->pos(const_cast< PRMInstance< GUM_SCALAR >* >(_query_.first));
387 = match.atPos(pos)->get(_query_.second->safeName()).type().variable();
388 NodeId id = data.vars.first(&var);
389 data.barren.erase(id);
390 data.inners().erase(id);
391 data.obs().erase(id);
392 data.outputs().erase(id);
393 data.queries().insert(id);
394 _found_query_ = true;
395 _query_data_ = std::make_pair(pos, _query_.second->safeName());
396 break;
397 }
398 }
399 }
400 }
PRMInference< GUM_SCALAR >::Chain _query_
The query.
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)
std::string _str_(const PRMInstance< GUM_SCALAR > *i, const PRMAttribute< GUM_SCALAR > *a) const
bool _allInstanceNoRefAttr_(typename StructuredInference::PData &data, std::pair< Idx, std::string > attr)
std::pair< Idx, std::string > _query_data_

References _allInstanceNoRefAttr_(), _found_query_, _insertNodeInElimLists_(), _query_, _query_data_, _str_(), gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNode(), gum::prm::StructuredInference< GUM_SCALAR >::PData::barren, gum::Set< Key >::erase(), gum::Set< Key >::exists(), gum::prm::StructuredInference< GUM_SCALAR >::PData::graph, gum::prm::StructuredInference< GUM_SCALAR >::PData::inners(), gum::BijectionImplementation< T1, T2, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >::insert(), gum::Set< Key >::insert(), gum::prm::StructuredInference< GUM_SCALAR >::PData::map, gum::prm::StructuredInference< GUM_SCALAR >::PData::matches, gum::prm::StructuredInference< GUM_SCALAR >::PData::mod, gum::prm::StructuredInference< GUM_SCALAR >::PData::node2attr, gum::prm::StructuredInference< GUM_SCALAR >::PData::obs(), gum::prm::StructuredInference< GUM_SCALAR >::PData::outputs(), gum::prm::StructuredInference< GUM_SCALAR >::PData::queries(), and gum::prm::StructuredInference< GUM_SCALAR >::PData::vars.

Referenced by _reducePattern_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _buildReduceGraph_()

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::_buildReduceGraph_ ( RGData & data)
private

This calls reducePattern() over each pattern and then build the reduced graph which is used for inference. The reduce graph is a triangulated instance graph.

Definition at line 224 of file structuredInference_tpl.h.

225 {
226 // Launch the pattern mining
227 plopTimer.reset();
228
229 if (_mining_) _gspan_->discoverPatterns();
230
231 mining_time = plopTimer.step();
232 // Reducing each used pattern
233 plopTimer.reset();
235
236 for (Iter p = _gspan_->patterns().begin(); p != _gspan_->patterns().end(); ++p)
237 if (_gspan_->matches(**p).size()) _reducePattern_(*p);
238
239 pattern_time = plopTimer.step();
240 // reducing instance not already reduced in a pattern
242 // Adding edges using the pools
244 // Placing the query where it belongs
245 NodeId id = data.var2node.second(&(_query_.second->type().variable()));
246 data.outputs().erase(id);
247 data.queries().insert(id);
248 // Triangulating, then eliminating
249 PartialOrderedTriangulation t(&(data.reducedGraph), &(data.mods), &(data.partial_order));
250 const std::vector< NodeId >& elim_order = t.eliminationOrder();
251
252 for (size_t i = 0; i < data.outputs().size(); ++i)
253 eliminateNode(data.var2node.first(elim_order[i]), data.pool, _trash_);
254 }
void _reducePattern_(const gspan::Pattern *p)
Proceed with the elimination of all inner variables (observed or not) of all usable matches of Patter...
void _addEdgesInReducedGraph_(RGData &data)
Add the nodes in the reduced graph.
void _reduceAloneInstances_(RGData &data)
Add the reduced tensors of instances not in any used patterns.
void eliminateNode(const DiscreteVariable *var, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.

References _addEdgesInReducedGraph_(), _gspan_, _mining_, _query_, _reduceAloneInstances_(), _reducePattern_(), _trash_, gum::prm::eliminateNode(), gum::StaticTriangulation::eliminationOrder(), gum::Set< Key >::erase(), gum::Set< Key >::insert(), mining_time, gum::prm::StructuredInference< GUM_SCALAR >::RGData::mods, gum::prm::StructuredInference< GUM_SCALAR >::RGData::outputs(), gum::prm::StructuredInference< GUM_SCALAR >::RGData::partial_order, pattern_time, plopTimer, gum::prm::StructuredInference< GUM_SCALAR >::RGData::pool, gum::prm::StructuredInference< GUM_SCALAR >::RGData::queries(), gum::prm::StructuredInference< GUM_SCALAR >::RGData::reducedGraph, and gum::prm::StructuredInference< GUM_SCALAR >::RGData::var2node.

Referenced by posterior_(), and searchPatterns().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _eliminateObservedNodes_()

template<typename GUM_SCALAR>
Set< Tensor< GUM_SCALAR > * > * gum::prm::StructuredInference< GUM_SCALAR >::_eliminateObservedNodes_ ( typename StructuredInference< GUM_SCALAR >::PData & data,
const Set< Tensor< GUM_SCALAR > * > & pool,
const Sequence< PRMInstance< GUM_SCALAR > * > & match,
const std::vector< NodeId > & elim_order )
private

Add in data.queries() any queried variable in one of data.pattern matches.

Proceeds with the elimination of observed variables in math and then call translatePotSet().

Definition at line 487 of file structuredInference_tpl.h.

491 {
494 size_t end = data.inners().size() + data.obs().size();
495
496 for (size_t idx = data.inners().size(); idx < end; ++idx) {
497 target = data.map[data.vars.first(data.vars.second(elim_order[idx]))];
498 eliminateNode(&(match[target.first]->get(target.second).type().variable()),
499 *my_pool,
500 _trash_);
501 }
502
503 return my_pool;
504 }
Set< Tensor< GUM_SCALAR > * > * _translatePotSet_(typename StructuredInference::PData &data, const Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match)
Translate a given Tensor Set into one w.r.t. variables in match.

References _translatePotSet_(), _trash_, gum::prm::eliminateNode(), gum::prm::StructuredInference< GUM_SCALAR >::PData::inners(), gum::prm::StructuredInference< GUM_SCALAR >::PData::map, gum::prm::StructuredInference< GUM_SCALAR >::PData::obs(), gum::Set< Key >::size(), and gum::prm::StructuredInference< GUM_SCALAR >::PData::vars.

Referenced by _reducePattern_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _eliminateObservedNodesInSource_()

template<typename GUM_SCALAR>
Set< Tensor< GUM_SCALAR > * > * gum::prm::StructuredInference< GUM_SCALAR >::_eliminateObservedNodesInSource_ ( typename StructuredInference< GUM_SCALAR >::PData & data,
const Set< Tensor< GUM_SCALAR > * > & pool,
const Sequence< PRMInstance< GUM_SCALAR > * > & match,
const std::vector< NodeId > & elim_order )
private

Definition at line 467 of file structuredInference_tpl.h.

471 {
474 size_t end = data.inners().size() + data.obs().size();
475
476 for (size_t idx = data.inners().size(); idx < end; ++idx) {
477 target = data.map[data.vars.first(data.vars.second(elim_order[idx]))];
478 eliminateNode(&(match[target.first]->get(target.second).type().variable()),
479 *my_pool,
480 _trash_);
481 }
482
483 return my_pool;
484 }

References _trash_, gum::prm::eliminateNode(), gum::prm::StructuredInference< GUM_SCALAR >::PData::inners(), gum::prm::StructuredInference< GUM_SCALAR >::PData::map, gum::prm::StructuredInference< GUM_SCALAR >::PData::obs(), gum::Set< Key >::size(), and gum::prm::StructuredInference< GUM_SCALAR >::PData::vars.

Referenced by _reducePattern_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _EMap_()

template<typename GUM_SCALAR>
PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::_EMap_ ( const PRMInstance< GUM_SCALAR > * i)
privateinherited

Private getter over evidences, if necessary creates an EMap for i.

Definition at line 116 of file PRMInference_tpl.h.

116 {
117 if (_evidences_.exists(i)) {
118 return *(_evidences_[i]);
119 } else {
121 return *(_evidences_[i]);
122 }
123 }
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
HashTable< const PRMInstance< GUM_SCALAR > *, EMap * > _evidences_
Mapping of evidence over PRMInstance<GUM_SCALAR>'s nodes.

References _evidences_.

Referenced by removeEvidence().

Here is the caller graph for this function:

◆ _insertNodeInElimLists_()

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::_insertNodeInElimLists_ ( typename StructuredInference< GUM_SCALAR >::PData & data,
const Sequence< PRMInstance< GUM_SCALAR > * > & match,
PRMInstance< GUM_SCALAR > * inst,
PRMAttribute< GUM_SCALAR > * attr,
NodeId id,
std::pair< Idx, std::string > & v )
private

Definition at line 314 of file structuredInference_tpl.h.

320 {
321 if ((*inst).hasRefAttr((*inst).get(v.second).id())) {
323 = inst->getRefAttr(inst->get(v.second).id());
324
325 for (auto r = refs.begin(); r != refs.end(); ++r) {
326 if (!match.exists(r->first)) {
327 data.outputs().insert(id);
328 break;
329 }
330 }
331 }
332
333 if (!(data.outputs().size() && (data.outputs().exists(id)))) {
334 for (const auto m: data.matches) {
335 if (this->hasEvidence(std::make_pair((*m)[v.first], &((*m)[v.first]->get(v.second))))) {
336 GUM_ASSERT(inst->type().name() == (*m)[v.first]->type().name());
337 GUM_ASSERT(inst->get(v.second).safeName() == (*m)[v.first]->get(v.second).safeName());
338 data.obs().insert(id);
339 break;
340 }
341 }
342
343 if (!(data.obs().size() && (data.obs().exists(id)))) data.inners().insert(id);
344 }
345 }
bool hasEvidence() const
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
virtual std::string name() const
Tells this algorithm to use pattern mining or not.

References gum::Set< Key >::exists(), gum::prm::PRMInstance< GUM_SCALAR >::get(), gum::prm::PRMInstance< GUM_SCALAR >::getRefAttr(), gum::prm::PRMInference< GUM_SCALAR >::hasEvidence(), gum::prm::StructuredInference< GUM_SCALAR >::PData::inners(), gum::Set< Key >::insert(), gum::prm::StructuredInference< GUM_SCALAR >::PData::matches, gum::prm::StructuredInference< GUM_SCALAR >::PData::obs(), gum::prm::StructuredInference< GUM_SCALAR >::PData::outputs(), gum::Set< Key >::size(), and gum::prm::PRMInstance< GUM_SCALAR >::type().

Referenced by _buildPatternGraph_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _reduceAloneInstances_()

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_ ( RGData & data)
private

Add the reduced tensors of instances not in any used patterns.

Definition at line 595 of file structuredInference_tpl.h.

596 {
598 Tensor< GUM_SCALAR >* pot = nullptr;
600
601 for (const auto& elt: *this->sys_) {
602 inst = elt.second;
603
604 if (!_reducedInstances_.exists(inst)) {
605 // Checking if its not an empty class
606 if (inst->size()) {
608
609 try {
610 data = _cdata_map_[&(inst->type())];
611 } catch (NotFound const&) {
613 _cdata_map_.insert(&(inst->type()), data);
614 }
615
616 data->instances.insert(inst);
617 // Filling up the partial ordering
619
620 if (data->inners().size()) partial_order.push_back(data->inners());
621
622 if (data->aggregators().size())
623 for (const auto agg: data->aggregators())
624 partial_order[0].insert(agg);
625
626 if (data->outputs().size()) partial_order.push_back(data->outputs());
627
628 if (_query_.first == inst) {
629 // First case, the instance contains the query
630 partial_order[0].erase(_query_.second->id());
631
632 if (partial_order[0].empty()) partial_order.erase(0);
633
634 if (partial_order.size() > 1) {
635 partial_order[1].erase(_query_.second->id());
636
637 if (partial_order[1].empty()) partial_order.erase(1);
638 }
639
641 query_set.insert(_query_.second->id());
642 partial_order.insert(query_set);
643
644 // Adding the tensors
645 for (auto attr = inst->begin(); attr != inst->end(); ++attr)
646 pool.insert(&(const_cast< Tensor< GUM_SCALAR >& >((*(attr.val())).cpf())));
647
648 // Adding evidences if any
649 if (this->hasEvidence(inst))
650 for (const auto& elt: this->evidence(inst))
651 pool.insert(const_cast< Tensor< GUM_SCALAR >* >(elt.second));
652
653 PartialOrderedTriangulation t(&(data->moral_graph), &(data->mods), &(partial_order));
654 const std::vector< NodeId >& v = t.eliminationOrder();
655
656 if (partial_order.size() > 1)
657 for (size_t idx = 0; idx < partial_order[0].size(); ++idx)
658 eliminateNode(&(inst->get(v[idx]).type().variable()), pool, _trash_);
659 } else if (this->hasEvidence(inst)) {
660 // Second case, the instance has evidences
661 // Adding the tensors
662 for (const auto& elt: *inst)
663 pool.insert(&const_cast< Tensor< GUM_SCALAR >& >(elt.second->cpf()));
664
665 // Adding evidences
666 for (const auto& elt: this->evidence(inst))
667 pool.insert(const_cast< Tensor< GUM_SCALAR >* >(elt.second));
668
669 PartialOrderedTriangulation t(&(data->moral_graph), &(data->mods), &(partial_order));
670
671 for (size_t idx = 0; idx < partial_order[0].size(); ++idx)
672 eliminateNode(&(inst->get(t.eliminationOrder()[idx]).type().variable()),
673 pool,
674 _trash_);
675 } else {
676 // Last cast, the instance neither contains evidences nor
677 // instances
678 // We translate the class level tensors into the instance ones
679 // and
680 // proceed with elimination
681 for (const auto srcPot: data->pool) {
682 pot = copyTensor(inst->bijection(), *srcPot);
683 pool.insert(pot);
684 _trash_.insert(pot);
685 }
686
687 for (const auto agg: data->c.aggregates())
688 pool.insert(&(const_cast< Tensor< GUM_SCALAR >& >(inst->get(agg->id()).cpf())));
689
690 // We eliminate inner aggregators with their parents if necessary
691 // (see
692 // CData constructor)
693 Size size = data->inners().size() + data->aggregators().size();
694
695 for (size_t idx = data->inners().size(); idx < size; ++idx)
696 eliminateNode(&(inst->get(data->elim_order()[idx]).type().variable()),
697 pool,
698 _trash_);
699 }
700
701 for (const auto pot: pool)
702 rg_data.pool.insert(pot);
703 }
704 }
705 }
706 }
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
Set< const PRMInstance< GUM_SCALAR > * > _reducedInstances_
This keeps track of reduced instances.
Tensor< GUM_SCALAR > * copyTensor(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const Tensor< GUM_SCALAR > &source)
Returns a copy of a Tensor after applying a bijection over the variables in source.

References _cdata_map_, _query_, _reducedInstances_, _trash_, gum::prm::StructuredInference< GUM_SCALAR >::CData::aggregators(), gum::prm::PRMInstance< GUM_SCALAR >::begin(), gum::prm::PRMInstance< GUM_SCALAR >::bijection(), gum::prm::StructuredInference< GUM_SCALAR >::CData::c, gum::prm::copyTensor(), gum::prm::StructuredInference< GUM_SCALAR >::CData::elim_order(), gum::prm::eliminateNode(), gum::StaticTriangulation::eliminationOrder(), gum::prm::PRMInstance< GUM_SCALAR >::end(), gum::List< Val >::erase(), gum::prm::PRMInference< GUM_SCALAR >::evidence(), gum::prm::PRMInstance< GUM_SCALAR >::get(), gum::prm::PRMInference< GUM_SCALAR >::hasEvidence(), gum::prm::StructuredInference< GUM_SCALAR >::CData::inners(), gum::List< Val >::insert(), gum::Set< Key >::insert(), gum::prm::StructuredInference< GUM_SCALAR >::CData::instances, gum::prm::StructuredInference< GUM_SCALAR >::CData::mods, gum::prm::StructuredInference< GUM_SCALAR >::CData::moral_graph, gum::prm::StructuredInference< GUM_SCALAR >::CData::outputs(), gum::prm::StructuredInference< GUM_SCALAR >::CData::pool, gum::prm::StructuredInference< GUM_SCALAR >::RGData::pool, gum::List< Val >::push_back(), gum::List< Val >::size(), gum::prm::PRMInstance< GUM_SCALAR >::size(), gum::Set< Key >::size(), gum::prm::PRMInference< GUM_SCALAR >::sys_, and gum::prm::PRMInstance< GUM_SCALAR >::type().

Referenced by _buildReduceGraph_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _reducePattern_()

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::_reducePattern_ ( const gspan::Pattern * p)
private

Proceed with the elimination of all inner variables (observed or not) of all usable matches of Pattern p. Inner variables which are part of the query are not eliminated.

Definition at line 257 of file structuredInference_tpl.h.

257 {
260 _buildPatternGraph_(data, pool, **(data.matches.begin()));
262 PartialOrderedTriangulation t(&(data.graph), &(data.mod), data.partial_order());
263 const std::vector< NodeId >& elim_order = t.eliminationOrder();
264
265 for (size_t i = 0; i < data.inners().size(); ++i)
266 if (!data.barren.exists(elim_order[i]))
267 eliminateNode(data.vars.second(elim_order[i]), pool, _trash_);
268
271
272 for (const auto elt: **iter)
273 _reducedInstances_.insert(elt);
274
275 if (data.obs().size())
277 else _elim_map_.insert(*iter, new Set< Tensor< GUM_SCALAR >* >(pool));
278
279 ++iter;
280
281 if (data.obs().size()) {
282 for (; iter != data.matches.end(); ++iter) {
283 try {
285 } catch (OperationNotAllowed const&) { fake_patterns.insert(*iter); }
286 }
287 } else {
288 for (; iter != data.matches.end(); ++iter) {
289 try {
291 } catch (OperationNotAllowed const&) { fake_patterns.insert(*iter); }
292 }
293 }
294
295 for (const auto pat: fake_patterns) {
296 for (const auto elt: *pat)
297 _reducedInstances_.erase(elt);
298
299 data.matches.erase(pat);
300 }
301
302 obs_time += plopTimer.step();
303
304 if (data.queries().size())
305 for (const auto m: data.matches)
306 if (!(m->exists(const_cast< PRMInstance< GUM_SCALAR >* >(_query_.first))))
308 &(m->atPos(_query_data_.first)->get(_query_data_.second).type().variable()),
309 *(_elim_map_[m]),
310 _trash_);
311 }
Set< Tensor< GUM_SCALAR > * > * _eliminateObservedNodes_(typename StructuredInference::PData &data, const Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match, const std::vector< NodeId > &elim_order)
Add in data.queries() any queried variable in one of data.pattern matches.
void _removeBarrenNodes_(typename StructuredInference::PData &data, Set< Tensor< GUM_SCALAR > * > &pool)
void _buildPatternGraph_(PData &data, Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match)
Build the DAG corresponding to Pattern data.pattern, initialize pool with all the Tensors of all vari...
Set< Tensor< GUM_SCALAR > * > * _eliminateObservedNodesInSource_(typename StructuredInference::PData &data, const Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match, const std::vector< NodeId > &elim_order)

References _buildPatternGraph_(), _elim_map_, _eliminateObservedNodes_(), _eliminateObservedNodesInSource_(), _gspan_, _query_, _query_data_, _reducedInstances_, _removeBarrenNodes_(), _translatePotSet_(), _trash_, gum::prm::StructuredInference< GUM_SCALAR >::PData::barren, gum::prm::eliminateNode(), gum::StaticTriangulation::eliminationOrder(), gum::Set< Key >::exists(), gum::prm::StructuredInference< GUM_SCALAR >::PData::graph, gum::prm::StructuredInference< GUM_SCALAR >::PData::inners(), gum::Set< Key >::insert(), gum::prm::StructuredInference< GUM_SCALAR >::PData::matches, gum::prm::StructuredInference< GUM_SCALAR >::PData::mod, gum::prm::StructuredInference< GUM_SCALAR >::PData::obs(), obs_time, gum::prm::StructuredInference< GUM_SCALAR >::PData::partial_order(), plopTimer, gum::prm::StructuredInference< GUM_SCALAR >::PData::queries(), gum::Set< Key >::size(), and gum::prm::StructuredInference< GUM_SCALAR >::PData::vars.

Referenced by _buildReduceGraph_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _removeBarrenNodes_()

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::_removeBarrenNodes_ ( typename StructuredInference< GUM_SCALAR >::PData & data,
Set< Tensor< GUM_SCALAR > * > & pool )
private

Definition at line 414 of file structuredInference_tpl.h.

416 {
418
419 for (const auto node: data.barren) {
420 for (const auto pot: pool)
421 if (pot->contains(*data.vars.second(node))) {
422 pool.erase(pot);
423 break;
424 }
425
426 for (const auto nei: data.graph.neighbours(node))
427 if (data.inners().exists(nei)) {
428 try {
429 candidates.insert(nei);
430 } catch (DuplicateElement const&) {}
431 }
432 }
433
434 NodeId node;
435 Tensor< GUM_SCALAR >* my_pot = nullptr;
436 short count = 0;
437
438 while (candidates.size()) {
439 node = candidates.back();
440 candidates.erase(node);
441 count = 0;
442
443 for (const auto pot: pool) {
444 if (pot->contains(*data.vars.second(node))) {
445 ++count;
446 my_pot = pot;
447 }
448 }
449
450 if (count == 1) {
451 pool.erase(my_pot);
452 data.barren.insert(node);
453
454 for (const auto nei: data.graph.neighbours(node)) {
455 if (data.inners().exists(nei)) {
456 try {
457 candidates.insert(nei);
458 } catch (DuplicateElement const&) {}
459 }
460 }
461 }
462 }
463 }

References gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::back(), gum::prm::StructuredInference< GUM_SCALAR >::PData::barren, gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::erase(), gum::Set< Key >::exists(), gum::prm::StructuredInference< GUM_SCALAR >::PData::graph, gum::prm::StructuredInference< GUM_SCALAR >::PData::inners(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::insert(), gum::Set< Key >::insert(), gum::EdgeGraphPart::neighbours(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::size(), and gum::prm::StructuredInference< GUM_SCALAR >::PData::vars.

Referenced by _reducePattern_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _removeNode_()

template<typename GUM_SCALAR>
INLINE void gum::prm::StructuredInference< GUM_SCALAR >::_removeNode_ ( typename StructuredInference< GUM_SCALAR >::PData & data,
NodeId id,
Set< Tensor< GUM_SCALAR > * > & pool )
private

Definition at line 987 of file structuredInference_tpl.h.

990 {
991 data.graph.eraseNode(id);
992 GUM_ASSERT(!data.graph.exists(id));
993 data.mod.erase(id);
994 GUM_ASSERT(!data.mod.exists(id));
995 data.node2attr.eraseFirst(id);
996 GUM_ASSERT(!data.node2attr.existsFirst(id));
997 data.map.erase(id);
998 GUM_ASSERT(!data.map.exists(id));
999 data.vars.eraseFirst(id);
1000 GUM_ASSERT(!data.vars.existsFirst(id));
1001 data.inners().erase(id);
1002 GUM_ASSERT(!data.inners().exists(id));
1003 pool.erase(data.pots[id]);
1004 GUM_ASSERT(!pool.exists(data.pots[id]));
1005 data.pots.erase(id);
1006 GUM_ASSERT(!data.pots.exists(id));
1007 }

References gum::Set< Key >::erase(), gum::BijectionImplementation< T1, T2, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >::eraseFirst(), gum::UndiGraph::eraseNode(), gum::NodeGraphPart::exists(), gum::Set< Key >::exists(), gum::BijectionImplementation< T1, T2, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >::existsFirst(), gum::prm::StructuredInference< GUM_SCALAR >::PData::graph, gum::prm::StructuredInference< GUM_SCALAR >::PData::inners(), gum::prm::StructuredInference< GUM_SCALAR >::PData::map, gum::prm::StructuredInference< GUM_SCALAR >::PData::mod, gum::prm::StructuredInference< GUM_SCALAR >::PData::node2attr, gum::prm::StructuredInference< GUM_SCALAR >::PData::pots, and gum::prm::StructuredInference< GUM_SCALAR >::PData::vars.

Here is the call graph for this function:

◆ _str_() [1/3]

template<typename GUM_SCALAR>
INLINE std::string gum::prm::StructuredInference< GUM_SCALAR >::_str_ ( const PRMInstance< GUM_SCALAR > * i,
const PRMAttribute< GUM_SCALAR > & a ) const
private

Definition at line 949 of file structuredInference_tpl.h.

950 {
951 return i->name() + _dot_ + a.safeName();
952 }

References _dot_, gum::prm::PRMObject::name(), and gum::prm::PRMClassElement< GUM_SCALAR >::safeName().

Here is the call graph for this function:

◆ _str_() [2/3]

template<typename GUM_SCALAR>
INLINE std::string gum::prm::StructuredInference< GUM_SCALAR >::_str_ ( const PRMInstance< GUM_SCALAR > * i,
const PRMAttribute< GUM_SCALAR > * a ) const
private

Definition at line 942 of file structuredInference_tpl.h.

943 {
944 return i->name() + _dot_ + a->safeName();
945 }

References _dot_, gum::prm::PRMObject::name(), and gum::prm::PRMClassElement< GUM_SCALAR >::safeName().

Referenced by _buildPatternGraph_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _str_() [3/3]

template<typename GUM_SCALAR>
INLINE std::string gum::prm::StructuredInference< GUM_SCALAR >::_str_ ( const PRMInstance< GUM_SCALAR > * i,
const PRMSlotChain< GUM_SCALAR > & a ) const
private

Definition at line 956 of file structuredInference_tpl.h.

957 {
958 return i->name() + _dot_ + a.lastElt().safeName();
959 }

References _dot_, gum::prm::PRMSlotChain< GUM_SCALAR >::lastElt(), and gum::prm::PRMObject::name().

Here is the call graph for this function:

◆ _translatePotSet_()

template<typename GUM_SCALAR>
Set< Tensor< GUM_SCALAR > * > * gum::prm::StructuredInference< GUM_SCALAR >::_translatePotSet_ ( typename StructuredInference< GUM_SCALAR >::PData & data,
const Set< Tensor< GUM_SCALAR > * > & pool,
const Sequence< PRMInstance< GUM_SCALAR > * > & match )
private

Translate a given Tensor Set into one w.r.t. variables in match.

Definition at line 507 of file structuredInference_tpl.h.

510 {
511#ifdef DEBUG
512
513 for (const auto iter = data.matches.begin(); iter != data.matches.end(); ++iter) {
514 GUM_ASSERT((**iter).size() == match.size());
515
516 for (Size idx = 0; idx < match.size(); ++idx) {
517 GUM_ASSERT((**iter).atPos(idx)->type() == match.atPos(idx)->type());
518 }
519 }
520
521#endif
525 const Sequence< PRMInstance< GUM_SCALAR >* >& source = **(data.matches.begin());
526
527 for (Size idx = 0; idx < match.size(); ++idx) {
529 const auto& chains = source[idx]->type().slotChains();
530
531 for (const auto sc: chains) {
532#ifdef DEBUG
533 GUM_ASSERT(!(sc->isMultiple()));
534#endif
535
536 try {
537 bij.insert(&(source[idx]
538 ->getInstance(sc->id())
539 .get(sc->lastElt().safeName())
540 .type()
541 .variable()),
542 &(match[idx]
543 ->getInstance(sc->id())
544 .get(sc->lastElt().safeName())
545 .type()
546 .variable()));
547 } catch (DuplicateElement const&) {
548 try {
549 if (bij.first(&(match[idx]
550 ->getInstance(sc->id())
551 .get(sc->lastElt().safeName())
552 .type()
553 .variable()))
554 != &(source[idx]
555 ->getInstance(sc->id())
556 .get(sc->lastElt().safeName())
557 .type()
558 .variable())) {
559 delete my_pool;
560 GUM_ERROR(OperationNotAllowed, "fake pattern")
561 }
562 } catch (NotFound const&) {
563 delete my_pool;
564 GUM_ERROR(OperationNotAllowed, "fake pattern")
565 }
566 }
567 }
568 }
569
570 for (const auto p: pool) {
571 for (const auto v: p->variablesSequence()) {
572 try {
573 target = data.map[data.vars.first(v)];
574 bij.insert(v, &(match[target.first]->get(target.second).type().variable()));
575 } catch (NotFound const&) {
576 GUM_ASSERT(bij.existsFirst(v));
577 } catch (DuplicateElement const&) {}
578 }
579
580 try {
581 my_pool->insert(copyTensor(bij, *p));
582 } catch (Exception const&) {
583 for (const auto pot: *my_pool)
584 delete pot;
585
586 delete my_pool;
587 GUM_ERROR(OperationNotAllowed, "fake pattern")
588 }
589 }
590
591 return my_pool;
592 }
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References _reducedInstances_, gum::prm::copyTensor(), gum::BijectionImplementation< T1, T2, Gen >::existsFirst(), gum::BijectionImplementation< T1, T2, Gen >::first(), GUM_ERROR, gum::BijectionImplementation< T1, T2, Gen >::insert(), gum::Set< Key >::insert(), gum::prm::StructuredInference< GUM_SCALAR >::PData::map, gum::prm::StructuredInference< GUM_SCALAR >::PData::matches, and gum::prm::StructuredInference< GUM_SCALAR >::PData::vars.

Referenced by _eliminateObservedNodes_(), and _reducePattern_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addEvidence()

template<typename GUM_SCALAR>
void gum::prm::PRMInference< GUM_SCALAR >::addEvidence ( const Chain & chain,
const Tensor< GUM_SCALAR > & p )
inherited

Add an evidence to the given instance's elt.

Parameters
chainThe variable being observed.
pThe Tensor added (by copy) as evidence.
Exceptions
NotFoundRaised if elt does not belong to i.
OperationNotAllowedRaised if p is inconsistent with elt.

Definition at line 126 of file PRMInference_tpl.h.

127 {
128 if (chain.first->exists(chain.second->id())) {
129 if ((p.nbrDim() != 1) || (!p.contains(chain.second->type().variable())))
130 GUM_ERROR(OperationNotAllowed, "illegal evidence for the given PRMAttribute.")
131
133 e->add(chain.second->type().variable());
134 Instantiation i(*e);
135
136 for (i.setFirst(); !i.end(); i.inc())
137 e->set(i, p.get(i));
138
140
141 if (emap.exists(chain.second->id())) {
142 delete emap[chain.second->id()];
143 emap[chain.second->id()] = e;
144 } else {
145 emap.insert(chain.second->id(), e);
146 }
147
149 } else {
151 "the given PRMAttribute does not belong to this "
152 "Instance<GUM_SCALAR>.");
153 }
154 }
EMap & _EMap_(const PRMInstance< GUM_SCALAR > *i)
Private getter over evidences, if necessary creates an EMap for i.
virtual void evidenceAdded_(const Chain &chain)=0
This method is called whenever an evidence is added, but AFTER any processing made by PRMInference.

◆ clearEvidence()

template<typename GUM_SCALAR>
void gum::prm::PRMInference< GUM_SCALAR >::clearEvidence ( )
inherited

Remove all evidences.

Definition at line 56 of file PRMInference_tpl.h.

56 {
57 for (const auto& elt: _evidences_) {
58 for (const auto& elt2: *elt.second)
59 delete elt2.second;
60
61 delete elt.second;
62 }
63
64 _evidences_.clear();
65 }

References _evidences_.

Referenced by operator=().

Here is the caller graph for this function:

◆ evidence() [1/4]

template<typename GUM_SCALAR>
INLINE PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > & i)
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 171 of file PRMInference_tpl.h.

171 {
172 try {
173 return *(_evidences_[&i]);
174 } catch (NotFound const&) { GUM_ERROR(NotFound, "this instance has no evidence.") }
175 }

References _evidences_, and GUM_ERROR.

Referenced by gum::prm::SVE< GUM_SCALAR >::_eliminateNodesWithEvidence_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesWithEvidence_(), gum::prm::SVE< GUM_SCALAR >::_insertEvidence_(), gum::prm::SVED< GUM_SCALAR >::_insertEvidence_(), gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_(), gum::prm::GroundedInference< GUM_SCALAR >::evidenceAdded_(), hasEvidence(), posterior(), and gum::prm::StructuredInference< GUM_SCALAR >::posterior_().

Here is the caller graph for this function:

◆ evidence() [2/4]

template<typename GUM_SCALAR>
INLINE const PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > & i) const
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 179 of file PRMInference_tpl.h.

179 {
180 try {
181 return *(_evidences_[&i]);
182 } catch (NotFound const&) { GUM_ERROR(NotFound, "this instance has no evidence.") }
183 }

References _evidences_.

◆ evidence() [3/4]

template<typename GUM_SCALAR>
INLINE PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > * i)
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 187 of file PRMInference_tpl.h.

187 {
188 try {
189 return *(_evidences_[i]);
190 } catch (NotFound const&) { GUM_ERROR(NotFound, "this instance has no evidence.") }
191 }

◆ evidence() [4/4]

template<typename GUM_SCALAR>
INLINE const PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > * i) const
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 195 of file PRMInference_tpl.h.

195 {
196 try {
197 return *(_evidences_[i]);
198 } catch (NotFound const&) { GUM_ERROR(NotFound, "this instance has no evidence.") }
199 }

References _evidences_, and GUM_ERROR.

◆ evidenceAdded_() [1/2]

template<typename GUM_SCALAR>
virtual void gum::prm::PRMInference< GUM_SCALAR >::evidenceAdded_ ( const Chain & chain)
protectedpure virtualinherited

This method is called whenever an evidence is added, but AFTER any processing made by PRMInference.

Implemented in gum::prm::SVE< GUM_SCALAR >, and gum::prm::SVED< GUM_SCALAR >.

◆ evidenceAdded_() [2/2]

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::evidenceAdded_ ( const typename PRMInference< GUM_SCALAR >::Chain & chain)
protectedvirtual

See PRMInference::evidenceAdded_().

Definition at line 114 of file structuredInference_tpl.h.

115 {}

◆ evidenceRemoved_() [1/2]

template<typename GUM_SCALAR>
virtual void gum::prm::PRMInference< GUM_SCALAR >::evidenceRemoved_ ( const Chain & chain)
protectedpure virtualinherited

This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference.

Implemented in gum::prm::SVE< GUM_SCALAR >, and gum::prm::SVED< GUM_SCALAR >.

Referenced by removeEvidence().

Here is the caller graph for this function:

◆ evidenceRemoved_() [2/2]

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::evidenceRemoved_ ( const typename PRMInference< GUM_SCALAR >::Chain & chain)
protectedvirtual

See PRMInference::evidenceRemoved_().

Definition at line 118 of file structuredInference_tpl.h.

119 {}

◆ gspan() [1/2]

template<typename GUM_SCALAR>
INLINE GSpan< GUM_SCALAR > & gum::prm::StructuredInference< GUM_SCALAR >::gspan ( )

Returns the instance of gspan used to search patterns.

Definition at line 977 of file structuredInference_tpl.h.

977 {
978 return *_gspan_;
979 }

References _gspan_.

◆ gspan() [2/2]

template<typename GUM_SCALAR>
INLINE const GSpan< GUM_SCALAR > & gum::prm::StructuredInference< GUM_SCALAR >::gspan ( ) const

Returns the instance of gspan used to search patterns.

Definition at line 982 of file structuredInference_tpl.h.

982 {
983 return *_gspan_;
984 }

References _gspan_.

◆ hasEvidence() [1/4]

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( ) const
inherited

Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.

Definition at line 217 of file PRMInference_tpl.h.

217 {
218 return (_evidences_.size() != (Size)0);
219 }

References _evidences_.

◆ hasEvidence() [2/4]

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( const Chain & chain) const
inherited

Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.

Definition at line 212 of file PRMInference_tpl.h.

212 {
213 return (hasEvidence(chain.first)) ? evidence(chain.first).exists(chain.second->id()) : false;
214 }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.

References evidence(), and hasEvidence().

Here is the call graph for this function:

◆ hasEvidence() [3/4]

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( const PRMInstance< GUM_SCALAR > & i) const
inherited

◆ hasEvidence() [4/4]

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( const PRMInstance< GUM_SCALAR > * i) const
inherited

Returns EMap of evidences over i.

Definition at line 207 of file PRMInference_tpl.h.

207 {
208 return _evidences_.exists(i);
209 }

References _evidences_.

◆ info()

template<typename GUM_SCALAR>
std::string gum::prm::StructuredInference< GUM_SCALAR >::info ( ) const

Definition at line 200 of file structuredInference_tpl.h.

200 {
202 s << "Triangulation time: " << triang_time << std::endl;
203 s << "Pattern mining time: " << mining_time << std::endl;
204 s << "Pattern elimination time: " << pattern_time << std::endl;
205 s << "Inner node elimination time: " << inner_time << std::endl;
206 s << "Observed node elimination time: " << obs_time << std::endl;
207 s << "Full inference time: " << full_time << std::endl;
208 s << "#patterns: " << _gspan_->patterns().size() << std::endl;
209 Size count = 0;
211
212 for (Iter p = _gspan_->patterns().begin(); p != _gspan_->patterns().end(); ++p) {
213 if (_gspan_->matches(**p).size()) {
214 s << "Pattern n°" << count++ << " match count: " << _gspan_->matches(**p).size()
215 << std::endl;
216 s << "Pattern n°" << count++ << " instance count: " << (**p).size() << std::endl;
217 }
218 }
219
220 return s.str();
221 }

References _gspan_, full_time, inner_time, mining_time, obs_time, pattern_time, and triang_time.

◆ joint()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMInference< GUM_SCALAR >::joint ( const std::vector< Chain > & chains,
Tensor< GUM_SCALAR > & j )
inherited

Compute the joint probability of the formals attributes pointed by chains and stores it in m.

Parameters
chainsA Set of strings of the form instance.attribute.
jAn empty CPF which will be filed by the joint probability over chains.
Exceptions
NotFoundRaised if some chain in chains does not point to a formal attribute.
OperationNotAllowedRaise if m is not empty.

Definition at line 261 of file PRMInference_tpl.h.

263 {
264 if (j.nbrDim() > 0) { GUM_ERROR(OperationNotAllowed, "the given Tensor is not empty.") }
265
266 for (auto chain = chains.begin(); chain != chains.end(); ++chain) {
267 j.add(chain->second->type().variable());
268 }
269
270 joint_(chains, j);
271 }
virtual void joint_(const std::vector< Chain > &queries, Tensor< GUM_SCALAR > &j)=0
Generic method to compute the posterior of given element.

References GUM_ERROR, and joint_().

Here is the call graph for this function:

◆ joint_() [1/2]

template<typename GUM_SCALAR>
virtual void gum::prm::PRMInference< GUM_SCALAR >::joint_ ( const std::vector< Chain > & queries,
Tensor< GUM_SCALAR > & j )
protectedpure virtualinherited

Generic method to compute the posterior of given element.

Parameters
queriesSet of pairs of PRMInstance<GUM_SCALAR> and PRMAttribute<GUM_SCALAR>.
jCPF filled with the joint probability of queries. It is initialized properly.

Implemented in gum::prm::SVE< GUM_SCALAR >, and gum::prm::SVED< GUM_SCALAR >.

Referenced by joint().

Here is the caller graph for this function:

◆ joint_() [2/2]

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::joint_ ( const std::vector< typename PRMInference< GUM_SCALAR >::Chain > & queries,
Tensor< GUM_SCALAR > & j )
protectedvirtual

See PRMInference::joint_().

Definition at line 193 of file structuredInference_tpl.h.

195 {
196 GUM_ERROR(FatalError, "not implemented")
197 }

References GUM_ERROR.

◆ name()

template<typename GUM_SCALAR>
INLINE std::string gum::prm::StructuredInference< GUM_SCALAR >::name ( ) const
virtual

Tells this algorithm to use pattern mining or not.

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 972 of file structuredInference_tpl.h.

972 {
973 return "StructuredInference";
974 }

◆ operator=()

template<typename GUM_SCALAR>
StructuredInference< GUM_SCALAR > & gum::prm::StructuredInference< GUM_SCALAR >::operator= ( const StructuredInference< GUM_SCALAR > & source)

Copy operator.

Definition at line 102 of file structuredInference_tpl.h.

103 {
104 this->prm_ = source.prm_;
105 this->sys_ = source.sys_;
106
107 if (this->_gspan_) delete this->_gspan_;
108
109 this->_gspan_ = new GSpan< GUM_SCALAR >(*(this->prm_), *(this->sys_));
110 return *this;
111 }

References StructuredInference(), _gspan_, gum::prm::PRMInference< GUM_SCALAR >::prm_, and gum::prm::PRMInference< GUM_SCALAR >::sys_.

Here is the call graph for this function:

◆ posterior()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMInference< GUM_SCALAR >::posterior ( const Chain & chain,
Tensor< GUM_SCALAR > & m )
inherited

Compute the posterior of the formal attribute pointed by chain and stores it in m.

Parameters
chainA string of the form instance.attribute.
mAn empty CPF which will be filed by the posterior of chain.
Exceptions
NotFoundRaised if chain is invalid.
TypeErrorRaised if chain does not point to an PRMAttribute<GUM_SCALAR>.
OperationNotAllowedRaise if m is not empty.

Definition at line 235 of file PRMInference_tpl.h.

237 {
238 if (m.nbrDim() > 0) { GUM_ERROR(OperationNotAllowed, "the given Tensor is not empty.") }
239
240 if (hasEvidence(chain)) {
241 m.add(chain.second->type().variable());
242 const Tensor< GUM_SCALAR >& e = *(evidence(chain.first)[chain.second->id()]);
243 Instantiation i(m), j(e);
244
245 for (i.setFirst(), j.setFirst(); !i.end(); i.inc(), j.inc())
246 m.set(i, e.get(j));
247 } else {
248 if (chain.second != &(chain.first->get(chain.second->safeName()))) {
250 = std::make_pair(chain.first, &(chain.first->get(chain.second->safeName())));
251 m.add(good_chain.second->type().variable());
253 } else {
254 m.add(chain.second->type().variable());
256 }
257 }
258 }
virtual void posterior_(const Chain &chain, Tensor< GUM_SCALAR > &m)=0
Generic method to compute the posterior of given element.

References gum::prm::PRMInstance< GUM_SCALAR >::end(), evidence(), GUM_ERROR, hasEvidence(), gum::Instantiation::inc(), and gum::Instantiation::setFirst().

Here is the call graph for this function:

◆ posterior_() [1/2]

template<typename GUM_SCALAR>
virtual void gum::prm::PRMInference< GUM_SCALAR >::posterior_ ( const Chain & chain,
Tensor< GUM_SCALAR > & m )
protectedpure virtualinherited

Generic method to compute the posterior of given element.

Parameters
chain
mCPF filled with the posterior of elt. It is initialized properly.

Implemented in gum::prm::SVE< GUM_SCALAR >, and gum::prm::SVED< GUM_SCALAR >.

◆ posterior_() [2/2]

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::posterior_ ( const typename PRMInference< GUM_SCALAR >::Chain & chain,
Tensor< GUM_SCALAR > & m )
protectedvirtual

See PRMInference::posterior_().

Definition at line 122 of file structuredInference_tpl.h.

124 {
125 timer.reset();
126 _found_query_ = false;
127 _query_ = chain;
129
130 if (!this->hasEvidence() && (chain.second->cpf().nbrDim() == 1)) {
132
133 for (i.setFirst(); !i.end(); i.inc())
134 m.set(i, chain.second->cpf().get(i));
135
136 return;
137 } else if (this->hasEvidence(chain)) {
139 const Tensor< GUM_SCALAR >* e = this->evidence(_query_.first)[_query_.second->id()];
140
141 for (i.setFirst(); !i.end(); i.inc())
142 m.set(i, e->get(i));
143
144 return;
145 }
146
149
150 if (data.pool.size() > 1) {
151 for (const auto pot: data.pool)
152 if (pot->contains(_query_.second->type().variable())) pots.insert(pot);
153
154 if (pots.size() == 1) {
155 Tensor< GUM_SCALAR >* pot = const_cast< Tensor< GUM_SCALAR >* >(*(pots.begin()));
156 GUM_ASSERT(pot->contains(_query_.second->type().variable()));
157 GUM_ASSERT(pot->variablesSequence().size() == 1);
158 Instantiation i(*pot), j(m);
159
160 for (i.setFirst(), j.setFirst(); !i.end(); i.inc(), j.inc())
161 m.set(j, pot->get(i));
162 } else {
164 Tensor< GUM_SCALAR >* tmp = Comb.execute(pots);
165 Instantiation i(m), j(*tmp);
166
167 for (i.setFirst(), j.setFirst(); !i.end(); i.inc(), j.inc())
168 m.set(i, tmp->get(j));
169
170 delete tmp;
171 }
172 } else {
173 Tensor< GUM_SCALAR >* pot = *(data.pool.begin());
174 GUM_ASSERT(pot->contains(_query_.second->type().variable()));
175 GUM_ASSERT(pot->variablesSequence().size() == 1);
176 Instantiation i(*pot), j(m);
177
178 for (i.setFirst(), j.setFirst(); !i.end(); i.inc(), j.inc())
179 m.set(j, pot->get(i));
180 }
181
182 m.normalize();
183
184 if (_pdata_) {
185 delete _pdata_;
186 _pdata_ = 0;
187 }
188
189 full_time = timer.step();
190 }
void _buildReduceGraph_(RGData &data)
This calls reducePattern() over each pattern and then build the reduced graph which is used for infer...

References _buildReduceGraph_(), _found_query_, _pdata_, _query_, gum::Set< Key >::begin(), gum::Instantiation::end(), gum::prm::PRMInference< GUM_SCALAR >::evidence(), gum::MultiDimCombinationDefault< TABLE >::execute(), full_time, gum::prm::PRMInference< GUM_SCALAR >::hasEvidence(), gum::Instantiation::inc(), gum::Set< Key >::insert(), gum::prm::multTensor(), gum::prm::StructuredInference< GUM_SCALAR >::RGData::pool, gum::Instantiation::setFirst(), gum::Set< Key >::size(), and timer.

Here is the call graph for this function:

◆ removeEvidence()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMInference< GUM_SCALAR >::removeEvidence ( const Chain & chain)
inherited

Remove evidence on the given instance's elt.

Parameters
chainThe variable being observed.
Exceptions
NotFoundRaised if the given names are not found.
TypeErrorRaised if the elt is not an PRMAttribute<GUM_SCALAR>.

Definition at line 222 of file PRMInference_tpl.h.

222 {
223 try {
224 if (_EMap_(chain.first).exists(chain.second->id())) {
226 delete _EMap_(chain.first)[chain.second->id()];
227 _EMap_(chain.first).erase(chain.second->id());
228 }
229 } catch (NotFound const&) {
230 // Ok, we are only removing
231 }
232 }
void erase(const Key &key)
Removes a given element from the hash table.
virtual void evidenceRemoved_(const Chain &chain)=0
This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference...

References _EMap_(), and evidenceRemoved_().

Here is the call graph for this function:

◆ searchPatterns()

template<typename GUM_SCALAR>
void gum::prm::StructuredInference< GUM_SCALAR >::searchPatterns ( )

Search for patterns without doing any computations.

Definition at line 927 of file structuredInference_tpl.h.

927 {
928 const PRMInstance< GUM_SCALAR >* i = (this->sys_->begin()).val();
929 _query_ = std::make_pair(i, i->begin().val());
930 _found_query_ = false;
933 }

References _buildReduceGraph_(), _found_query_, _query_, gum::prm::PRMInstance< GUM_SCALAR >::begin(), and gum::prm::PRMInference< GUM_SCALAR >::sys_.

Here is the call graph for this function:

◆ setPatternMining()

template<typename GUM_SCALAR>
INLINE void gum::prm::StructuredInference< GUM_SCALAR >::setPatternMining ( bool b)

Tells this algorithm to use pattern mining or not.

Definition at line 936 of file structuredInference_tpl.h.

936 {
937 _mining_ = b;
938 }

References _mining_.

Member Data Documentation

◆ _cdata_map_

template<typename GUM_SCALAR>
HashTable< const PRMClass< GUM_SCALAR >*, CData* > gum::prm::StructuredInference< GUM_SCALAR >::_cdata_map_
private

Mapping between a Class<GUM_SCALAR> and data about instances reduced using only Class<GUM_SCALAR> level information.

Definition at line 275 of file structuredInference.h.

Referenced by ~StructuredInference(), and _reduceAloneInstances_().

◆ _dot_

template<typename GUM_SCALAR>
std::string gum::prm::StructuredInference< GUM_SCALAR >::_dot_
private

Unreduce the match containing the query.

Used to create strings

Definition at line 378 of file structuredInference.h.

Referenced by StructuredInference(), StructuredInference(), _str_(), _str_(), and _str_().

◆ _elim_map_

template<typename GUM_SCALAR>
HashTable< const Sequence< PRMInstance< GUM_SCALAR >* >*, Set< Tensor< GUM_SCALAR >* >* > gum::prm::StructuredInference< GUM_SCALAR >::_elim_map_
private

Mapping between a Pattern's match and its tensor pool after inner variables were eliminated.

Definition at line 269 of file structuredInference.h.

Referenced by ~StructuredInference(), _addEdgesInReducedGraph_(), and _reducePattern_().

◆ _evidences_

template<typename GUM_SCALAR>
HashTable< const PRMInstance< GUM_SCALAR >*, EMap* > gum::prm::PRMInference< GUM_SCALAR >::_evidences_
privateinherited

Mapping of evidence over PRMInstance<GUM_SCALAR>'s nodes.

Definition at line 245 of file PRMInference.h.

Referenced by PRMInference(), _EMap_(), clearEvidence(), evidence(), evidence(), evidence(), hasEvidence(), hasEvidence(), and hasEvidence().

◆ _found_query_

template<typename GUM_SCALAR>
bool gum::prm::StructuredInference< GUM_SCALAR >::_found_query_
private

Flag with an explicit name.

Definition at line 296 of file structuredInference.h.

Referenced by StructuredInference(), _buildPatternGraph_(), posterior_(), and searchPatterns().

◆ _gspan_

template<typename GUM_SCALAR>
GSpan< GUM_SCALAR >* gum::prm::StructuredInference< GUM_SCALAR >::_gspan_
private

◆ _mining_

template<typename GUM_SCALAR>
bool gum::prm::StructuredInference< GUM_SCALAR >::_mining_
private

Flag which tells to use pattern mining or not.

Definition at line 293 of file structuredInference.h.

Referenced by StructuredInference(), StructuredInference(), _buildReduceGraph_(), and setPatternMining().

◆ _outputs_

template<typename GUM_SCALAR>
HashTable< const PRMClass< GUM_SCALAR >*, std::vector< NodeId >* > gum::prm::StructuredInference< GUM_SCALAR >::_outputs_
private

Definition at line 280 of file structuredInference.h.

Referenced by ~StructuredInference().

◆ _pdata_

template<typename GUM_SCALAR>
PData* gum::prm::StructuredInference< GUM_SCALAR >::_pdata_
private

The pattern data of the pattern which one of its matches contains the query.

Definition at line 290 of file structuredInference.h.

Referenced by StructuredInference(), StructuredInference(), ~StructuredInference(), and posterior_().

◆ _query_

template<typename GUM_SCALAR>
PRMInference<GUM_SCALAR>::Chain gum::prm::StructuredInference< GUM_SCALAR >::_query_
private

◆ _query_data_

template<typename GUM_SCALAR>
std::pair< Idx, std::string > gum::prm::StructuredInference< GUM_SCALAR >::_query_data_
private

Definition at line 297 of file structuredInference.h.

Referenced by _buildPatternGraph_(), and _reducePattern_().

◆ _reducedInstances_

template<typename GUM_SCALAR>
Set< const PRMInstance< GUM_SCALAR >* > gum::prm::StructuredInference< GUM_SCALAR >::_reducedInstances_
private

This keeps track of reduced instances.

Definition at line 283 of file structuredInference.h.

Referenced by _reduceAloneInstances_(), _reducePattern_(), and _translatePotSet_().

◆ _trash_

template<typename GUM_SCALAR>
Set< Tensor< GUM_SCALAR >* > gum::prm::StructuredInference< GUM_SCALAR >::_trash_
private

Keeping track of create tensors to delete them after inference.

Definition at line 278 of file structuredInference.h.

Referenced by ~StructuredInference(), _buildReduceGraph_(), _eliminateObservedNodes_(), _eliminateObservedNodesInSource_(), _reduceAloneInstances_(), and _reducePattern_().

◆ full_time

template<typename GUM_SCALAR>
double gum::prm::StructuredInference< GUM_SCALAR >::full_time

Definition at line 395 of file structuredInference.h.

Referenced by StructuredInference(), info(), and posterior_().

◆ inner_time

template<typename GUM_SCALAR>
double gum::prm::StructuredInference< GUM_SCALAR >::inner_time

Definition at line 393 of file structuredInference.h.

Referenced by StructuredInference(), and info().

◆ mining_time

template<typename GUM_SCALAR>
double gum::prm::StructuredInference< GUM_SCALAR >::mining_time

Definition at line 391 of file structuredInference.h.

Referenced by StructuredInference(), _buildReduceGraph_(), and info().

◆ obs_time

template<typename GUM_SCALAR>
double gum::prm::StructuredInference< GUM_SCALAR >::obs_time

Definition at line 394 of file structuredInference.h.

Referenced by StructuredInference(), _reducePattern_(), and info().

◆ pattern_time

template<typename GUM_SCALAR>
double gum::prm::StructuredInference< GUM_SCALAR >::pattern_time

Definition at line 392 of file structuredInference.h.

Referenced by StructuredInference(), _buildReduceGraph_(), and info().

◆ plopTimer

template<typename GUM_SCALAR>
Timer gum::prm::StructuredInference< GUM_SCALAR >::plopTimer

Definition at line 389 of file structuredInference.h.

Referenced by _buildReduceGraph_(), and _reducePattern_().

◆ prm_

◆ sys_

◆ timer

template<typename GUM_SCALAR>
Timer gum::prm::StructuredInference< GUM_SCALAR >::timer

Definition at line 388 of file structuredInference.h.

Referenced by posterior_().

◆ triang_time

template<typename GUM_SCALAR>
double gum::prm::StructuredInference< GUM_SCALAR >::triang_time

Definition at line 390 of file structuredInference.h.

Referenced by StructuredInference(), and info().


The documentation for this class was generated from the following files: