![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>. More...
#include <agrum/PRM/PRMInference.h>
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 | |
Constructor & destructor. | |
| PRMInference (const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system) | |
| Default constructor. | |
| PRMInference (const PRMInference &source) | |
| Copy constructor. | |
| virtual | ~PRMInference () |
| Destructor. | |
| PRMInference & | operator= (const PRMInference &source) |
| Copy operator. | |
Getters & setters. | |
| virtual std::string | name () const =0 |
| Returns the name of the current inference algorithm. | |
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. | |
| EMap & | evidence (const PRMInstance< GUM_SCALAR > &i) |
| Returns EMap of evidences over i. | |
| EMap & | evidence (const PRMInstance< GUM_SCALAR > *i) |
| Returns EMap of evidences over i. | |
| const EMap & | evidence (const PRMInstance< GUM_SCALAR > &i) const |
| Returns EMap of evidences over i. | |
| const EMap & | evidence (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. | |
Private evidence handling methods and members. | |
| using | EvidenceIterator |
| Code alias. | |
| using | EvidenceConstIterator |
| Code alias. | |
| 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. | |
Protected members. | |
| 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. | |
| 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. | |
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
The main purpose of this class is to give a common interface between all inference algorithms and to handle evidences.
Definition at line 68 of file PRMInference.h.
| using gum::prm::PRMInference< GUM_SCALAR >::Chain = std::pair< const PRMInstance< GUM_SCALAR >*, const PRMAttribute< GUM_SCALAR >* > |
Code alias.
Definition at line 71 of file PRMInference.h.
| using gum::prm::PRMInference< GUM_SCALAR >::EMap = NodeProperty< const Tensor< GUM_SCALAR >* > |
Code alias.
Definition at line 74 of file PRMInference.h.
| using gum::prm::PRMInference< GUM_SCALAR >::EMapConstIterator |
Code alias.
Definition at line 80 of file PRMInference.h.
| using gum::prm::PRMInference< GUM_SCALAR >::EMapIterator = typename NodeProperty< const Tensor< GUM_SCALAR >* >::iterator_safe |
Code alias.
Definition at line 77 of file PRMInference.h.
|
private |
Code alias.
Definition at line 241 of file PRMInference.h.
|
private |
| INLINE gum::prm::PRMInference< GUM_SCALAR >::PRMInference | ( | const PRM< GUM_SCALAR > & | prm, |
| const PRMSystem< GUM_SCALAR > & | system ) |
Default constructor.
Definition at line 157 of file PRMInference_tpl.h.
References PRMInference(), prm_, and sys_.
Referenced by gum::prm::GroundedInference< GUM_SCALAR >::GroundedInference(), gum::prm::GroundedInference< GUM_SCALAR >::GroundedInference(), PRMInference(), PRMInference(), gum::prm::StructuredInference< GUM_SCALAR >::StructuredInference(), gum::prm::StructuredInference< GUM_SCALAR >::StructuredInference(), gum::prm::SVE< GUM_SCALAR >::SVE(), gum::prm::SVED< GUM_SCALAR >::SVED(), and operator=().
| gum::prm::PRMInference< GUM_SCALAR >::PRMInference | ( | const PRMInference< GUM_SCALAR > & | source | ) |
Copy constructor.
Definition at line 68 of file PRMInference_tpl.h.
References PRMInference(), _evidences_, gum::Instantiation::end(), gum::Instantiation::inc(), prm_, gum::Instantiation::setFirst(), and sys_.
|
virtual |
Destructor.
Definition at line 164 of file PRMInference_tpl.h.
|
private |
Private getter over evidences, if necessary creates an EMap for i.
Definition at line 116 of file PRMInference_tpl.h.
References _evidences_.
Referenced by removeEvidence().
| void gum::prm::PRMInference< GUM_SCALAR >::addEvidence | ( | const Chain & | chain, |
| const Tensor< GUM_SCALAR > & | p ) |
Add an evidence to the given instance's elt.
| chain | The variable being observed. |
| p | The Tensor added (by copy) as evidence. |
| NotFound | Raised if elt does not belong to i. |
| OperationNotAllowed | Raised if p is inconsistent with elt. |
Definition at line 126 of file PRMInference_tpl.h.
| void gum::prm::PRMInference< GUM_SCALAR >::clearEvidence | ( | ) |
Remove all evidences.
Definition at line 56 of file PRMInference_tpl.h.
References _evidences_.
Referenced by operator=().
| INLINE PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence | ( | const PRMInstance< GUM_SCALAR > & | i | ) |
Returns EMap of evidences over i.
| NotFound | if i has no evidence. |
Definition at line 171 of file PRMInference_tpl.h.
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_().
| INLINE const PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence | ( | const PRMInstance< GUM_SCALAR > & | i | ) | const |
Returns EMap of evidences over i.
| NotFound | if i has no evidence. |
Definition at line 179 of file PRMInference_tpl.h.
References _evidences_.
| INLINE PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence | ( | const PRMInstance< GUM_SCALAR > * | i | ) |
Returns EMap of evidences over i.
| NotFound | if i has no evidence. |
Definition at line 187 of file PRMInference_tpl.h.
| INLINE const PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence | ( | const PRMInstance< GUM_SCALAR > * | i | ) | const |
Returns EMap of evidences over i.
| NotFound | if i has no evidence. |
Definition at line 195 of file PRMInference_tpl.h.
References _evidences_, and GUM_ERROR.
|
protectedpure virtual |
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 >.
|
protectedpure virtual |
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().
| INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence | ( | ) | const |
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
Definition at line 217 of file PRMInference_tpl.h.
References _evidences_.
| INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence | ( | const Chain & | chain | ) | const |
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
Definition at line 212 of file PRMInference_tpl.h.
References evidence(), and hasEvidence().
| INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence | ( | const PRMInstance< GUM_SCALAR > & | i | ) | const |
Returns true if i has evidence.
Definition at line 202 of file PRMInference_tpl.h.
References _evidences_.
Referenced by gum::prm::SVE< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesDownward_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesUpward_(), gum::prm::StructuredInference< GUM_SCALAR >::_insertNodeInElimLists_(), gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_(), gum::prm::SVE< GUM_SCALAR >::_variableElimination_(), hasEvidence(), posterior(), and gum::prm::StructuredInference< GUM_SCALAR >::posterior_().
| INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence | ( | const PRMInstance< GUM_SCALAR > * | i | ) | const |
Returns EMap of evidences over i.
Definition at line 207 of file PRMInference_tpl.h.
References _evidences_.
| INLINE void gum::prm::PRMInference< GUM_SCALAR >::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.
| chains | A Set of strings of the form instance.attribute. |
| j | An empty CPF which will be filed by the joint probability over chains. |
| NotFound | Raised if some chain in chains does not point to a formal attribute. |
| OperationNotAllowed | Raise if m is not empty. |
Definition at line 261 of file PRMInference_tpl.h.
References GUM_ERROR, and joint_().
|
protectedpure virtual |
Generic method to compute the posterior of given element.
| queries | Set of pairs of PRMInstance<GUM_SCALAR> and PRMAttribute<GUM_SCALAR>. |
| j | CPF 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().
|
pure virtual |
Returns the name of the current inference algorithm.
Implemented in gum::prm::GroundedInference< GUM_SCALAR >, gum::prm::StructuredInference< GUM_SCALAR >, gum::prm::SVE< GUM_SCALAR >, and gum::prm::SVED< GUM_SCALAR >.
| PRMInference< GUM_SCALAR > & gum::prm::PRMInference< GUM_SCALAR >::operator= | ( | const PRMInference< GUM_SCALAR > & | source | ) |
Copy operator.
Definition at line 90 of file PRMInference_tpl.h.
References PRMInference(), clearEvidence(), prm_, and sys_.
| INLINE void gum::prm::PRMInference< GUM_SCALAR >::posterior | ( | const Chain & | chain, |
| Tensor< GUM_SCALAR > & | m ) |
Compute the posterior of the formal attribute pointed by chain and stores it in m.
| chain | A string of the form instance.attribute. |
| m | An empty CPF which will be filed by the posterior of chain. |
| NotFound | Raised if chain is invalid. |
| TypeError | Raised if chain does not point to an PRMAttribute<GUM_SCALAR>. |
| OperationNotAllowed | Raise if m is not empty. |
Definition at line 235 of file PRMInference_tpl.h.
References gum::prm::PRMInstance< GUM_SCALAR >::end(), evidence(), GUM_ERROR, hasEvidence(), gum::Instantiation::inc(), and gum::Instantiation::setFirst().
|
protectedpure virtual |
Generic method to compute the posterior of given element.
| chain | |
| m | CPF filled with the posterior of elt. It is initialized properly. |
Implemented in gum::prm::SVE< GUM_SCALAR >, and gum::prm::SVED< GUM_SCALAR >.
| INLINE void gum::prm::PRMInference< GUM_SCALAR >::removeEvidence | ( | const Chain & | chain | ) |
Remove evidence on the given instance's elt.
| chain | The variable being observed. |
| NotFound | Raised if the given names are not found. |
| TypeError | Raised if the elt is not an PRMAttribute<GUM_SCALAR>. |
Definition at line 222 of file PRMInference_tpl.h.
References _EMap_(), and evidenceRemoved_().
|
private |
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().
|
protected |
The PRM<GUM_SCALAR> on which inference is done.
Definition at line 224 of file PRMInference.h.
Referenced by PRMInference(), PRMInference(), gum::prm::StructuredInference< GUM_SCALAR >::StructuredInference(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), operator=(), and gum::prm::StructuredInference< GUM_SCALAR >::operator=().
|
protected |
The Model on which inference is done.
Definition at line 227 of file PRMInference.h.
Referenced by PRMInference(), PRMInference(), gum::prm::StructuredInference< GUM_SCALAR >::StructuredInference(), gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_(), operator=(), gum::prm::StructuredInference< GUM_SCALAR >::operator=(), and gum::prm::StructuredInference< GUM_SCALAR >::searchPatterns().