aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::VariableElimination< GUM_SCALAR > Class Template Reference

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

#include <variableElimination.h>

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

Public Member Functions

Potential< GUM_SCALAR > evidenceJointImpact (const NodeSet &targets, const NodeSet &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 NodeSet &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
 VariableElimination (const IBayesNet< GUM_SCALAR > *BN, RelevantPotentialsFinderType relevant_type=RelevantPotentialsFinderType::DSEP_BAYESBALL_POTENTIALS, FindBarrenNodesType=FindBarrenNodesType::FIND_BARREN_NODES)
 default constructor More...
 
 VariableElimination (const VariableElimination< GUM_SCALAR > &)=delete
 avoid copy constructors More...
 
VariableElimination< GUM_SCALAR > & operator= (const VariableElimination< GUM_SCALAR > &)=delete
 avoid copy operators More...
 
 ~VariableElimination () 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 JunctionTreejunctionTree (NodeId id)
 returns the join tree used for compute the posterior of node id 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 noexcept final
 returns the list of joint targets More...
 
virtual Size nbrJointTargets () const noexcept final
 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 I (const std::string &Xname, const std::string &Yname)
 Mutual information between X and Y. More...
 
GUM_SCALAR VI (NodeId X, NodeId Y)
 Variation of information between X and Y. More...
 
GUM_SCALAR VI (const std::string &Xname, const std::string &Yname)
 Variation of information between X and Y. More...
 
GUM_SCALAR jointMutualInformation (const NodeSet &targets)
 Mutual information between targets. More...
 
GUM_SCALAR jointMutualInformation (const std::vector< std::string > &targets)
 Mutual information between targets. 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 noexcept final
 returns the number of marginal targets More...
 
virtual const NodeSettargets () const noexcept final
 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...
 
Accessors / Modifiers
virtual const GraphicalModelmodel () 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 model More...
 
virtual bool isInferenceReady () const noexcept final
 returns whether the inference object is in a ready state More...
 
virtual bool isInferenceOutdatedStructure () const noexcept final
 returns whether the inference object is in a OutdatedStructure state More...
 
virtual bool isInferenceOutdatedPotentials () const noexcept final
 returns whether the inference object is in a OutdatedPotential state More...
 
virtual bool isInferenceDone () const noexcept final
 returns whether the inference object is in a InferenceDone 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 noexcept final
 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::OutdatedStructure, StateOfInference::OutdatedPotentials, StateOfInference::ReadyForInference, StateOfInference::Done }
 current state of the inference More...
 

Protected Member Functions

void onStateChanged_ () final
 fired when the stage is changed More...
 
void onEvidenceAdded_ (const NodeId id, bool isHardEvidence) final
 fired after a new evidence is inserted More...
 
void onEvidenceErased_ (const NodeId id, bool isHardEvidence) final
 fired before an evidence is removed More...
 
void onAllEvidenceErased_ (bool contains_hard_evidence) final
 fired before all the evidence are erased More...
 
void onEvidenceChanged_ (const NodeId id, bool hasChangedSoftHard) final
 fired after an evidence is changed, in particular when its status (soft/hard) changes More...
 
void onMarginalTargetAdded_ (const NodeId id) final
 fired after a new single target is inserted More...
 
void onMarginalTargetErased_ (const NodeId id) final
 fired before a single target is removed More...
 
virtual void onModelChanged_ (const GraphicalModel *bn) final
 fired after a new Bayes net has been assigned to the engine 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 updateOutdatedStructure_ () final
 prepares inference when the latter is in OutdatedStructure state More...
 
void updateOutdatedPotentials_ () final
 prepares inference when the latter is in OutdatedPotentials 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...
 
void setTargetedMode_ ()
 
bool isTargetedMode_ () const
 
void setOutdatedStructureState_ ()
 put the inference into an outdated model structure state More...
 
void setOutdatedPotentialsState_ ()
 puts the inference into an OutdatedPotentials state if it is not already in an OutdatedStructure state More...
 
virtual void setState_ (const StateOfInference state) final
 set the state of the inference engine and call the notification onStateChanged_ when necessary (i.e. when the state has effectively changed). More...
 
void setModel_ (const GraphicalModel *model)
 
void setModelDuringConstruction_ (const GraphicalModel *model)
 assigns a model during the inference engine construction More...
 
bool hasNoModel_ () const
 

Detailed Description

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

<agrum/BN/inference/variableElimination.h>

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

Definition at line 68 of file variableElimination.h.

Member Typedef Documentation

◆ _PotentialSet_

template<typename GUM_SCALAR >
typedef Set< const Potential< GUM_SCALAR >* > gum::VariableElimination< GUM_SCALAR >::_PotentialSet_
private

Definition at line 223 of file variableElimination.h.

◆ _PotentialSetIterator_

template<typename GUM_SCALAR >
typedef SetIteratorSafe< const Potential< GUM_SCALAR >* > gum::VariableElimination< GUM_SCALAR >::_PotentialSetIterator_
private

Definition at line 224 of file variableElimination.h.

Member Enumeration Documentation

◆ StateOfInference

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

current state of the inference

graphicalModelInference can be in one of 4 different states:

  • OutdatedStructure: in this state, the inference is fully unprepared to be applied because some events changed the "logical" structure of the model: for instance a node received a hard evidence, which implies that its outgoing arcs can be removed from the model, hence involving a structural change in the model.
  • OutdatedPotentials: in this state, the structure of the model 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.
Enumerator
OutdatedStructure 
OutdatedPotentials 
ReadyForInference 
Done 

Definition at line 106 of file graphicalModelInference.h.

107  {
108  OutdatedStructure,
109  OutdatedPotentials,
110  ReadyForInference,
111  Done
112  };

Constructor & Destructor Documentation

◆ VariableElimination() [1/2]

default constructor

◆ VariableElimination() [2/2]

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

avoid copy constructors

◆ ~VariableElimination()

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

destructor

Member Function Documentation

◆ _collectMessage_()

template<typename GUM_SCALAR >
std::pair< _PotentialSet_, _PotentialSet_ > gum::VariableElimination< GUM_SCALAR >::_collectMessage_ ( NodeId  id,
NodeId  from 
)
private

actually perform the collect phase

◆ _createNewJT_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::_createNewJT_ ( const NodeSet targets)
private

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

◆ _findRelevantPotentialsGetAll_()

template<typename GUM_SCALAR >
void gum::VariableElimination< 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

◆ _findRelevantPotentialsWithdSeparation2_()

template<typename GUM_SCALAR >
void gum::VariableElimination< 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

◆ _findRelevantPotentialsWithdSeparation3_()

template<typename GUM_SCALAR >
void gum::VariableElimination< 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

◆ _findRelevantPotentialsWithdSeparation_()

template<typename GUM_SCALAR >
void gum::VariableElimination< 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

◆ _findRelevantPotentialsXX_()

template<typename GUM_SCALAR >
void gum::VariableElimination< 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

◆ _marginalizeOut_()

template<typename GUM_SCALAR >
_PotentialSet_ gum::VariableElimination< 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

◆ _NodePotentials_()

template<typename GUM_SCALAR >
std::pair< _PotentialSet_, _PotentialSet_ > gum::VariableElimination< GUM_SCALAR >::_NodePotentials_ ( NodeId  node)
private

returns the CPT + evidence of a node projected w.r.t. hard evidence

◆ _produceMessage_()

template<typename GUM_SCALAR >
std::pair< _PotentialSet_, _PotentialSet_ > gum::VariableElimination< GUM_SCALAR >::_produceMessage_ ( NodeId  from_id,
NodeId  to_id,
std::pair< _PotentialSet_, _PotentialSet_ > &&  incoming_messages 
)
private

creates the message sent by clique from_id to clique to_id

◆ _removeBarrenVariables_()

template<typename GUM_SCALAR >
_PotentialSet_ gum::VariableElimination< GUM_SCALAR >::_removeBarrenVariables_ ( _PotentialSet_ pot_list,
Set< const DiscreteVariable * > &  del_vars 
)
private

◆ _setCombinationFunction_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::_setCombinationFunction_ ( Potential< GUM_SCALAR > *(*)(const Potential< GUM_SCALAR > &, const Potential< GUM_SCALAR > &)  comb)
private

sets the operator for performing the combinations

◆ _setProjectionFunction_()

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

sets the operator for performing the projections

◆ addAllTargets()

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

adds all nodes as targets

Definition at line 130 of file marginalTargetedInference_tpl.h.

130  {
131  // check if the node belongs to the Bayesian network
132  if (this->hasNoModel_())
133  GUM_ERROR(NullElement,
134  "No Bayes net has been assigned to the "
135  "inference algorithm");
136 
137 
138  setTargetedMode_(); // does nothing if already in targeted mode
139  for (const auto target: this->BN().dag()) {
140  if (!_targets_.contains(target)) {
141  _targets_.insert(target);
142  onMarginalTargetAdded_(target);
144  }
145  }
146  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual void onMarginalTargetAdded_(const NodeId id)=0
fired after a new marginal target is inserted
NodeSet _targets_
the set of marginal targets
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ addEvidence() [1/8]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 228 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

228  {
230  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
Potential< GUM_SCALAR > _createHardEvidence_(NodeId id, Idx val) const
create the internal structure for a hard evidence
+ Here is the call graph for this function:

◆ addEvidence() [2/8]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 234 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

235  {
236  addEvidence(this->model().idFromName(nodeName), val);
237  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
+ Here is the call graph for this function:

◆ addEvidence() [3/8]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 241 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

242  {
243  addEvidence(id, this->model().variable(id)[label]);
244  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
+ Here is the call graph for this function:

◆ addEvidence() [4/8]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 248 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

249  {
250  NodeId id = this->model().idFromName(nodeName);
251  addEvidence(id, this->model().variable(id)[label]);
252  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ addEvidence() [5/8]

template<typename GUM_SCALAR >
void gum::GraphicalModelInference< 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 256 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

257  {
258  // checks that the evidence is meaningful
259  if (_model_ == nullptr)
260  GUM_ERROR(NullElement,
261  "No Bayes net has been assigned to the "
262  "inference algorithm");
263 
264  if (!_model_->exists(id)) { GUM_ERROR(UndefinedElement, id << " is not a NodeId in the model") }
265 
266  if (_model_->variable(id).domainSize() != vals.size()) {
267  GUM_ERROR(InvalidArgument,
268  "node " << _model_->variable(id)
269  << " and its evidence vector have different sizes.");
270  }
271 
272  Potential< GUM_SCALAR > pot;
273  pot.add(_model_->variable(id));
274  pot.fillWith(vals);
275  addEvidence(std::move(pot));
276  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual Size domainSize() const =0
virtual bool exists(NodeId node) const =0
Return true if this node exists in this graphical model.
const GraphicalModel * _model_
the Bayes net on which we perform inferences
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ addEvidence() [6/8]

template<typename GUM_SCALAR >
void gum::GraphicalModelInference< 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 280 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

281  {
282  addEvidence(this->model().idFromName(nodeName), vals);
283  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
+ Here is the call graph for this function:

◆ addEvidence() [7/8]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 325 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

325  {
326  Potential< GUM_SCALAR > new_pot(pot);
327  addEvidence(std::move(new_pot));
328  }
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:

◆ addEvidence() [8/8]

template<typename GUM_SCALAR >
void gum::GraphicalModelInference< 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 287 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

287  {
288  // check if the potential corresponds to an evidence
289  if (pot.nbrDim() != 1) { GUM_ERROR(InvalidArgument, pot << " is not mono-dimensional.") }
290  if (_model_ == nullptr)
291  GUM_ERROR(NullElement,
292  "No Bayes net has been assigned to the "
293  "inference algorithm");
294 
295  NodeId id = _model_->nodeId(pot.variable(0));
296 
297  if (hasEvidence(id)) {
298  GUM_ERROR(InvalidArgument,
299  " node " << id << " already has an evidence. Please use chgEvidence().");
300  }
301 
302  // check whether we have a hard evidence (and also check whether the
303  // potential only contains 0 (in this case, this will automatically raise
304  // an exception) )
305  Idx val;
306  bool is_hard_evidence = _isHardEvidence_(pot, val);
307 
308  // insert the evidence
309  _evidence_.insert(id,
310  new Potential< GUM_SCALAR >(std::forward< Potential< GUM_SCALAR > >(pot)));
311  if (is_hard_evidence) { // pot is deterministic
312  _hard_evidence_.insert(id, val);
314  } else {
316  }
318  onEvidenceAdded_(id, is_hard_evidence);
319  }
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual void onEvidenceAdded_(const NodeId id, bool isHardEvidence)=0
fired after a new evidence is inserted
NodeProperty< const Potential< GUM_SCALAR > *> _evidence_
the set of evidence entered into the network
NodeProperty< Idx > _hard_evidence_
assign to each node with a hard evidence the index of its observed value
bool _isHardEvidence_(const Potential< GUM_SCALAR > &pot, Idx &val) const
checks whether a potential corresponds to a hard evidence or not
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node src discrete var pointer.
NodeSet _hard_evidence_nodes_
the set of nodes that received hard evidence
NodeSet _soft_evidence_nodes_
the set of nodes that received soft evidence
const GraphicalModel * _model_
the Bayes net on which we perform inferences
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ addJointTarget()

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 111 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

111  {
112  // check if the nodes in the target belong to the Bayesian network
113  if (this->hasNoModel_())
114  GUM_ERROR(NullElement,
115  "No Bayes net has been assigned to the "
116  "inference algorithm");
117 
118  const auto& dag = this->BN().dag();
119  for (const auto node: joint_target) {
120  if (!dag.exists(node)) {
121  GUM_ERROR(UndefinedElement,
122  "at least one one in " << joint_target << " does not belong to the bn");
123  }
124  }
125 
126  // check that the joint_target set does not contain the new target
127  if (_joint_targets_.contains(joint_target)) return;
128 
129  // check if joint_target is a subset of an already existing target
130  for (const auto& target: _joint_targets_) {
131  if (target.isProperSupersetOf(joint_target)) return;
132  }
133 
134  // check if joint_target is not a superset of an already existing target
135  // in this case, we need to remove old existing target
136  for (auto iter = _joint_targets_.beginSafe(); iter != _joint_targets_.endSafe(); ++iter) {
137  if (iter->isProperSubsetOf(joint_target)) eraseJointTarget(*iter);
138  }
139 
140  this->setTargetedMode_(); // does nothing if already in targeted mode
141  _joint_targets_.insert(joint_target);
142  onJointTargetAdded_(joint_target);
144  }
virtual void onJointTargetAdded_(const NodeSet &set)=0
fired after a new joint target is inserted
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
Set< NodeSet > _joint_targets_
the set of joint targets
virtual void eraseJointTarget(const NodeSet &joint_target) final
removes an existing joint target
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:51
+ Here is the call graph for this function:

◆ addListOfEvidence()

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 333 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

334  {
335  for (const auto pot: potlist)
336  addEvidence(*pot);
337  }
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:

◆ addSetOfEvidence()

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 342 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

343  {
344  for (const auto pot: potset)
345  addEvidence(*pot);
346  }
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:

◆ addTarget() [1/2]

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 107 of file marginalTargetedInference_tpl.h.

107  {
108  // check if the node belongs to the Bayesian network
109  if (this->hasNoModel_())
110  GUM_ERROR(NullElement,
111  "No Bayes net has been assigned to the "
112  "inference algorithm");
113 
114  if (!this->BN().dag().exists(target)) {
115  GUM_ERROR(UndefinedElement, target << " is not a NodeId in the bn")
116  }
117 
118  setTargetedMode_(); // does nothing if already in targeted mode
119  // add the new target
120  if (!_targets_.contains(target)) {
121  _targets_.insert(target);
122  onMarginalTargetAdded_(target);
124  }
125  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual void onMarginalTargetAdded_(const NodeId id)=0
fired after a new marginal target is inserted
NodeSet _targets_
the set of marginal targets
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ addTarget() [2/2]

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 151 of file marginalTargetedInference_tpl.h.

151  {
152  // check if the node belongs to the Bayesian network
153  if (this->hasNoModel_())
154  GUM_ERROR(NullElement,
155  "No Bayes net has been assigned to the "
156  "inference algorithm");
157 
158  addTarget(this->BN().idFromName(nodeName));
159  }
virtual void addTarget(NodeId target) final
Add a marginal target to the list of 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:51

◆ BN()

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 57 of file BayesNetInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

57  {
58  return static_cast< const IBayesNet< GUM_SCALAR >& >(this->model());
59  }
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
+ Here is the call graph for this function:

◆ chgEvidence() [1/7]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 402 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

402  {
404  }
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:

◆ chgEvidence() [2/7]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 408 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

409  {
410  chgEvidence(this->model().idFromName(nodeName), val);
411  }
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
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:

◆ chgEvidence() [3/7]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 415 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

416  {
417  chgEvidence(id, this->model().variable(id)[label]);
418  }
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
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:

◆ chgEvidence() [4/7]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 422 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

423  {
424  NodeId id = this->model().idFromName(nodeName);
425  chgEvidence(id, this->model().variable(id)[label]);
426  }
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ chgEvidence() [5/7]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 431 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

432  {
433  // check whether this corresponds to an evidence
434  if (_model_ == nullptr)
435  GUM_ERROR(NullElement,
436  "No Bayes net has been assigned to the "
437  "inference algorithm");
438 
439  if (!_model_->exists(id)) { GUM_ERROR(UndefinedElement, id << " is not a NodeId in the model") }
440 
441  if (_model_->variable(id).domainSize() != vals.size()) {
442  GUM_ERROR(InvalidArgument,
443  "node " << _model_->variable(id) << " and its evidence have different sizes.");
444  }
445 
446  // create the potential corresponding to vals
447  Potential< GUM_SCALAR > pot;
448  pot.add(_model_->variable(id));
449  pot.fillWith(vals);
450  chgEvidence(pot);
451  }
virtual Size domainSize() const =0
virtual bool exists(NodeId node) const =0
Return true if this node exists in this graphical model.
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
const GraphicalModel * _model_
the Bayes net on which we perform inferences
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ chgEvidence() [6/7]

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 456 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

457  {
458  chgEvidence(this->model().idFromName(nodeName), vals);
459  }
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
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:

◆ chgEvidence() [7/7]

template<typename GUM_SCALAR >
void gum::GraphicalModelInference< 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 464 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

464  {
465  // check if the potential corresponds to an evidence
466  if (pot.nbrDim() != 1) {
467  GUM_ERROR(InvalidArgument, pot << " is not a mono-dimensional potential.")
468  }
469  if (_model_ == nullptr)
470  GUM_ERROR(NullElement,
471  "No Bayes net has been assigned to the "
472  "inference algorithm");
473 
474  NodeId id = _model_->nodeId(pot.variable(0));
475 
476  if (!hasEvidence(id)) {
477  GUM_ERROR(InvalidArgument, id << " has no evidence. Please use addEvidence().")
478  }
479 
480  // check whether we have a hard evidence (and also check whether the
481  // potential only contains 0 (in this case, this will automatically raise
482  // an exception) )
483  Idx val;
484  bool is_hard_evidence = _isHardEvidence_(pot, val);
485 
486  // modify the evidence already stored
487  const Potential< GUM_SCALAR >* localPot = _evidence_[id];
488  Instantiation I(pot);
489  for (I.setFirst(); !I.end(); I.inc()) {
490  localPot->set(I, pot[I]);
491  }
492 
493  // the inference state will be different
494  // whether evidence change from Hard to Soft or not.
495  bool hasChangedSoftHard = false;
496 
497  if (is_hard_evidence) {
498  if (!hasHardEvidence(id)) {
499  hasChangedSoftHard = true;
500  _hard_evidence_.insert(id, val);
503  } else {
504  _hard_evidence_[id] = val;
505  }
506  } else {
507  if (hasHardEvidence(id)) { // evidence was hard
508  _hard_evidence_.erase(id);
511  hasChangedSoftHard = true;
512  }
513  }
514 
515  if (hasChangedSoftHard) {
517  } else {
519  }
520 
521  onEvidenceChanged_(id, hasChangedSoftHard);
522  }
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
NodeProperty< const Potential< GUM_SCALAR > *> _evidence_
the set of evidence entered into the network
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
NodeProperty< Idx > _hard_evidence_
assign to each node with a hard evidence the index of its observed value
bool _isHardEvidence_(const Potential< GUM_SCALAR > &pot, Idx &val) const
checks whether a potential corresponds to a hard evidence or not
virtual void onEvidenceChanged_(const NodeId id, bool hasChangedSoftHard)=0
fired after an evidence is changed, in particular when its status (soft/hard) changes ...
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node src discrete var pointer.
NodeSet _hard_evidence_nodes_
the set of nodes that received hard evidence
NodeSet _soft_evidence_nodes_
the set of nodes that received soft evidence
const GraphicalModel * _model_
the Bayes net on which we perform inferences
virtual bool isInferenceOutdatedStructure() const noexcept final
returns whether the inference object is in a OutdatedStructure state
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ clear()

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

clears all the data structures allocated for the last inference

Reimplemented in gum::ShaferShenoyLIMIDInference< GUM_SCALAR >.

Definition at line 139 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

139  {
142  }
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:

◆ domainSizes()

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

get the domain sizes of the random variables of the model

Definition at line 159 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

159  {
160  return _domain_sizes_;
161  }
NodeProperty< Size > _domain_sizes_
the domain sizes of the random variables
+ Here is the call graph for this function:

◆ eraseAllEvidence()

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< GUM_SCALAR >::eraseAllEvidence ( )
finalvirtualinherited

removes all the evidence entered into the network

Definition at line 553 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

553  {
554  bool has_hard_evidence = !_hard_evidence_.empty();
555  this->onAllEvidenceErased_(has_hard_evidence);
556 
557  for (const auto& pair: _evidence_) {
558  if (pair.second != nullptr) { delete (pair.second); }
559  }
560 
561  _evidence_.clear();
562  _hard_evidence_.clear();
565 
566  if (has_hard_evidence) {
568  } else {
570  }
571  }
virtual void onAllEvidenceErased_(bool contains_hard_evidence)=0
fired before all the evidence are erased
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
NodeProperty< const Potential< GUM_SCALAR > *> _evidence_
the set of evidence entered into the network
NodeProperty< Idx > _hard_evidence_
assign to each node with a hard evidence the index of its observed value
NodeSet _hard_evidence_nodes_
the set of nodes that received hard evidence
NodeSet _soft_evidence_nodes_
the set of nodes that received soft evidence
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
virtual bool isInferenceOutdatedStructure() const noexcept final
returns whether the inference object is in a OutdatedStructure state
+ Here is the call graph for this function:

◆ eraseAllJointTargets()

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

Clear all previously defined joint targets.

Definition at line 91 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

91  {
92  if (_joint_targets_.size() > 0) {
93  // we already are in target mode. So no this->setTargetedMode_(); is needed
95  _joint_targets_.clear();
97  }
98  }
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
Set< NodeSet > _joint_targets_
the set of joint targets
virtual void onAllJointTargetsErased_()=0
fired before a all the joint targets are removed
+ Here is the call graph for this function:

◆ eraseAllMarginalTargets()

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

Clear all the previously defined marginal targets.

Definition at line 84 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

84  {
86  }
virtual void eraseAllTargets()
Clear all previously defined targets.
+ Here is the call graph for this function:

◆ eraseAllTargets()

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 103 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

103  {
106  }
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:

◆ eraseEvidence() [1/2]

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

removed the evidence, if any, corresponding to node id

Definition at line 527 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

527  {
528  if (hasEvidence(id)) {
529  if (hasHardEvidence(id)) {
530  onEvidenceErased_(id, true);
531  _hard_evidence_.erase(id);
534  } else {
535  onEvidenceErased_(id, false);
538  }
539 
540  delete (_evidence_[id]);
541  _evidence_.erase(id);
542  }
543  }
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
NodeProperty< const Potential< GUM_SCALAR > *> _evidence_
the set of evidence entered into the network
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
NodeProperty< Idx > _hard_evidence_
assign to each node with a hard evidence the index of its observed value
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 void onEvidenceErased_(const NodeId id, bool isHardEvidence)=0
fired before an evidence is removed
NodeSet _soft_evidence_nodes_
the set of nodes that received soft evidence
virtual bool isInferenceOutdatedStructure() const noexcept final
returns whether the inference object is in a OutdatedStructure state
+ Here is the call graph for this function:

◆ eraseEvidence() [2/2]

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

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

Definition at line 546 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

546  {
547  eraseEvidence(this->model().idFromName(nodeName));
548  }
virtual const GraphicalModel & model() 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:

◆ eraseJointTarget()

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 149 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

149  {
150  // check if the nodes in the target belong to the Bayesian network
151  if (this->hasNoModel_())
152  GUM_ERROR(NullElement,
153  "No Bayes net has been assigned to the "
154  "inference algorithm");
155 
156  const auto& dag = this->BN().dag();
157  for (const auto node: joint_target) {
158  if (!dag.exists(node)) {
159  GUM_ERROR(UndefinedElement,
160  "at least one one in " << joint_target << " does not belong to the bn");
161  }
162  }
163 
164  // check that the joint_target set does not contain the new target
165  if (_joint_targets_.contains(joint_target)) {
166  // note that we have to be in target mode when we are here
167  // so, no this->setTargetedMode_(); is necessary
168  onJointTargetErased_(joint_target);
169  _joint_targets_.erase(joint_target);
171  }
172  }
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
Set< NodeSet > _joint_targets_
the set of joint targets
virtual void onJointTargetErased_(const NodeSet &set)=0
fired before a joint target is removed
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:51
+ Here is the call graph for this function:

◆ eraseTarget() [1/2]

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 164 of file marginalTargetedInference_tpl.h.

164  {
165  // check if the node belongs to the Bayesian network
166  if (this->hasNoModel_())
167  GUM_ERROR(NullElement,
168  "No Bayes net has been assigned to the "
169  "inference algorithm");
170 
171  if (!this->BN().dag().exists(target)) {
172  GUM_ERROR(UndefinedElement, target << " is not a NodeId in the bn")
173  }
174 
175 
176  if (_targets_.contains(target)) {
177  _targeted_mode_ = true; // we do not use setTargetedMode_ because we do not
178  // want to clear the targets
179  onMarginalTargetErased_(target);
180  _targets_.erase(target);
182  }
183  }
bool _targeted_mode_
whether the actual targets are default
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
NodeSet _targets_
the set of marginal targets
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual void onMarginalTargetErased_(const NodeId id)=0
fired before a marginal target is removed
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ eraseTarget() [2/2]

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 188 of file marginalTargetedInference_tpl.h.

188  {
189  // check if the node belongs to the Bayesian network
190  if (this->hasNoModel_())
191  GUM_ERROR(NullElement,
192  "No Bayes net has been assigned to the "
193  "inference algorithm");
194 
195  eraseTarget(this->BN().idFromName(nodeName));
196  }
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target
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:51

◆ evidence()

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

returns the set of evidence

Definition at line 605 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

605  {
606  return _evidence_;
607  }
NodeProperty< const Potential< GUM_SCALAR > *> _evidence_
the set of evidence entered into the network
+ Here is the call graph for this function:

◆ evidenceImpact() [1/2]

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact ( NodeId  target,
const NodeSet 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 268 of file marginalTargetedInference_tpl.h.

268  {
269  const auto& vtarget = this->BN().variable(target);
270 
271  if (evs.contains(target)) {
272  GUM_ERROR(InvalidArgument,
273  "Target <" << vtarget.name() << "> (" << target << ") can not be in evs (" << evs
274  << ").");
275  }
276  auto condset = this->BN().minimalCondSet(target, evs);
277 
278  Potential< GUM_SCALAR > res;
279  this->eraseAllTargets();
280  this->eraseAllEvidence();
281  res.add(this->BN().variable(target));
282  this->addTarget(target);
283  for (const auto& n: condset) {
284  res.add(this->BN().variable(n));
285  this->addEvidence(n, 0);
286  }
287 
288  Instantiation inst(res);
289  for (inst.setFirst(); !inst.end(); inst.incNotVar(vtarget)) {
290  // inferring
291  for (const auto& n: condset)
292  this->chgEvidence(n, inst.val(this->BN().variable(n)));
293  this->makeInference();
294  // populate res
295  for (inst.setFirstVar(vtarget); !inst.end(); inst.incVar(vtarget)) {
296  res.set(inst, this->posterior(target)[inst]);
297  }
298  inst.setFirstVar(vtarget); // remove inst.end() flag
299  }
300 
301  return res;
302  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.
virtual const Potential< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
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.
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ evidenceImpact() [2/2]

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 306 of file marginalTargetedInference_tpl.h.

308  {
309  const auto& bn = this->BN();
310  return evidenceImpact(bn.idFromName(target), bn.nodeset(evs));
311  }
Potential< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet &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.

◆ evidenceJointImpact() [1/2]

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact ( const NodeSet targets,
const NodeSet 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 NodeSet of the targeted variables
evsthe NodeSet of observed variables
Returns
a Potential

Definition at line 322 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

323  {
324  if (!(evs * targets).empty()) {
325  GUM_ERROR(InvalidArgument,
326  "Targets (" << targets << ") can not intersect evs (" << evs << ").");
327  }
328  auto condset = this->BN().minimalCondSet(targets, evs);
329 
330  this->eraseAllTargets();
331  this->eraseAllEvidence();
332 
333  Instantiation iTarget;
334  Potential< GUM_SCALAR > res;
335  for (const auto& target: targets) {
336  res.add(this->BN().variable(target));
337  iTarget.add(this->BN().variable(target));
338  }
339  this->addJointTarget(targets);
340 
341  for (const auto& n: condset) {
342  res.add(this->BN().variable(n));
343  this->addEvidence(n, 0);
344  }
345 
346  Instantiation inst(res);
347  for (inst.setFirstOut(iTarget); !inst.end(); inst.incOut(iTarget)) {
348  // inferring
349  for (const auto& n: condset)
350  this->chgEvidence(n, inst.val(this->BN().variable(n)));
351  this->makeInference();
352  // populate res
353  for (inst.setFirstIn(iTarget); !inst.end(); inst.incIn(iTarget)) {
354  res.set(inst, this->jointPosterior(targets)[inst]);
355  }
356  inst.setFirstIn(iTarget); // remove inst.end() flag
357  }
358 
359  return res;
360  }
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...
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const Potential< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ evidenceJointImpact() [2/2]

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 targeted variables
evsthe vector of std::string of observed variables
Returns
a Potential

Definition at line 363 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

365  {
366  const auto& bn = this->BN();
367  return evidenceJointImpact(bn.nodeset(targets), bn.nodeset(evs));
368  }
Potential< GUM_SCALAR > evidenceJointImpact(const NodeSet &targets, const NodeSet &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:

◆ H() [1/2]

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 253 of file marginalTargetedInference_tpl.h.

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

◆ H() [2/2]

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 261 of file marginalTargetedInference_tpl.h.

261  {
262  return H(this->BN().idFromName(nodeName));
263  }
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.

◆ hardEvidence()

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

indicate for each node with hard evidence which value it took

Definition at line 597 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

597  {
598  return _hard_evidence_;
599  }
NodeProperty< Idx > _hard_evidence_
assign to each node with a hard evidence the index of its observed value
+ Here is the call graph for this function:

◆ hardEvidenceNodes()

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

returns the set of nodes with hard evidence

the set of nodes that received hard evidence

Definition at line 619 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

619  {
620  return _hard_evidence_nodes_;
621  }
NodeSet _hard_evidence_nodes_
the set of nodes that received hard evidence
+ Here is the call graph for this function:

◆ hasEvidence() [1/3]

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

indicates whether some node(s) have received evidence

Definition at line 351 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

351  {
352  return !_evidence_.empty();
353  }
NodeProperty< const Potential< GUM_SCALAR > *> _evidence_
the set of evidence entered into the network
+ Here is the call graph for this function:

◆ hasEvidence() [2/3]

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

indicates whether node id has received an evidence

Definition at line 358 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

358  {
359  return _evidence_.exists(id);
360  }
NodeProperty< const Potential< GUM_SCALAR > *> _evidence_
the set of evidence entered into the network
+ Here is the call graph for this function:

◆ hasEvidence() [3/3]

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

indicates whether node id has received an evidence

Definition at line 380 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

380  {
381  return hasEvidence(this->model().idFromName(nodeName));
382  }
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
+ Here is the call graph for this function:

◆ hasHardEvidence() [1/2]

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

indicates whether node id has received a hard evidence

Definition at line 365 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

365  {
366  return _hard_evidence_nodes_.exists(id);
367  }
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:600
NodeSet _hard_evidence_nodes_
the set of nodes that received hard evidence
+ Here is the call graph for this function:

◆ hasHardEvidence() [2/2]

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

indicates whether node id has received a hard evidence

Definition at line 388 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

388  {
389  return hasHardEvidence(this->model().idFromName(nodeName));
390  }
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
+ Here is the call graph for this function:

◆ hasNoModel_()

template<typename GUM_SCALAR >
bool gum::GraphicalModelInference< GUM_SCALAR >::hasNoModel_ ( ) const
inlineprotectedinherited

Definition at line 527 of file graphicalModelInference.h.

527 { return _model_ == nullptr; };
const GraphicalModel * _model_
the Bayes net on which we perform inferences

◆ hasSoftEvidence() [1/2]

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

indicates whether node id has received a soft evidence

Definition at line 372 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

372  {
373  return _soft_evidence_nodes_.exists(id);
374  }
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:600
NodeSet _soft_evidence_nodes_
the set of nodes that received soft evidence
+ Here is the call graph for this function:

◆ hasSoftEvidence() [2/2]

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

indicates whether node id has received a soft evidence

Definition at line 396 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

396  {
397  return hasSoftEvidence(this->model().idFromName(nodeName));
398  }
virtual bool hasSoftEvidence(NodeId id) const final
indicates whether node id has received a soft evidence
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
+ Here is the call graph for this function:

◆ I() [1/2]

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 266 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

266  {
267  Potential< GUM_SCALAR > pX, pY, *pXY = nullptr;
268  if (X == Y) { GUM_ERROR(OperationNotAllowed, "Mutual Information I(X,Y) with X==Y") }
269 
270  try {
271  // here use unnormalized joint posterior rather than just posterior
272  // to avoid saving the posterior in the cache of the inference engines
273  // like LazyPropagation or SahferShenoy.
274  pXY = this->unnormalizedJointPosterior_({X, Y});
275  pXY->normalize();
276  pX = pXY->margSumOut({&(this->BN().variable(Y))});
277  pY = pXY->margSumOut({&(this->BN().variable(X))});
278  } catch (...) {
279  if (pXY != nullptr) { delete pXY; }
280  throw;
281  }
282 
283  Instantiation i(*pXY);
284  auto res = (GUM_SCALAR)0;
285 
286  for (i.setFirst(); !i.end(); ++i) {
287  GUM_SCALAR vXY = (*pXY)[i];
288  GUM_SCALAR vX = pX[i];
289  GUM_SCALAR vY = pY[i];
290 
291  if (vXY > (GUM_SCALAR)0) {
292  if (vX == (GUM_SCALAR)0 || vY == (GUM_SCALAR)0) {
293  GUM_ERROR(OperationNotAllowed,
294  "Mutual Information (X,Y) with P(X)=0 or P(Y)=0 "
295  "and P(X,Y)>0");
296  }
297 
298  res += vXY * (std::log2(vXY) - std::log2(vX) - std::log2(vY));
299  }
300  }
301 
302  delete pXY;
303 
304  return res;
305  }
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:51
Potential< GUM_SCALAR > log2(const Potential< GUM_SCALAR > &arg)
Definition: potential.h:590
+ Here is the call graph for this function:

◆ I() [2/2]

template<typename GUM_SCALAR >
GUM_SCALAR gum::JointTargetedInference< GUM_SCALAR >::I ( const std::string &  Xname,
const std::string &  Yname 
)
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 247 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

248  {
249  return I(this->BN().idFromName(Xname), this->BN().idFromName(Yname));
250  }
GUM_SCALAR I(NodeId X, NodeId Y)
Mutual information between X and Y.
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:

◆ isInferenceDone()

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

returns whether the inference object is in a InferenceDone 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 84 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

84  {
85  return (_state_ == StateOfInference::Done);
86  }
StateOfInference _state_
the current state of the inference (outdated/ready/done)
+ Here is the call graph for this function:

◆ isInferenceOutdatedPotentials()

template<typename GUM_SCALAR >
INLINE bool gum::GraphicalModelInference< GUM_SCALAR >::isInferenceOutdatedPotentials ( ) const
finalvirtualnoexceptinherited

returns whether the inference object is in a OutdatedPotential state

Definition at line 79 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

79  {
81  }
StateOfInference _state_
the current state of the inference (outdated/ready/done)
+ Here is the call graph for this function:

◆ isInferenceOutdatedStructure()

template<typename GUM_SCALAR >
INLINE bool gum::GraphicalModelInference< GUM_SCALAR >::isInferenceOutdatedStructure ( ) const
finalvirtualnoexceptinherited

returns whether the inference object is in a OutdatedStructure state

Definition at line 73 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

73  {
75  }
StateOfInference _state_
the current state of the inference (outdated/ready/done)
+ Here is the call graph for this function:

◆ isInferenceReady()

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

returns whether the inference object is in a ready state

Definition at line 68 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

68  {
70  }
StateOfInference _state_
the current state of the inference (outdated/ready/done)
+ Here is the call graph for this function:

◆ isJointTarget()

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 67 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

67  {
68  if (this->hasNoModel_())
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)) { GUM_ERROR(UndefinedElement, var << " is not a NodeId in the bn") }
76  }
77 
78  return _joint_targets_.contains(vars);
79  }
Set< NodeSet > _joint_targets_
the set of joint 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:51
+ Here is the call graph for this function:

◆ isTarget() [1/2]

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.

73  {
74  // check that the variable belongs to the bn
75  if (this->hasNoModel_())
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  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
NodeSet _targets_
the set of marginal 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:51

◆ isTarget() [2/2]

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.

88  {
89  return isTarget(this->BN().idFromName(nodeName));
90  }
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

◆ isTargetedMode_()

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

Definition at line 315 of file marginalTargetedInference_tpl.h.

315  {
316  return _targeted_mode_;
317  }
bool _targeted_mode_
whether the actual targets are default

◆ jointMutualInformation() [1/2]

template<typename GUM_SCALAR >
GUM_SCALAR gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation ( const NodeSet targets)
inherited

Mutual information between targets.

See also
https://en.wikipedia.org/wiki/Interaction_information
Parameters
targetsthe NodeSet of the targeted variables

Definition at line 372 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

372  {
373  const auto& bn = this->BN();
374  const Size siz = targets.size();
375  if (siz <= 1) {
376  GUM_ERROR(InvalidArgument,
377  "jointMutualInformation needs at least 2 variables (targets=" << targets << ")");
378  }
379 
380  this->eraseAllTargets();
381  this->eraseAllEvidence();
382  this->addJointTarget(targets);
383  this->makeInference();
384  const auto po = this->jointPosterior(targets);
385 
386  gum::Instantiation caracteristic;
387  gum::Instantiation variables;
388  for (const auto nod: targets) {
389  const auto& var = bn.variable(nod);
390  auto pv = new gum::RangeVariable(var.name(), "", 0, 1);
391  caracteristic.add(*pv);
392  variables.add(var);
393  }
394 
395  Set< const DiscreteVariable* > sov;
396 
397  const GUM_SCALAR start = (siz % 2 == 0) ? GUM_SCALAR(-1.0) : GUM_SCALAR(1.0);
398  GUM_SCALAR sign;
399  GUM_SCALAR res = GUM_SCALAR(0.0);
400 
401  caracteristic.setFirst();
402  for (caracteristic.inc(); !caracteristic.end(); caracteristic.inc()) {
403  sov.clear();
404  sign = start;
405  for (Idx i = 0; i < caracteristic.nbrDim(); i++) {
406  if (caracteristic.val(i) == 1) {
407  sign = -sign;
408  sov.insert(&variables.variable(i));
409  }
410  }
411  res += sign * po.margSumIn(sov).entropy();
412  }
413 
414  for (Idx i = 0; i < caracteristic.nbrDim(); i++) {
415  delete &caracteristic.variable(i);
416  }
417 
418  return res;
419  }
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...
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Idx val(Idx i) const
Returns the current value of the variable at position i.
void inc()
Operator increment.
virtual const Potential< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
Defines a discrete random variable over an integer interval.
Definition: rangeVariable.h:53
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:82
void setFirst()
Assign the first values to the tuple of the Instantiation.
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:694
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
bool end() const
Returns true if the Instantiation reached the end.
+ Here is the call graph for this function:

◆ jointMutualInformation() [2/2]

template<typename GUM_SCALAR >
GUM_SCALAR gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation ( const std::vector< std::string > &  targets)
inherited

Mutual information between targets.

See also
https://en.wikipedia.org/wiki/Interaction_information
Parameters
targetsthe vector of std::string of the targeted variables

Definition at line 422 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

423  {
424  return jointMutualInformation(this->BN().ids(targets));
425  }
GUM_SCALAR jointMutualInformation(const NodeSet &targets)
Mutual information between targets.
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:

◆ jointPosterior()

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 195 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

195  {
196  // try to get the smallest set of targets that contains "nodes"
197  NodeSet set;
198  bool found_exact_target = false;
199 
200  if (_joint_targets_.contains(nodes)) {
201  set = nodes;
202  found_exact_target = true;
203  } else {
204  for (const auto& target: _joint_targets_) {
205  if (nodes.isProperSubsetOf(target)) {
206  set = target;
207  break;
208  }
209  }
210  }
211 
212  if (set.empty()) {
213  GUM_ERROR(UndefinedElement,
214  " no joint target containing " << nodes << " could be found among "
215  << _joint_targets_);
216  }
217 
218  if (!this->isInferenceDone()) { this->makeInference(); }
219 
220  if (found_exact_target)
221  return jointPosterior_(nodes);
222  else
223  return jointPosterior_(nodes, set);
224  }
Set< NodeSet > _joint_targets_
the set of joint targets
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual const Potential< GUM_SCALAR > & jointPosterior_(const NodeSet &set)=0
asks derived classes for the joint posterior of a declared target set
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ jointPosterior_() [1/2]

template<typename GUM_SCALAR >
const Potential< GUM_SCALAR >& gum::VariableElimination< 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 >.

◆ jointPosterior_() [2/2]

template<typename GUM_SCALAR >
const Potential< GUM_SCALAR >& gum::VariableElimination< 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 >.

◆ jointTargets()

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 177 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

177  {
178  return _joint_targets_;
179  }
Set< NodeSet > _joint_targets_
the set of joint targets
+ Here is the call graph for this function:

◆ junctionTree()

template<typename GUM_SCALAR >
const JunctionTree* gum::VariableElimination< GUM_SCALAR >::junctionTree ( NodeId  id)

returns the join tree used for compute the posterior of node id

◆ makeInference()

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< 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 664 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

664  {
665  if (isInferenceDone()) { return; }
666 
667  if (!isInferenceReady()) { prepareInference(); }
668 
669  makeInference_();
670 
672  }
virtual void prepareInference() final
prepare the internal inference structures for the next inference
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
virtual void makeInference_()=0
called when the inference has to be performed effectively
virtual bool isInferenceReady() const noexcept final
returns whether the inference object is in a ready state
+ Here is the call graph for this function:

◆ makeInference_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::makeInference_ ( )
finalprotectedvirtual

called when the inference has to be performed effectively

Once the inference is done, fillPosterior_ can be called.

Implements gum::GraphicalModelInference< GUM_SCALAR >.

◆ model()

template<typename GUM_SCALAR >
INLINE const GraphicalModel & gum::GraphicalModelInference< GUM_SCALAR >::model ( ) 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 107 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

107  {
108  if (_model_ == nullptr)
109  GUM_ERROR(UndefinedElement,
110  "No Bayes net has been assigned to "
111  "the inference algorithm.");
112  return *_model_;
113  }
const GraphicalModel * _model_
the Bayes net on which we perform inferences
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ nbrEvidence()

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

returns the number of evidence entered into the Bayesian network

Definition at line 576 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

576  {
577  return _evidence_.size();
578  }
NodeProperty< const Potential< GUM_SCALAR > *> _evidence_
the set of evidence entered into the network
+ Here is the call graph for this function:

◆ nbrHardEvidence()

template<typename GUM_SCALAR >
INLINE Size gum::GraphicalModelInference< GUM_SCALAR >::nbrHardEvidence ( ) const
finalvirtualinherited

returns the number of hard evidence entered into the Bayesian network

Definition at line 583 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

583  {
584  return _hard_evidence_nodes_.size();
585  }
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:694
+ Here is the call graph for this function:

◆ nbrJointTargets()

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 183 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

183  {
184  return _joint_targets_.size();
185  }
Set< NodeSet > _joint_targets_
the set of joint targets
+ Here is the call graph for this function:

◆ nbrSoftEvidence()

template<typename GUM_SCALAR >
INLINE Size gum::GraphicalModelInference< GUM_SCALAR >::nbrSoftEvidence ( ) const
finalvirtualinherited

returns the number of soft evidence entered into the Bayesian network

Definition at line 590 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

590  {
591  return _soft_evidence_nodes_.size();
592  }
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:694
+ Here is the call graph for this function:

◆ nbrTargets()

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

returns the number of marginal targets

Definition at line 207 of file marginalTargetedInference_tpl.h.

207  {
208  return _targets_.size();
209  }
NodeSet _targets_
the set of marginal targets
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:694

◆ onAllEvidenceErased_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onAllEvidenceErased_ ( bool  contains_hard_evidence)
finalprotectedvirtual

fired before all the evidence are erased

Implements gum::GraphicalModelInference< GUM_SCALAR >.

◆ onAllJointTargetsErased_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onAllJointTargetsErased_ ( )
finalprotectedvirtual

fired before a all the joint targets are removed

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ onAllMarginalTargetsAdded_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onAllMarginalTargetsAdded_ ( )
finalprotectedvirtual

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

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

◆ onAllMarginalTargetsErased_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onAllMarginalTargetsErased_ ( )
finalprotectedvirtual

fired before a all the single targets are removed

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

◆ onAllTargetsErased_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onAllTargetsErased_ ( )
finalprotectedvirtual

fired before a all single and joint_targets are removed

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ onEvidenceAdded_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onEvidenceAdded_ ( const NodeId  id,
bool  isHardEvidence 
)
finalprotectedvirtual

fired after a new evidence is inserted

Implements gum::GraphicalModelInference< GUM_SCALAR >.

◆ onEvidenceChanged_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onEvidenceChanged_ ( const 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::GraphicalModelInference< GUM_SCALAR >.

◆ onEvidenceErased_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onEvidenceErased_ ( const NodeId  id,
bool  isHardEvidence 
)
finalprotectedvirtual

fired before an evidence is removed

Implements gum::GraphicalModelInference< GUM_SCALAR >.

◆ onJointTargetAdded_()

template<typename GUM_SCALAR >
void gum::VariableElimination< 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 >.

◆ onJointTargetErased_()

template<typename GUM_SCALAR >
void gum::VariableElimination< 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 >.

◆ onMarginalTargetAdded_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onMarginalTargetAdded_ ( const NodeId  id)
finalprotectedvirtual

fired after a new single target is inserted

Parameters
idThe target variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

◆ onMarginalTargetErased_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onMarginalTargetErased_ ( const NodeId  id)
finalprotectedvirtual

fired before a single target is removed

Parameters
idThe target variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

◆ onModelChanged_()

template<typename GUM_SCALAR >
virtual void gum::VariableElimination< GUM_SCALAR >::onModelChanged_ ( const GraphicalModel bn)
finalprotectedvirtual

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

Reimplemented from gum::JointTargetedInference< GUM_SCALAR >.

◆ onStateChanged_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::onStateChanged_ ( )
inlinefinalprotectedvirtual

fired when the stage is changed

Implements gum::GraphicalModelInference< GUM_SCALAR >.

Definition at line 128 of file variableElimination.h.

128 {};

◆ operator=()

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

avoid copy operators

◆ posterior() [1/2]

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 229 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

229  {
230  if (this->isTarget(node))
232  else
233  return jointPosterior(NodeSet{node});
234  }
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:

◆ posterior() [2/2]

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 239 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

239  {
240  return posterior(this->BN().idFromName(nodeName));
241  }
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:

◆ posterior_()

template<typename GUM_SCALAR >
const Potential< GUM_SCALAR >& gum::VariableElimination< GUM_SCALAR >::posterior_ ( NodeId  id)
finalprotectedvirtual

returns the posterior of a given variable

Parameters
idThe variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

◆ prepareInference()

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

prepare the internal inference structures for the next inference

Definition at line 645 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

645  {
646  if (isInferenceReady() || isInferenceDone()) { return; }
647 
648  if (_model_ == nullptr)
649  GUM_ERROR(NullElement,
650  "No model been assigned to the "
651  "inference algorithm");
652 
655  else
657 
659  }
virtual void updateOutdatedPotentials_()=0
prepares inference when the latter is in OutdatedPotentials state
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual void updateOutdatedStructure_()=0
prepares inference when the latter is in OutdatedStructure state
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
StateOfInference _state_
the current state of the inference (outdated/ready/done)
virtual bool isInferenceReady() const noexcept final
returns whether the inference object is in a ready state
const GraphicalModel * _model_
the Bayes net on which we perform inferences
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ setBN()

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 64 of file BayesNetInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

64  {
65  this->setModel_(bn);
66  }
void setModel_(const GraphicalModel *model)
+ Here is the call graph for this function:

◆ setFindBarrenNodesType()

template<typename GUM_SCALAR >
void gum::VariableElimination< 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).

◆ setModel_()

template<typename GUM_SCALAR >
void gum::GraphicalModelInference< GUM_SCALAR >::setModel_ ( const GraphicalModel model)
protectedinherited

Definition at line 118 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

118  {
119  clear();
120  _model_ = model;
124  }
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
void _computeDomainSizes_()
computes the domain sizes of the random variables
virtual void onModelChanged_(const GraphicalModel *model)=0
fired after a new Bayes net has been assigned to the engine
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual void clear()
clears all the data structures allocated for the last inference
const GraphicalModel * _model_
the Bayes net on which we perform inferences
+ Here is the call graph for this function:

◆ setModelDuringConstruction_()

template<typename GUM_SCALAR >
void gum::GraphicalModelInference< GUM_SCALAR >::setModelDuringConstruction_ ( const GraphicalModel model)
protectedinherited

assigns a model during the inference engine construction

Definition at line 129 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

130  {
131  _model_ = model;
134  }
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
void _computeDomainSizes_()
computes the domain sizes of the random variables
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
const GraphicalModel * _model_
the Bayes net on which we perform inferences
+ Here is the call graph for this function:

◆ setOutdatedPotentialsState_()

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< GUM_SCALAR >::setOutdatedPotentialsState_ ( )
protectedinherited

puts the inference into an OutdatedPotentials state if it is not already in an OutdatedStructure state

OutdatedPotentials: in this state, the structure of the model 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 638 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

638  {
640  }
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:

◆ setOutdatedStructureState_()

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< GUM_SCALAR >::setOutdatedStructureState_ ( )
protectedinherited

put the inference into an outdated model structure state

OutdatedStructure: in this state, the inference is fully unprepared to be applied because some events changed the "logical" structure of the model: for instance a node received a hard evidence, which implies that its outgoing arcs can be removed from the model, hence involving a structural change in the model. 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 graphicalModelInference may be smarter than graphicalModelInference 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 OutdatedPotentials 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 630 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

630  {
632  }
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:

◆ setRelevantPotentialsFinderType()

template<typename GUM_SCALAR >
void gum::VariableElimination< 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.

◆ setState_()

template<typename GUM_SCALAR >
INLINE void gum::GraphicalModelInference< GUM_SCALAR >::setState_ ( const StateOfInference  state)
finalprotectedvirtualinherited

set the state of the inference engine and call the notification onStateChanged_ when necessary (i.e. when the state has effectively changed).

Definition at line 98 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

98  {
99  if (_state_ != state) {
100  _state_ = state;
101  onStateChanged_();
102  }
103  }
virtual StateOfInference state() const noexcept final
returns the state of the inference engine
StateOfInference _state_
the current state of the inference (outdated/ready/done)
virtual void onStateChanged_()=0
fired when the stage is changed
+ Here is the call graph for this function:

◆ setTargetedMode_()

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

Definition at line 319 of file marginalTargetedInference_tpl.h.

319  {
320  if (!_targeted_mode_) {
321  _targets_.clear();
322  _targeted_mode_ = true;
323  }
324  }
bool _targeted_mode_
whether the actual targets are default
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
NodeSet _targets_
the set of marginal targets

◆ setTriangulation()

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

use a new triangulation algorithm

◆ softEvidenceNodes()

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

returns the set of nodes with soft evidence

the set of nodes that received soft evidence

Definition at line 612 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

612  {
613  return _soft_evidence_nodes_;
614  }
NodeSet _soft_evidence_nodes_
the set of nodes that received soft evidence
+ Here is the call graph for this function:

◆ state()

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

returns the state of the inference engine

Definition at line 92 of file graphicalModelInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

92  {
93  return _state_;
94  }
StateOfInference _state_
the current state of the inference (outdated/ready/done)
+ Here is the call graph for this function:

◆ targets()

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

returns the list of marginal targets

Definition at line 201 of file marginalTargetedInference_tpl.h.

201  {
202  return _targets_;
203  }
NodeSet _targets_
the set of marginal targets

◆ unnormalizedJointPosterior_() [1/2]

template<typename GUM_SCALAR >
Potential< GUM_SCALAR >* gum::VariableElimination< GUM_SCALAR >::unnormalizedJointPosterior_ ( NodeId  id)
finalprotectedvirtual

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

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ unnormalizedJointPosterior_() [2/2]

template<typename GUM_SCALAR >
Potential< GUM_SCALAR >* gum::VariableElimination< GUM_SCALAR >::unnormalizedJointPosterior_ ( const NodeSet set)
finalprotectedvirtual

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

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ updateOutdatedPotentials_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::updateOutdatedPotentials_ ( )
finalprotectedvirtual

prepares inference when the latter is in OutdatedPotentials state

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

Implements gum::GraphicalModelInference< GUM_SCALAR >.

◆ updateOutdatedStructure_()

template<typename GUM_SCALAR >
void gum::VariableElimination< GUM_SCALAR >::updateOutdatedStructure_ ( )
finalprotectedvirtual

prepares inference when the latter is in OutdatedStructure state

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

Implements gum::GraphicalModelInference< GUM_SCALAR >.

◆ VI() [1/2]

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 315 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

315  {
316  return this->H(X) + this->H(Y) - 2 * I(X, Y);
317  }
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:

◆ VI() [2/2]

template<typename GUM_SCALAR >
GUM_SCALAR gum::JointTargetedInference< GUM_SCALAR >::VI ( const std::string &  Xname,
const std::string &  Yname 
)
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

Definition at line 253 of file jointTargetedInference_tpl.h.

References gum::Set< Key, Alloc >::emplace().

254  {
255  return VI(this->BN().idFromName(Xname), this->BN().idFromName(Yname));
256  }
GUM_SCALAR VI(NodeId X, NodeId Y)
Variation of information between X and Y.
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:

Member Data Documentation

◆ _barren_nodes_type_

template<typename GUM_SCALAR >
FindBarrenNodesType gum::VariableElimination< GUM_SCALAR >::_barren_nodes_type_
private

the type of barren nodes computation we wish

Definition at line 237 of file variableElimination.h.

◆ _clique_potentials_

template<typename GUM_SCALAR >
HashTable< NodeId, NodeSet > gum::VariableElimination< GUM_SCALAR >::_clique_potentials_
private

for each BN node, indicate in which clique its CPT will be stored

Definition at line 267 of file variableElimination.h.

◆ _combination_op_

template<typename GUM_SCALAR >
Potential< GUM_SCALAR >*(* gum::VariableElimination< GUM_SCALAR >::_combination_op_) (const Potential< GUM_SCALAR > &, const Potential< GUM_SCALAR > &)
inlineprivate

the operator for performing the combinations

Definition at line 245 of file variableElimination.h.

246  {
static INLINE Potential< GUM_SCALAR > * VENewmultiPotential(const Potential< GUM_SCALAR > &t1, const Potential< GUM_SCALAR > &t2)

◆ _find_relevant_potential_type_

template<typename GUM_SCALAR >
RelevantPotentialsFinderType gum::VariableElimination< GUM_SCALAR >::_find_relevant_potential_type_
private

the type of relevant potential finding algorithm to be used

Definition at line 228 of file variableElimination.h.

◆ _findRelevantPotentials_

template<typename GUM_SCALAR >
void(VariableElimination< GUM_SCALAR >::* gum::VariableElimination< 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 232 of file variableElimination.h.

◆ _graph_

template<typename GUM_SCALAR >
UndiGraph gum::VariableElimination< 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 258 of file variableElimination.h.

◆ _JT_

template<typename GUM_SCALAR >
JunctionTree* gum::VariableElimination< GUM_SCALAR >::_JT_ {nullptr}
private

the junction tree used to answer the last inference query

Definition at line 261 of file variableElimination.h.

◆ _node_to_clique_

template<typename GUM_SCALAR >
HashTable< NodeId, NodeId > gum::VariableElimination< GUM_SCALAR >::_node_to_clique_
private

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

Definition at line 264 of file variableElimination.h.

◆ _one_minus_epsilon_

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

for comparisons with 1 - epsilon

Definition at line 277 of file variableElimination.h.

◆ _projection_op_

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

the operator for performing the projections

Definition at line 240 of file variableElimination.h.

241  {
static INLINE Potential< GUM_SCALAR > * VENewprojPotential(const Potential< GUM_SCALAR > &t1, const Set< const DiscreteVariable * > &del_vars)

◆ _target_posterior_

template<typename GUM_SCALAR >
Potential< GUM_SCALAR >* gum::VariableElimination< GUM_SCALAR >::_target_posterior_ {nullptr}
private

the posterior computed during the last inference

the posterior is owned by VariableElimination.

Definition at line 274 of file variableElimination.h.

◆ _targets2clique_

template<typename GUM_SCALAR >
NodeId gum::VariableElimination< GUM_SCALAR >::_targets2clique_
private

indicate a clique that contains all the nodes of the target

Definition at line 270 of file variableElimination.h.

◆ _triangulation_

template<typename GUM_SCALAR >
Triangulation* gum::VariableElimination< GUM_SCALAR >::_triangulation_
private

the triangulation class creating the junction tree used for inference

Definition at line 247 of file variableElimination.h.


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