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

<agrum/MN/inference/ShaferShenoyMNInference.h> More...

#include <ShaferShenoyMNInference.h>

+ Inheritance diagram for gum::ShaferShenoyMNInference< GUM_SCALAR >:
+ Collaboration diagram for gum::ShaferShenoyMNInference< 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
 ShaferShenoyMNInference (const IMarkovNet< GUM_SCALAR > *MN, bool use_binary_join_tree=true)
 default constructor More...
 
 ~ShaferShenoyMNInference () final
 destructor More...
 
Accessors / Modifiers
void setTriangulation (const Triangulation &new_triangulation)
 use a new triangulation algorithm More...
 
const JoinTreejoinTree ()
 returns the current join tree used More...
 
const JunctionTreejunctionTree ()
 returns the current junction tree More...
 
GUM_SCALAR evidenceProbability ()
 returns the probability of evidence More...
 
Probability computations
virtual const Potential< GUM_SCALAR > & jointPosterior (const NodeSet &nodes) final
 Compute the joint posterior of a set of nodes. More...
 
virtual const Potential< GUM_SCALAR > & posterior (NodeId node) final
 Computes and returns the posterior of a node. More...
 
virtual const Potential< GUM_SCALAR > & posterior (const std::string &nodeName) final
 Computes and returns the posterior of a node. More...
 
Targets
virtual void eraseAllTargets ()
 Clear all previously defined targets (marginal and joint targets) More...
 
virtual void eraseAllJointTargets () final
 Clear all previously defined joint targets. More...
 
virtual void eraseAllMarginalTargets () final
 Clear all the previously defined marginal targets. More...
 
virtual void addJointTarget (const NodeSet &joint_target) final
 Add a set of nodes as a new joint target. As a collateral effect, every node is added as a marginal target. More...
 
virtual void eraseJointTarget (const NodeSet &joint_target) final
 removes an existing joint target More...
 
virtual bool isJointTarget (const NodeSet &vars) const final
 return true if target is a joint target. More...
 
virtual const Set< NodeSet > & jointTargets () const 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 &X, const std::string &Y)
 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 &X, const std::string &Y)
 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 setMN (const IMarkovNet< GUM_SCALAR > *mn)
 assigns a new MN to the inference engine More...
 
virtual const IMarkovNet< GUM_SCALAR > & MN () const final
 Returns a constant reference over the IMarkovNet 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

virtual bool isExactJointComputable_ (const NodeSet &vars) final
 check if the vars form a possible computable joint (can be redefined by subclass) More...
 
virtual NodeSet superForJointComputable_ (const NodeSet &vars) final
 
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 onMarkovNetChanged_ (const IMarkovNet< GUM_SCALAR > *mn) final
 fired after a new Markov 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 MN 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...
 
virtual void onModelChanged_ (const GraphicalModel *mn)
 fired after a new Markov net has been assigned to the engine 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::ShaferShenoyMNInference< GUM_SCALAR >

<agrum/MN/inference/ShaferShenoyMNInference.h>

Implementation of Shafer-Shenoy's propagation algorithm for inference in Markov Networks

Definition at line 66 of file ShaferShenoyMNInference.h.

Member Typedef Documentation

◆ PotentialSet__

template<typename GUM_SCALAR >
typedef Set< const Potential< GUM_SCALAR >* > gum::ShaferShenoyMNInference< GUM_SCALAR >::PotentialSet__
private

Definition at line 208 of file ShaferShenoyMNInference.h.

◆ PotentialSetIterator__

template<typename GUM_SCALAR >
typedef SetIteratorSafe< const Potential< GUM_SCALAR >* > gum::ShaferShenoyMNInference< GUM_SCALAR >::PotentialSetIterator__
private

Definition at line 210 of file ShaferShenoyMNInference.h.

Member Enumeration Documentation

◆ EvidenceChangeType

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

the possible types of evidence changes

Enumerator
EVIDENCE_ADDED 
EVIDENCE_ERASED 
EVIDENCE_MODIFIED 

Definition at line 336 of file ShaferShenoyMNInference.h.

◆ 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

◆ ShaferShenoyMNInference() [1/2]

template<typename GUM_SCALAR >
gum::ShaferShenoyMNInference< GUM_SCALAR >::ShaferShenoyMNInference ( const IMarkovNet< GUM_SCALAR > *  MN,
bool  use_binary_join_tree = true 
)
explicit

default constructor

◆ ~ShaferShenoyMNInference()

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

destructor

◆ ShaferShenoyMNInference() [2/2]

template<typename GUM_SCALAR >
gum::ShaferShenoyMNInference< GUM_SCALAR >::ShaferShenoyMNInference ( const ShaferShenoyMNInference< GUM_SCALAR > &  )
private

avoid copy constructors

Member Function Documentation

◆ addAllTargets()

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

adds all nodes as targets

Definition at line 137 of file marginalTargetedMNInference_tpl.h.

137  {
138  // check if the node belongs to the Markov network
139  if (this->hasNoModel_())
140  GUM_ERROR(NullElement,
141  "No Markov net has been assigned to the "
142  "inference algorithm");
143 
144 
145  setTargetedMode_(); // does nothing if already in targeted mode
146  for (const auto target: this->MN().graph()) {
147  if (!targets__.contains(target)) {
148  targets__.insert(target);
149  onMarginalTargetAdded_(target);
150  this->setState_(
152  }
153  }
154  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:580
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
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
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ 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 243 of file graphicalModelInference_tpl.h.

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

244  {
246  }
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 250 of file graphicalModelInference_tpl.h.

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

252  {
253  addEvidence(this->model().idFromName(nodeName), val);
254  }
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 259 of file graphicalModelInference_tpl.h.

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

260  {
261  addEvidence(id, this->model().variable(id)[label]);
262  }
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 266 of file graphicalModelInference_tpl.h.

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

268  {
269  NodeId id = this->model().idFromName(nodeName);
270  addEvidence(id, this->model().variable(id)[label]);
271  }
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 275 of file graphicalModelInference_tpl.h.

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

277  {
278  // checks that the evidence is meaningful
279  if (model__ == nullptr)
280  GUM_ERROR(NullElement,
281  "No Bayes net has been assigned to the "
282  "inference algorithm");
283 
284  if (!model__->exists(id)) {
285  GUM_ERROR(UndefinedElement, id << " is not a NodeId in the model");
286  }
287 
288  if (model__->variable(id).domainSize() != vals.size()) {
289  GUM_ERROR(InvalidArgument,
290  "node " << model__->variable(id)
291  << " and its evidence vector have different sizes.");
292  }
293 
294  Potential< GUM_SCALAR > pot;
295  pot.add(model__->variable(id));
296  pot.fillWith(vals);
297  addEvidence(std::move(pot));
298  }
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.
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
const GraphicalModel * model__
the Bayes net on which we perform inferences
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ 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 302 of file graphicalModelInference_tpl.h.

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

304  {
305  addEvidence(this->model().idFromName(nodeName), vals);
306  }
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 352 of file graphicalModelInference_tpl.h.

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

353  {
354  Potential< GUM_SCALAR > new_pot(pot);
355  addEvidence(std::move(new_pot));
356  }
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 310 of file graphicalModelInference_tpl.h.

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

311  {
312  // check if the potential corresponds to an evidence
313  if (pot.nbrDim() != 1) {
314  GUM_ERROR(InvalidArgument, pot << " is not mono-dimensional.");
315  }
316  if (model__ == nullptr)
317  GUM_ERROR(NullElement,
318  "No Bayes net has been assigned to the "
319  "inference algorithm");
320 
321  NodeId id = model__->nodeId(pot.variable(0));
322 
323  if (hasEvidence(id)) {
324  GUM_ERROR(InvalidArgument,
325  " node " << id
326  << " already has an evidence. Please use chgEvidence().");
327  }
328 
329  // check whether we have a hard evidence (and also check whether the
330  // potential only contains 0 (in this case, this will automatically raise
331  // an exception) )
332  Idx val;
333  bool is_hard_evidence = isHardEvidence__(pot, val);
334 
335  // insert the evidence
336  evidence__.insert(
337  id,
338  new Potential< GUM_SCALAR >(std::forward< Potential< GUM_SCALAR > >(pot)));
339  if (is_hard_evidence) { // pot is deterministic
340  hard_evidence__.insert(id, val);
342  } else {
344  }
346  onEvidenceAdded_(id, is_hard_evidence);
347  }
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
NodeSet hard_evidence_nodes__
the set of nodes that received hard evidence
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
NodeSet soft_evidence_nodes__
the set of nodes that received soft evidence
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node src discrete var pointer.
const GraphicalModel * model__
the Bayes net on which we perform inferences
NodeProperty< Idx > hard_evidence__
assign to each node with a hard evidence the index of its observed value
NodeProperty< const Potential< GUM_SCALAR > *> evidence__
the set of evidence entered into the network
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:632
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ addJointTarget()

template<typename GUM_SCALAR >
void gum::JointTargetedMNInference< 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 Markov net

Definition at line 118 of file jointTargetedMNInference_tpl.h.

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

119  {
120  // check if the nodes in the target belong to the Markov network
121  if (this->hasNoModel_())
122  GUM_ERROR(NullElement,
123  "No Markov net has been assigned to the "
124  "inference algorithm");
125 
126  const auto& dag = this->MN().graph();
127  for (const auto node: joint_target) {
128  if (!dag.exists(node)) {
129  GUM_ERROR(UndefinedElement,
130  "at least one one in " << joint_target
131  << " does not belong to the mn");
132  }
133  }
134 
135  if (isExactJointComputable_(joint_target)) return;
136  if (!superForJointComputable_(joint_target).empty()) return;
137 
138  // check if joint_target is a subset of an already existing target
139  for (const auto& target: joint_targets__) {
140  if (target.isProperSupersetOf(joint_target)) return;
141  }
142 
143  // check if joint_target is not a superset of an already existing target
144  // in this case, we need to remove old existing target
145  for (auto iter = joint_targets__.beginSafe();
146  iter != joint_targets__.endSafe();
147  ++iter) {
148  if (iter->isProperSubsetOf(joint_target)) eraseJointTarget(*iter);
149  }
150 
151  this->setTargetedMode_(); // does nothing if already in targeted mode
152  joint_targets__.insert(joint_target);
153  onJointTargetAdded_(joint_target);
154  this->setState_(
156  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual void eraseJointTarget(const NodeSet &joint_target) final
removes an existing joint target
virtual NodeSet superForJointComputable_(const NodeSet &vars)
Set< NodeSet > joint_targets__
the set of joint targets
virtual bool isExactJointComputable_(const NodeSet &vars)
check if the vars form a possible computable joint (can be redefined by subclass) ...
virtual void onJointTargetAdded_(const NodeSet &set)=0
fired after a new joint target is inserted
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ 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 361 of file graphicalModelInference_tpl.h.

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

362  {
363  for (const auto pot: potlist)
364  addEvidence(*pot);
365  }
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 370 of file graphicalModelInference_tpl.h.

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

371  {
372  for (const auto pot: potset)
373  addEvidence(*pot);
374  }
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::MarginalTargetedMNInference< GUM_SCALAR >::addTarget ( NodeId  target)
finalvirtualinherited

Add a marginal target to the list of targets.

Exceptions
UndefinedElementif target is not a NodeId in the Markov net

Definition at line 112 of file marginalTargetedMNInference_tpl.h.

112  {
113  // check if the node belongs to the Markov network
114  if (this->hasNoModel_())
115  GUM_ERROR(NullElement,
116  "No Markov net has been assigned to the "
117  "inference algorithm");
118 
119  if (!this->MN().graph().exists(target)) {
120  GUM_ERROR(UndefinedElement,
121  target << " is not a NodeId in the Markov network");
122  }
123 
124  setTargetedMode_(); // does nothing if already in targeted mode
125  // add the new target
126  if (!targets__.contains(target)) {
127  targets__.insert(target);
128  onMarginalTargetAdded_(target);
129  this->setState_(
131  }
132  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:580
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
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
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ addTarget() [2/2]

template<typename GUM_SCALAR >
void gum::MarginalTargetedMNInference< 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 Markov net

Definition at line 159 of file marginalTargetedMNInference_tpl.h.

160  {
161  // check if the node belongs to the Markov network
162  if (this->hasNoModel_())
163  GUM_ERROR(NullElement,
164  "No Markov net has been assigned to the "
165  "inference algorithm");
166 
167  addTarget(this->MN().idFromName(nodeName));
168  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ 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 432 of file graphicalModelInference_tpl.h.

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

433  {
435  }
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 439 of file graphicalModelInference_tpl.h.

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

441  {
442  chgEvidence(this->model().idFromName(nodeName), val);
443  }
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 448 of file graphicalModelInference_tpl.h.

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

449  {
450  chgEvidence(id, this->model().variable(id)[label]);
451  }
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 455 of file graphicalModelInference_tpl.h.

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

457  {
458  NodeId id = this->model().idFromName(nodeName);
459  chgEvidence(id, this->model().variable(id)[label]);
460  }
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 464 of file graphicalModelInference_tpl.h.

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

466  {
467  // check whether this corresponds to an evidence
468  if (model__ == nullptr)
469  GUM_ERROR(NullElement,
470  "No Bayes net has been assigned to the "
471  "inference algorithm");
472 
473  if (!model__->exists(id)) {
474  GUM_ERROR(UndefinedElement, id << " is not a NodeId in the model");
475  }
476 
477  if (model__->variable(id).domainSize() != vals.size()) {
478  GUM_ERROR(InvalidArgument,
479  "node " << model__->variable(id)
480  << " and its evidence have different sizes.");
481  }
482 
483  // create the potential corresponding to vals
484  Potential< GUM_SCALAR > pot;
485  pot.add(model__->variable(id));
486  pot.fillWith(vals);
487  chgEvidence(pot);
488  }
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
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it&#39;s node id.
const GraphicalModel * model__
the Bayes net on which we perform inferences
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ 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 492 of file graphicalModelInference_tpl.h.

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

494  {
495  chgEvidence(this->model().idFromName(nodeName), vals);
496  }
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 501 of file graphicalModelInference_tpl.h.

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

502  {
503  // check if the potential corresponds to an evidence
504  if (pot.nbrDim() != 1) {
505  GUM_ERROR(InvalidArgument, pot << " is not a mono-dimensional potential.");
506  }
507  if (model__ == nullptr)
508  GUM_ERROR(NullElement,
509  "No Bayes net has been assigned to the "
510  "inference algorithm");
511 
512  NodeId id = model__->nodeId(pot.variable(0));
513 
514  if (!hasEvidence(id)) {
515  GUM_ERROR(InvalidArgument,
516  id << " has no evidence. Please use addEvidence().");
517  }
518 
519  // check whether we have a hard evidence (and also check whether the
520  // potential only contains 0 (in this case, this will automatically raise
521  // an exception) )
522  Idx val;
523  bool is_hard_evidence = isHardEvidence__(pot, val);
524 
525  // modify the evidence already stored
526  const Potential< GUM_SCALAR >* localPot = evidence__[id];
527  Instantiation I(pot);
528  for (I.setFirst(); !I.end(); I.inc()) {
529  localPot->set(I, pot[I]);
530  }
531 
532  // the inference state will be different
533  // whether evidence change from Hard to Soft or not.
534  bool hasChangedSoftHard = false;
535 
536  if (is_hard_evidence) {
537  if (!hasHardEvidence(id)) {
538  hasChangedSoftHard = true;
539  hard_evidence__.insert(id, val);
542  } else {
543  hard_evidence__[id] = val;
544  }
545  } else {
546  if (hasHardEvidence(id)) { // evidence was hard
547  hard_evidence__.erase(id);
550  hasChangedSoftHard = true;
551  }
552  }
553 
554  if (hasChangedSoftHard) {
556  } else {
559  }
560  }
561 
562  onEvidenceChanged_(id, hasChangedSoftHard);
563  }
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
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:675
NodeSet hard_evidence_nodes__
the set of nodes that received hard evidence
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
NodeSet soft_evidence_nodes__
the set of nodes that received soft evidence
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node src discrete var pointer.
const GraphicalModel * model__
the Bayes net on which we perform inferences
NodeProperty< Idx > hard_evidence__
assign to each node with a hard evidence the index of its observed value
NodeProperty< const Potential< GUM_SCALAR > *> evidence__
the set of evidence entered into the network
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:632
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ 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 147 of file graphicalModelInference_tpl.h.

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

147  {
150  }
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:

◆ collectMessage__()

template<typename GUM_SCALAR >
void gum::ShaferShenoyMNInference< GUM_SCALAR >::collectMessage__ ( NodeId  id,
NodeId  from 
)
private

actually perform the collect phase

◆ computeJoinTreeRoots__()

template<typename GUM_SCALAR >
void gum::ShaferShenoyMNInference< GUM_SCALAR >::computeJoinTreeRoots__ ( )
private

compute a root for each connected component of propagator__

◆ createNewJT__()

template<typename GUM_SCALAR >
void gum::ShaferShenoyMNInference< GUM_SCALAR >::createNewJT__ ( )
private

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

◆ diffuseMessageInvalidations__()

template<typename GUM_SCALAR >
void gum::ShaferShenoyMNInference< GUM_SCALAR >::diffuseMessageInvalidations__ ( NodeId  from,
NodeId  to,
NodeSet cliques_invalidated 
)
private

invalidate all the messages sent from a given clique

◆ 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 168 of file graphicalModelInference_tpl.h.

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

168  {
169  return domain_sizes__;
170  }
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 597 of file graphicalModelInference_tpl.h.

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

597  {
598  bool has_hard_evidence = !hard_evidence__.empty();
599  this->onAllEvidenceErased_(has_hard_evidence);
600 
601  for (const auto& pair: evidence__) {
602  if (pair.second != nullptr) { delete (pair.second); }
603  }
604 
605  evidence__.clear();
606  hard_evidence__.clear();
609 
610  if (has_hard_evidence) {
612  } else {
615  }
616  }
617  }
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...
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:374
NodeProperty< Idx > hard_evidence__
assign to each node with a hard evidence the index of its observed value
NodeProperty< const Potential< GUM_SCALAR > *> evidence__
the set of evidence entered into the network
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::JointTargetedMNInference< GUM_SCALAR >::eraseAllJointTargets ( )
finalvirtualinherited

Clear all previously defined joint targets.

Definition at line 97 of file jointTargetedMNInference_tpl.h.

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

97  {
98  if (joint_targets__.size() > 0) {
99  // we already are in target mode. So no this->setTargetedMode_(); is needed
101  joint_targets__.clear();
102  this->setState_(
104  }
105  }
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::JointTargetedMNInference< GUM_SCALAR >::eraseAllMarginalTargets ( )
finalvirtualinherited

Clear all the previously defined marginal targets.

Definition at line 90 of file jointTargetedMNInference_tpl.h.

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

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

◆ eraseAllTargets()

template<typename GUM_SCALAR >
INLINE void gum::JointTargetedMNInference< 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::MarginalTargetedMNInference< GUM_SCALAR >.

Definition at line 110 of file jointTargetedMNInference_tpl.h.

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

110  {
113  }
virtual void eraseAllJointTargets() final
Clear all previously defined joint targets.
virtual void eraseAllMarginalTargets() final
Clear all the previously defined marginal 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 568 of file graphicalModelInference_tpl.h.

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

568  {
569  if (hasEvidence(id)) {
570  if (hasHardEvidence(id)) {
571  onEvidenceErased_(id, true);
572  hard_evidence__.erase(id);
575  } else {
576  onEvidenceErased_(id, false);
580  }
581  }
582 
583  delete (evidence__[id]);
584  evidence__.erase(id);
585  }
586  }
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
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:675
NodeSet hard_evidence_nodes__
the set of nodes that received hard evidence
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
NodeSet soft_evidence_nodes__
the set of nodes that received soft evidence
virtual void onEvidenceErased_(const NodeId id, bool isHardEvidence)=0
fired before an evidence is removed
NodeProperty< Idx > hard_evidence__
assign to each node with a hard evidence the index of its observed value
NodeProperty< const Potential< GUM_SCALAR > *> evidence__
the set of evidence entered into the network
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 589 of file graphicalModelInference_tpl.h.

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

590  {
591  eraseEvidence(this->model().idFromName(nodeName));
592  }
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::JointTargetedMNInference< 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 161 of file jointTargetedMNInference_tpl.h.

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

162  {
163  // check if the nodes in the target belong to the Markov network
164  if (this->hasNoModel_())
165  GUM_ERROR(NullElement,
166  "No Markov net has been assigned to the "
167  "inference algorithm");
168 
169  const auto& dag = this->MN().graph();
170  for (const auto node: joint_target) {
171  if (!dag.exists(node)) {
172  GUM_ERROR(UndefinedElement,
173  "at least one one in " << joint_target
174  << " does not belong to the mn");
175  }
176  }
177 
178  // check that the joint_target set does not contain the new target
179  if (joint_targets__.contains(joint_target)) {
180  // note that we have to be in target mode when we are here
181  // so, no this->setTargetedMode_(); is necessary
182  onJointTargetErased_(joint_target);
183  joint_targets__.erase(joint_target);
184  this->setState_(
186  }
187  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
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
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ eraseTarget() [1/2]

template<typename GUM_SCALAR >
void gum::MarginalTargetedMNInference< 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 173 of file marginalTargetedMNInference_tpl.h.

173  {
174  // check if the node belongs to the Markov network
175  if (this->hasNoModel_())
176  GUM_ERROR(NullElement,
177  "No Markov net has been assigned to the "
178  "inference algorithm");
179 
180  if (!this->MN().graph().exists(target)) {
181  GUM_ERROR(UndefinedElement,
182  target << " is not a NodeId in the Markov network");
183  }
184 
185 
186  if (targets__.contains(target)) {
187  targeted_mode__ = true; // we do not use setTargetedMode_ because we do not
188  // want to clear the targets
189  onMarginalTargetErased_(target);
190  targets__.erase(target);
191  this->setState_(
193  }
194  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:580
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
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:675
NodeSet targets__
the set of marginal targets
bool targeted_mode__
whether the actual targets are default
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
virtual void onMarginalTargetErased_(const NodeId id)=0
fired before a marginal target is removed

◆ eraseTarget() [2/2]

template<typename GUM_SCALAR >
void gum::MarginalTargetedMNInference< 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 199 of file marginalTargetedMNInference_tpl.h.

200  {
201  // check if the node belongs to the Markov network
202  if (this->hasNoModel_())
203  GUM_ERROR(NullElement,
204  "No Markov net has been assigned to the "
205  "inference algorithm");
206 
207  eraseTarget(this->MN().idFromName(nodeName));
208  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ 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 652 of file graphicalModelInference_tpl.h.

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

652  {
653  return evidence__;
654  }
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::MarginalTargetedMNInference< 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
mnthe MarkovNet
targetthe nodeId of the targetted variable
evsthe vector of nodeId of the observed variables
Returns
a Potential

Definition at line 287 of file marginalTargetedMNInference_tpl.h.

289  {
290  const auto& vtarget = this->MN().variable(target);
291 
292  if (evs.contains(target)) {
293  GUM_ERROR(InvalidArgument,
294  "Target <" << vtarget.name() << "> (" << target
295  << ") can not be in evs (" << evs << ").");
296  }
297  auto condset = this->MN().minimalCondSet(target, evs);
298 
299  Potential< GUM_SCALAR > res;
300  this->eraseAllTargets();
301  this->eraseAllEvidence();
302  res.add(this->MN().variable(target));
303  this->addTarget(target);
304  for (const auto& n: condset) {
305  res.add(this->MN().variable(n));
306  this->addEvidence(n, 0);
307  }
308 
309  Instantiation inst(res);
310  for (inst.setFirst(); !inst.end(); inst.incNotVar(vtarget)) {
311  // inferring
312  for (const auto& n: condset)
313  this->chgEvidence(n, inst.val(this->MN().variable(n)));
314  this->makeInference();
315  // populate res
316  for (inst.setFirstVar(vtarget); !inst.end(); inst.incVar(vtarget)) {
317  res.set(inst, this->posterior(target)[inst]);
318  }
319  inst.setFirstVar(vtarget); // remove inst.end() flag
320  }
321 
322  return res;
323  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
virtual void eraseAllTargets()
Clear all previously defined targets.
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 makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ evidenceImpact() [2/2]

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::MarginalTargetedMNInference< 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 328 of file marginalTargetedMNInference_tpl.h.

330  {
331  const auto& mn = this->MN();
332  return evidenceImpact(mn.idFromName(target), mn.nodeset(evs));
333  }
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 IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.

◆ evidenceJointImpact() [1/2]

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::JointTargetedMNInference< 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 336 of file jointTargetedMNInference_tpl.h.

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

338  {
339  if (!(evs * targets).empty()) {
340  GUM_ERROR(InvalidArgument,
341  "Targets (" << targets << ") can not intersect evs (" << evs
342  << ").");
343  }
344  auto condset = this->MN().minimalCondSet(targets, evs);
345 
346  this->eraseAllTargets();
347  this->eraseAllEvidence();
348 
349  Instantiation iTarget;
350  Potential< GUM_SCALAR > res;
351  for (const auto& target: targets) {
352  res.add(this->MN().variable(target));
353  iTarget.add(this->MN().variable(target));
354  }
355  this->addJointTarget(targets);
356 
357  for (const auto& n: condset) {
358  res.add(this->MN().variable(n));
359  this->addEvidence(n, 0);
360  }
361 
362  Instantiation inst(res);
363  for (inst.setFirstOut(iTarget); !inst.end(); inst.incOut(iTarget)) {
364  // inferring
365  for (const auto& n: condset)
366  this->chgEvidence(n, inst.val(this->MN().variable(n)));
367  this->makeInference();
368  // populate res
369  for (inst.setFirstIn(iTarget); !inst.end(); inst.incIn(iTarget)) {
370  res.set(inst, this->jointPosterior(targets)[inst]);
371  }
372  inst.setFirstIn(iTarget); // remove inst.end() flag
373  }
374 
375  return res;
376  }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
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 const NodeSet & targets() const noexcept final
returns the list of marginal targets
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 void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
virtual void eraseAllTargets()
Clear all previously defined targets (marginal and joint targets)
+ Here is the call graph for this function:

◆ evidenceJointImpact() [2/2]

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::JointTargetedMNInference< 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 380 of file jointTargetedMNInference_tpl.h.

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

382  {
383  const auto& mn = this->MN();
384  return evidenceJointImpact(mn.nodeset(targets), mn.nodeset(evs));
385  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
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) ...
+ Here is the call graph for this function:

◆ evidenceProbability()

template<typename GUM_SCALAR >
GUM_SCALAR gum::ShaferShenoyMNInference< GUM_SCALAR >::evidenceProbability ( )
virtual

returns the probability of evidence

Implements gum::EvidenceMNInference< GUM_SCALAR >.

◆ H() [1/2]

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::MarginalTargetedMNInference< 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 271 of file marginalTargetedMNInference_tpl.h.

271  {
272  return posterior(X).entropy();
273  }
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::MarginalTargetedMNInference< 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 280 of file marginalTargetedMNInference_tpl.h.

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

◆ 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 644 of file graphicalModelInference_tpl.h.

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

644  {
645  return hard_evidence__;
646  }
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 668 of file graphicalModelInference_tpl.h.

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

668  {
669  return hard_evidence_nodes__;
670  }
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 379 of file graphicalModelInference_tpl.h.

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

379  {
380  return !evidence__.empty();
381  }
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 386 of file graphicalModelInference_tpl.h.

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

386  {
387  return evidence__.exists(id);
388  }
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 409 of file graphicalModelInference_tpl.h.

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

410  {
411  return hasEvidence(this->model().idFromName(nodeName));
412  }
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 394 of file graphicalModelInference_tpl.h.

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

394  {
395  return hard_evidence_nodes__.exists(id);
396  }
NodeSet hard_evidence_nodes__
the set of nodes that received hard evidence
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:626
+ 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 417 of file graphicalModelInference_tpl.h.

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

418  {
419  return hasHardEvidence(this->model().idFromName(nodeName));
420  }
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 533 of file graphicalModelInference.h.

533 { 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 402 of file graphicalModelInference_tpl.h.

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

402  {
403  return soft_evidence_nodes__.exists(id);
404  }
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:626
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 425 of file graphicalModelInference_tpl.h.

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

426  {
427  return hasSoftEvidence(this->model().idFromName(nodeName));
428  }
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::JointTargetedMNInference< 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 277 of file jointTargetedMNInference_tpl.h.

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

277  {
278  Potential< GUM_SCALAR > pX, pY, *pXY = nullptr;
279  if (X == Y) {
280  GUM_ERROR(OperationNotAllowed, "Mutual Information I(X,Y) with X==Y");
281  }
282 
283  try {
284  // here use unnormalized joint posterior rather than just posterior
285  // to avoid saving the posterior in the cache of the inference engines
286  // like LazyPropagation or Shafer-Shenoy.
287  pXY = this->unnormalizedJointPosterior_({X, Y});
288  pXY->normalize();
289  pX = pXY->margSumOut({&(this->MN().variable(Y))});
290  pY = pXY->margSumOut({&(this->MN().variable(X))});
291  } catch (...) {
292  if (pXY != nullptr) { delete pXY; }
293  throw;
294  }
295 
296  Instantiation i(*pXY);
297  auto res = (GUM_SCALAR)0;
298 
299  for (i.setFirst(); !i.end(); ++i) {
300  GUM_SCALAR vXY = (*pXY)[i];
301  GUM_SCALAR vX = pX[i];
302  GUM_SCALAR vY = pY[i];
303 
304  if (vXY > (GUM_SCALAR)0) {
305  if (vX == (GUM_SCALAR)0 || vY == (GUM_SCALAR)0) {
306  GUM_ERROR(OperationNotAllowed,
307  "Mutual Information (X,Y) with P(X)=0 or P(Y)=0 "
308  "and P(X,Y)>0");
309  }
310 
311  res += vXY * (std::log2(vXY) - std::log2(vX) - std::log2(vY));
312  }
313  }
314 
315  delete pXY;
316 
317  return res;
318  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
virtual Potential< GUM_SCALAR > * unnormalizedJointPosterior_(const NodeSet &set)=0
returns a fresh unnormalized joint posterior of a given set of variables
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
Potential< GUM_SCALAR > log2(const Potential< GUM_SCALAR > &arg)
Definition: potential.h:612
+ Here is the call graph for this function:

◆ I() [2/2]

template<typename GUM_SCALAR >
GUM_SCALAR gum::JointTargetedMNInference< GUM_SCALAR >::I ( const std::string &  X,
const std::string &  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 258 of file jointTargetedMNInference_tpl.h.

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

259  {
260  return I(this->MN().idFromName(Xname), this->MN().idFromName(Yname));
261  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
GUM_SCALAR I(NodeId X, NodeId Y)
Mutual information between X and Y.
+ Here is the call graph for this function:

◆ invalidateAllMessages__()

template<typename GUM_SCALAR >
void gum::ShaferShenoyMNInference< GUM_SCALAR >::invalidateAllMessages__ ( )
private

invalidate all messages, posteriors and created potentials

◆ isExactJointComputable_()

template<typename GUM_SCALAR >
virtual bool gum::ShaferShenoyMNInference< GUM_SCALAR >::isExactJointComputable_ ( const NodeSet vars)
finalprotectedvirtual

check if the vars form a possible computable joint (can be redefined by subclass)

Reimplemented from gum::JointTargetedMNInference< GUM_SCALAR >.

◆ 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 89 of file graphicalModelInference_tpl.h.

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

89  {
90  return (state__ == StateOfInference::Done);
91  }
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 82 of file graphicalModelInference_tpl.h.

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

83  {
85  }
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 75 of file graphicalModelInference_tpl.h.

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

76  {
78  }
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 70 of file graphicalModelInference_tpl.h.

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

70  {
72  }
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::JointTargetedMNInference< GUM_SCALAR >::isJointTarget ( const NodeSet vars) const
finalvirtualinherited

return true if target is a joint target.

Definition at line 69 of file jointTargetedMNInference_tpl.h.

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

70  {
71  if (this->hasNoModel_())
72  GUM_ERROR(NullElement,
73  "No Markov net has been assigned to the "
74  "inference algorithm");
75 
76  const auto& gra = this->MN().graph();
77  for (const auto var: vars) {
78  if (!gra.exists(var)) {
79  GUM_ERROR(UndefinedElement,
80  var << " is not a NodeId in the Markov network");
81  }
82  }
83 
84  return joint_targets__.contains(vars);
85  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
Set< NodeSet > joint_targets__
the set of joint targets
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ isNewJTNeeded__()

template<typename GUM_SCALAR >
bool gum::ShaferShenoyMNInference< GUM_SCALAR >::isNewJTNeeded__ ( ) const
private

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

◆ isTarget() [1/2]

template<typename GUM_SCALAR >
INLINE bool gum::MarginalTargetedMNInference< GUM_SCALAR >::isTarget ( NodeId  node) const
finalvirtualinherited

return true if variable is a (marginal) target

Definition at line 75 of file marginalTargetedMNInference_tpl.h.

75  {
76  // check that the variable belongs to the mn
77  if (this->hasNoModel_())
78  GUM_ERROR(NullElement,
79  "No Markov net has been assigned to the "
80  "inference algorithm");
81  if (!this->MN().graph().exists(node)) {
82  GUM_ERROR(UndefinedElement,
83  node << " is not a NodeId in the Markov network");
84  }
85 
86  return targets__.contains(node);
87  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:580
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
NodeSet targets__
the set of marginal targets
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ isTarget() [2/2]

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

return true if variable is a (marginal) target

Definition at line 91 of file marginalTargetedMNInference_tpl.h.

92  {
93  return isTarget(this->MN().idFromName(nodeName));
94  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target

◆ isTargetedMode_()

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

Definition at line 337 of file marginalTargetedMNInference_tpl.h.

337  {
338  return targeted_mode__;
339  }
bool targeted_mode__
whether the actual targets are default

◆ jointMutualInformation() [1/2]

template<typename GUM_SCALAR >
GUM_SCALAR gum::JointTargetedMNInference< 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 389 of file jointTargetedMNInference_tpl.h.

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

390  {
391  const auto& mn = this->MN();
392  const Size siz = targets.size();
393  if (siz <= 1) {
394  GUM_ERROR(InvalidArgument,
395  "jointMutualInformation needs at least 2 variables (targets="
396  << targets << ")");
397  }
398 
399  this->eraseAllTargets();
400  this->eraseAllEvidence();
401  this->addJointTarget(targets);
402  this->makeInference();
403  const auto po = this->jointPosterior(targets);
404 
405  gum::Instantiation caracteristic;
406  gum::Instantiation variables;
407  for (const auto nod: targets) {
408  const auto& var = mn.variable(nod);
409  auto pv = new gum::RangeVariable(var.name(), "", 0, 1);
410  caracteristic.add(*pv);
411  variables.add(var);
412  }
413 
414  Set< const DiscreteVariable* > sov;
415 
416  const GUM_SCALAR start = (siz % 2 == 0) ? GUM_SCALAR(-1.0) : GUM_SCALAR(1.0);
417  GUM_SCALAR sign;
418  GUM_SCALAR res = GUM_SCALAR(0.0);
419 
420  caracteristic.setFirst();
421  for (caracteristic.inc(); !caracteristic.end(); caracteristic.inc()) {
422  sov.clear();
423  sign = start;
424  for (Idx i = 0; i < caracteristic.nbrDim(); i++) {
425  if (caracteristic.val(i) == 1) {
426  sign = -sign;
427  sov.insert(&variables.variable(i));
428  }
429  }
430  res += sign * po.margSumIn(sov).entropy();
431  }
432 
433  for (Idx i = 0; i < caracteristic.nbrDim(); i++) {
434  delete &caracteristic.variable(i);
435  }
436 
437  return res;
438  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
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.
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
Idx val(Idx i) const
Returns the current value of the variable at position i.
virtual const Potential< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
void inc()
Operator increment.
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
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:720
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
bool end() const
Returns true if the Instantiation reached the end.
virtual void eraseAllTargets()
Clear all previously defined targets (marginal and joint targets)
+ Here is the call graph for this function:

◆ jointMutualInformation() [2/2]

template<typename GUM_SCALAR >
GUM_SCALAR gum::JointTargetedMNInference< 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 441 of file jointTargetedMNInference_tpl.h.

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

442  {
443  return jointMutualInformation(this->MN().nodeset(targets));
444  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
GUM_SCALAR jointMutualInformation(const NodeSet &targets)
Mutual information between targets.
+ Here is the call graph for this function:

◆ jointPosterior()

template<typename GUM_SCALAR >
const Potential< GUM_SCALAR > & gum::JointTargetedMNInference< 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 212 of file jointTargetedMNInference_tpl.h.

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

212  {
213  // try to get the smallest set of targets that contains "nodes"
214  bool found_exact_target = false;
215  NodeSet super_target;
216 
217  if (isExactJointComputable_(nodes)) {
218  found_exact_target = true;
219  } else {
220  super_target = superForJointComputable_(nodes);
221  if (super_target.empty()) {
222  GUM_ERROR(UndefinedElement,
223  "No joint target containing "
224  << nodes << " could be found among " << joint_targets__);
225  }
226  }
227 
228  if (!this->isInferenceDone()) { this->makeInference(); }
229 
230  if (found_exact_target)
231  return jointPosterior_(nodes);
232  else
233  return jointPosterior_(nodes, super_target);
234  }
virtual const Potential< GUM_SCALAR > & jointPosterior_(const NodeSet &set)=0
asks derived classes for the joint posterior of a declared target set
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual NodeSet superForJointComputable_(const NodeSet &vars)
Set< NodeSet > joint_targets__
the set of joint targets
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
virtual bool isExactJointComputable_(const NodeSet &vars)
check if the vars form a possible computable joint (can be redefined by subclass) ...
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ jointPosterior_() [1/2]

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

◆ jointPosterior_() [2/2]

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

◆ joinTree()

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

returns the current join tree used

◆ jointTargets()

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

returns the list of joint targets

returns the list of target sets

Definition at line 193 of file jointTargetedMNInference_tpl.h.

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

193  {
194  return joint_targets__;
195  }
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::ShaferShenoyMNInference< GUM_SCALAR >::junctionTree ( )

returns the current junction tree

◆ 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 714 of file graphicalModelInference_tpl.h.

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

714  {
715  if (isInferenceDone()) { return; }
716 
717  if (!isInferenceReady()) { prepareInference(); }
718 
719  makeInference_();
720 
722  }
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::ShaferShenoyMNInference< 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 >.

◆ marginalizeOut__()

template<typename GUM_SCALAR >
PotentialSet__ gum::ShaferShenoyMNInference< 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

◆ MN()

template<typename GUM_SCALAR >
INLINE const IMarkovNet< GUM_SCALAR > & gum::MarkovNetInference< GUM_SCALAR >::MN ( ) const
finalvirtualinherited

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

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

Definition at line 59 of file MarkovNetInference_tpl.h.

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

59  {
60  return static_cast< const IMarkovNet< GUM_SCALAR >& >(this->model());
61  }
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:

◆ 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 114 of file graphicalModelInference_tpl.h.

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

114  {
115  if (model__ == nullptr)
116  GUM_ERROR(UndefinedElement,
117  "No Bayes net has been assigned to "
118  "the inference algorithm.");
119  return *model__;
120  }
const GraphicalModel * model__
the Bayes net on which we perform inferences
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ 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 622 of file graphicalModelInference_tpl.h.

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

622  {
623  return evidence__.size();
624  }
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 629 of file graphicalModelInference_tpl.h.

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

629  {
630  return hard_evidence_nodes__.size();
631  }
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:720
+ Here is the call graph for this function:

◆ nbrJointTargets()

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

returns the number of joint targets

returns the number of target sets

Definition at line 200 of file jointTargetedMNInference_tpl.h.

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

200  {
201  return joint_targets__.size();
202  }
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 636 of file graphicalModelInference_tpl.h.

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

636  {
637  return soft_evidence_nodes__.size();
638  }
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:720
+ Here is the call graph for this function:

◆ nbrTargets()

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

returns the number of marginal targets

Definition at line 221 of file marginalTargetedMNInference_tpl.h.

221  {
222  return targets__.size();
223  }
NodeSet targets__
the set of marginal targets
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:720

◆ onAllEvidenceErased_()

template<typename GUM_SCALAR >
void gum::ShaferShenoyMNInference< 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::ShaferShenoyMNInference< GUM_SCALAR >::onAllJointTargetsErased_ ( )
finalprotectedvirtual

fired before a all the joint targets are removed

Implements gum::JointTargetedMNInference< GUM_SCALAR >.

◆ onAllMarginalTargetsAdded_()

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

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

Implements gum::MarginalTargetedMNInference< GUM_SCALAR >.

◆ onAllMarginalTargetsErased_()

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

fired before a all the single targets are removed

Implements gum::MarginalTargetedMNInference< GUM_SCALAR >.

◆ onAllTargetsErased_()

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

fired before a all single and joint_targets are removed

Implements gum::JointTargetedMNInference< GUM_SCALAR >.

◆ onEvidenceAdded_()

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

◆ onJointTargetErased_()

template<typename GUM_SCALAR >
void gum::ShaferShenoyMNInference< GUM_SCALAR >::onJointTargetErased_ ( const NodeSet set)
finalprotectedvirtual

fired before a joint target is removed

Parameters
setThe set of target variable's ids.

Implements gum::JointTargetedMNInference< GUM_SCALAR >.

◆ onMarginalTargetAdded_()

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

fired after a new single target is inserted

Parameters
idThe target variable's id.

Implements gum::MarginalTargetedMNInference< GUM_SCALAR >.

◆ onMarginalTargetErased_()

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

fired before a single target is removed

Parameters
idThe target variable's id.

Implements gum::MarginalTargetedMNInference< GUM_SCALAR >.

◆ onMarkovNetChanged_()

template<typename GUM_SCALAR >
virtual void gum::ShaferShenoyMNInference< GUM_SCALAR >::onMarkovNetChanged_ ( const IMarkovNet< GUM_SCALAR > *  mn)
finalprotectedvirtual

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

◆ onModelChanged_()

template<typename GUM_SCALAR >
void gum::JointTargetedMNInference< GUM_SCALAR >::onModelChanged_ ( const GraphicalModel mn)
protectedvirtualinherited

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

Reimplemented from gum::MarginalTargetedMNInference< GUM_SCALAR >.

Definition at line 55 of file jointTargetedMNInference_tpl.h.

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

56  {
59  joint_targets__.clear();
60  }
virtual void onModelChanged_(const GraphicalModel *mn)
fired after a new Markov net has been assigned to the engine
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:

◆ onStateChanged_()

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

fired when the stage is changed

Implements gum::GraphicalModelInference< GUM_SCALAR >.

Definition at line 112 of file ShaferShenoyMNInference.h.

112 {};

◆ operator=()

template<typename GUM_SCALAR >
ShaferShenoyMNInference< GUM_SCALAR >& gum::ShaferShenoyMNInference< GUM_SCALAR >::operator= ( const ShaferShenoyMNInference< GUM_SCALAR > &  )
private

avoid copy operators

◆ posterior() [1/2]

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

Definition at line 240 of file jointTargetedMNInference_tpl.h.

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

240  {
241  if (this->isTarget(node))
243  else
244  return jointPosterior(NodeSet{node});
245  }
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::JointTargetedMNInference< 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::MarginalTargetedMNInference< GUM_SCALAR >.

Definition at line 249 of file jointTargetedMNInference_tpl.h.

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

250  {
251  return posterior(this->MN().idFromName(nodeName));
252  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
virtual const Potential< GUM_SCALAR > & posterior(NodeId node) final
Computes and returns the posterior of a node.
+ Here is the call graph for this function:

◆ posterior_()

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

returns the posterior of a given variable

Parameters
idThe variable's id.

Implements gum::MarginalTargetedMNInference< 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 695 of file graphicalModelInference_tpl.h.

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

695  {
696  if (isInferenceReady() || isInferenceDone()) { return; }
697 
698  if (model__ == nullptr)
699  GUM_ERROR(NullElement,
700  "No model been assigned to the "
701  "inference algorithm");
702 
705  else
707 
709  }
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:54
+ Here is the call graph for this function:

◆ produceMessage__()

template<typename GUM_SCALAR >
void gum::ShaferShenoyMNInference< GUM_SCALAR >::produceMessage__ ( NodeId  from_id,
NodeId  to_id 
)
private

creates the message sent by clique from_id to clique to_id

◆ setCombinationFunction__()

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

sets the operator for performing the combinations

◆ setMN()

template<typename GUM_SCALAR >
void gum::MarkovNetInference< GUM_SCALAR >::setMN ( const IMarkovNet< GUM_SCALAR > *  mn)
virtualinherited

assigns a new MN to the inference engine

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

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

Definition at line 67 of file MarkovNetInference_tpl.h.

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

67  {
68  this->setModel_(mn);
69  }
void setModel_(const GraphicalModel *model)
+ Here is the call graph for this function:

◆ setModel_()

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

Definition at line 125 of file graphicalModelInference_tpl.h.

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

126  {
127  clear();
128  model__ = model;
132  }
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 137 of file graphicalModelInference_tpl.h.

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

138  {
139  model__ = model;
142  }
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 688 of file graphicalModelInference_tpl.h.

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

688  {
690  }
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 679 of file graphicalModelInference_tpl.h.

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

679  {
681  }
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:

◆ setProjectionFunction__()

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

sets the operator for performing the projections

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

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

104  {
105  if (state__ != state) {
106  state__ = state;
107  onStateChanged_();
108  }
109  }
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::MarginalTargetedMNInference< GUM_SCALAR >::setTargetedMode_ ( )
protectedinherited

Definition at line 341 of file marginalTargetedMNInference_tpl.h.

341  {
342  if (!targeted_mode__) {
343  targets__.clear();
344  targeted_mode__ = true;
345  }
346  }
NodeSet targets__
the set of marginal targets
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:374
bool targeted_mode__
whether the actual targets are default

◆ setTriangulation()

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

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

660  {
661  return soft_evidence_nodes__;
662  }
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 97 of file graphicalModelInference_tpl.h.

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

97  {
98  return state__;
99  }
StateOfInference state__
the current state of the inference (outdated/ready/done)
+ Here is the call graph for this function:

◆ superForJointComputable_()

template<typename GUM_SCALAR >
virtual NodeSet gum::ShaferShenoyMNInference< GUM_SCALAR >::superForJointComputable_ ( const NodeSet vars)
finalprotectedvirtual

◆ targets()

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

returns the list of marginal targets

Definition at line 214 of file marginalTargetedMNInference_tpl.h.

214  {
215  return targets__;
216  }
NodeSet targets__
the set of marginal targets

◆ unnormalizedJointPosterior_() [1/2]

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

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

Implements gum::JointTargetedMNInference< GUM_SCALAR >.

◆ unnormalizedJointPosterior_() [2/2]

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

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

Implements gum::JointTargetedMNInference< GUM_SCALAR >.

◆ updateOutdatedPotentials_()

template<typename GUM_SCALAR >
void gum::ShaferShenoyMNInference< 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 updateOutdatedStructure_ and makeMNInference_.

Implements gum::GraphicalModelInference< GUM_SCALAR >.

◆ updateOutdatedStructure_()

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

Implements gum::GraphicalModelInference< GUM_SCALAR >.

◆ VI() [1/2]

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::JointTargetedMNInference< 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 328 of file jointTargetedMNInference_tpl.h.

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

329  {
330  return this->H(X) + this->H(Y) - 2 * I(X, Y);
331  }
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::JointTargetedMNInference< GUM_SCALAR >::VI ( const std::string &  X,
const std::string &  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

Definition at line 264 of file jointTargetedMNInference_tpl.h.

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

265  {
266  return VI(this->MN().idFromName(Xname), this->MN().idFromName(Yname));
267  }
virtual const IMarkovNet< GUM_SCALAR > & MN() const final
Returns a constant reference over the IMarkovNet referenced by this class.
GUM_SCALAR VI(NodeId X, NodeId Y)
Variation of information between X and Y.
+ Here is the call graph for this function:

Member Data Documentation

◆ clique_potentials__

template<typename GUM_SCALAR >
NodeProperty< const Potential< GUM_SCALAR >* > gum::ShaferShenoyMNInference< GUM_SCALAR >::clique_potentials__
private

the potentials stored into the cliques by Shafer-Shenoy

For a given clique, there is an entry in clique_potentials__ if and only if the clique received some potential(s). In this case, the potential stored is the combination of all the corresponding list of potentials in clique_potentials_list__.

Definition at line 279 of file ShaferShenoyMNInference.h.

◆ clique_potentials_list__

template<typename GUM_SCALAR >
NodeProperty< PotentialSet__ > gum::ShaferShenoyMNInference< GUM_SCALAR >::clique_potentials_list__
private

the list of all potentials stored in the cliques

This structure contains a list for each clique in the join tree. If a clique did not received any potential, then its list is empty but the entry for the clique does exist. Note that clique potentials contain also soft evidence and the factors that were projected to remove their variables that received hard evidence. The product of all these potentials is precisely the potential stored into clique_potentials__

Definition at line 272 of file ShaferShenoyMNInference.h.

◆ combination_op__

template<typename GUM_SCALAR >
Potential< GUM_SCALAR >*(* gum::ShaferShenoyMNInference< GUM_SCALAR >::combination_op__) (const Potential< GUM_SCALAR > &, const Potential< GUM_SCALAR > &)
inlineprivate

the operator for performing the combinations

Definition at line 218 of file ShaferShenoyMNInference.h.

219  {
static INLINE Potential< GUM_SCALAR > * SSNewMNmultiPotential(const Potential< GUM_SCALAR > &t1, const Potential< GUM_SCALAR > &t2)

◆ created_messages__

template<typename GUM_SCALAR >
ArcProperty< PotentialSet__ > gum::ShaferShenoyMNInference< GUM_SCALAR >::created_messages__
private

the set of potentials created for the last inference messages

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

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

Definition at line 292 of file ShaferShenoyMNInference.h.

◆ evidence_changes__

template<typename GUM_SCALAR >
NodeProperty< EvidenceChangeType > gum::ShaferShenoyMNInference< GUM_SCALAR >::evidence_changes__
private

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

Definition at line 345 of file ShaferShenoyMNInference.h.

◆ factor_to_clique__

template<typename GUM_SCALAR >
HashTable< NodeSet, NodeId > gum::ShaferShenoyMNInference< GUM_SCALAR >::factor_to_clique__
private

for each node of reduced_graph__ (~ in the Markov net), associate an ID in the JT

Definition at line 257 of file ShaferShenoyMNInference.h.

◆ hard_ev_nodes__

template<typename GUM_SCALAR >
NodeSet gum::ShaferShenoyMNInference< GUM_SCALAR >::hard_ev_nodes__
private

the hard evidence nodes which were projected in factors

Definition at line 333 of file ShaferShenoyMNInference.h.

◆ hard_ev_projected_factors__

template<typename GUM_SCALAR >
HashTable< NodeSet, const Potential< GUM_SCALAR >* > gum::ShaferShenoyMNInference< GUM_SCALAR >::hard_ev_projected_factors__
private

the factors that were projected due to hard evidence nodes

For each factor containing the nodes that contain some hard evidence, assigns a new projected factor that does not contain these nodes anymore.

Warning
These potentials are owned by the inference class.

Definition at line 330 of file ShaferShenoyMNInference.h.

◆ is_new_jt_needed__

template<typename GUM_SCALAR >
bool gum::ShaferShenoyMNInference< GUM_SCALAR >::is_new_jt_needed__ {true}
private

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

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

Definition at line 244 of file ShaferShenoyMNInference.h.

◆ joint_target_posteriors__

template<typename GUM_SCALAR >
HashTable< NodeSet, const Potential< GUM_SCALAR >* > gum::ShaferShenoyMNInference< GUM_SCALAR >::joint_target_posteriors__
private

the set of set target posteriors computed during the last inference

the posteriors are owned by ShaferShenoyMNInference.

Definition at line 300 of file ShaferShenoyMNInference.h.

◆ joint_target_to_clique__

template<typename GUM_SCALAR >
HashTable< NodeSet, NodeId > gum::ShaferShenoyMNInference< GUM_SCALAR >::joint_target_to_clique__
private

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

Definition at line 262 of file ShaferShenoyMNInference.h.

◆ junctionTree__

template<typename GUM_SCALAR >
JunctionTree* gum::ShaferShenoyMNInference< GUM_SCALAR >::junctionTree__ {nullptr}
private

the junction tree to answer the last inference query

Definition at line 238 of file ShaferShenoyMNInference.h.

◆ messages_computed__

template<typename GUM_SCALAR >
ArcProperty< bool > gum::ShaferShenoyMNInference< GUM_SCALAR >::messages_computed__
private

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

indicates whether a message (from one clique to another) has been computed Here, all the messages, computed or not, are put into the property, only the Boolean makes the difference between messages computed and those that were not computed

Definition at line 313 of file ShaferShenoyMNInference.h.

◆ node_to_clique__

template<typename GUM_SCALAR >
NodeProperty< NodeId > gum::ShaferShenoyMNInference< GUM_SCALAR >::node_to_clique__
private

Definition at line 259 of file ShaferShenoyMNInference.h.

◆ node_to_soft_evidence__

template<typename GUM_SCALAR >
NodeProperty< const Potential< GUM_SCALAR >* > gum::ShaferShenoyMNInference< GUM_SCALAR >::node_to_soft_evidence__
private

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

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

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

Definition at line 322 of file ShaferShenoyMNInference.h.

◆ one_minus_epsilon__

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

for comparisons with 1 - epsilon

Definition at line 348 of file ShaferShenoyMNInference.h.

◆ projection_op__

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

the operator for performing the projections

Definition at line 213 of file ShaferShenoyMNInference.h.

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

◆ propagator__

template<typename GUM_SCALAR >
JoinTree* gum::ShaferShenoyMNInference< GUM_SCALAR >::propagator__ {nullptr}
private

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

Definition at line 235 of file ShaferShenoyMNInference.h.

◆ reduced_graph__

template<typename GUM_SCALAR >
UndiGraph gum::ShaferShenoyMNInference< GUM_SCALAR >::reduced_graph__
private

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

If all nodes are targets, this graph corresponds to the graph of the MN. Otherwise, it may be a subgraph of this moral graph.

Definition at line 232 of file ShaferShenoyMNInference.h.

◆ roots__

template<typename GUM_SCALAR >
NodeSet gum::ShaferShenoyMNInference< GUM_SCALAR >::roots__
private

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

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

Warning
roots__ should be computed only when evidenceProbability is called.

Definition at line 253 of file ShaferShenoyMNInference.h.

◆ separator_potentials__

template<typename GUM_SCALAR >
ArcProperty< PotentialSet__ > gum::ShaferShenoyMNInference< GUM_SCALAR >::separator_potentials__
private

the list of all potentials stored in the separators after inferences

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

Definition at line 284 of file ShaferShenoyMNInference.h.

◆ target_posteriors__

template<typename GUM_SCALAR >
NodeProperty< const Potential< GUM_SCALAR >* > gum::ShaferShenoyMNInference< GUM_SCALAR >::target_posteriors__
private

the set of single posteriors computed during the last inference

the posteriors are owned by ShaferShenoyMNInference.

Definition at line 296 of file ShaferShenoyMNInference.h.

◆ triangulation__

template<typename GUM_SCALAR >
Triangulation* gum::ShaferShenoyMNInference< GUM_SCALAR >::triangulation__
private

the triangulation class creating the junction tree used for inference

Definition at line 220 of file ShaferShenoyMNInference.h.

◆ use_binary_join_tree__

template<typename GUM_SCALAR >
bool gum::ShaferShenoyMNInference< GUM_SCALAR >::use_binary_join_tree__ {true}
private

indicates whether we should transform junction trees into binary join trees

Definition at line 227 of file ShaferShenoyMNInference.h.


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