aGrUM  0.13.2
gum::LazyPropagation< GUM_SCALAR > Class Template Reference

<agrum/BN/inference/lazyPropagation.h> More...

#include <lazyPropagation.h>

+ Inheritance diagram for gum::LazyPropagation< GUM_SCALAR >:
+ Collaboration diagram for gum::LazyPropagation< GUM_SCALAR >:

Public Member Functions

Potential< GUM_SCALAR > evidenceJointImpact (const std::vector< NodeId > &targets, const std::vector< NodeId > &evs)
 Create a gum::Potential for P(joint targets|evs) (for all instanciation of targets and evs) More...
 
Potential< GUM_SCALAR > evidenceJointImpact (const std::vector< std::string > &targets, const std::vector< std::string > &evs)
 Create a gum::Potential for P(joint targets|evs) (for all instanciation of targets and evs) More...
 
Potential< GUM_SCALAR > evidenceImpact (NodeId target, const std::vector< NodeId > &evs)
 Create a gum::Potential for P(target|evs) (for all instanciation of target and evs) More...
 
Potential< GUM_SCALAR > evidenceImpact (const std::string &target, const std::vector< std::string > &evs)
 Create a gum::Potential for P(target|evs) (for all instanciation of target and evs) More...
 
Constructors / Destructors
 LazyPropagation (const IBayesNet< GUM_SCALAR > *BN, RelevantPotentialsFinderType=RelevantPotentialsFinderType::DSEP_BAYESBALL_POTENTIALS, FindBarrenNodesType=FindBarrenNodesType::FIND_BARREN_NODES, bool use_binary_join_tree=true)
 default constructor More...
 
 LazyPropagation (const LazyPropagation< GUM_SCALAR > &)=delete
 avoid copy constructors More...
 
LazyPropagation< GUM_SCALAR > & operator= (const LazyPropagation< GUM_SCALAR > &)=delete
 avoid copy operators More...
 
 ~LazyPropagation () final
 destructor More...
 
Accessors / Modifiers
void setTriangulation (const Triangulation &new_triangulation)
 use a new triangulation algorithm More...
 
void setRelevantPotentialsFinderType (RelevantPotentialsFinderType type)
 sets how we determine the relevant potentials to combine More...
 
void setFindBarrenNodesType (FindBarrenNodesType type)
 sets how we determine barren nodes More...
 
const JoinTreejoinTree ()
 returns the current join tree used More...
 
const JunctionTreejunctionTree ()
 returns the current junction tree More...
 
GUM_SCALAR evidenceProbability () final
 returns the probability of evidence More...
 
Probability computations
virtual const Potential< GUM_SCALAR > & jointPosterior (const NodeSet &nodes) final
 Compute the joint posterior of a set of nodes. More...
 
virtual const Potential< GUM_SCALAR > & posterior (NodeId node) final
 Computes and returns the posterior of a node. More...
 
virtual const Potential< GUM_SCALAR > & posterior (const std::string &nodeName) final
 Computes and returns the posterior of a node. More...
 
Targets
virtual void eraseAllTargets ()
 Clear all previously defined targets (marginal and joint targets) More...
 
virtual void eraseAllJointTargets () final
 Clear all previously defined joint targets. More...
 
virtual void eraseAllMarginalTargets () final
 Clear all the previously defined marginal targets. More...
 
virtual void addJointTarget (const NodeSet &joint_target) final
 Add a set of nodes as a new joint target. As a collateral effect, every node is added as a marginal target. More...
 
virtual void eraseJointTarget (const NodeSet &joint_target) final
 removes an existing joint target More...
 
virtual bool isJointTarget (const NodeSet &vars) const final
 return true if target is a joint target. More...
 
virtual const Set< NodeSet > & jointTargets () const noexceptfinal
 returns the list of joint targets More...
 
virtual Size nbrJointTargets () const noexceptfinal
 returns the number of joint targets More...
 
Information Theory related functions
GUM_SCALAR I (NodeId X, NodeId Y)
 Mutual information between X and Y. More...
 
GUM_SCALAR VI (NodeId X, NodeId Y)
 Variation of information between X and Y. More...
 
Targets
virtual void addAllTargets () final
 adds all nodes as targets More...
 
virtual void addTarget (NodeId target) final
 Add a marginal target to the list of targets. More...
 
virtual void addTarget (const std::string &nodeName) final
 Add a marginal target to the list of targets. More...
 
virtual void eraseTarget (NodeId target) final
 removes an existing (marginal) target More...
 
virtual void eraseTarget (const std::string &nodeName) final
 removes an existing (marginal) target More...
 
virtual bool isTarget (NodeId node) const final
 return true if variable is a (marginal) target More...
 
virtual bool isTarget (const std::string &nodeName) const final
 return true if variable is a (marginal) target More...
 
virtual const Size nbrTargets () const noexceptfinal
 returns the number of marginal targets More...
 
virtual const NodeSettargets () const noexceptfinal
 returns the list of marginal targets More...
 
Information Theory related functions
virtual GUM_SCALAR H (NodeId X) final
 Entropy Compute Shanon's entropy of a node given the observation. More...
 
virtual GUM_SCALAR H (const std::string &nodeName) final
 Entropy Compute Shanon's entropy of a node given the observation. More...
 
Accessors / Modifiers
virtual void setBN (const IBayesNet< GUM_SCALAR > *bn)
 assigns a new BN to the inference engine More...
 
virtual const IBayesNet< GUM_SCALAR > & BN () const final
 Returns a constant reference over the IBayesNet referenced by this class. More...
 
virtual const NodeProperty< Size > & domainSizes () const final
 get the domain sizes of the random variables of the BN More...
 
virtual bool isInferenceReady () const noexceptfinal
 returns whether the inference object is in a ready state More...
 
virtual bool isInferenceOutdatedBNStructure () const noexceptfinal
 returns whether the inference object is in a OutdatedBNStructure state More...
 
virtual bool isInferenceOutdatedBNPotentials () const noexceptfinal
 returns whether the inference object is in a OutdatedBNPotential state More...
 
virtual bool isInferenceDone () const noexceptfinal
 returns whether the inference object is in a InferenceDone state More...
 
virtual bool isDone () const noexceptfinal
 returns whether the inference object is in a done state More...
 
virtual void prepareInference () final
 prepare the internal inference structures for the next inference More...
 
virtual void makeInference () final
 perform the heavy computations needed to compute the targets' posteriors More...
 
virtual void clear ()
 clears all the data structures allocated for the last inference More...
 
virtual StateOfInference state () const noexceptfinal
 returns the state of the inference engine More...
 
Evidence
virtual void addEvidence (NodeId id, const Idx val) final
 adds a new hard evidence on node id More...
 
virtual void addEvidence (const std::string &nodeName, const Idx val) final
 adds a new hard evidence on node named nodeName More...
 
virtual void addEvidence (NodeId id, const std::string &label) final
 adds a new hard evidence on node id More...
 
virtual void addEvidence (const std::string &nodeName, const std::string &label) final
 adds a new hard evidence on node named nodeName More...
 
virtual void addEvidence (NodeId id, const std::vector< GUM_SCALAR > &vals) final
 adds a new evidence on node id (might be soft or hard) More...
 
virtual void addEvidence (const std::string &nodeName, const std::vector< GUM_SCALAR > &vals) final
 adds a new evidence on node named nodeName (might be soft or hard) More...
 
virtual void addEvidence (const Potential< GUM_SCALAR > &pot) final
 adds a new evidence on node id (might be soft or hard) More...
 
virtual void addEvidence (Potential< GUM_SCALAR > &&pot) final
 adds a new evidence on node id (might be soft or hard) More...
 
virtual void addSetOfEvidence (const Set< const Potential< GUM_SCALAR > * > &potset) final
 adds a new set of evidence More...
 
virtual void addListOfEvidence (const List< const Potential< GUM_SCALAR > * > &potlist) final
 adds a new list of evidence More...
 
virtual void chgEvidence (NodeId id, const Idx val) final
 change the value of an already existing hard evidence More...
 
virtual void chgEvidence (const std::string &nodeName, const Idx val) final
 change the value of an already existing hard evidence More...
 
virtual void chgEvidence (NodeId id, const std::string &label) final
 change the value of an already existing hard evidence More...
 
virtual void chgEvidence (const std::string &nodeName, const std::string &label) final
 change the value of an already existing hard evidence More...
 
virtual void chgEvidence (NodeId id, const std::vector< GUM_SCALAR > &vals) final
 change the value of an already existing evidence (might be soft or hard) More...
 
virtual void chgEvidence (const std::string &nodeName, const std::vector< GUM_SCALAR > &vals) final
 change the value of an already existing evidence (might be soft or hard) More...
 
virtual void chgEvidence (const Potential< GUM_SCALAR > &pot) final
 change the value of an already existing evidence (might be soft or hard) More...
 
virtual void eraseAllEvidence () final
 removes all the evidence entered into the network More...
 
virtual void eraseEvidence (NodeId id) final
 removed the evidence, if any, corresponding to node id More...
 
virtual void eraseEvidence (const std::string &nodeName) final
 removed the evidence, if any, corresponding to node of name nodeName More...
 
virtual bool hasEvidence () const final
 indicates whether some node(s) have received evidence More...
 
virtual bool hasEvidence (NodeId id) const final
 indicates whether node id has received an evidence More...
 
virtual bool hasEvidence (const std::string &nodeName) const final
 indicates whether node id has received an evidence More...
 
virtual bool hasHardEvidence (NodeId id) const final
 indicates whether node id has received a hard evidence More...
 
virtual bool hasHardEvidence (const std::string &nodeName) const final
 indicates whether node id has received a hard evidence More...
 
virtual bool hasSoftEvidence (NodeId id) const final
 indicates whether node id has received a soft evidence More...
 
virtual bool hasSoftEvidence (const std::string &nodeName) const final
 indicates whether node id has received a soft evidence More...
 
virtual Size nbrEvidence () const final
 returns the number of evidence entered into the Bayesian network More...
 
virtual Size nbrHardEvidence () const final
 returns the number of hard evidence entered into the Bayesian network More...
 
virtual Size nbrSoftEvidence () const final
 returns the number of soft evidence entered into the Bayesian network More...
 
const NodeProperty< const Potential< GUM_SCALAR > * > & evidence () const
 returns the set of evidence More...
 
const NodeSetsoftEvidenceNodes () const
 returns the set of nodes with soft evidence More...
 
const NodeSethardEvidenceNodes () const
 returns the set of nodes with hard evidence More...
 
const NodeProperty< Idx > & hardEvidence () const
 indicate for each node with hard evidence which value it took More...
 

Public Types

enum  StateOfInference { StateOfInference::OutdatedBNStructure, StateOfInference::OutdatedBNPotentials, StateOfInference::ReadyForInference, StateOfInference::Done }
 current state of the inference More...
 

Protected Member Functions

void _onEvidenceAdded (NodeId id, bool isHardEvidence) final
 fired after a new evidence is inserted More...
 
void _onEvidenceErased (NodeId id, bool isHardEvidence) final
 fired before an evidence is removed More...
 
void _onAllEvidenceErased (bool has_hard_evidence) final
 fired before all the evidence are erased More...
 
void _onEvidenceChanged (NodeId id, bool hasChangedSoftHard) final
 fired after an evidence is changed, in particular when its status (soft/hard) changes More...
 
void _onMarginalTargetAdded (NodeId id) final
 fired after a new single target is inserted More...
 
void _onMarginalTargetErased (NodeId id) final
 fired before a single target is removed More...
 
void _onJointTargetAdded (const NodeSet &set) final
 fired after a new joint target is inserted More...
 
void _onJointTargetErased (const NodeSet &set) final
 fired before a joint target is removed More...
 
void _onAllMarginalTargetsAdded () final
 fired after all the nodes of the BN are added as single targets More...
 
void _onAllMarginalTargetsErased () final
 fired before a all the single targets are removed More...
 
void _onAllJointTargetsErased () final
 fired before a all the joint targets are removed More...
 
void _onAllTargetsErased () final
 fired before a all single and joint_targets are removed More...
 
void _onStateChanged () final
 fired when the stage is changed More...
 
void _updateOutdatedBNStructure () final
 prepares inference when the latter is in OutdatedBNStructure state More...
 
void _updateOutdatedBNPotentials () final
 prepares inference when the latter is in OutdatedBNPotentials state More...
 
void _makeInference () final
 called when the inference has to be performed effectively More...
 
const Potential< GUM_SCALAR > & _posterior (NodeId id) final
 returns the posterior of a given variable More...
 
const Potential< GUM_SCALAR > & _jointPosterior (const NodeSet &set) final
 returns the posterior of a declared target set More...
 
const Potential< GUM_SCALAR > & _jointPosterior (const NodeSet &wanted_target, const NodeSet &declared_target) final
 asks derived classes for the joint posterior of a set of variables not declared as a joint target More...
 
Potential< GUM_SCALAR > * _unnormalizedJointPosterior (NodeId id) final
 returns a fresh potential equal to P(argument,evidence) More...
 
Potential< GUM_SCALAR > * _unnormalizedJointPosterior (const NodeSet &set) final
 returns a fresh potential equal to P(argument,evidence) More...
 
virtual void _onBayesNetChanged (const IBayesNet< GUM_SCALAR > *bn)
 fired after a new Bayes net has been assigned to the engine More...
 
void _setTargetedMode ()
 
bool _isTargetedMode () const
 
void _setOutdatedBNStructureState ()
 put the inference into an outdated BN structure state More...
 
void _setOutdatedBNPotentialsState ()
 puts the inference into an OutdatedBNPotentials state if it is not already in an OutdatedBNStructure state More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::LazyPropagation< GUM_SCALAR >

<agrum/BN/inference/lazyPropagation.h>

Implementation of a Shafer-Shenoy's-like version of lazy propagation for inference in Bayesian Networks

Definition at line 68 of file lazyPropagation.h.

Member Typedef Documentation

template<typename GUM_SCALAR>
typedef Set< const Potential< GUM_SCALAR >* > gum::LazyPropagation< GUM_SCALAR >::__PotentialSet
private

Definition at line 239 of file lazyPropagation.h.

template<typename GUM_SCALAR>
typedef SetIteratorSafe< const Potential< GUM_SCALAR >* > gum::LazyPropagation< GUM_SCALAR >::__PotentialSetIterator
private

Definition at line 241 of file lazyPropagation.h.

Member Enumeration Documentation

template<typename GUM_SCALAR>
enum gum::LazyPropagation::EvidenceChangeType
private

the possible types of evidence changes

Enumerator
EVIDENCE_ADDED 
EVIDENCE_ERASED 
EVIDENCE_MODIFIED 

Definition at line 370 of file lazyPropagation.h.

template<typename GUM_SCALAR >
enum gum::BayesNetInference::StateOfInference
stronginherited

current state of the inference

BayesNetInference can be in one of 4 different states:

  • OutdatedBNStructure: in this state, the inference is fully unprepared to be applied because some events changed the "logical" structure of the BN: for instance a node received a hard evidence, which implies that its outgoing arcs can be removed from the BN, hence involving a structural change in the BN. As a consequence, the (incremental) inference (probably) needs a significant amount of preparation to be ready for the next inference. In a Lazy propagation, for instance, this step amounts to compute a new join tree, hence a new structure in which inference will be applied. Note that classes that inherit from BayesNetInference may be smarter than BayesNetInference and may, in some situations, find out that their data structures are still ok for inference and, therefore, only resort to perform the actions related to the OutdatedBNPotentials state. As an example, consider a LazyPropagation inference in Bayes Net A->B->C->D->E in which C has received hard evidence e_C and E is the only target. In this case, A and B are not needed for inference, the only potentials that matter are P(D|e_C) and P(E|D). So the smallest join tree needed for inference contains only one clique DE. Now, adding new evidence e_A on A has no impact on E given hard evidence e_C. In this case, LazyPropagation can be smart and not update its join tree.
  • OutdatedBNPotentials: in this state, the structure of the BN remains unchanged, only some potentials stored in it have changed. Therefore, the inference probably just needs to invalidate some already computed potentials to be ready. Only a light amount of preparation is needed to be able to perform inference.
  • Ready4Inference: in this state, all the data structures are ready for inference. There just remains to perform the inference computations.
  • Done: the heavy computations of inference have been done. There might still remain a few light computations to perform to get the posterior potentials we need. Typically, in Lazy Propagation, all the messages in the join tree have been computed but, to get the potentials, we still need to perform the combinations of the potentials in the cliques with the messages sent to the cliques. In some inference algorithms, this step may even be empty.
Enumerator
OutdatedBNStructure 
OutdatedBNPotentials 
ReadyForInference 
Done 

Definition at line 180 of file BayesNetInference.h.

180  {
181  OutdatedBNStructure,
182  OutdatedBNPotentials,
183  ReadyForInference,
184  Done
185  };

Constructor & Destructor Documentation

template<typename GUM_SCALAR>
gum::LazyPropagation< GUM_SCALAR >::LazyPropagation ( const IBayesNet< GUM_SCALAR > *  BN,
RelevantPotentialsFinderType  = RelevantPotentialsFinderType::DSEP_BAYESBALL_POTENTIALS,
FindBarrenNodesType  = FindBarrenNodesType::FIND_BARREN_NODES,
bool  use_binary_join_tree = true 
)
explicit

default constructor

template<typename GUM_SCALAR>
gum::LazyPropagation< GUM_SCALAR >::LazyPropagation ( const LazyPropagation< GUM_SCALAR > &  )
delete

avoid copy constructors

template<typename GUM_SCALAR>
gum::LazyPropagation< GUM_SCALAR >::~LazyPropagation ( )
final

destructor

Member Function Documentation

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__collectMessage ( NodeId  id,
NodeId  from 
)
private

actually perform the collect phase

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__computeJoinTreeRoots ( )
private

compute a root for each connected component of __JT

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__createNewJT ( )
private

create a new junction tree as well as its related data structures

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__diffuseMessageInvalidations ( NodeId  from_id,
NodeId  to_id,
NodeSet invalidated_cliques 
)
private

invalidate all the messages sent from a given clique

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__findRelevantPotentialsGetAll ( __PotentialSet pot_list,
Set< const DiscreteVariable * > &  kept_vars 
)
private

update a set of potentials: the remaining are those to be combined to produce a message on a separator

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__findRelevantPotentialsWithdSeparation ( __PotentialSet pot_list,
Set< const DiscreteVariable * > &  kept_vars 
)
private

update a set of potentials: the remaining are those to be combined to produce a message on a separator

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__findRelevantPotentialsWithdSeparation2 ( __PotentialSet pot_list,
Set< const DiscreteVariable * > &  kept_vars 
)
private

update a set of potentials: the remaining are those to be combined to produce a message on a separator

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__findRelevantPotentialsWithdSeparation3 ( __PotentialSet pot_list,
Set< const DiscreteVariable * > &  kept_vars 
)
private

update a set of potentials: the remaining are those to be combined to produce a message on a separator

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__findRelevantPotentialsXX ( __PotentialSet pot_list,
Set< const DiscreteVariable * > &  kept_vars 
)
private

update a set of potentials: the remaining are those to be combined to produce a message on a separator

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__invalidateAllMessages ( )
private

invalidate all messages, posteriors and created potentials

template<typename GUM_SCALAR>
bool gum::LazyPropagation< GUM_SCALAR >::__isNewJTNeeded ( ) const
private

check whether a new join tree is really needed for the next inference

template<typename GUM_SCALAR>
__PotentialSet gum::LazyPropagation< GUM_SCALAR >::__marginalizeOut ( __PotentialSet  pot_list,
Set< const DiscreteVariable * > &  del_vars,
Set< const DiscreteVariable * > &  kept_vars 
)
private

removes variables del_vars from a list of potentials and returns the resulting list

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__produceMessage ( NodeId  from_id,
NodeId  to_id 
)
private

creates the message sent by clique from_id to clique to_id

template<typename GUM_SCALAR>
__PotentialSet gum::LazyPropagation< GUM_SCALAR >::__removeBarrenVariables ( __PotentialSet pot_list,
Set< const DiscreteVariable * > &  del_vars 
)
private
template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__setCombinationFunction ( Potential< GUM_SCALAR > *(*)(const Potential< GUM_SCALAR > &, const Potential< GUM_SCALAR > &)  comb)
private

sets the operator for performing the combinations

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::__setProjectionFunction ( Potential< GUM_SCALAR > *(*)(const Potential< GUM_SCALAR > &, const Set< const DiscreteVariable * > &)  proj)
private

sets the operator for performing the projections

template<typename GUM_SCALAR >
INLINE bool gum::MarginalTargetedInference< GUM_SCALAR >::_isTargetedMode ( ) const
protectedinherited

Definition at line 339 of file marginalTargetedInference_tpl.h.

References gum::MarginalTargetedInference< GUM_SCALAR >::__targeted_mode.

339  {
340  return __targeted_mode;
341  }
bool __targeted_mode
whether the actual targets are default
template<typename GUM_SCALAR>
const Potential< GUM_SCALAR >& gum::LazyPropagation< GUM_SCALAR >::_jointPosterior ( const NodeSet set)
finalprotectedvirtual

returns the posterior of a declared target set

Parameters
setThe set of ids of the variables whose joint posterior is looked for.

Implements gum::JointTargetedInference< GUM_SCALAR >.

Referenced by gum::LazyPropagation< GUM_SCALAR >::_onStateChanged().

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
const Potential< GUM_SCALAR >& gum::LazyPropagation< GUM_SCALAR >::_jointPosterior ( const NodeSet wanted_target,
const NodeSet declared_target 
)
finalprotectedvirtual

asks derived classes for the joint posterior of a set of variables not declared as a joint target

Parameters
wanted_targetThe set of ids of the variables whose joint posterior is looked for.
declared_targetthe joint target declared by the user that contains set

Implements gum::JointTargetedInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_makeInference ( )
finalprotectedvirtual

called when the inference has to be performed effectively

Once the inference is done, _fillPosterior can be called.

Implements gum::BayesNetInference< GUM_SCALAR >.

Referenced by gum::LazyPropagation< GUM_SCALAR >::_onStateChanged().

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onAllEvidenceErased ( bool  has_hard_evidence)
finalprotectedvirtual

fired before all the evidence are erased

Implements gum::BayesNetInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onAllJointTargetsErased ( )
finalprotectedvirtual

fired before a all the joint targets are removed

Implements gum::JointTargetedInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onAllMarginalTargetsAdded ( )
finalprotectedvirtual

fired after all the nodes of the BN are added as single targets

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onAllMarginalTargetsErased ( )
finalprotectedvirtual

fired before a all the single targets are removed

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onAllTargetsErased ( )
finalprotectedvirtual

fired before a all single and joint_targets are removed

Implements gum::JointTargetedInference< GUM_SCALAR >.

template<typename GUM_SCALAR >
void gum::JointTargetedInference< GUM_SCALAR >::_onBayesNetChanged ( const IBayesNet< GUM_SCALAR > *  bn)
protectedvirtualinherited

fired after a new Bayes net has been assigned to the engine

Reimplemented from gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 52 of file jointTargetedInference_tpl.h.

References gum::JointTargetedInference< GUM_SCALAR >::__joint_targets, gum::JointTargetedInference< GUM_SCALAR >::_onAllJointTargetsErased(), and gum::MarginalTargetedInference< GUM_SCALAR >::_onBayesNetChanged().

53  {
56  __joint_targets.clear();
57  }
virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR > *bn)
fired after a new Bayes net has been assigned to the engine
virtual void _onAllJointTargetsErased()=0
fired before a all the joint targets are removed
Set< NodeSet > __joint_targets
the set of joint targets

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onEvidenceAdded ( NodeId  id,
bool  isHardEvidence 
)
finalprotectedvirtual

fired after a new evidence is inserted

Implements gum::BayesNetInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onEvidenceChanged ( NodeId  id,
bool  hasChangedSoftHard 
)
finalprotectedvirtual

fired after an evidence is changed, in particular when its status (soft/hard) changes

Parameters
nodeIdthe node of the changed evidence
hasChangedSoftHardtrue if the evidence has changed from Soft to Hard or from Hard to Soft

Implements gum::BayesNetInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onEvidenceErased ( NodeId  id,
bool  isHardEvidence 
)
finalprotectedvirtual

fired before an evidence is removed

Implements gum::BayesNetInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onJointTargetAdded ( const NodeSet set)
finalprotectedvirtual

fired after a new joint target is inserted

Parameters
setThe set of target variable's ids.

Implements gum::JointTargetedInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onJointTargetErased ( const NodeSet set)
finalprotectedvirtual

fired before a joint target is removed

Parameters
setThe set of target variable's ids.

Implements gum::JointTargetedInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onMarginalTargetAdded ( NodeId  id)
finalprotectedvirtual

fired after a new single target is inserted

Parameters
idThe target variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onMarginalTargetErased ( NodeId  id)
finalprotectedvirtual

fired before a single target is removed

Parameters
idThe target variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_onStateChanged ( )
inlinefinalprotectedvirtual
template<typename GUM_SCALAR>
const Potential< GUM_SCALAR >& gum::LazyPropagation< GUM_SCALAR >::_posterior ( NodeId  id)
finalprotectedvirtual

returns the posterior of a given variable

Parameters
idThe variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

Referenced by gum::LazyPropagation< GUM_SCALAR >::_onStateChanged().

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::_setOutdatedBNPotentialsState ( )
protectedinherited

puts the inference into an OutdatedBNPotentials state if it is not already in an OutdatedBNStructure state

OutdatedBNPotentials: in this state, the structure of the BN remains unchanged, only some potentials stored in it have changed. Therefore, the inference probably just needs to invalidate some already computed potentials to be ready. Only a light amount of preparation is needed to be able to perform inference.

Definition at line 682 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__setState(), and gum::BayesNetInference< GUM_SCALAR >::OutdatedBNPotentials.

682  {
684  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::_setOutdatedBNStructureState ( )
protectedinherited

put the inference into an outdated BN structure state

OutdatedBNStructure: in this state, the inference is fully unprepared to be applied because some events changed the "logical" structure of the BN: for instance a node received a hard evidence, which implies that its outgoing arcs can be removed from the BN, hence involving a structural change in the BN. As a consequence, the (incremental) inference (probably) needs a significant amount of preparation to be ready for the next inference. In a Lazy propagation, for instance, this step amounts to compute a new join tree, hence a new structure in which inference will be applied. Note that classes that inherit from BayesNetInference may be smarter than BayesNetInference and may, in some situations, find out that their data structures are still ok for inference and, therefore, only resort to perform the actions related to the OutdatedBNPotentials state. As an example, consider a LazyPropagation inference in Bayes Net A->B->C->D->E in which C has received hard evidence e_C and E is the only target. In this case, A and B are not needed for inference, the only potentials that matter are P(D|e_C) and P(E|D). So the smallest join tree needed for inference contains only one clique DE. Now, adding new evidence e_A on A has no impact on E given hard evidence e_C. In this case, LazyPropagation can be smart and not update its join tree.

Definition at line 674 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__setState(), and gum::BayesNetInference< GUM_SCALAR >::OutdatedBNStructure.

674  {
676  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::MarginalTargetedInference< GUM_SCALAR >::_setTargetedMode ( )
protectedinherited

Definition at line 343 of file marginalTargetedInference_tpl.h.

References gum::MarginalTargetedInference< GUM_SCALAR >::__targeted_mode, gum::MarginalTargetedInference< GUM_SCALAR >::__targets, and gum::Set< Key, Alloc >::clear().

Referenced by gum::MarginalTargetedInference< GUM_SCALAR >::addAllTargets(), gum::JointTargetedInference< GUM_SCALAR >::addJointTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), and gum::MarginalTargetedInference< GUM_SCALAR >::eraseAllTargets().

343  {
344  if (!__targeted_mode) {
345  __targets.clear();
346  __targeted_mode = true;
347  }
348  }
NodeSet __targets
the set of marginal targets
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:375
bool __targeted_mode
whether the actual targets are default

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
Potential< GUM_SCALAR >* gum::LazyPropagation< GUM_SCALAR >::_unnormalizedJointPosterior ( NodeId  id)
finalprotectedvirtual

returns a fresh potential equal to P(argument,evidence)

Implements gum::JointTargetedInference< GUM_SCALAR >.

Referenced by gum::LazyPropagation< GUM_SCALAR >::_onStateChanged().

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
Potential< GUM_SCALAR >* gum::LazyPropagation< GUM_SCALAR >::_unnormalizedJointPosterior ( const NodeSet set)
finalprotectedvirtual

returns a fresh potential equal to P(argument,evidence)

Implements gum::JointTargetedInference< GUM_SCALAR >.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_updateOutdatedBNPotentials ( )
finalprotectedvirtual

prepares inference when the latter is in OutdatedBNPotentials state

Note that the values of evidence are not necessarily known and can be changed between _updateOutdatedBNPotentials and _makeInference.

Implements gum::BayesNetInference< GUM_SCALAR >.

Referenced by gum::LazyPropagation< GUM_SCALAR >::_onStateChanged().

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::_updateOutdatedBNStructure ( )
finalprotectedvirtual

prepares inference when the latter is in OutdatedBNStructure state

Note that the values of evidence are not necessarily known and can be changed between _updateOutdatedBNStructure and _makeInference.

Implements gum::BayesNetInference< GUM_SCALAR >.

Referenced by gum::LazyPropagation< GUM_SCALAR >::_onStateChanged().

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
void gum::MarginalTargetedInference< GUM_SCALAR >::addAllTargets ( )
finalvirtualinherited

adds all nodes as targets

Definition at line 133 of file marginalTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::MarginalTargetedInference< GUM_SCALAR >::__targets, gum::MarginalTargetedInference< GUM_SCALAR >::_onMarginalTargetAdded(), gum::MarginalTargetedInference< GUM_SCALAR >::_setTargetedMode(), gum::Set< Key, Alloc >::contains(), GUM_ERROR, and gum::Set< Key, Alloc >::insert().

133  {
134  // check if the node belongs to the Bayesian network
135  if (this->__bn == nullptr)
136  GUM_ERROR(NullElement,
137  "No Bayes net has been assigned to the "
138  "inference algorithm");
139 
140 
141  _setTargetedMode(); // does nothing if already in targeted mode
142  for (const auto target : this->__bn->dag()) {
143  if (!__targets.contains(target)) {
144  __targets.insert(target);
145  _onMarginalTargetAdded(target);
146  this->__setState(
148  }
149  }
150  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
NodeSet __targets
the set of marginal targets
virtual void _onMarginalTargetAdded(NodeId id)=0
fired after a new marginal target is inserted
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:581
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::addEvidence ( NodeId  id,
const Idx  val 
)
finalvirtualinherited

adds a new hard evidence on node id

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif id already has an evidence

Definition at line 244 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__createHardEvidence().

Referenced by gum::LoopySamplingInference< GUM_SCALAR, APPROX >::_makeInference(), gum::BayesNetInference< GUM_SCALAR >::addEvidence(), gum::BayesNetInference< GUM_SCALAR >::addListOfEvidence(), gum::BayesNetInference< GUM_SCALAR >::addSetOfEvidence(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), and gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact().

245  {
247  }
Potential< GUM_SCALAR > __createHardEvidence(NodeId id, Idx val) const
create the internal structure for a hard evidence
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::addEvidence ( const std::string &  nodeName,
const Idx  val 
)
finalvirtualinherited

adds a new hard evidence on node named nodeName

Exceptions
UndefinedElementif nodeName does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif nodeName already has an evidence

Definition at line 252 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::addEvidence(), and gum::BayesNetInference< GUM_SCALAR >::BN().

253  {
254  addEvidence(this->BN().idFromName(nodeName), val);
255  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::addEvidence ( NodeId  id,
const std::string &  label 
)
finalvirtualinherited

adds a new hard evidence on node id

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif id already has an evidence

Definition at line 260 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::addEvidence(), and gum::BayesNetInference< GUM_SCALAR >::BN().

261  {
262  addEvidence(id, this->BN().variable(id)[label]);
263  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::addEvidence ( const std::string &  nodeName,
const std::string &  label 
)
finalvirtualinherited

adds a new hard evidence on node named nodeName

Exceptions
UndefinedElementif nodeName does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif nodeName already has an evidence

Definition at line 268 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::addEvidence(), and gum::BayesNetInference< GUM_SCALAR >::BN().

269  {
270  NodeId id = this->BN().idFromName(nodeName);
271  addEvidence(id, this->BN().variable(id)[label]);
272  }
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
void gum::BayesNetInference< GUM_SCALAR >::addEvidence ( NodeId  id,
const std::vector< GUM_SCALAR > &  vals 
)
finalvirtualinherited

adds a new evidence on node id (might be soft or hard)

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif id already has an evidence
FatalErrorif vals=[0,0,...,0]
InvalidArgumentif the size of vals is different from the domain size of node id

Definition at line 276 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::MultiDimDecorator< GUM_SCALAR >::add(), gum::BayesNetInference< GUM_SCALAR >::addEvidence(), and GUM_ERROR.

277  {
278  // checks that the evidence is meaningful
279  if (__bn == nullptr)
280  GUM_ERROR(NullElement,
281  "No Bayes net has been assigned to the "
282  "inference algorithm");
283 
284  if (!__bn->dag().exists(id)) {
285  GUM_ERROR(UndefinedElement, id << " is not a NodeId in the bn");
286  }
287 
288  if (__bn->variable(id).domainSize() != vals.size()) {
289  GUM_ERROR(InvalidArgument,
290  "node " << __bn->variable(id)
291  << " and its evidence vector have different sizes.");
292  }
293 
294  Potential< GUM_SCALAR > pot;
295  pot.add(__bn->variable(id));
296  pot.fillWith(vals);
297  addEvidence(std::move(pot));
298  }
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
void gum::BayesNetInference< GUM_SCALAR >::addEvidence ( const std::string &  nodeName,
const std::vector< GUM_SCALAR > &  vals 
)
finalvirtualinherited

adds a new evidence on node named nodeName (might be soft or hard)

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif nodeName already has an evidence
FatalErrorif vals=[0,0,...,0]
InvalidArgumentif the size of vals is different from the domain size of node nodeName

Definition at line 302 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::addEvidence(), and gum::BayesNetInference< GUM_SCALAR >::BN().

303  {
304  addEvidence(this->BN().idFromName(nodeName), vals);
305  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::addEvidence ( const Potential< GUM_SCALAR > &  pot)
finalvirtualinherited

adds a new evidence on node id (might be soft or hard)

Exceptions
UndefinedElementif the potential is defined over several nodes
UndefinedElementif the node on which the potential is defined does not belong to the Bayesian network
InvalidArgumentif the node of the potential already has an evidence
FatalErrorif pot=[0,0,...,0]

Definition at line 351 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::addEvidence().

352  {
353  Potential< GUM_SCALAR > new_pot(pot);
354  addEvidence(std::move(new_pot));
355  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
void gum::BayesNetInference< GUM_SCALAR >::addEvidence ( Potential< GUM_SCALAR > &&  pot)
finalvirtualinherited

adds a new evidence on node id (might be soft or hard)

Exceptions
UndefinedElementif the potential is defined over several nodes
UndefinedElementif the node on which the potential is defined does not belong to the Bayesian network
InvalidArgumentif the node of the potential already has an evidence
FatalErrorif pot=[0,0,...,0]

Definition at line 310 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::BayesNetInference< GUM_SCALAR >::__evidence, gum::BayesNetInference< GUM_SCALAR >::__hard_evidence, gum::BayesNetInference< GUM_SCALAR >::__hard_evidence_nodes, gum::BayesNetInference< GUM_SCALAR >::__isHardEvidence(), gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::BayesNetInference< GUM_SCALAR >::__soft_evidence_nodes, gum::BayesNetInference< GUM_SCALAR >::_onEvidenceAdded(), GUM_ERROR, gum::BayesNetInference< GUM_SCALAR >::hasEvidence(), gum::Set< Key, Alloc >::insert(), and gum::BayesNetInference< GUM_SCALAR >::OutdatedBNStructure.

310  {
311  // check if the potential corresponds to an evidence
312  if (pot.nbrDim() != 1) {
313  GUM_ERROR(InvalidArgument, pot << " is not mono-dimensional.");
314  }
315  if (__bn == nullptr)
316  GUM_ERROR(NullElement,
317  "No Bayes net has been assigned to the "
318  "inference algorithm");
319 
320  NodeId id = __bn->nodeId(pot.variable(0));
321 
322  if (hasEvidence(id)) {
323  GUM_ERROR(InvalidArgument,
324  " node " << id
325  << " already has an evidence. Please use chgEvidence().");
326  }
327 
328  // check whether we have a hard evidence (and also check whether the
329  // potential only contains 0 (in this case, this will automatically raise
330  // an exception) )
331  Idx val;
332  bool is_hard_evidence = __isHardEvidence(pot, val);
333 
334  // insert the evidence
335  __evidence.insert(
336  id,
337  new Potential< GUM_SCALAR >(std::forward< Potential< GUM_SCALAR > >(pot)));
338  if (is_hard_evidence) { // pot is deterministic
339  __hard_evidence.insert(id, val);
341  } else {
343  }
345  _onEvidenceAdded(id, is_hard_evidence);
346  }
NodeProperty< const Potential< GUM_SCALAR > * > __evidence
the set of evidence entered into the network
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
NodeProperty< Idx > __hard_evidence
assign to each node with a hard evidence the index of its observed value
virtual void _onEvidenceAdded(NodeId id, bool isHardEvidence)=0
fired after a new evidence is inserted
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
bool __isHardEvidence(const Potential< GUM_SCALAR > &pot, Idx &val) const
checks whether a potential corresponds to a hard evidence or not
NodeSet __soft_evidence_nodes
the set of nodes that received soft evidence
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
NodeSet __hard_evidence_nodes
the set of nodes that received hard evidence
unsigned long Idx
Type for indexes.
Definition: types.h:43
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
void gum::JointTargetedInference< GUM_SCALAR >::addJointTarget ( const NodeSet joint_target)
finalvirtualinherited

Add a set of nodes as a new joint target. As a collateral effect, every node is added as a marginal target.

Exceptions
UndefinedElementif some node(s) do not belong to the Bayes net

Definition at line 114 of file jointTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::JointTargetedInference< GUM_SCALAR >::__joint_targets, gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::JointTargetedInference< GUM_SCALAR >::_onJointTargetAdded(), gum::MarginalTargetedInference< GUM_SCALAR >::_setTargetedMode(), gum::JointTargetedInference< GUM_SCALAR >::eraseJointTarget(), and GUM_ERROR.

Referenced by gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact().

115  {
116  // check if the nodes in the target belong to the Bayesian network
117  if (this->__bn == nullptr)
118  GUM_ERROR(NullElement,
119  "No Bayes net has been assigned to the "
120  "inference algorithm");
121 
122  const auto& dag = this->__bn->dag();
123  for (const auto node : joint_target) {
124  if (!dag.exists(node)) {
125  GUM_ERROR(UndefinedElement,
126  "at least one one in " << joint_target
127  << " does not belong to the bn");
128  }
129  }
130 
131  // check that the joint_target set does not contain the new target
132  if (__joint_targets.contains(joint_target)) return;
133 
134  // check if joint_target is a subset of an already existing target
135  for (const auto& target : __joint_targets) {
136  if (target.isSupersetOf(joint_target)) return;
137  }
138 
139  // check if joint_target is not a superset of an already existing target
140  // in this case, we need to remove old existing target
141  for (auto iter = __joint_targets.beginSafe();
142  iter != __joint_targets.endSafe();
143  ++iter) {
144  if (iter->isSubsetOf(joint_target)) eraseJointTarget(*iter);
145  }
146 
147  this->_setTargetedMode(); // does nothing if already in targeted mode
148  __joint_targets.insert(joint_target);
149  _onJointTargetAdded(joint_target);
150  this->__setState(
152  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual void _onJointTargetAdded(const NodeSet &set)=0
fired after a new joint target is inserted
virtual void eraseJointTarget(const NodeSet &joint_target) final
removes an existing joint target
Set< NodeSet > __joint_targets
the set of joint targets
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::addListOfEvidence ( const List< const Potential< GUM_SCALAR > * > &  potlist)
finalvirtualinherited

adds a new list of evidence

Exceptions
UndefinedElementif some potential is defined over several nodes
UndefinedElementif the node on which some potential is defined does not belong to the Bayesian network
InvalidArgumentif the node of some potential already has an evidence
FatalErrorif pot=[0,0,...,0]

Definition at line 360 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::addEvidence().

361  {
362  for (const auto pot : potlist)
363  addEvidence(*pot);
364  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::addSetOfEvidence ( const Set< const Potential< GUM_SCALAR > * > &  potset)
finalvirtualinherited

adds a new set of evidence

Exceptions
UndefinedElementif some potential is defined over several nodes
UndefinedElementif the node on which some potential is defined does not belong to the Bayesian network
InvalidArgumentif the node of some potential already has an evidence
FatalErrorif pot=[0,0,...,0]

Definition at line 369 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::addEvidence().

370  {
371  for (const auto pot : potset)
372  addEvidence(*pot);
373  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
void gum::MarginalTargetedInference< GUM_SCALAR >::addTarget ( NodeId  target)
finalvirtualinherited

Add a marginal target to the list of targets.

Exceptions
UndefinedElementif target is not a NodeId in the Bayes net

Definition at line 109 of file marginalTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::MarginalTargetedInference< GUM_SCALAR >::__targets, gum::MarginalTargetedInference< GUM_SCALAR >::_onMarginalTargetAdded(), gum::MarginalTargetedInference< GUM_SCALAR >::_setTargetedMode(), gum::Set< Key, Alloc >::contains(), GUM_ERROR, and gum::Set< Key, Alloc >::insert().

Referenced by gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), and gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact().

109  {
110  // check if the node belongs to the Bayesian network
111  if (this->__bn == nullptr)
112  GUM_ERROR(NullElement,
113  "No Bayes net has been assigned to the "
114  "inference algorithm");
115 
116  if (!this->__bn->dag().exists(target)) {
117  GUM_ERROR(UndefinedElement, target << " is not a NodeId in the bn");
118  }
119 
120  _setTargetedMode(); // does nothing if already in targeted mode
121  // add the new target
122  if (!__targets.contains(target)) {
123  __targets.insert(target);
124  _onMarginalTargetAdded(target);
125  this->__setState(
127  }
128  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
NodeSet __targets
the set of marginal targets
virtual void _onMarginalTargetAdded(NodeId id)=0
fired after a new marginal target is inserted
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:581
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
void gum::MarginalTargetedInference< GUM_SCALAR >::addTarget ( const std::string &  nodeName)
finalvirtualinherited

Add a marginal target to the list of targets.

Exceptions
UndefinedElementif target is not a NodeId in the Bayes net

Definition at line 155 of file marginalTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), and GUM_ERROR.

156  {
157  // check if the node belongs to the Bayesian network
158  if (this->__bn == nullptr)
159  GUM_ERROR(NullElement,
160  "No Bayes net has been assigned to the "
161  "inference algorithm");
162 
163  addTarget(this->__bn->idFromName(nodeName));
164  }
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE const IBayesNet< GUM_SCALAR > & gum::BayesNetInference< GUM_SCALAR >::BN ( ) const
finalvirtualinherited

Returns a constant reference over the IBayesNet referenced by this class.

Exceptions
UndefinedElementis raised if no Bayes net has been assigned to the inference.

Definition at line 118 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, and GUM_ERROR.

Referenced by gum::WeightedSampling< GUM_SCALAR >::_draw(), gum::MonteCarloSampling< GUM_SCALAR >::_draw(), gum::ImportanceSampling< GUM_SCALAR >::_draw(), gum::SamplingInference< GUM_SCALAR >::_posterior(), gum::BayesNetInference< GUM_SCALAR >::addEvidence(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::SamplingInference< GUM_SCALAR >::contextualize(), gum::SamplingInference< GUM_SCALAR >::currentPosterior(), gum::BayesNetInference< GUM_SCALAR >::eraseEvidence(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::MarginalTargetedInference< GUM_SCALAR >::H(), gum::BayesNetInference< GUM_SCALAR >::hasEvidence(), gum::BayesNetInference< GUM_SCALAR >::hasHardEvidence(), gum::BayesNetInference< GUM_SCALAR >::hasSoftEvidence(), gum::JointTargetedInference< GUM_SCALAR >::I(), gum::MarginalTargetedInference< GUM_SCALAR >::posterior(), gum::JointTargetedInference< GUM_SCALAR >::posterior(), gum::SamplingInference< GUM_SCALAR >::samplingBN(), and gum::Estimator< GUM_SCALAR >::setFromLBP().

118  {
119  if (__bn == nullptr)
120  GUM_ERROR(UndefinedElement,
121  "No Bayes net has been assigned to "
122  "the inference algorithm.");
123  return *__bn;
124  }
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::chgEvidence ( NodeId  id,
const Idx  val 
)
finalvirtualinherited

change the value of an already existing hard evidence

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif id does not already have an evidence

Definition at line 429 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__createHardEvidence().

Referenced by gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), and gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact().

430  {
432  }
Potential< GUM_SCALAR > __createHardEvidence(NodeId id, Idx val) const
create the internal structure for a hard evidence
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::chgEvidence ( const std::string &  nodeName,
const Idx  val 
)
finalvirtualinherited

change the value of an already existing hard evidence

Exceptions
UndefinedElementif nodeName does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif id does not already have an evidence

Definition at line 437 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::BayesNetInference< GUM_SCALAR >::chgEvidence().

438  {
439  chgEvidence(this->BN().idFromName(nodeName), val);
440  }
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::chgEvidence ( NodeId  id,
const std::string &  label 
)
finalvirtualinherited

change the value of an already existing hard evidence

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif id does not already have an evidence

Definition at line 445 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::BayesNetInference< GUM_SCALAR >::chgEvidence().

446  {
447  chgEvidence(id, this->BN().variable(id)[label]);
448  }
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::chgEvidence ( const std::string &  nodeName,
const std::string &  label 
)
finalvirtualinherited

change the value of an already existing hard evidence

Exceptions
UndefinedElementif nodeName does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif id does not already have an evidence

Definition at line 453 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::BayesNetInference< GUM_SCALAR >::chgEvidence().

454  {
455  NodeId id = this->BN().idFromName(nodeName);
456  chgEvidence(id, this->BN().variable(id)[label]);
457  }
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::chgEvidence ( NodeId  id,
const std::vector< GUM_SCALAR > &  vals 
)
finalvirtualinherited

change the value of an already existing evidence (might be soft or hard)

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif the node does not already have an evidence
FatalErrorif vals=[0,0,...,0]
InvalidArgumentif the size of vals is different from the domain size of node id

Definition at line 461 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::MultiDimDecorator< GUM_SCALAR >::add(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), and GUM_ERROR.

462  {
463  // check whether this corresponds to an evidence
464  if (__bn == nullptr)
465  GUM_ERROR(NullElement,
466  "No Bayes net has been assigned to the "
467  "inference algorithm");
468 
469  if (!__bn->dag().exists(id)) {
470  GUM_ERROR(UndefinedElement, id << " is not a NodeId in the bn");
471  }
472 
473  if (__bn->variable(id).domainSize() != vals.size()) {
474  GUM_ERROR(InvalidArgument,
475  "node " << __bn->variable(id)
476  << " and its evidence have different sizes.");
477  }
478 
479  // create the potential corresponding to vals
480  Potential< GUM_SCALAR > pot;
481  pot.add(__bn->variable(id));
482  pot.fillWith(vals);
483  chgEvidence(pot);
484  }
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::chgEvidence ( const std::string &  nodeName,
const std::vector< GUM_SCALAR > &  vals 
)
finalvirtualinherited

change the value of an already existing evidence (might be soft or hard)

Exceptions
UndefinedElementif nodeName does not belong to the Bayesian network
InvalidArgumentif the node does not already have an evidence
FatalErrorif vals=[0,0,...,0]
InvalidArgumentif the size of vals is different from the domain size of node id

Definition at line 488 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::BayesNetInference< GUM_SCALAR >::chgEvidence().

489  {
490  chgEvidence(this->BN().idFromName(nodeName), vals);
491  }
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
void gum::BayesNetInference< GUM_SCALAR >::chgEvidence ( const Potential< GUM_SCALAR > &  pot)
finalvirtualinherited

change the value of an already existing evidence (might be soft or hard)

Exceptions
UndefinedElementif the potential is defined over several nodes
UndefinedElementif the node on which the potential is defined does not belong to the Bayesian network
InvalidArgumentif the node of the potential does not already have an evidence
FatalErrorif pot=[0,0,...,0]

Definition at line 496 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::BayesNetInference< GUM_SCALAR >::__evidence, gum::BayesNetInference< GUM_SCALAR >::__hard_evidence, gum::BayesNetInference< GUM_SCALAR >::__hard_evidence_nodes, gum::BayesNetInference< GUM_SCALAR >::__isHardEvidence(), gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::BayesNetInference< GUM_SCALAR >::__soft_evidence_nodes, gum::BayesNetInference< GUM_SCALAR >::_onEvidenceChanged(), gum::Instantiation::end(), gum::Set< Key, Alloc >::erase(), GUM_ERROR, gum::BayesNetInference< GUM_SCALAR >::hasEvidence(), gum::BayesNetInference< GUM_SCALAR >::hasHardEvidence(), gum::Instantiation::inc(), gum::Set< Key, Alloc >::insert(), gum::BayesNetInference< GUM_SCALAR >::isInferenceOutdatedBNStructure(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), gum::BayesNetInference< GUM_SCALAR >::OutdatedBNPotentials, gum::BayesNetInference< GUM_SCALAR >::OutdatedBNStructure, gum::MultiDimDecorator< GUM_SCALAR >::set(), gum::Instantiation::setFirst(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().

497  {
498  // check if the potential corresponds to an evidence
499  if (pot.nbrDim() != 1) {
500  GUM_ERROR(InvalidArgument, pot << " is not a mono-dimensional potential.");
501  }
502  if (__bn == nullptr)
503  GUM_ERROR(NullElement,
504  "No Bayes net has been assigned to the "
505  "inference algorithm");
506 
507  NodeId id = __bn->nodeId(pot.variable(0));
508 
509  if (!hasEvidence(id)) {
510  GUM_ERROR(InvalidArgument,
511  id << " has no evidence. Please use addEvidence().");
512  }
513 
514  // check whether we have a hard evidence (and also check whether the
515  // potential only contains 0 (in this case, this will automatically raise
516  // an exception) )
517  Idx val;
518  bool is_hard_evidence = __isHardEvidence(pot, val);
519 
520  // modify the evidence already stored
521  const Potential< GUM_SCALAR >* localPot = __evidence[id];
522  Instantiation I(pot);
523  for (I.setFirst(); !I.end(); I.inc()) {
524  localPot->set(I, pot[I]);
525  }
526 
527  // the inference state will be different
528  // whether evidence change from Hard to Soft or not.
529  bool hasChangedSoftHard = false;
530 
531  if (is_hard_evidence) {
532  if (!hasHardEvidence(id)) {
533  hasChangedSoftHard = true;
534  __hard_evidence.insert(id, val);
537  } else {
538  __hard_evidence[id] = val;
539  }
540  } else {
541  if (hasHardEvidence(id)) { // evidence was hard
542  __hard_evidence.erase(id);
545  hasChangedSoftHard = true;
546  }
547  }
548 
549  if (hasChangedSoftHard) {
551  } else {
554  }
555  }
556 
557  _onEvidenceChanged(id, hasChangedSoftHard);
558  }
NodeProperty< const Potential< GUM_SCALAR > * > __evidence
the set of evidence entered into the network
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
NodeProperty< Idx > __hard_evidence
assign to each node with a hard evidence the index of its observed value
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual void _onEvidenceChanged(NodeId id, bool hasChangedSoftHard)=0
fired after an evidence is changed, in particular when its status (soft/hard) changes ...
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:656
bool __isHardEvidence(const Potential< GUM_SCALAR > &pot, Idx &val) const
checks whether a potential corresponds to a hard evidence or not
NodeSet __soft_evidence_nodes
the set of nodes that received soft evidence
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
NodeSet __hard_evidence_nodes
the set of nodes that received hard evidence
virtual bool isInferenceOutdatedBNStructure() const noexceptfinal
returns whether the inference object is in a OutdatedBNStructure state
unsigned long Idx
Type for indexes.
Definition: types.h:43
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::clear ( )
virtualinherited

clears all the data structures allocated for the last inference

Definition at line 150 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::BayesNetInference< GUM_SCALAR >::eraseAllEvidence(), and gum::BayesNetInference< GUM_SCALAR >::OutdatedBNStructure.

Referenced by gum::BayesNetInference< GUM_SCALAR >::setBN().

150  {
153  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
virtual void eraseAllEvidence() final
removes all the evidence entered into the network

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE const NodeProperty< Size > & gum::BayesNetInference< GUM_SCALAR >::domainSizes ( ) const
finalvirtualinherited

get the domain sizes of the random variables of the BN

Definition at line 171 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__domain_sizes.

171  {
172  return __domain_sizes;
173  }
NodeProperty< Size > __domain_sizes
the domain sizes of the random variables
template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::eraseAllEvidence ( )
finalvirtualinherited

removes all the evidence entered into the network

Definition at line 592 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__evidence, gum::BayesNetInference< GUM_SCALAR >::__hard_evidence, gum::BayesNetInference< GUM_SCALAR >::__hard_evidence_nodes, gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::BayesNetInference< GUM_SCALAR >::__soft_evidence_nodes, gum::BayesNetInference< GUM_SCALAR >::_onAllEvidenceErased(), gum::Set< Key, Alloc >::clear(), gum::BayesNetInference< GUM_SCALAR >::isInferenceOutdatedBNStructure(), gum::BayesNetInference< GUM_SCALAR >::OutdatedBNPotentials, and gum::BayesNetInference< GUM_SCALAR >::OutdatedBNStructure.

Referenced by gum::BayesNetInference< GUM_SCALAR >::clear(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), and gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact().

592  {
593  bool has_hard_evidence = !__hard_evidence.empty();
594  this->_onAllEvidenceErased(has_hard_evidence);
595 
596  for (const auto& pair : __evidence) {
597  if (pair.second != nullptr) { delete (pair.second); }
598  }
599 
600  __evidence.clear();
601  __hard_evidence.clear();
604 
605  if (has_hard_evidence) {
607  } else {
610  }
611  }
612  }
NodeProperty< const Potential< GUM_SCALAR > * > __evidence
the set of evidence entered into the network
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
NodeProperty< Idx > __hard_evidence
assign to each node with a hard evidence the index of its observed value
virtual void _onAllEvidenceErased(bool contains_hard_evidence)=0
fired before all the evidence are erased
NodeSet __soft_evidence_nodes
the set of nodes that received soft evidence
NodeSet __hard_evidence_nodes
the set of nodes that received hard evidence
virtual bool isInferenceOutdatedBNStructure() const noexceptfinal
returns whether the inference object is in a OutdatedBNStructure state
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:375

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::JointTargetedInference< GUM_SCALAR >::eraseAllJointTargets ( )
finalvirtualinherited

Clear all previously defined joint targets.

Definition at line 93 of file jointTargetedInference_tpl.h.

References gum::JointTargetedInference< GUM_SCALAR >::__joint_targets, gum::BayesNetInference< GUM_SCALAR >::__setState(), and gum::JointTargetedInference< GUM_SCALAR >::_onAllJointTargetsErased().

Referenced by gum::JointTargetedInference< GUM_SCALAR >::eraseAllTargets().

93  {
94  if (__joint_targets.size() > 0) {
95  // we already are in target mode. So no this->_setTargetedMode(); is needed
97  __joint_targets.clear();
98  this->__setState(
100  }
101  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
virtual void _onAllJointTargetsErased()=0
fired before a all the joint targets are removed
Set< NodeSet > __joint_targets
the set of joint targets

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::JointTargetedInference< GUM_SCALAR >::eraseAllMarginalTargets ( )
finalvirtualinherited

Clear all the previously defined marginal targets.

Definition at line 86 of file jointTargetedInference_tpl.h.

References gum::MarginalTargetedInference< GUM_SCALAR >::eraseAllTargets().

Referenced by gum::JointTargetedInference< GUM_SCALAR >::eraseAllTargets().

86  {
88  }
virtual void eraseAllTargets()
Clear all previously defined targets.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::JointTargetedInference< GUM_SCALAR >::eraseAllTargets ( )
virtualinherited

Clear all previously defined targets (marginal and joint targets)

Clear all previously defined targets. As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).

Reimplemented from gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 106 of file jointTargetedInference_tpl.h.

References gum::JointTargetedInference< GUM_SCALAR >::eraseAllJointTargets(), and gum::JointTargetedInference< GUM_SCALAR >::eraseAllMarginalTargets().

Referenced by gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact().

106  {
109  }
virtual void eraseAllMarginalTargets() final
Clear all the previously defined marginal targets.
virtual void eraseAllJointTargets() final
Clear all previously defined joint targets.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::eraseEvidence ( NodeId  id)
finalvirtualinherited

removed the evidence, if any, corresponding to node id

Definition at line 563 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__evidence, gum::BayesNetInference< GUM_SCALAR >::__hard_evidence, gum::BayesNetInference< GUM_SCALAR >::__hard_evidence_nodes, gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::BayesNetInference< GUM_SCALAR >::__soft_evidence_nodes, gum::BayesNetInference< GUM_SCALAR >::_onEvidenceErased(), gum::Set< Key, Alloc >::erase(), gum::BayesNetInference< GUM_SCALAR >::hasEvidence(), gum::BayesNetInference< GUM_SCALAR >::hasHardEvidence(), gum::BayesNetInference< GUM_SCALAR >::isInferenceOutdatedBNStructure(), gum::BayesNetInference< GUM_SCALAR >::OutdatedBNPotentials, and gum::BayesNetInference< GUM_SCALAR >::OutdatedBNStructure.

Referenced by gum::BayesNetInference< GUM_SCALAR >::eraseEvidence().

563  {
564  if (hasEvidence(id)) {
565  if (hasHardEvidence(id)) {
566  _onEvidenceErased(id, true);
567  __hard_evidence.erase(id);
570  } else {
571  _onEvidenceErased(id, false);
575  }
576  }
577 
578  delete (__evidence[id]);
579  __evidence.erase(id);
580  }
581  }
NodeProperty< const Potential< GUM_SCALAR > * > __evidence
the set of evidence entered into the network
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
NodeProperty< Idx > __hard_evidence
assign to each node with a hard evidence the index of its observed value
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:656
NodeSet __soft_evidence_nodes
the set of nodes that received soft evidence
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
virtual void _onEvidenceErased(NodeId id, bool isHardEvidence)=0
fired before an evidence is removed
NodeSet __hard_evidence_nodes
the set of nodes that received hard evidence
virtual bool isInferenceOutdatedBNStructure() const noexceptfinal
returns whether the inference object is in a OutdatedBNStructure state

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::eraseEvidence ( const std::string &  nodeName)
finalvirtualinherited

removed the evidence, if any, corresponding to node of name nodeName

Definition at line 585 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::BayesNetInference< GUM_SCALAR >::eraseEvidence().

585  {
586  eraseEvidence(this->BN().idFromName(nodeName));
587  }
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual void eraseEvidence(NodeId id) final
removed the evidence, if any, corresponding to node id

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
void gum::JointTargetedInference< GUM_SCALAR >::eraseJointTarget ( const NodeSet joint_target)
finalvirtualinherited

removes an existing joint target

Warning
If the joint target does not already exist, the method does nothing. In particular, it does not raise any exception.

Definition at line 157 of file jointTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::JointTargetedInference< GUM_SCALAR >::__joint_targets, gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::JointTargetedInference< GUM_SCALAR >::_onJointTargetErased(), and GUM_ERROR.

Referenced by gum::JointTargetedInference< GUM_SCALAR >::addJointTarget().

158  {
159  // check if the nodes in the target belong to the Bayesian network
160  if (this->__bn == nullptr)
161  GUM_ERROR(NullElement,
162  "No Bayes net has been assigned to the "
163  "inference algorithm");
164 
165  const auto& dag = this->__bn->dag();
166  for (const auto node : joint_target) {
167  if (!dag.exists(node)) {
168  GUM_ERROR(UndefinedElement,
169  "at least one one in " << joint_target
170  << " does not belong to the bn");
171  }
172  }
173 
174  // check that the joint_target set does not contain the new target
175  if (__joint_targets.contains(joint_target)) {
176  // note that we have to be in target mode when we are here
177  // so, no this->_setTargetedMode(); is necessary
178  _onJointTargetErased(joint_target);
179  __joint_targets.erase(joint_target);
180  this->__setState(
182  }
183  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual void _onJointTargetErased(const NodeSet &set)=0
fired before a joint target is removed
Set< NodeSet > __joint_targets
the set of joint targets
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
void gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget ( NodeId  target)
finalvirtualinherited

removes an existing (marginal) target

Warning
If the target does not already exist, the method does nothing. In particular, it does not raise any exception.

Definition at line 169 of file marginalTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::MarginalTargetedInference< GUM_SCALAR >::__targeted_mode, gum::MarginalTargetedInference< GUM_SCALAR >::__targets, gum::MarginalTargetedInference< GUM_SCALAR >::_onMarginalTargetErased(), gum::Set< Key, Alloc >::contains(), gum::Set< Key, Alloc >::erase(), and GUM_ERROR.

Referenced by gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget().

169  {
170  // check if the node belongs to the Bayesian network
171  if (this->__bn == nullptr)
172  GUM_ERROR(NullElement,
173  "No Bayes net has been assigned to the "
174  "inference algorithm");
175 
176  if (!this->__bn->dag().exists(target)) {
177  GUM_ERROR(UndefinedElement, target << " is not a NodeId in the bn");
178  }
179 
180 
181  if (__targets.contains(target)) {
182  __targeted_mode = true; // we do not use _setTargetedMode because we do not
183  // want to clear the targets
184  _onMarginalTargetErased(target);
185  __targets.erase(target);
186  this->__setState(
188  }
189  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
NodeSet __targets
the set of marginal targets
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:656
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:581
bool __targeted_mode
whether the actual targets are default
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
virtual void _onMarginalTargetErased(NodeId id)=0
fired before a marginal target is removed

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
void gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget ( const std::string &  nodeName)
finalvirtualinherited

removes an existing (marginal) target

Warning
If the target does not already exist, the method does nothing. In particular, it does not raise any exception.

Definition at line 194 of file marginalTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget(), and GUM_ERROR.

195  {
196  // check if the node belongs to the Bayesian network
197  if (this->__bn == nullptr)
198  GUM_ERROR(NullElement,
199  "No Bayes net has been assigned to the "
200  "inference algorithm");
201 
202  eraseTarget(this->__bn->idFromName(nodeName));
203  }
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE const NodeProperty< const Potential< GUM_SCALAR > * > & gum::BayesNetInference< GUM_SCALAR >::evidence ( ) const
inherited

returns the set of evidence

Definition at line 647 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__evidence.

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_onContextualize(), and gum::MarginalTargetedInference< GUM_SCALAR >::posterior().

647  {
648  return __evidence;
649  }
NodeProperty< const Potential< GUM_SCALAR > * > __evidence
the set of evidence entered into the network

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact ( NodeId  target,
const std::vector< NodeId > &  evs 
)
inherited

Create a gum::Potential for P(target|evs) (for all instanciation of target and evs)

Warning
If some evs are d-separated, they are not included in the Potential
Parameters
bnthe BayesNet
targetthe nodeId of the targetted variable
evsthe vector of nodeId of the observed variables
Returns
a Potential

Definition at line 281 of file marginalTargetedInference_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::add(), gum::BayesNetInference< GUM_SCALAR >::addEvidence(), gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), gum::BayesNetInference< GUM_SCALAR >::BN(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::Set< Key, Alloc >::contains(), gum::Instantiation::end(), gum::BayesNetInference< GUM_SCALAR >::eraseAllEvidence(), gum::MarginalTargetedInference< GUM_SCALAR >::eraseAllTargets(), GUM_ERROR, gum::Instantiation::incNotVar(), gum::Instantiation::incVar(), gum::BayesNetInference< GUM_SCALAR >::makeInference(), gum::MarginalTargetedInference< GUM_SCALAR >::posterior(), gum::MultiDimDecorator< GUM_SCALAR >::set(), gum::Instantiation::setFirst(), gum::Instantiation::setFirstVar(), and gum::Instantiation::val().

Referenced by gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact().

282  {
283  const auto& vtarget = this->BN().variable(target);
284 
285  NodeSet soids(Size(evs.size()));
286  for (const auto& e : evs)
287  soids << e;
288  if (soids.contains(target)) {
289  GUM_ERROR(InvalidArgument,
290  "Target <" << vtarget.name() << "> (" << target
291  << ") can not be in evs (" << evs << ").");
292  }
293  auto condset = this->BN().minimalCondSet(target, soids);
294 
295  Potential< GUM_SCALAR > res;
296  this->eraseAllTargets();
297  this->eraseAllEvidence();
298  res.add(this->BN().variable(target));
299  this->addTarget(target);
300  for (const auto& n : condset) {
301  res.add(this->BN().variable(n));
302  this->addEvidence(n, 0);
303  }
304 
305  Instantiation inst(res);
306  for (inst.setFirst(); !inst.end(); inst.incNotVar(vtarget)) {
307  // inferring
308  for (const auto& n : condset)
309  this->chgEvidence(n, inst.val(this->BN().variable(n)));
310  this->makeInference();
311  // populate res
312  for (inst.setFirstVar(vtarget); !inst.end(); inst.incVar(vtarget)) {
313  res.set(inst, this->posterior(target)[inst]);
314  }
315  inst.setFirstVar(vtarget); // remove inst.end() flag
316  }
317 
318  return res;
319  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual const Potential< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
virtual void eraseAllTargets()
Clear all previously defined targets.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact ( const std::string &  target,
const std::vector< std::string > &  evs 
)
inherited

Create a gum::Potential for P(target|evs) (for all instanciation of target and evs)

Warning
If some evs are d-separated, they are not included in the Potential
Parameters
targetthe nodeId of the target variable
evsthe nodeId of the observed variable
Returns
a Potential

Definition at line 323 of file marginalTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact().

324  {
325  const auto& bn = this->BN();
326 
327  std::vector< NodeId > evsId;
328  evsId.reserve(evs.size());
329  std::transform(std::begin(evs),
330  std::end(evs),
331  std::back_inserter(evsId),
332  [&bn](const std::string& s) { return bn.idFromName(s); });
333 
334  return evidenceImpact(bn.idFromName(target), evsId);
335  }
Potential< GUM_SCALAR > evidenceImpact(NodeId target, const std::vector< NodeId > &evs)
Create a gum::Potential for P(target|evs) (for all instanciation of target and evs) ...
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact ( const std::vector< NodeId > &  targets,
const std::vector< NodeId > &  evs 
)
inherited

Create a gum::Potential for P(joint targets|evs) (for all instanciation of targets and evs)

Warning
If some evs are d-separated, they are not included in the Potential
Parameters
targetsthe vector of nodeId of the targetted variables
evsthe vector of nodeId of observed variables
Returns
a Potential

Definition at line 328 of file jointTargetedInference_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::add(), gum::Instantiation::add(), gum::BayesNetInference< GUM_SCALAR >::addEvidence(), gum::JointTargetedInference< GUM_SCALAR >::addJointTarget(), gum::BayesNetInference< GUM_SCALAR >::BN(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::Instantiation::end(), gum::BayesNetInference< GUM_SCALAR >::eraseAllEvidence(), gum::JointTargetedInference< GUM_SCALAR >::eraseAllTargets(), GUM_ERROR, gum::Instantiation::incIn(), gum::Instantiation::incOut(), gum::JointTargetedInference< GUM_SCALAR >::jointPosterior(), gum::BayesNetInference< GUM_SCALAR >::makeInference(), gum::MultiDimDecorator< GUM_SCALAR >::set(), gum::Instantiation::setFirstIn(), gum::Instantiation::setFirstOut(), and gum::Instantiation::val().

Referenced by gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact().

329  {
330  NodeSet sotargets(Size(targets.size()));
331  for (const auto& e : targets)
332  sotargets << e;
333 
334  NodeSet soevs(Size(evs.size()));
335  for (const auto& e : evs)
336  soevs << e;
337 
338  if (!(soevs * sotargets).empty()) {
339  GUM_ERROR(InvalidArgument,
340  "Targets (" << targets << ") can not intersect evs (" << evs
341  << ").");
342  }
343  auto condset = this->BN().minimalCondSet(sotargets, soevs);
344 
345  this->eraseAllTargets();
346  this->eraseAllEvidence();
347 
348  Instantiation iTarget;
349  Potential< GUM_SCALAR > res;
350  for (const auto& target : sotargets) {
351  res.add(this->BN().variable(target));
352  iTarget.add(this->BN().variable(target));
353  }
354  this->addJointTarget(sotargets);
355 
356  for (const auto& n : condset) {
357  res.add(this->BN().variable(n));
358  this->addEvidence(n, 0);
359  }
360 
361  Instantiation inst(res);
362  for (inst.setFirstOut(iTarget); !inst.end(); inst.incOut(iTarget)) {
363  // inferring
364  for (const auto& n : condset)
365  this->chgEvidence(n, inst.val(this->BN().variable(n)));
366  this->makeInference();
367  // populate res
368  for (inst.setFirstIn(iTarget); !inst.end(); inst.incIn(iTarget)) {
369  res.set(inst, this->jointPosterior(sotargets)[inst]);
370  }
371  inst.setFirstIn(iTarget); // remove inst.end() flag
372  }
373 
374  return res;
375  }
virtual void eraseAllTargets()
Clear all previously defined targets (marginal and joint targets)
virtual void addJointTarget(const NodeSet &joint_target) final
Add a set of nodes as a new joint target. As a collateral effect, every node is added as a marginal t...
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual const Potential< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact ( const std::vector< std::string > &  targets,
const std::vector< std::string > &  evs 
)
inherited

Create a gum::Potential for P(joint targets|evs) (for all instanciation of targets and evs)

Warning
If some evs are d-separated, they are not included in the Potential
Parameters
targetsthe vector of std::string of the targetted variables
evsthe vector of std::string of observed variables
Returns
a Potential

Definition at line 379 of file jointTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact().

381  {
382  const auto& bn = this->BN();
383  auto transf = [&bn](const std::string& s) { return bn.idFromName(s); };
384 
385  std::vector< NodeId > targetsId;
386  targetsId.reserve(targets.size());
387  std::transform(std::begin(targets),
388  std::end(targets),
389  std::back_inserter(targetsId),
390  transf);
391 
392  std::vector< NodeId > evsId;
393  evsId.reserve(evs.size());
394  std::transform(
395  std::begin(evs), std::end(evs), std::back_inserter(evsId), transf);
396 
397  return evidenceJointImpact(targetsId, evsId);
398  }
Potential< GUM_SCALAR > evidenceJointImpact(const std::vector< NodeId > &targets, const std::vector< NodeId > &evs)
Create a gum::Potential for P(joint targets|evs) (for all instanciation of targets and evs) ...
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
GUM_SCALAR gum::LazyPropagation< GUM_SCALAR >::evidenceProbability ( )
finalvirtual

returns the probability of evidence

Implements gum::EvidenceInference< GUM_SCALAR >.

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::MarginalTargetedInference< GUM_SCALAR >::H ( NodeId  X)
finalvirtualinherited

Entropy Compute Shanon's entropy of a node given the observation.

See also
http://en.wikipedia.org/wiki/Information_entropy

Definition at line 266 of file marginalTargetedInference_tpl.h.

References gum::MarginalTargetedInference< GUM_SCALAR >::posterior().

Referenced by gum::MarginalTargetedInference< GUM_SCALAR >::H(), and gum::JointTargetedInference< GUM_SCALAR >::VI().

266  {
267  return posterior(X).entropy();
268  }
virtual const Potential< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::MarginalTargetedInference< GUM_SCALAR >::H ( const std::string &  nodeName)
finalvirtualinherited

Entropy Compute Shanon's entropy of a node given the observation.

See also
http://en.wikipedia.org/wiki/Information_entropy

Definition at line 275 of file marginalTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::MarginalTargetedInference< GUM_SCALAR >::H().

275  {
276  return H(this->BN().idFromName(nodeName));
277  }
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon&#39;s entropy of a node given the observation.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE const NodeProperty< Idx > & gum::BayesNetInference< GUM_SCALAR >::hardEvidence ( ) const
inherited

indicate for each node with hard evidence which value it took

Definition at line 639 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__hard_evidence.

Referenced by gum::WeightedSampling< GUM_SCALAR >::_draw(), gum::MonteCarloSampling< GUM_SCALAR >::_draw(), gum::ImportanceSampling< GUM_SCALAR >::_draw(), and gum::SamplingInference< GUM_SCALAR >::contextualize().

639  {
640  return __hard_evidence;
641  }
NodeProperty< Idx > __hard_evidence
assign to each node with a hard evidence the index of its observed value

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE const NodeSet & gum::BayesNetInference< GUM_SCALAR >::hardEvidenceNodes ( ) const
inherited

returns the set of nodes with hard evidence

the set of nodes that received hard evidence

Definition at line 663 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__hard_evidence_nodes.

Referenced by gum::WeightedSampling< GUM_SCALAR >::_draw(), gum::MonteCarloSampling< GUM_SCALAR >::_draw(), gum::ImportanceSampling< GUM_SCALAR >::_draw(), gum::ImportanceSampling< GUM_SCALAR >::_onContextualize(), gum::SamplingInference< GUM_SCALAR >::_setEstimatorFromBN(), gum::SamplingInference< GUM_SCALAR >::_setEstimatorFromLBP(), gum::SamplingInference< GUM_SCALAR >::contextualize(), and gum::MarginalTargetedInference< GUM_SCALAR >::posterior().

663  {
664  return __hard_evidence_nodes;
665  }
NodeSet __hard_evidence_nodes
the set of nodes that received hard evidence

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::hasEvidence ( ) const
finalvirtualinherited

indicates whether some node(s) have received evidence

Definition at line 378 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__evidence.

Referenced by gum::BayesNetInference< GUM_SCALAR >::addEvidence(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::BayesNetInference< GUM_SCALAR >::eraseEvidence(), and gum::BayesNetInference< GUM_SCALAR >::hasEvidence().

378  {
379  return !__evidence.empty();
380  }
NodeProperty< const Potential< GUM_SCALAR > * > __evidence
the set of evidence entered into the network

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::hasEvidence ( NodeId  id) const
finalvirtualinherited

indicates whether node id has received an evidence

Definition at line 385 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__evidence.

385  {
386  return __evidence.exists(id);
387  }
NodeProperty< const Potential< GUM_SCALAR > * > __evidence
the set of evidence entered into the network
template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::hasEvidence ( const std::string &  nodeName) const
finalvirtualinherited

indicates whether node id has received an evidence

Definition at line 406 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::BayesNetInference< GUM_SCALAR >::hasEvidence().

407  {
408  return hasEvidence(this->BN().idFromName(nodeName));
409  }
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::hasHardEvidence ( NodeId  id) const
finalvirtualinherited

indicates whether node id has received a hard evidence

Definition at line 392 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__hard_evidence_nodes, and gum::Set< Key, Alloc >::exists().

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_draw(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::BayesNetInference< GUM_SCALAR >::eraseEvidence(), and gum::BayesNetInference< GUM_SCALAR >::hasHardEvidence().

392  {
393  return __hard_evidence_nodes.exists(id);
394  }
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:607
NodeSet __hard_evidence_nodes
the set of nodes that received hard evidence

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::hasHardEvidence ( const std::string &  nodeName) const
finalvirtualinherited

indicates whether node id has received a hard evidence

Definition at line 414 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::BayesNetInference< GUM_SCALAR >::hasHardEvidence().

415  {
416  return hasHardEvidence(this->BN().idFromName(nodeName));
417  }
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::hasSoftEvidence ( NodeId  id) const
finalvirtualinherited

indicates whether node id has received a soft evidence

Definition at line 399 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__soft_evidence_nodes, and gum::Set< Key, Alloc >::exists().

Referenced by gum::BayesNetInference< GUM_SCALAR >::hasSoftEvidence().

399  {
400  return __soft_evidence_nodes.exists(id);
401  }
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:607
NodeSet __soft_evidence_nodes
the set of nodes that received soft evidence

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::hasSoftEvidence ( const std::string &  nodeName) const
finalvirtualinherited

indicates whether node id has received a soft evidence

Definition at line 422 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::BayesNetInference< GUM_SCALAR >::hasSoftEvidence().

423  {
424  return hasSoftEvidence(this->BN().idFromName(nodeName));
425  }
virtual bool hasSoftEvidence(NodeId id) const final
indicates whether node id has received a soft evidence
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
GUM_SCALAR gum::JointTargetedInference< GUM_SCALAR >::I ( NodeId  X,
NodeId  Y 
)
inherited

Mutual information between X and Y.

See also
http://en.wikipedia.org/wiki/Mutual_information
Warning
Due to limitation of joint, may not be able to compute this value
Exceptions
OperationNotAllowedin these cases

Definition at line 268 of file jointTargetedInference_tpl.h.

References gum::JointTargetedInference< GUM_SCALAR >::_unnormalizedJointPosterior(), gum::BayesNetInference< GUM_SCALAR >::BN(), gum::Instantiation::end(), GUM_ERROR, gum::Potential< GUM_SCALAR >::margSumOut(), gum::Potential< GUM_SCALAR >::normalize(), and gum::Instantiation::setFirst().

Referenced by gum::JointTargetedInference< GUM_SCALAR >::VI().

268  {
269  Potential< GUM_SCALAR > pX, pY, *pXY = nullptr;
270  if (X == Y) {
271  GUM_ERROR(OperationNotAllowed, "Mutual Information I(X,Y) with X==Y");
272  }
273 
274  try {
275  // here use unnormalized joint posterior rather than just posterior
276  // to avoid saving the posterior in the cache of the inference engines
277  // like LazyPropagation or SahferShenoy.
278  pXY = this->_unnormalizedJointPosterior({X, Y});
279  pXY->normalize();
280  pX = pXY->margSumOut({&(this->BN().variable(Y))});
281  pY = pXY->margSumOut({&(this->BN().variable(X))});
282  } catch (...) {
283  if (pXY != nullptr) {
284  delete pXY;
285  }
286  throw;
287  }
288 
289  Instantiation i(*pXY);
290  auto res = (GUM_SCALAR)0;
291 
292  for (i.setFirst(); !i.end(); ++i) {
293  GUM_SCALAR vXY = (*pXY)[i];
294  GUM_SCALAR vX = pX[i];
295  GUM_SCALAR vY = pY[i];
296 
297  if (vXY > (GUM_SCALAR)0) {
298  if (vX == (GUM_SCALAR)0 || vY == (GUM_SCALAR)0) {
299  GUM_ERROR(OperationNotAllowed,
300  "Mutual Information (X,Y) with P(X)=0 or P(Y)=0 "
301  "and P(X,Y)>0");
302  }
303 
304  res += vXY * (log2(vXY) - log2(vX) - log2(vY));
305  }
306  }
307 
308  delete pXY;
309 
310  return res;
311  }
virtual Potential< GUM_SCALAR > * _unnormalizedJointPosterior(const NodeSet &set)=0
returns a fresh unnormalized joint posterior of a given set of variables
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::isDone ( ) const
finalvirtualnoexceptinherited

returns whether the inference object is in a done state

The inference object is in a done state when the posteriors can be retrieved without performing a new inference, i.e., all the heavy computations have already been performed. Typically, in a junction tree algorithm, this corresponds to a situation in which all the messages needed in the JT have been computed and sent.

Definition at line 93 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__state, and gum::BayesNetInference< GUM_SCALAR >::Done.

Referenced by gum::JointTargetedInference< GUM_SCALAR >::jointPosterior(), gum::BayesNetInference< GUM_SCALAR >::makeInference(), gum::MarginalTargetedInference< GUM_SCALAR >::posterior(), and gum::BayesNetInference< GUM_SCALAR >::prepareInference().

93  {
94  return (__state == StateOfInference::Done);
95  }
StateOfInference __state
the current state of the inference (outdated/ready/done)

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::isInferenceDone ( ) const
finalvirtualnoexceptinherited

returns whether the inference object is in a InferenceDone state

Definition at line 86 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__state, and gum::BayesNetInference< GUM_SCALAR >::Done.

86  {
87  return (__state == StateOfInference::Done);
88  }
StateOfInference __state
the current state of the inference (outdated/ready/done)
template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::isInferenceOutdatedBNPotentials ( ) const
finalvirtualnoexceptinherited

returns whether the inference object is in a OutdatedBNPotential state

Definition at line 80 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__state, and gum::BayesNetInference< GUM_SCALAR >::OutdatedBNPotentials.

81  {
83  }
StateOfInference __state
the current state of the inference (outdated/ready/done)
template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::isInferenceOutdatedBNStructure ( ) const
finalvirtualnoexceptinherited

returns whether the inference object is in a OutdatedBNStructure state

Definition at line 73 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__state, and gum::BayesNetInference< GUM_SCALAR >::OutdatedBNStructure.

Referenced by gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::BayesNetInference< GUM_SCALAR >::eraseAllEvidence(), and gum::BayesNetInference< GUM_SCALAR >::eraseEvidence().

74  {
76  }
StateOfInference __state
the current state of the inference (outdated/ready/done)

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetInference< GUM_SCALAR >::isInferenceReady ( ) const
finalvirtualnoexceptinherited

returns whether the inference object is in a ready state

Definition at line 67 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__state, and gum::BayesNetInference< GUM_SCALAR >::ReadyForInference.

Referenced by gum::SamplingInference< GUM_SCALAR >::_onStateChanged(), gum::BayesNetInference< GUM_SCALAR >::makeInference(), and gum::BayesNetInference< GUM_SCALAR >::prepareInference().

67  {
69  }
StateOfInference __state
the current state of the inference (outdated/ready/done)

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::JointTargetedInference< GUM_SCALAR >::isJointTarget ( const NodeSet vars) const
finalvirtualinherited

return true if target is a joint target.

Definition at line 66 of file jointTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::JointTargetedInference< GUM_SCALAR >::__joint_targets, and GUM_ERROR.

67  {
68  if (this->__bn == nullptr)
69  GUM_ERROR(NullElement,
70  "No Bayes net has been assigned to the "
71  "inference algorithm");
72 
73  const auto& dag = this->__bn->dag();
74  for (const auto var : vars) {
75  if (!dag.exists(var)) {
76  GUM_ERROR(UndefinedElement, var << " is not a NodeId in the bn");
77  }
78  }
79 
80  return __joint_targets.contains(vars);
81  }
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
Set< NodeSet > __joint_targets
the set of joint targets
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
template<typename GUM_SCALAR >
INLINE bool gum::MarginalTargetedInference< GUM_SCALAR >::isTarget ( NodeId  node) const
finalvirtualinherited

return true if variable is a (marginal) target

Definition at line 73 of file marginalTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::MarginalTargetedInference< GUM_SCALAR >::__targets, gum::Set< Key, Alloc >::contains(), and GUM_ERROR.

Referenced by gum::MarginalTargetedInference< GUM_SCALAR >::isTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::posterior(), and gum::JointTargetedInference< GUM_SCALAR >::posterior().

73  {
74  // check that the variable belongs to the bn
75  if (this->__bn == nullptr)
76  GUM_ERROR(NullElement,
77  "No Bayes net has been assigned to the "
78  "inference algorithm");
79  if (!this->__bn->dag().exists(node)) {
80  GUM_ERROR(UndefinedElement, node << " is not a NodeId in the bn");
81  }
82 
83  return __targets.contains(node);
84  }
NodeSet __targets
the set of marginal targets
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:581
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::MarginalTargetedInference< GUM_SCALAR >::isTarget ( const std::string &  nodeName) const
finalvirtualinherited

return true if variable is a (marginal) target

Definition at line 88 of file marginalTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, and gum::MarginalTargetedInference< GUM_SCALAR >::isTarget().

89  {
90  return isTarget(this->__bn->idFromName(nodeName));
91  }
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
const Potential< GUM_SCALAR > & gum::JointTargetedInference< GUM_SCALAR >::jointPosterior ( const NodeSet nodes)
finalvirtualinherited

Compute the joint posterior of a set of nodes.

Returns
a const ref to the posterior joint probability of the set of nodes.
Parameters
nodesthe set of nodes whose posterior joint probability is wanted
Warning
for efficiency reasons, the potential is stored into the inference engine and is returned by reference. In order to ensure that the potential may still exist even if the Inference object is destroyed, the user has to copy it explicitly.
prepareInference and makeInference may be applied if needed.
Exceptions
UndefinedElementif nodes is not in the targets

Definition at line 208 of file jointTargetedInference_tpl.h.

References gum::JointTargetedInference< GUM_SCALAR >::__joint_targets, gum::JointTargetedInference< GUM_SCALAR >::_jointPosterior(), GUM_ERROR, gum::BayesNetInference< GUM_SCALAR >::isDone(), gum::Set< Key, Alloc >::isSubsetOf(), and gum::BayesNetInference< GUM_SCALAR >::makeInference().

Referenced by gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), and gum::JointTargetedInference< GUM_SCALAR >::posterior().

208  {
209  // try to get the smallest set of targets that contains "nodes"
210  NodeSet set;
211  bool found_exact_target = false;
212 
213  if (__joint_targets.contains(nodes)) {
214  set = nodes;
215  found_exact_target = true;
216  } else {
217  for (const auto& target : __joint_targets) {
218  if (nodes.isSubsetOf(target)) {
219  set = target;
220  break;
221  }
222  }
223  }
224 
225  if (set.empty()) {
226  GUM_ERROR(UndefinedElement,
227  " no joint target containing " << nodes << "could be found");
228  }
229 
230  if (!this->isDone()) { this->makeInference(); }
231 
232  if (found_exact_target)
233  return _jointPosterior(nodes);
234  else
235  return _jointPosterior(nodes, set);
236  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
virtual const Potential< GUM_SCALAR > & _jointPosterior(const NodeSet &set)=0
asks derived classes for the joint posterior of a declared target set
Set< NodeSet > __joint_targets
the set of joint targets
virtual bool isDone() const noexceptfinal
returns whether the inference object is in a done state
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR>
const JoinTree* gum::LazyPropagation< GUM_SCALAR >::joinTree ( )

returns the current join tree used

Lazy Propagation does not use a junction tree but a binary join tree because this may enable faster inferences. So do not be surprised to see that somes cliques are contained into others in this tree.

template<typename GUM_SCALAR >
INLINE const Set< NodeSet > & gum::JointTargetedInference< GUM_SCALAR >::jointTargets ( ) const
finalvirtualnoexceptinherited

returns the list of joint targets

returns the list of target sets

Definition at line 189 of file jointTargetedInference_tpl.h.

References gum::JointTargetedInference< GUM_SCALAR >::__joint_targets.

189  {
190  return __joint_targets;
191  }
Set< NodeSet > __joint_targets
the set of joint targets
template<typename GUM_SCALAR>
const JunctionTree* gum::LazyPropagation< GUM_SCALAR >::junctionTree ( )

returns the current junction tree

Lazy Propagation does not use a junction tree but a binary join tree because this may enable faster inferences. This method return the junction tree, before optimizations

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::makeInference ( )
finalvirtualinherited

perform the heavy computations needed to compute the targets' posteriors

In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done "lightly" by multiplying and projecting those messages.

Definition at line 708 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::BayesNetInference< GUM_SCALAR >::_makeInference(), gum::BayesNetInference< GUM_SCALAR >::Done, gum::BayesNetInference< GUM_SCALAR >::isDone(), gum::BayesNetInference< GUM_SCALAR >::isInferenceReady(), and gum::BayesNetInference< GUM_SCALAR >::prepareInference().

Referenced by gum::LoopySamplingInference< GUM_SCALAR, APPROX >::_makeInference(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::JointTargetedInference< GUM_SCALAR >::jointPosterior(), and gum::MarginalTargetedInference< GUM_SCALAR >::posterior().

708  {
709  if (isDone()) { return; }
710 
711  if (!isInferenceReady()) { prepareInference(); }
712 
713  _makeInference();
714 
716  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
virtual bool isInferenceReady() const noexceptfinal
returns whether the inference object is in a ready state
virtual void _makeInference()=0
called when the inference has to be performed effectively
virtual void prepareInference() final
prepare the internal inference structures for the next inference
virtual bool isDone() const noexceptfinal
returns whether the inference object is in a done state

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE Size gum::BayesNetInference< GUM_SCALAR >::nbrEvidence ( ) const
finalvirtualinherited

returns the number of evidence entered into the Bayesian network

Definition at line 617 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__evidence.

617  {
618  return __evidence.size();
619  }
NodeProperty< const Potential< GUM_SCALAR > * > __evidence
the set of evidence entered into the network
template<typename GUM_SCALAR >
INLINE Size gum::BayesNetInference< GUM_SCALAR >::nbrHardEvidence ( ) const
finalvirtualinherited

returns the number of hard evidence entered into the Bayesian network

Definition at line 624 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__hard_evidence_nodes, and gum::Set< Key, Alloc >::size().

624  {
625  return __hard_evidence_nodes.size();
626  }
NodeSet __hard_evidence_nodes
the set of nodes that received hard evidence
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE Size gum::JointTargetedInference< GUM_SCALAR >::nbrJointTargets ( ) const
finalvirtualnoexceptinherited

returns the number of joint targets

returns the number of target sets

Definition at line 195 of file jointTargetedInference_tpl.h.

References gum::JointTargetedInference< GUM_SCALAR >::__joint_targets.

196  {
197  return __joint_targets.size();
198  }
Set< NodeSet > __joint_targets
the set of joint targets
template<typename GUM_SCALAR >
INLINE Size gum::BayesNetInference< GUM_SCALAR >::nbrSoftEvidence ( ) const
finalvirtualinherited

returns the number of soft evidence entered into the Bayesian network

Definition at line 631 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__soft_evidence_nodes, and gum::Set< Key, Alloc >::size().

631  {
632  return __soft_evidence_nodes.size();
633  }
NodeSet __soft_evidence_nodes
the set of nodes that received soft evidence
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE const Size gum::MarginalTargetedInference< GUM_SCALAR >::nbrTargets ( ) const
finalvirtualnoexceptinherited

returns the number of marginal targets

Definition at line 215 of file marginalTargetedInference_tpl.h.

References gum::MarginalTargetedInference< GUM_SCALAR >::__targets, and gum::Set< Key, Alloc >::size().

216  {
217  return __targets.size();
218  }
NodeSet __targets
the set of marginal targets
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
LazyPropagation< GUM_SCALAR >& gum::LazyPropagation< GUM_SCALAR >::operator= ( const LazyPropagation< GUM_SCALAR > &  )
delete

avoid copy operators

template<typename GUM_SCALAR >
const Potential< GUM_SCALAR > & gum::JointTargetedInference< GUM_SCALAR >::posterior ( NodeId  node)
finalvirtualinherited

Computes and returns the posterior of a node.

Returns
a const ref to the posterior probability of the node.
Parameters
nodethe node for which we need a posterior probability
Warning
for efficiency reasons, the potential is stored into the inference engine and is returned by reference. In order to ensure that the potential may still exist even if the Inference object is destroyed, the user has to copy it explicitly.
prepareInference and makeInference may be applied if needed by the posterior method.
Exceptions
UndefinedElementif node is not in the set of targets

Reimplemented from gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 242 of file jointTargetedInference_tpl.h.

References gum::MarginalTargetedInference< GUM_SCALAR >::isTarget(), gum::JointTargetedInference< GUM_SCALAR >::jointPosterior(), and gum::MarginalTargetedInference< GUM_SCALAR >::posterior().

Referenced by gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN(), and gum::JointTargetedInference< GUM_SCALAR >::posterior().

242  {
243  if (this->isTarget(node))
245  else
246  return jointPosterior(NodeSet{node});
247  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target
virtual const Potential< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
virtual const Potential< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
const Potential< GUM_SCALAR > & gum::JointTargetedInference< GUM_SCALAR >::posterior ( const std::string &  nodeName)
finalvirtualinherited

Computes and returns the posterior of a node.

Returns
a const ref to the posterior probability of the node.
Parameters
nodethe node for which we need a posterior probability
Warning
for efficiency reasons, the potential is stored into the inference engine and is returned by reference. In order to ensure that the potential may still exist even if the Inference object is destroyed, the user has to copy it explicitly.
prepareInference and makeInference may be applied if needed by the posterior method.
Exceptions
UndefinedElementif node is not in the set of targets

Reimplemented from gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 252 of file jointTargetedInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::JointTargetedInference< GUM_SCALAR >::posterior().

252  {
253  return posterior(this->BN().idFromName(nodeName));
254  }
virtual const Potential< GUM_SCALAR > & posterior(NodeId node) final
Computes and returns the posterior of a node.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::BayesNetInference< GUM_SCALAR >::prepareInference ( )
finalvirtualinherited

prepare the internal inference structures for the next inference

Definition at line 689 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::BayesNetInference< GUM_SCALAR >::__state, gum::BayesNetInference< GUM_SCALAR >::_updateOutdatedBNPotentials(), gum::BayesNetInference< GUM_SCALAR >::_updateOutdatedBNStructure(), GUM_ERROR, gum::BayesNetInference< GUM_SCALAR >::isDone(), gum::BayesNetInference< GUM_SCALAR >::isInferenceReady(), gum::BayesNetInference< GUM_SCALAR >::OutdatedBNStructure, and gum::BayesNetInference< GUM_SCALAR >::ReadyForInference.

Referenced by gum::BayesNetInference< GUM_SCALAR >::makeInference(), and gum::SamplingInference< GUM_SCALAR >::samplingBN().

689  {
690  if (isInferenceReady() || isDone()) { return; }
691 
692  if (__bn == nullptr)
693  GUM_ERROR(NullElement,
694  "No Bayes net has been assigned to the "
695  "inference algorithm");
696 
699  else
701 
703  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
StateOfInference __state
the current state of the inference (outdated/ready/done)
virtual bool isInferenceReady() const noexceptfinal
returns whether the inference object is in a ready state
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual void _updateOutdatedBNPotentials()=0
prepares inference when the latter is in OutdatedBNPotentials state
virtual void _updateOutdatedBNStructure()=0
prepares inference when the latter is in OutdatedBNStructure state
virtual bool isDone() const noexceptfinal
returns whether the inference object is in a done state
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
void gum::BayesNetInference< GUM_SCALAR >::setBN ( const IBayesNet< GUM_SCALAR > *  bn)
virtualinherited

assigns a new BN to the inference engine

Assigns a new BN to the BayesNetInference engine and sends messages to the descendants of BayesNetInference to inform them that the BN has changed.

Warning
By default, all the nodes of the Bayes net are targets.
note that, by aGrUM's rule, the bn is not copied into the inference engine but only referenced.

Definition at line 129 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__bn, gum::BayesNetInference< GUM_SCALAR >::__computeDomainSizes(), gum::BayesNetInference< GUM_SCALAR >::__setState(), gum::BayesNetInference< GUM_SCALAR >::_onBayesNetChanged(), gum::BayesNetInference< GUM_SCALAR >::clear(), and gum::BayesNetInference< GUM_SCALAR >::OutdatedBNStructure.

129  {
130  clear();
131  __bn = bn;
133  _onBayesNetChanged(bn);
135  }
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR > *bn)=0
fired after a new Bayes net has been assigned to the engine
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual void clear()
clears all the data structures allocated for the last inference
void __computeDomainSizes()
computes the domain sizes of the random variables

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::setFindBarrenNodesType ( FindBarrenNodesType  type)

sets how we determine barren nodes

Barren nodes are unnecessary for probability inference, so they can be safely discarded in this case (type = FIND_BARREN_NODES). This speeds-up inference. However, there are some cases in which we do not want to remove barren nodes, typically when we want to answer queries such as Most Probable Explanations (MPE).

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::setRelevantPotentialsFinderType ( RelevantPotentialsFinderType  type)

sets how we determine the relevant potentials to combine

When a clique sends a message to a separator, it first constitute the set of the potentials it contains and of the potentials contained in the messages it received. If RelevantPotentialsFinderType = FIND_ALL, all these potentials are combined and projected to produce the message sent to the separator. If RelevantPotentialsFinderType = DSEP_BAYESBALL_NODES, then only the set of potentials d-connected to the variables of the separator are kept for combination and projection.

template<typename GUM_SCALAR>
void gum::LazyPropagation< GUM_SCALAR >::setTriangulation ( const Triangulation new_triangulation)

use a new triangulation algorithm

template<typename GUM_SCALAR >
INLINE const NodeSet & gum::BayesNetInference< GUM_SCALAR >::softEvidenceNodes ( ) const
inherited

returns the set of nodes with soft evidence

the set of nodes that received soft evidence

Definition at line 655 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__soft_evidence_nodes.

Referenced by gum::SamplingInference< GUM_SCALAR >::contextualize().

655  {
656  return __soft_evidence_nodes;
657  }
NodeSet __soft_evidence_nodes
the set of nodes that received soft evidence

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE BayesNetInference< GUM_SCALAR >::StateOfInference gum::BayesNetInference< GUM_SCALAR >::state ( ) const
finalvirtualnoexceptinherited

returns the state of the inference engine

Definition at line 101 of file BayesNetInference_tpl.h.

References gum::BayesNetInference< GUM_SCALAR >::__state.

Referenced by gum::BayesNetInference< GUM_SCALAR >::__setState().

101  {
102  return __state;
103  }
StateOfInference __state
the current state of the inference (outdated/ready/done)

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE const NodeSet & gum::MarginalTargetedInference< GUM_SCALAR >::targets ( ) const
finalvirtualnoexceptinherited

returns the list of marginal targets

Definition at line 208 of file marginalTargetedInference_tpl.h.

References gum::MarginalTargetedInference< GUM_SCALAR >::__targets.

Referenced by gum::SamplingInference< GUM_SCALAR >::contextualize().

209  {
210  return __targets;
211  }
NodeSet __targets
the set of marginal targets

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::JointTargetedInference< GUM_SCALAR >::VI ( NodeId  X,
NodeId  Y 
)
inherited

Variation of information between X and Y.

See also
http://en.wikipedia.org/wiki/Variation_of_information
Warning
Due to limitation of joint, may not be able to compute this value
Exceptions
OperationNotAllowedin these cases
See also
http://en.wikipedia.org/wiki/Variation_of_information
Warning
Due to limitation of , may not be able to compute this value
Exceptions
OperationNotAllowedin these cases

Definition at line 321 of file jointTargetedInference_tpl.h.

References gum::MarginalTargetedInference< GUM_SCALAR >::H(), and gum::JointTargetedInference< GUM_SCALAR >::I().

321  {
322  return this->H(X) + this->H(Y) - 2 * I(X, Y);
323  }
GUM_SCALAR I(NodeId X, NodeId Y)
Mutual information between X and Y.
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon&#39;s entropy of a node given the observation.

+ Here is the call graph for this function:

Member Data Documentation

template<typename GUM_SCALAR>
const GUM_SCALAR gum::LazyPropagation< GUM_SCALAR >::__1_minus_epsilon {GUM_SCALAR(1.0 - 1e-6)}
private

for comparisons with 1 - epsilon

Definition at line 377 of file lazyPropagation.h.

template<typename GUM_SCALAR>
FindBarrenNodesType gum::LazyPropagation< GUM_SCALAR >::__barren_nodes_type
private

the type of barren nodes computation we wish

Definition at line 254 of file lazyPropagation.h.

template<typename GUM_SCALAR>
NodeProperty< __PotentialSet > gum::LazyPropagation< GUM_SCALAR >::__clique_potentials
private

the list of all potentials stored in the cliques

This structure contains a list for each clique in the join tree. If a clique did not received any potential, then its list is empty but the entry for the clique does exist. Note that clique potentials contain also soft evidence and the CPTs that were projected to remove their variables that received hard evidence.

Definition at line 314 of file lazyPropagation.h.

template<typename GUM_SCALAR>
Potential< GUM_SCALAR >*(* gum::LazyPropagation< GUM_SCALAR >::__combination_op) (const Potential< GUM_SCALAR > &, const Potential< GUM_SCALAR > &)
inlineprivate

the operator for performing the combinations

Definition at line 262 of file lazyPropagation.h.

263  {
static INLINE Potential< GUM_SCALAR > * LPNewmultiPotential(const Potential< GUM_SCALAR > &t1, const Potential< GUM_SCALAR > &t2)
template<typename GUM_SCALAR>
NodeProperty< GUM_SCALAR > gum::LazyPropagation< GUM_SCALAR >::__constants
private

the constants resulting from the projections of CPTs defined over only hard evidence nodes remove this constant and insert the notion of a constant into potentials/multidim arrays

Definition at line 341 of file lazyPropagation.h.

template<typename GUM_SCALAR>
ArcProperty< __PotentialSet > gum::LazyPropagation< GUM_SCALAR >::__created_potentials
private

the set of potentials created for the last inference messages

This structure contains only the arcs on which potentials have been created.

Warning
Note that the CPTs that were projected due to hard evidence do not belong to this structure, they are kept in __hard_ev_projected_CPTs.

Definition at line 327 of file lazyPropagation.h.

template<typename GUM_SCALAR>
NodeProperty< EvidenceChangeType > gum::LazyPropagation< GUM_SCALAR >::__evidence_changes
private

indicates which nodes of the BN have evidence that changed since the last inference

Definition at line 374 of file lazyPropagation.h.

template<typename GUM_SCALAR>
RelevantPotentialsFinderType gum::LazyPropagation< GUM_SCALAR >::__find_relevant_potential_type
private

the type of relevant potential finding algorithm to be used

Definition at line 245 of file lazyPropagation.h.

template<typename GUM_SCALAR>
void(LazyPropagation< GUM_SCALAR >::* gum::LazyPropagation< GUM_SCALAR >::__findRelevantPotentials) (Set< const Potential< GUM_SCALAR > * > &pot_list, Set< const DiscreteVariable * > &kept_vars)
private

update a set of potentials: the remaining are those to be combined to produce a message on a separator

Definition at line 249 of file lazyPropagation.h.

template<typename GUM_SCALAR>
UndiGraph gum::LazyPropagation< GUM_SCALAR >::__graph
private

the undigraph extracted from the BN and used to construct the join tree

If all nodes are targets, this graph corresponds to the moral graph of the BN. Otherwise, it may be a subgraph of this moral graph. For instance if the BN is A->B->C and only B is a target, __graph will be equal to A-B if we exploit barren nodes (C is a barren node and, therefore, can be removed for inference).

Definition at line 279 of file lazyPropagation.h.

template<typename GUM_SCALAR>
NodeSet gum::LazyPropagation< GUM_SCALAR >::__hard_ev_nodes
private

the hard evidence nodes which were projected in CPTs

Definition at line 367 of file lazyPropagation.h.

template<typename GUM_SCALAR>
NodeProperty< const Potential< GUM_SCALAR >* > gum::LazyPropagation< GUM_SCALAR >::__hard_ev_projected_CPTs
private

the CPTs that were projected due to hard evidence nodes

For each node whose CPT is defined over some nodes that contain some hard evidence, assigns a new projected CPT that does not contain these nodes anymore.

Warning
These potentials are owned by LayPropagation.

Definition at line 364 of file lazyPropagation.h.

template<typename GUM_SCALAR>
bool gum::LazyPropagation< GUM_SCALAR >::__is_new_jt_needed {true}
private

indicates whether a new join tree is needed for the next inference

when modifying the set of hard evidence, we can determine that the current JT is no more appropriate for inference. This variable enables us to keep track of this.

Definition at line 291 of file lazyPropagation.h.

template<typename GUM_SCALAR>
HashTable< NodeSet, const Potential< GUM_SCALAR >* > gum::LazyPropagation< GUM_SCALAR >::__joint_target_posteriors
private

the set of set target posteriors computed during the last inference

the posteriors are owned by LazyPropagation.

Definition at line 335 of file lazyPropagation.h.

template<typename GUM_SCALAR>
HashTable< NodeSet, NodeId > gum::LazyPropagation< GUM_SCALAR >::__joint_target_to_clique
private

for each set target, assign a clique in the JT that contains it

Definition at line 306 of file lazyPropagation.h.

template<typename GUM_SCALAR>
JoinTree* gum::LazyPropagation< GUM_SCALAR >::__JT {nullptr}
private

the join (or junction) tree used to answer the last inference query

Definition at line 282 of file lazyPropagation.h.

template<typename GUM_SCALAR>
JunctionTree* gum::LazyPropagation< GUM_SCALAR >::__junctionTree {nullptr}
private

the junction tree to answer the last inference query

Definition at line 285 of file lazyPropagation.h.

template<typename GUM_SCALAR>
ArcProperty< bool > gum::LazyPropagation< GUM_SCALAR >::__messages_computed
private

indicates whether a message (from one clique to another) has been computed

Here, all the messages, computed or not, are put into the property, only the Boolean makes the difference between messages computed and those that were not computed

Definition at line 348 of file lazyPropagation.h.

template<typename GUM_SCALAR>
HashTable< NodeId, NodeId > gum::LazyPropagation< GUM_SCALAR >::__node_to_clique
private

for each node of __graph (~ in the Bayes net), associate an ID in the JT

Definition at line 303 of file lazyPropagation.h.

template<typename GUM_SCALAR>
NodeProperty< const Potential< GUM_SCALAR >* > gum::LazyPropagation< GUM_SCALAR >::__node_to_soft_evidence
private

the soft evidence stored in the cliques per their assigned node in the BN

This variable is useful for method _updateOutdatedBNPotentials: it enables to know which soft evidence should be removed/added into the cliques of the join tree.

Warning
These potentials are not owned by LazyPropagation, they are only referenced by it. Only the cliques that contain evidence are filled in this structure.

Definition at line 357 of file lazyPropagation.h.

template<typename GUM_SCALAR>
Potential< GUM_SCALAR >*(* gum::LazyPropagation< GUM_SCALAR >::__projection_op) (const Potential< GUM_SCALAR > &, const Set< const DiscreteVariable * > &)
inlineprivate

the operator for performing the projections

Definition at line 257 of file lazyPropagation.h.

static INLINE Potential< GUM_SCALAR > * LPNewprojPotential(const Potential< GUM_SCALAR > &t1, const Set< const DiscreteVariable * > &del_vars)
template<typename GUM_SCALAR>
NodeSet gum::LazyPropagation< GUM_SCALAR >::__roots
private

a clique node used as a root in each connected component of __JT

For usual probabilistic inference, roots is useless. This is useful when computing the probability of evidence. In this case, we need to compute this probability in every connected component and multiply them to get the overall probability of evidence.

Warning
__roots should be computed only when evidenceProbability is called.

Definition at line 300 of file lazyPropagation.h.

template<typename GUM_SCALAR>
ArcProperty< __PotentialSet > gum::LazyPropagation< GUM_SCALAR >::__separator_potentials
private

the list of all potentials stored in the separators after inferences

This structure contains all the arcs of the join tree (edges in both directions) whether the arc received any potential or not.

Definition at line 319 of file lazyPropagation.h.

template<typename GUM_SCALAR>
NodeProperty< const Potential< GUM_SCALAR >* > gum::LazyPropagation< GUM_SCALAR >::__target_posteriors
private

the set of single posteriors computed during the last inference

the posteriors are owned by LazyPropagation.

Definition at line 331 of file lazyPropagation.h.

template<typename GUM_SCALAR>
Triangulation* gum::LazyPropagation< GUM_SCALAR >::__triangulation
private

the triangulation class creating the junction tree used for inference

Definition at line 264 of file lazyPropagation.h.

template<typename GUM_SCALAR>
bool gum::LazyPropagation< GUM_SCALAR >::__use_binary_join_tree {true}
private

indicates whether we should transform junction trees into binary join trees

Definition at line 271 of file lazyPropagation.h.


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