![]() |
aGrUM
0.16.0
|
This class is an implementation of the Structured Variable Elimination algorithm on PRM<GUM_SCALAR>. More...
#include <agrum/PRM/SVE.h>
Public Member Functions | |
Constructors & destructor. | |
SVE (const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system) | |
Default Constructor. More... | |
~SVE () | |
Destructor. More... | |
Getters & setters. | |
virtual std::string | name () const |
Returns the name of the current inference algorithm. More... | |
Query methods. | |
void | marginal (const Chain &chain, Potential< GUM_SCALAR > &m) |
Compute the marginal of the formal attribute pointed by chain and stores it in m. More... | |
void | joint (const std::vector< Chain > &chains, Potential< GUM_SCALAR > &j) |
Compute the joint probability of the formals attributes pointed by chains and stores it in m. More... | |
Evidence handling. | |
EMap & | evidence (const PRMInstance< GUM_SCALAR > &i) |
Returns EMap of evidences over i. More... | |
EMap & | evidence (const PRMInstance< GUM_SCALAR > *i) |
Returns EMap of evidences over i. More... | |
const EMap & | evidence (const PRMInstance< GUM_SCALAR > &i) const |
Returns EMap of evidences over i. More... | |
const EMap & | evidence (const PRMInstance< GUM_SCALAR > *i) const |
Returns EMap of evidences over i. More... | |
bool | hasEvidence (const PRMInstance< GUM_SCALAR > &i) const |
Returns true if i has evidence. More... | |
bool | hasEvidence (const PRMInstance< GUM_SCALAR > *i) const |
Returns EMap of evidences over i. More... | |
bool | hasEvidence (const Chain &chain) const |
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a. More... | |
bool | hasEvidence () const |
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a. More... | |
void | addEvidence (const Chain &chain, const Potential< GUM_SCALAR > &p) |
Add an evidence to the given instance's elt. More... | |
void | removeEvidence (const Chain &chain) |
Remove evidence on the given instance's elt. More... | |
void | clearEvidence () |
Remove all evidences. More... | |
Public Types | |
typedef NodeProperty< const Potential< GUM_SCALAR > *> | EMap |
Code alias. More... | |
typedef NodeProperty< const Potential< GUM_SCALAR > *>::iterator_safe | EMapIterator |
Code alias. More... | |
typedef NodeProperty< const Potential< GUM_SCALAR > *>::const_iterator_safe | EMapConstIterator |
Code alias. More... | |
Protected Attributes | |
Protected members. | |
PRM< GUM_SCALAR > const * | _prm |
The PRM<GUM_SCALAR> on which inference is done. More... | |
PRMSystem< GUM_SCALAR > const * | _sys |
The Model on which inference is done. More... | |
Query methods. | |
typedef PRMInference< GUM_SCALAR >::Chain | Chain |
Code alias. More... | |
virtual void | _evidenceAdded (const Chain &chain) |
See PRMInference<GUM_SCALAR>::_evidenceAdded(). More... | |
virtual void | _evidenceRemoved (const Chain &chain) |
See PRMInference<GUM_SCALAR>::_evidenceRemoved(). More... | |
virtual void | _marginal (const Chain &chain, Potential< GUM_SCALAR > &m) |
See PRMInference<GUM_SCALAR>::_marginal(). More... | |
virtual void | _joint (const std::vector< Chain > &queries, Potential< GUM_SCALAR > &j) |
See PRMInference<GUM_SCALAR>::_joint(). More... | |
This class is an implementation of the Structured Variable Elimination algorithm on PRM<GUM_SCALAR>.
|
private |
|
private |
|
private |
|
protected |
|
inherited |
Code alias.
Definition at line 60 of file PRMInference.h.
|
inherited |
Code alias.
Definition at line 69 of file PRMInference.h.
|
inherited |
Code alias.
Definition at line 65 of file PRMInference.h.
INLINE gum::prm::SVE< GUM_SCALAR >::SVE | ( | const PRM< GUM_SCALAR > & | prm, |
const PRMSystem< GUM_SCALAR > & | system | ||
) |
Default Constructor.
Definition at line 620 of file SVE_tpl.h.
gum::prm::SVE< GUM_SCALAR >::~SVE | ( | ) |
Destructor.
Definition at line 108 of file SVE_tpl.h.
|
private |
When there is a loop in the references some variable elimination must be delayed, this methods add such variable to __delayedVariables to keep track of them.
i | An PRMInstance<GUM_SCALAR> with a child of j->get(id). |
j | The PRMInstance<GUM_SCALAR> with the delayed variable. |
id | The NodeId of the delayed variable. |
Definition at line 678 of file SVE_tpl.h.
References gum::prm::SVE< GUM_SCALAR >::__delayedVariables, gum::prm::SVE< GUM_SCALAR >::__delayedVariablesCounters, gum::prm::PRMInstance< GUM_SCALAR >::get(), gum::HashTable< Key, Val, Alloc >::insert(), and gum::prm::PRMObject::name().
|
private |
Returns true if second can be eliminated before first.
Definition at line 649 of file SVE_tpl.h.
References gum::prm::SVE< GUM_SCALAR >::__class_elim_order, gum::prm::SVE< GUM_SCALAR >::__initElimOrder(), gum::prm::SVE< GUM_SCALAR >::__trim(), gum::SequenceImplementation< Key, Alloc, Gen >::pos(), and gum::prm::PRMInstance< GUM_SCALAR >::type().
|
private |
Returns true if second can be eliminated before first.
Definition at line 210 of file SVE_tpl.h.
References gum::MultiDimBucket< GUM_SCALAR >::add(), gum::MultiDimBucket< GUM_SCALAR >::allVariables(), and gum::Set< Key, Alloc >::insert().
|
private |
Returns true if second can be eliminated before first.
Definition at line 128 of file SVE_tpl.h.
References gum::prm::PRMInstance< GUM_SCALAR >::begin(), gum::prm::PRMInstance< GUM_SCALAR >::beginInvRef(), gum::prm::eliminateNodes(), gum::StaticTriangulation::eliminationOrder(), gum::List< Val, Alloc >::empty(), gum::prm::PRMInstance< GUM_SCALAR >::end(), gum::prm::PRMInstance< GUM_SCALAR >::endInvRef(), gum::Set< Key, Alloc >::exists(), gum::List< Val, Alloc >::front(), gum::prm::PRMInstance< GUM_SCALAR >::getInstances(), gum::Set< Key, Alloc >::insert(), gum::List< Val, Alloc >::insert(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::DAGmodel::moralGraph(), gum::List< Val, Alloc >::popFront(), gum::prm::PRMInstance< GUM_SCALAR >::type(), and gum::prm::InstanceBayesNet< GUM_SCALAR >::variable().
|
private |
Returns true if second can be eliminated before first.
Definition at line 236 of file SVE_tpl.h.
References gum::prm::PRMInstance< GUM_SCALAR >::beginInvRef(), gum::Set< Key, Alloc >::empty(), gum::prm::PRMInstance< GUM_SCALAR >::endInvRef(), gum::prm::PRMInstance< GUM_SCALAR >::getInstances(), gum::Set< Key, Alloc >::insert(), and gum::prm::PRMInstance< GUM_SCALAR >::type().
|
private |
Returns true if second can be eliminated before first.
Definition at line 331 of file SVE_tpl.h.
References gum::prm::PRMInstance< GUM_SCALAR >::beginInvRef(), gum::prm::PRMInstance< GUM_SCALAR >::endInvRef(), gum::prm::PRMInstance< GUM_SCALAR >::getInstances(), gum::List< Val, Alloc >::insert(), and gum::prm::PRMInstance< GUM_SCALAR >::type().
|
private |
Returns true if second can be eliminated before first.
Definition at line 382 of file SVE_tpl.h.
References gum::prm::eliminateNodes(), gum::StaticTriangulation::eliminationOrder(), gum::Set< Key, Alloc >::exists(), gum::prm::PRMInstance< GUM_SCALAR >::get(), GUM_ERROR, gum::Set< Key, Alloc >::insert(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::DAGmodel::moralGraph(), gum::prm::PRMInstance< GUM_SCALAR >::type(), and gum::prm::InstanceBayesNet< GUM_SCALAR >::variable().
|
private |
Returns true if second can be eliminated before first.
Definition at line 661 of file SVE_tpl.h.
References gum::prm::PRMInstance< GUM_SCALAR >::get(), and gum::prm::PRMClassElement< GUM_SCALAR >::id().
|
private |
Returns true if second can be eliminated before first.
Definition at line 637 of file SVE_tpl.h.
References gum::prm::SVE< GUM_SCALAR >::__elim_orders.
|
private |
Returns true if second can be eliminated before first.
Definition at line 544 of file SVE_tpl.h.
References gum::Set< Key, Alloc >::contains(), gum::prm::ClassDependencyGraph< GUM_SCALAR >::dag(), gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::exists(), gum::prm::ClassDependencyGraph< GUM_SCALAR >::get(), gum::Set< Key, Alloc >::insert(), gum::SequenceImplementation< Key, Alloc, Gen >::insert(), and gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::insert().
Referenced by gum::prm::SVE< GUM_SCALAR >::__checkElimOrder().
|
private |
Returns true if second can be eliminated before first.
Definition at line 490 of file SVE_tpl.h.
References gum::prm::PRMClassElementContainer< GUM_SCALAR >::containerDag(), gum::prm::eliminateNode(), gum::StaticTriangulation::eliminationOrder(), gum::Set< Key, Alloc >::erase(), gum::Set< Key, Alloc >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), gum::Set< Key, Alloc >::insert(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::isInnerNode(), gum::prm::PRMClass< GUM_SCALAR >::isOutputNode(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::DAGmodel::moralGraph(), gum::List< Val, Alloc >::push_back(), and gum::Set< Key, Alloc >::size().
|
private |
Returns true if second can be eliminated before first.
Definition at line 629 of file SVE_tpl.h.
References gum::prm::PRMInference< GUM_SCALAR >::evidence(), and gum::Set< Key, Alloc >::insert().
|
private |
Returns true if second can be eliminated before first.
Definition at line 470 of file SVE_tpl.h.
References gum::prm::PRMInstance< GUM_SCALAR >::bijection(), gum::prm::copyPotential(), gum::Set< Key, Alloc >::insert(), and gum::prm::PRMInstance< GUM_SCALAR >::type().
|
private |
Returns true if second can be eliminated before first.
Definition at line 642 of file SVE_tpl.h.
Referenced by gum::prm::SVE< GUM_SCALAR >::__checkElimOrder().
|
private |
Returns true if second can be eliminated before first.
Definition at line 289 of file SVE_tpl.h.
References gum::prm::eliminateNodes(), gum::Set< Key, Alloc >::exists(), gum::Set< Key, Alloc >::insert(), gum::prm::PRMInstance< GUM_SCALAR >::type(), and gum::prm::InstanceBayesNet< GUM_SCALAR >::variable().
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
See PRMInference<GUM_SCALAR>::_joint().
Implements gum::prm::PRMInference< GUM_SCALAR >.
Definition at line 614 of file SVE_tpl.h.
References GUM_ERROR.
|
protectedvirtual |
See PRMInference<GUM_SCALAR>::_marginal().
Implements gum::prm::PRMInference< GUM_SCALAR >.
Definition at line 581 of file SVE_tpl.h.
References gum::prm::PRMClassElement< GUM_SCALAR >::id(), gum::Set< Key, Alloc >::insert(), gum::Potential< GUM_SCALAR >::normalize(), gum::prm::PRMAttribute< GUM_SCALAR >::type(), and gum::prm::PRMType::variable().
|
inherited |
Add an evidence to the given instance's elt.
chain | The variable being observed. |
p | The Potential 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 109 of file PRMInference_tpl.h.
Referenced by gum::prm::o3prmr::O3prmrInterpreter::observe().
|
inherited |
Remove all evidences.
Definition at line 36 of file PRMInference_tpl.h.
|
inherited |
Returns EMap of evidences over i.
NotFound | if i has no evidence. |
Definition at line 156 of file PRMInference_tpl.h.
Referenced by gum::prm::SVED< GUM_SCALAR >::__insertEvidence(), gum::prm::SVE< GUM_SCALAR >::__insertEvidence(), gum::prm::StructuredInference< GUM_SCALAR >::__reduceAloneInstances(), and gum::prm::StructuredInference< GUM_SCALAR >::_marginal().
|
inherited |
Returns EMap of evidences over i.
NotFound | if i has no evidence. |
Definition at line 177 of file PRMInference_tpl.h.
|
inherited |
Returns EMap of evidences over i.
NotFound | if i has no evidence. |
Definition at line 166 of file PRMInference_tpl.h.
|
inherited |
Returns EMap of evidences over i.
NotFound | if i has no evidence. |
Definition at line 187 of file PRMInference_tpl.h.
|
inherited |
Returns true if i has evidence.
Definition at line 197 of file PRMInference_tpl.h.
Referenced by gum::prm::o3prmr::O3prmrInterpreter::observe(), and gum::prm::o3prmr::O3prmrInterpreter::unobserve().
|
inherited |
Returns EMap of evidences over i.
Definition at line 203 of file PRMInference_tpl.h.
|
inherited |
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
Definition at line 209 of file PRMInference_tpl.h.
|
inherited |
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
Definition at line 216 of file PRMInference_tpl.h.
Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__insertNodeInElimLists(), gum::prm::StructuredInference< GUM_SCALAR >::__reduceAloneInstances(), and gum::prm::StructuredInference< GUM_SCALAR >::_marginal().
|
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 263 of file PRMInference_tpl.h.
|
inherited |
Compute the marginal 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 marginal of chain. |
NotFound | Raised if chain is invalid. |
WrongType | Raised if chain does not point to an PRMAttribute<GUM_SCALAR>. |
OperationNotAllowed | Raise if m is not empty. |
Definition at line 234 of file PRMInference_tpl.h.
Referenced by gum::prm::o3prmr::O3prmrInterpreter::query().
|
virtual |
Returns the name of the current inference algorithm.
Implements gum::prm::PRMInference< 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. |
WrongType | Raised if the elt is not an PRMAttribute<GUM_SCALAR>. |
Definition at line 221 of file PRMInference_tpl.h.
Referenced by gum::prm::o3prmr::O3prmrInterpreter::unobserve().
|
private |
Definition at line 128 of file SVE.h.
Referenced by gum::prm::SVE< GUM_SCALAR >::__checkElimOrder().
|
private |
Definition at line 132 of file SVE.h.
Referenced by gum::prm::SVE< GUM_SCALAR >::__addDelayedVariable().
|
private |
Some variable must be delayed for more than one PRMInstance<GUM_SCALAR>, when the delayed variable counter reach 0 it can be eliminated.
Definition at line 139 of file SVE.h.
Referenced by gum::prm::SVE< GUM_SCALAR >::__addDelayedVariable().
|
private |
Definition at line 124 of file SVE.h.
Referenced by gum::prm::SVE< GUM_SCALAR >::__getElimOrder().
|
private |
|
private |
|
protectedinherited |
The PRM<GUM_SCALAR> on which inference is done.
Definition at line 213 of file PRMInference.h.
Referenced by gum::prm::StructuredInference< GUM_SCALAR >::operator=(), gum::prm::PRMInference< double >::operator=(), and gum::prm::StructuredInference< GUM_SCALAR >::StructuredInference().
|
protectedinherited |
The Model on which inference is done.
Definition at line 216 of file PRMInference.h.
Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__reduceAloneInstances(), gum::prm::StructuredInference< GUM_SCALAR >::operator=(), gum::prm::PRMInference< double >::operator=(), gum::prm::StructuredInference< GUM_SCALAR >::searchPatterns(), and gum::prm::StructuredInference< GUM_SCALAR >::StructuredInference().