![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
<agrum/PRM/groundedInference.h> More...
#include <groundedInference.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. | |
| GroundedInference (const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system) | |
| Default constructor. | |
| virtual | ~GroundedInference () |
| Destructor. | |
Getters & setters. | |
| MarginalTargetedInference< GUM_SCALAR > & | getBNInference () |
| Returns the bayesnet inference engine used by this class. | |
| void | setBNInference (MarginalTargetedInference< GUM_SCALAR > *bn_inf) |
| Defines the bayesnet inference engine used by this class. | |
| virtual std::string | name () const |
| Returns the bayesnet inference engine used by this class. | |
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. | |
Protected Member Functions | |
Private evidence handling methods and members. | |
| virtual void | evidenceAdded_ (const typename PRMInference< GUM_SCALAR >::Chain &chain) |
| This method is called whenever an evidence is added, but AFTER any processing made by PRMInference. | |
| virtual void | evidenceRemoved_ (const typename PRMInference< GUM_SCALAR >::Chain &chain) |
| This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference. | |
| virtual void | posterior_ (const typename PRMInference< GUM_SCALAR >::Chain &chain, Tensor< GUM_SCALAR > &m) |
| Generic method to compute the marginal of given element. | |
| virtual void | joint_ (const std::vector< typename PRMInference< GUM_SCALAR >::Chain > &queries, Tensor< GUM_SCALAR > &j) |
| Generic method to compute the marginal of given element. | |
Private Member Functions | |
| GroundedInference (const GroundedInference &source) | |
| Copy constructor. | |
| GroundedInference & | operator= (const GroundedInference &source) |
| Copy operator. | |
Private Attributes | |
| MarginalTargetedInference< GUM_SCALAR > * | _inf_ |
| The bayesnet inference engine used by this class. | |
| List< const Tensor< GUM_SCALAR > * > | _obs_ |
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. | |
<agrum/PRM/groundedInference.h>
This class is used to realise grounded inference in a PRM<GUM_SCALAR>.
The best way to build this class is to use the static creation methods.
Definition at line 66 of file groundedInference.h.
|
inherited |
Code alias.
Definition at line 71 of file PRMInference.h.
|
inherited |
Code alias.
Definition at line 74 of file PRMInference.h.
|
inherited |
Code alias.
Definition at line 80 of file PRMInference.h.
|
inherited |
Code alias.
Definition at line 77 of file PRMInference.h.
|
privateinherited |
Code alias.
Definition at line 241 of file PRMInference.h.
|
privateinherited |
| INLINE gum::prm::GroundedInference< GUM_SCALAR >::GroundedInference | ( | const PRM< GUM_SCALAR > & | prm, |
| const PRMSystem< GUM_SCALAR > & | system ) |
Default constructor.
Definition at line 109 of file groundedInference_tpl.h.
References GroundedInference(), gum::prm::PRMInference< GUM_SCALAR >::PRMInference(), and _inf_.
Referenced by GroundedInference(), GroundedInference(), ~GroundedInference(), and operator=().
|
virtual |
Destructor.
Definition at line 56 of file groundedInference_tpl.h.
References GroundedInference(), _inf_, and _obs_.
|
private |
Copy constructor.
Definition at line 116 of file groundedInference_tpl.h.
References GroundedInference(), gum::prm::PRMInference< GUM_SCALAR >::PRMInference(), _inf_, and GUM_ERROR.
|
privateinherited |
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().
|
inherited |
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.
|
inherited |
Remove all evidences.
Definition at line 56 of file PRMInference_tpl.h.
References _evidences_.
Referenced by operator=().
|
inherited |
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_().
|
inherited |
Returns EMap of evidences over i.
| NotFound | if i has no evidence. |
Definition at line 179 of file PRMInference_tpl.h.
References _evidences_.
|
inherited |
Returns EMap of evidences over i.
| NotFound | if i has no evidence. |
Definition at line 187 of file PRMInference_tpl.h.
|
inherited |
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.
|
protectedvirtual |
This method is called whenever an evidence is added, but AFTER any processing made by PRMInference.
Definition at line 70 of file groundedInference_tpl.h.
References _inf_, _obs_, gum::prm::PRMInference< GUM_SCALAR >::evidence(), gum::Instantiation::inc(), and gum::Instantiation::setFirst().
|
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 >.
|
protectedvirtual |
This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference.
Definition at line 89 of file groundedInference_tpl.h.
|
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().
| INLINE MarginalTargetedInference< GUM_SCALAR > & gum::prm::GroundedInference< GUM_SCALAR >::getBNInference | ( | ) |
Returns the bayesnet inference engine used by this class.
| NotFound | Raised if no inference engine have been defined for this class. |
Definition at line 131 of file groundedInference_tpl.h.
|
inherited |
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
Definition at line 217 of file PRMInference_tpl.h.
References _evidences_.
|
inherited |
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
Definition at line 212 of file PRMInference_tpl.h.
References evidence(), and hasEvidence().
|
inherited |
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_().
|
inherited |
Returns EMap of evidences over i.
Definition at line 207 of file PRMInference_tpl.h.
References _evidences_.
|
inherited |
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_().
|
protectedvirtual |
Generic method to compute the marginal of given element.
| queries | Set of pairs of PRMInstance and PRMAttribute. |
| j | CPF filled with the joint probability of queries. It is initialized properly. |
Definition at line 168 of file groundedInference_tpl.h.
References GUM_ERROR.
|
protectedpure virtualinherited |
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().
|
virtual |
Returns the bayesnet inference engine used by this class.
| NotFound | Raised if no inference engine have been defined for this class. |
Implements gum::prm::PRMInference< GUM_SCALAR >.
Definition at line 175 of file groundedInference_tpl.h.
|
private |
Copy operator.
Definition at line 125 of file groundedInference_tpl.h.
References GroundedInference(), and GUM_ERROR.
|
inherited |
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().
|
protectedvirtual |
Generic method to compute the marginal of given element.
| chain | |
| m | CPF filled with the marginal of elt. It is initialized properly. |
Definition at line 148 of file groundedInference_tpl.h.
|
protectedpure virtualinherited |
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 >.
|
inherited |
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_().
| INLINE void gum::prm::GroundedInference< GUM_SCALAR >::setBNInference | ( | MarginalTargetedInference< GUM_SCALAR > * | bn_inf | ) |
Defines the bayesnet inference engine used by this class.
The inference engine is given to this class, it will be deleted when ~GroundedInference() is called.
| bn_inf | The bayesnet inference engine used by this class. |
| OperationNotAllowed | If bn_inf does not inference over the SystemBayesNet of this class. |
Definition at line 140 of file groundedInference_tpl.h.
References _inf_.
|
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().
|
private |
The bayesnet inference engine used by this class.
Definition at line 148 of file groundedInference.h.
Referenced by GroundedInference(), GroundedInference(), ~GroundedInference(), evidenceAdded_(), evidenceRemoved_(), getBNInference(), posterior_(), and setBNInference().
|
private |
Definition at line 150 of file groundedInference.h.
Referenced by ~GroundedInference(), evidenceAdded_(), evidenceRemoved_(), and posterior_().
|
protectedinherited |
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=().
|
protectedinherited |
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().