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

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

#include <ShaferShenoyInference.h>

+ Inheritance diagram for gum::ShaferShenoyInference< GUM_SCALAR >:
+ Collaboration diagram for gum::ShaferShenoyInference< 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
 ShaferShenoyInference (const IBayesNet< GUM_SCALAR > *BN, FindBarrenNodesType barren_type=FindBarrenNodesType::FIND_BARREN_NODES, bool use_binary_join_tree=true)
 default constructor More...
 
 ~ShaferShenoyInference () final
 destructor More...
 
Accessors / Modifiers
void setTriangulation (const Triangulation &new_triangulation)
 use a new triangulation algorithm More...
 
void setFindBarrenNodesType (FindBarrenNodesType type)
 sets how we determine barren nodes More...
 
const JoinTreejoinTree ()
 returns the current join tree used More...
 
const JunctionTreejunctionTree ()
 returns the current junction tree More...
 
GUM_SCALAR evidenceProbability ()
 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 &Xname, const std::string &Yname)
 Mutual information between X and Y. More...
 
GUM_SCALAR VI (NodeId X, NodeId Y)
 Variation of information between X and Y. More...
 
GUM_SCALAR VI (const std::string &Xname, const std::string &Yname)
 Variation of information between X and Y. More...
 
GUM_SCALAR jointMutualInformation (const NodeSet &targets)
 Mutual information between targets. More...
 
GUM_SCALAR jointMutualInformation (const std::vector< std::string > &targets)
 Mutual information between targets. More...
 
Targets
virtual void addAllTargets () final
 adds all nodes as targets More...
 
virtual void addTarget (NodeId target) final
 Add a marginal target to the list of targets. More...
 
virtual void addTarget (const std::string &nodeName) final
 Add a marginal target to the list of targets. More...
 
virtual void eraseTarget (NodeId target) final
 removes an existing (marginal) target More...
 
virtual void eraseTarget (const std::string &nodeName) final
 removes an existing (marginal) target More...
 
virtual bool isTarget (NodeId node) const final
 return true if variable is a (marginal) target More...
 
virtual bool isTarget (const std::string &nodeName) const final
 return true if variable is a (marginal) target More...
 
virtual const Size nbrTargets () const noexcept final
 returns the number of marginal targets More...
 
virtual const NodeSettargets () const noexcept final
 returns the list of marginal targets More...
 
Information Theory related functions
virtual GUM_SCALAR H (NodeId X) final
 Entropy Compute Shanon's entropy of a node given the observation. More...
 
virtual GUM_SCALAR H (const std::string &nodeName) final
 Entropy Compute Shanon's entropy of a node given the observation. More...
 
Accessors / Modifiers
virtual void setBN (const IBayesNet< GUM_SCALAR > *bn)
 assigns a new BN to the inference engine More...
 
virtual const IBayesNet< GUM_SCALAR > & BN () const final
 Returns a constant reference over the IBayesNet referenced by this class. More...
 
Accessors / Modifiers
virtual const GraphicalModelmodel () const final
 Returns a constant reference over the IBayesNet referenced by this class. More...
 
virtual const NodeProperty< Size > & domainSizes () const final
 get the domain sizes of the random variables of the model More...
 
virtual bool isInferenceReady () const noexcept final
 returns whether the inference object is in a ready state More...
 
virtual bool isInferenceOutdatedStructure () const noexcept final
 returns whether the inference object is in a OutdatedStructure state More...
 
virtual bool isInferenceOutdatedPotentials () const noexcept final
 returns whether the inference object is in a OutdatedPotential state More...
 
virtual bool isInferenceDone () const noexcept final
 returns whether the inference object is in a InferenceDone state More...
 
virtual void prepareInference () final
 prepare the internal inference structures for the next inference More...
 
virtual void makeInference () final
 perform the heavy computations needed to compute the targets' posteriors More...
 
virtual void clear ()
 clears all the data structures allocated for the last inference More...
 
virtual StateOfInference state () const noexcept final
 returns the state of the inference engine More...
 
Evidence
virtual void addEvidence (NodeId id, const Idx val) final
 adds a new hard evidence on node id More...
 
virtual void addEvidence (const std::string &nodeName, const Idx val) final
 adds a new hard evidence on node named nodeName More...
 
virtual void addEvidence (NodeId id, const std::string &label) final
 adds a new hard evidence on node id More...
 
virtual void addEvidence (const std::string &nodeName, const std::string &label) final
 adds a new hard evidence on node named nodeName More...
 
virtual void addEvidence (NodeId id, const std::vector< GUM_SCALAR > &vals) final
 adds a new evidence on node id (might be soft or hard) More...
 
virtual void addEvidence (const std::string &nodeName, const std::vector< GUM_SCALAR > &vals) final
 adds a new evidence on node named nodeName (might be soft or hard) More...
 
virtual void addEvidence (const Potential< GUM_SCALAR > &pot) final
 adds a new evidence on node id (might be soft or hard) More...
 
virtual void addEvidence (Potential< GUM_SCALAR > &&pot) final
 adds a new evidence on node id (might be soft or hard) More...
 
virtual void addSetOfEvidence (const Set< const Potential< GUM_SCALAR > * > &potset) final
 adds a new set of evidence More...
 
virtual void addListOfEvidence (const List< const Potential< GUM_SCALAR > * > &potlist) final
 adds a new list of evidence More...
 
virtual void chgEvidence (NodeId id, const Idx val) final
 change the value of an already existing hard evidence More...
 
virtual void chgEvidence (const std::string &nodeName, const Idx val) final
 change the value of an already existing hard evidence More...
 
virtual void chgEvidence (NodeId id, const std::string &label) final
 change the value of an already existing hard evidence More...
 
virtual void chgEvidence (const std::string &nodeName, const std::string &label) final
 change the value of an already existing hard evidence More...
 
virtual void chgEvidence (NodeId id, const std::vector< GUM_SCALAR > &vals) final
 change the value of an already existing evidence (might be soft or hard) More...
 
virtual void chgEvidence (const std::string &nodeName, const std::vector< GUM_SCALAR > &vals) final
 change the value of an already existing evidence (might be soft or hard) More...
 
virtual void chgEvidence (const Potential< GUM_SCALAR > &pot) final
 change the value of an already existing evidence (might be soft or hard) More...
 
virtual void eraseAllEvidence () final
 removes all the evidence entered into the network More...
 
virtual void eraseEvidence (NodeId id) final
 removed the evidence, if any, corresponding to node id More...
 
virtual void eraseEvidence (const std::string &nodeName) final
 removed the evidence, if any, corresponding to node of name nodeName More...
 
virtual bool hasEvidence () const final
 indicates whether some node(s) have received evidence More...
 
virtual bool hasEvidence (NodeId id) const final
 indicates whether node id has received an evidence More...
 
virtual bool hasEvidence (const std::string &nodeName) const final
 indicates whether node id has received an evidence More...
 
virtual bool hasHardEvidence (NodeId id) const final
 indicates whether node id has received a hard evidence More...
 
virtual bool hasHardEvidence (const std::string &nodeName) const final
 indicates whether node id has received a hard evidence More...
 
virtual bool hasSoftEvidence (NodeId id) const final
 indicates whether node id has received a soft evidence More...
 
virtual bool hasSoftEvidence (const std::string &nodeName) const final
 indicates whether node id has received a soft evidence More...
 
virtual Size nbrEvidence () const final
 returns the number of evidence entered into the Bayesian network More...
 
virtual Size nbrHardEvidence () const final
 returns the number of hard evidence entered into the Bayesian network More...
 
virtual Size nbrSoftEvidence () const final
 returns the number of soft evidence entered into the Bayesian network More...
 
const NodeProperty< const Potential< GUM_SCALAR > *> & evidence () const
 returns the set of evidence More...
 
const NodeSetsoftEvidenceNodes () const
 returns the set of nodes with soft evidence More...
 
const NodeSethardEvidenceNodes () const
 returns the set of nodes with hard evidence More...
 
const NodeProperty< Idx > & hardEvidence () const
 indicate for each node with hard evidence which value it took More...
 

Public Types

enum  StateOfInference { StateOfInference::OutdatedStructure, StateOfInference::OutdatedPotentials, StateOfInference::ReadyForInference, StateOfInference::Done }
 current state of the inference More...
 

Protected Member Functions

void onStateChanged_ () final
 fired when the stage is changed More...
 
void onEvidenceAdded_ (const NodeId id, bool isHardEvidence) final
 fired after a new evidence is inserted More...
 
void onEvidenceErased_ (const NodeId id, bool isHardEvidence) final
 fired before an evidence is removed More...
 
void onAllEvidenceErased_ (bool contains_hard_evidence) final
 fired before all the evidence are erased More...
 
void onEvidenceChanged_ (const NodeId id, bool hasChangedSoftHard) final
 fired after an evidence is changed, in particular when its status (soft/hard) changes More...
 
void onMarginalTargetAdded_ (const NodeId id) final
 fired after a new single target is inserted More...
 
void onMarginalTargetErased_ (const NodeId id) final
 fired before a single target is removed More...
 
virtual void onModelChanged_ (const GraphicalModel *bn) final
 fired after a new Bayes net has been assigned to the engine More...
 
void onJointTargetAdded_ (const NodeSet &set) final
 fired after a new joint target is inserted More...
 
void onJointTargetErased_ (const NodeSet &set) final
 fired before a joint target is removed More...
 
void onAllMarginalTargetsAdded_ () final
 fired after all the nodes of the BN are added as single targets More...
 
void onAllMarginalTargetsErased_ () final
 fired before a all the single targets are removed More...
 
void onAllJointTargetsErased_ () final
 fired before a all the joint targets are removed More...
 
void onAllTargetsErased_ () final
 fired before a all single and joint_targets are removed More...
 
void updateOutdatedStructure_ () final
 prepares inference when the latter is in OutdatedStructure state More...
 
void updateOutdatedPotentials_ () final
 prepares inference when the latter is in OutdatedPotentials state More...
 
void makeInference_ () final
 called when the inference has to be performed effectively More...
 
const Potential< GUM_SCALAR > & posterior_ (NodeId id) final
 returns the posterior of a given variable More...
 
const Potential< GUM_SCALAR > & jointPosterior_ (const NodeSet &set) final
 returns the posterior of a declared target set More...
 
const Potential< GUM_SCALAR > & jointPosterior_ (const NodeSet &wanted_target, const NodeSet &declared_target) final
 asks derived classes for the joint posterior of a set of variables not declared as a joint target More...
 
Potential< GUM_SCALAR > * unnormalizedJointPosterior_ (NodeId id) final
 returns a fresh potential equal to P(argument,evidence) More...
 
Potential< GUM_SCALAR > * unnormalizedJointPosterior_ (const NodeSet &set) final
 returns a fresh potential equal to P(argument,evidence) More...
 
void setTargetedMode_ ()
 
bool isTargetedMode_ () const
 
void setOutdatedStructureState_ ()
 put the inference into an outdated model structure state More...
 
void setOutdatedPotentialsState_ ()
 puts the inference into an OutdatedPotentials state if it is not already in an OutdatedStructure state More...
 
virtual void setState_ (const StateOfInference state) final
 set the state of the inference engine and call the notification onStateChanged_ when necessary (i.e. when the state has effectively changed). More...
 
void setModel_ (const GraphicalModel *model)
 
void setModelDuringConstruction_ (const GraphicalModel *model)
 assigns a model during the inference engine construction More...
 
bool hasNoModel_ () const
 

Detailed Description

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

<agrum/BN/inference/ShaferShenoyInference.h>

Implementation of Shafer-Shenoy's propagation algorithm for inference in Bayesian networks

Definition at line 67 of file ShaferShenoyInference.h.

Member Typedef Documentation

◆ PotentialSet__

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

Definition at line 221 of file ShaferShenoyInference.h.

◆ PotentialSetIterator__

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

Definition at line 223 of file ShaferShenoyInference.h.

Member Enumeration Documentation

◆ EvidenceChangeType

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

the possible types of evidence changes

Enumerator
EVIDENCE_ADDED 
EVIDENCE_ERASED 
EVIDENCE_MODIFIED 

Definition at line 352 of file ShaferShenoyInference.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

◆ ShaferShenoyInference() [1/2]

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

default constructor

◆ ~ShaferShenoyInference()

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

destructor

◆ ShaferShenoyInference() [2/2]

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

avoid copy constructors

Member Function Documentation

◆ addAllTargets()

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

adds all nodes as targets

Definition at line 135 of file marginalTargetedInference_tpl.h.

135  {
136  // check if the node belongs to the Bayesian network
137  if (this->hasNoModel_())
138  GUM_ERROR(NullElement,
139  "No Bayes net has been assigned to the "
140  "inference algorithm");
141 
142 
143  setTargetedMode_(); // does nothing if already in targeted mode
144  for (const auto target: this->BN().dag()) {
145  if (!targets__.contains(target)) {
146  targets__.insert(target);
147  onMarginalTargetAdded_(target);
150  }
151  }
152  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:580
GraphicalModelInference()
default constructor with a null model (useful for virtual inheritance)
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual void onMarginalTargetAdded_(const NodeId id)=0
fired after a new marginal target is inserted
NodeSet targets__
the set of marginal targets
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h: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::JointTargetedInference< GUM_SCALAR >::addJointTarget ( const NodeSet joint_target)
finalvirtualinherited

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

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

Definition at line 117 of file jointTargetedInference_tpl.h.

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

118  {
119  // check if the nodes in the target belong to the Bayesian network
120  if (this->hasNoModel_())
121  GUM_ERROR(NullElement,
122  "No Bayes net has been assigned to the "
123  "inference algorithm");
124 
125  const auto& dag = this->BN().dag();
126  for (const auto node: joint_target) {
127  if (!dag.exists(node)) {
128  GUM_ERROR(UndefinedElement,
129  "at least one one in " << joint_target
130  << " does not belong to the bn");
131  }
132  }
133 
134  // check that the joint_target set does not contain the new target
135  if (joint_targets__.contains(joint_target)) return;
136 
137  // check if joint_target is a subset of an already existing target
138  for (const auto& target: joint_targets__) {
139  if (target.isProperSupersetOf(joint_target)) return;
140  }
141 
142  // check if joint_target is not a superset of an already existing target
143  // in this case, we need to remove old existing target
144  for (auto iter = joint_targets__.beginSafe();
145  iter != joint_targets__.endSafe();
146  ++iter) {
147  if (iter->isProperSubsetOf(joint_target)) eraseJointTarget(*iter);
148  }
149 
150  this->setTargetedMode_(); // does nothing if already in targeted mode
151  joint_targets__.insert(joint_target);
152  onJointTargetAdded_(joint_target);
153  this->setState_(
155  }
virtual void onJointTargetAdded_(const NodeSet &set)=0
fired after a new joint target is inserted
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual void eraseJointTarget(const NodeSet &joint_target) final
removes an existing joint target
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
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:

◆ 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::MarginalTargetedInference< GUM_SCALAR >::addTarget ( NodeId  target)
finalvirtualinherited

Add a marginal target to the list of targets.

Exceptions
UndefinedElementif target is not a NodeId in the Bayes net

Definition at line 111 of file marginalTargetedInference_tpl.h.

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

◆ addTarget() [2/2]

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

Add a marginal target to the list of targets.

Exceptions
UndefinedElementif target is not a NodeId in the Bayes net

Definition at line 157 of file marginalTargetedInference_tpl.h.

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

◆ BN()

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

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

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

Definition at line 59 of file BayesNetInference_tpl.h.

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

59  {
60  return static_cast< const IBayesNet< 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:

◆ 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::ShaferShenoyInference< GUM_SCALAR >::collectMessage__ ( NodeId  id,
NodeId  from 
)
private

actually perform the collect phase

◆ computeJoinTreeRoots__()

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

compute a root for each connected component of JT__

◆ createNewJT__()

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

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

◆ diffuseMessageInvalidations__()

template<typename GUM_SCALAR>
void gum::ShaferShenoyInference< 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::JointTargetedInference< GUM_SCALAR >::eraseAllJointTargets ( )
finalvirtualinherited

Clear all previously defined joint targets.

Definition at line 96 of file jointTargetedInference_tpl.h.

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

96  {
97  if (joint_targets__.size() > 0) {
98  // we already are in target mode. So no this->setTargetedMode_(); is needed
100  joint_targets__.clear();
103  }
104  }
GraphicalModelInference()
default constructor with a null model (useful for virtual inheritance)
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual void onAllJointTargetsErased_()=0
fired before a all the joint targets are removed
Set< NodeSet > joint_targets__
the set of joint targets
+ Here is the call graph for this function:

◆ eraseAllMarginalTargets()

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

Clear all the previously defined marginal targets.

Definition at line 89 of file jointTargetedInference_tpl.h.

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

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

◆ eraseAllTargets()

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

Clear all previously defined targets (marginal and joint targets)

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

Reimplemented from gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 109 of file jointTargetedInference_tpl.h.

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

109  {
112  }
virtual void eraseAllMarginalTargets() final
Clear all the previously defined marginal targets.
virtual void eraseAllJointTargets() final
Clear all previously defined joint targets.
+ Here is the call graph for this function:

◆ eraseEvidence() [1/2]

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

removed the evidence, if any, corresponding to node id

Definition at line 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::JointTargetedInference< GUM_SCALAR >::eraseJointTarget ( const NodeSet joint_target)
finalvirtualinherited

removes an existing joint target

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

Definition at line 160 of file jointTargetedInference_tpl.h.

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

161  {
162  // check if the nodes in the target belong to the Bayesian network
163  if (this->hasNoModel_())
164  GUM_ERROR(NullElement,
165  "No Bayes net has been assigned to the "
166  "inference algorithm");
167 
168  const auto& dag = this->BN().dag();
169  for (const auto node: joint_target) {
170  if (!dag.exists(node)) {
171  GUM_ERROR(UndefinedElement,
172  "at least one one in " << joint_target
173  << " does not belong to the bn");
174  }
175  }
176 
177  // check that the joint_target set does not contain the new target
178  if (joint_targets__.contains(joint_target)) {
179  // note that we have to be in target mode when we are here
180  // so, no this->setTargetedMode_(); is necessary
181  onJointTargetErased_(joint_target);
182  joint_targets__.erase(joint_target);
185  }
186  }
GraphicalModelInference()
default constructor with a null model (useful for virtual inheritance)
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i...
virtual void onJointTargetErased_(const NodeSet &set)=0
fired before a joint target is removed
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
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:

◆ eraseTarget() [1/2]

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

removes an existing (marginal) target

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

Definition at line 171 of file marginalTargetedInference_tpl.h.

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

◆ eraseTarget() [2/2]

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

removes an existing (marginal) target

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

Definition at line 196 of file marginalTargetedInference_tpl.h.

197  {
198  // check if the node belongs to the Bayesian network
199  if (this->hasNoModel_())
200  GUM_ERROR(NullElement,
201  "No Bayes net has been assigned to the "
202  "inference algorithm");
203 
204  eraseTarget(this->BN().idFromName(nodeName));
205  }
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
#define GUM_ERROR(type, msg)
Definition: exceptions.h: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::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact ( NodeId  target,
const NodeSet evs 
)
inherited

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

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

Definition at line 284 of file marginalTargetedInference_tpl.h.

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

◆ evidenceImpact() [2/2]

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

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

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

Definition at line 323 of file marginalTargetedInference_tpl.h.

325  {
326  const auto& bn = this->BN();
327  return evidenceImpact(bn.idFromName(target), bn.nodeset(evs));
328  }
Potential< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet &evs)
Create a gum::Potential for P(target|evs) (for all instanciation of target and evs) ...
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.

◆ evidenceJointImpact() [1/2]

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact ( const NodeSet targets,
const NodeSet evs 
)
inherited

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

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

Definition at line 341 of file jointTargetedInference_tpl.h.

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

343  {
344  if (!(evs * targets).empty()) {
345  GUM_ERROR(InvalidArgument,
346  "Targets (" << targets << ") can not intersect evs (" << evs
347  << ").");
348  }
349  auto condset = this->BN().minimalCondSet(targets, evs);
350 
351  this->eraseAllTargets();
352  this->eraseAllEvidence();
353 
354  Instantiation iTarget;
355  Potential< GUM_SCALAR > res;
356  for (const auto& target: targets) {
357  res.add(this->BN().variable(target));
358  iTarget.add(this->BN().variable(target));
359  }
360  this->addJointTarget(targets);
361 
362  for (const auto& n: condset) {
363  res.add(this->BN().variable(n));
364  this->addEvidence(n, 0);
365  }
366 
367  Instantiation inst(res);
368  for (inst.setFirstOut(iTarget); !inst.end(); inst.incOut(iTarget)) {
369  // inferring
370  for (const auto& n: condset)
371  this->chgEvidence(n, inst.val(this->BN().variable(n)));
372  this->makeInference();
373  // populate res
374  for (inst.setFirstIn(iTarget); !inst.end(); inst.incIn(iTarget)) {
375  res.set(inst, this->jointPosterior(targets)[inst]);
376  }
377  inst.setFirstIn(iTarget); // remove inst.end() flag
378  }
379 
380  return res;
381  }
virtual void eraseAllTargets()
Clear all previously defined targets (marginal and joint targets)
virtual void addJointTarget(const NodeSet &joint_target) final
Add a set of nodes as a new joint target. As a collateral effect, every node is added as a marginal t...
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual const Potential< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ evidenceJointImpact() [2/2]

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

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

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

Definition at line 385 of file jointTargetedInference_tpl.h.

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

387  {
388  const auto& bn = this->BN();
389  return evidenceJointImpact(bn.nodeset(targets), bn.nodeset(evs));
390  }
Potential< GUM_SCALAR > evidenceJointImpact(const NodeSet &targets, const NodeSet &evs)
Create a gum::Potential for P(joint targets|evs) (for all instanciation of targets and evs) ...
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
+ Here is the call graph for this function:

◆ evidenceProbability()

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

returns the probability of evidence

Implements gum::EvidenceInference< GUM_SCALAR >.

◆ H() [1/2]

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

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

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

Definition at line 268 of file marginalTargetedInference_tpl.h.

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

◆ H() [2/2]

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

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

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

Definition at line 277 of file marginalTargetedInference_tpl.h.

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

◆ hardEvidence()

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

indicate for each node with hard evidence which value it took

Definition at line 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::JointTargetedInference< GUM_SCALAR >::I ( NodeId  X,
NodeId  Y 
)
inherited

Mutual information between X and Y.

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

Definition at line 283 of file jointTargetedInference_tpl.h.

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

283  {
284  Potential< GUM_SCALAR > pX, pY, *pXY = nullptr;
285  if (X == Y) {
286  GUM_ERROR(OperationNotAllowed, "Mutual Information I(X,Y) with X==Y");
287  }
288 
289  try {
290  // here use unnormalized joint posterior rather than just posterior
291  // to avoid saving the posterior in the cache of the inference engines
292  // like LazyPropagation or SahferShenoy.
293  pXY = this->unnormalizedJointPosterior_({X, Y});
294  pXY->normalize();
295  pX = pXY->margSumOut({&(this->BN().variable(Y))});
296  pY = pXY->margSumOut({&(this->BN().variable(X))});
297  } catch (...) {
298  if (pXY != nullptr) { delete pXY; }
299  throw;
300  }
301 
302  Instantiation i(*pXY);
303  auto res = (GUM_SCALAR)0;
304 
305  for (i.setFirst(); !i.end(); ++i) {
306  GUM_SCALAR vXY = (*pXY)[i];
307  GUM_SCALAR vX = pX[i];
308  GUM_SCALAR vY = pY[i];
309 
310  if (vXY > (GUM_SCALAR)0) {
311  if (vX == (GUM_SCALAR)0 || vY == (GUM_SCALAR)0) {
312  GUM_ERROR(OperationNotAllowed,
313  "Mutual Information (X,Y) with P(X)=0 or P(Y)=0 "
314  "and P(X,Y)>0");
315  }
316 
317  res += vXY * (std::log2(vXY) - std::log2(vX) - std::log2(vY));
318  }
319  }
320 
321  delete pXY;
322 
323  return res;
324  }
virtual Potential< GUM_SCALAR > * unnormalizedJointPosterior_(const NodeSet &set)=0
returns a fresh unnormalized joint posterior of a given set of variables
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
#define GUM_ERROR(type, msg)
Definition: exceptions.h: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::JointTargetedInference< GUM_SCALAR >::I ( const std::string &  Xname,
const std::string &  Yname 
)
inherited

Mutual information between X and Y.

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

Definition at line 264 of file jointTargetedInference_tpl.h.

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

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

◆ invalidateAllMessages__()

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

invalidate all messages, posteriors and created potentials

◆ 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::JointTargetedInference< GUM_SCALAR >::isJointTarget ( const NodeSet vars) const
finalvirtualinherited

return true if target is a joint target.

Definition at line 69 of file jointTargetedInference_tpl.h.

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

70  {
71  if (this->hasNoModel_())
72  GUM_ERROR(NullElement,
73  "No Bayes net has been assigned to the "
74  "inference algorithm");
75 
76  const auto& dag = this->BN().dag();
77  for (const auto var: vars) {
78  if (!dag.exists(var)) {
79  GUM_ERROR(UndefinedElement, var << " is not a NodeId in the bn");
80  }
81  }
82 
83  return joint_targets__.contains(vars);
84  }
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet 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::ShaferShenoyInference< 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::MarginalTargetedInference< GUM_SCALAR >::isTarget ( NodeId  node) const
finalvirtualinherited

return true if variable is a (marginal) target

Definition at line 75 of file marginalTargetedInference_tpl.h.

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

◆ isTarget() [2/2]

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

return true if variable is a (marginal) target

Definition at line 90 of file marginalTargetedInference_tpl.h.

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

◆ isTargetedMode_()

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

Definition at line 332 of file marginalTargetedInference_tpl.h.

332  {
333  return targeted_mode__;
334  }
bool targeted_mode__
whether the actual targets are default

◆ jointMutualInformation() [1/2]

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

Mutual information between targets.

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

Definition at line 394 of file jointTargetedInference_tpl.h.

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

395  {
396  const auto& bn = this->BN();
397  const Size siz = targets.size();
398  if (siz <= 1) {
399  GUM_ERROR(InvalidArgument,
400  "jointMutualInformation needs at least 2 variables (targets="
401  << targets << ")");
402  }
403 
404  this->eraseAllTargets();
405  this->eraseAllEvidence();
406  this->addJointTarget(targets);
407  this->makeInference();
408  const auto po = this->jointPosterior(targets);
409 
410  gum::Instantiation caracteristic;
411  gum::Instantiation variables;
412  for (const auto nod: targets) {
413  const auto& var = bn.variable(nod);
414  auto pv = new gum::RangeVariable(var.name(), "", 0, 1);
415  caracteristic.add(*pv);
416  variables.add(var);
417  }
418 
419  Set< const DiscreteVariable* > sov;
420 
421  const GUM_SCALAR start = (siz % 2 == 0) ? GUM_SCALAR(-1.0) : GUM_SCALAR(1.0);
422  GUM_SCALAR sign;
423  GUM_SCALAR res = GUM_SCALAR(0.0);
424 
425  caracteristic.setFirst();
426  for (caracteristic.inc(); !caracteristic.end(); caracteristic.inc()) {
427  sov.clear();
428  sign = start;
429  for (Idx i = 0; i < caracteristic.nbrDim(); i++) {
430  if (caracteristic.val(i) == 1) {
431  sign = -sign;
432  sov.insert(&variables.variable(i));
433  }
434  }
435  res += sign * po.margSumIn(sov).entropy();
436  }
437 
438  for (Idx i = 0; i < caracteristic.nbrDim(); i++) {
439  delete &caracteristic.variable(i);
440  }
441 
442  return res;
443  }
virtual void eraseAllTargets()
Clear all previously defined targets (marginal and joint targets)
virtual void addJointTarget(const NodeSet &joint_target) final
Add a set of nodes as a new joint target. As a collateral effect, every node is added as a marginal t...
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Idx val(Idx i) const
Returns the current value of the variable at position i.
void inc()
Operator increment.
virtual const Potential< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
Defines a discrete random variable over an integer interval.
Definition: rangeVariable.h:53
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:82
void setFirst()
Assign the first values to the tuple of the Instantiation.
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:720
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual void makeInference() final
perform the heavy computations needed to compute the targets&#39; posteriors
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
bool end() const
Returns true if the Instantiation reached the end.
+ Here is the call graph for this function:

◆ jointMutualInformation() [2/2]

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

Mutual information between targets.

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

Definition at line 446 of file jointTargetedInference_tpl.h.

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

447  {
448  return jointMutualInformation(this->BN().ids(targets));
449  }
GUM_SCALAR jointMutualInformation(const NodeSet &targets)
Mutual information between targets.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
+ Here is the call graph for this function:

◆ jointPosterior()

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

Compute the joint posterior of a set of nodes.

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

Definition at line 211 of file jointTargetedInference_tpl.h.

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

211  {
212  // try to get the smallest set of targets that contains "nodes"
213  NodeSet set;
214  bool found_exact_target = false;
215 
216  if (joint_targets__.contains(nodes)) {
217  set = nodes;
218  found_exact_target = true;
219  } else {
220  for (const auto& target: joint_targets__) {
221  if (nodes.isProperSubsetOf(target)) {
222  set = target;
223  break;
224  }
225  }
226  }
227 
228  if (set.empty()) {
229  GUM_ERROR(UndefinedElement,
230  " no joint target containing " << nodes << " could be found among "
231  << joint_targets__);
232  }
233 
234  if (!this->isInferenceDone()) { this->makeInference(); }
235 
236  if (found_exact_target)
237  return jointPosterior_(nodes);
238  else
239  return jointPosterior_(nodes, set);
240  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual const Potential< GUM_SCALAR > & jointPosterior_(const NodeSet &set)=0
asks derived classes for the joint posterior of a declared target set
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
Set< NodeSet > joint_targets__
the set of joint targets
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::ShaferShenoyInference< GUM_SCALAR >::jointPosterior_ ( const NodeSet set)
finalprotectedvirtual

returns the posterior of a declared target set

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

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ jointPosterior_() [2/2]

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

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

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

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ joinTree()

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

returns the current join tree used

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

◆ jointTargets()

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

returns the list of joint targets

returns the list of target sets

Definition at line 192 of file jointTargetedInference_tpl.h.

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

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

returns the current junction tree

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

◆ 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::ShaferShenoyInference< 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::ShaferShenoyInference< 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

◆ 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::JointTargetedInference< GUM_SCALAR >::nbrJointTargets ( ) const
finalvirtualnoexceptinherited

returns the number of joint targets

returns the number of target sets

Definition at line 199 of file jointTargetedInference_tpl.h.

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

199  {
200  return joint_targets__.size();
201  }
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::MarginalTargetedInference< GUM_SCALAR >::nbrTargets ( ) const
finalvirtualnoexceptinherited

returns the number of marginal targets

Definition at line 218 of file marginalTargetedInference_tpl.h.

218  {
219  return targets__.size();
220  }
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::ShaferShenoyInference< 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::ShaferShenoyInference< GUM_SCALAR >::onAllJointTargetsErased_ ( )
finalprotectedvirtual

fired before a all the joint targets are removed

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ onAllMarginalTargetsAdded_()

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

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

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

◆ onAllMarginalTargetsErased_()

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

fired before a all the single targets are removed

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

◆ onAllTargetsErased_()

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

fired before a all single and joint_targets are removed

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ onEvidenceAdded_()

template<typename GUM_SCALAR>
void gum::ShaferShenoyInference< 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::ShaferShenoyInference< 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::ShaferShenoyInference< 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::ShaferShenoyInference< GUM_SCALAR >::onJointTargetAdded_ ( const NodeSet set)
finalprotectedvirtual

fired after a new joint target is inserted

Parameters
setThe set of target variable's ids.

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ onJointTargetErased_()

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

fired before a joint target is removed

Parameters
setThe set of target variable's ids.

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ onMarginalTargetAdded_()

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

fired after a new single target is inserted

Parameters
idThe target variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

◆ onMarginalTargetErased_()

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

fired before a single target is removed

Parameters
idThe target variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

◆ onModelChanged_()

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

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

Reimplemented from gum::JointTargetedInference< GUM_SCALAR >.

◆ onStateChanged_()

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

fired when the stage is changed

Implements gum::GraphicalModelInference< GUM_SCALAR >.

Definition at line 125 of file ShaferShenoyInference.h.

125 {};

◆ operator=()

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

avoid copy operators

◆ posterior() [1/2]

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

Computes and returns the posterior of a node.

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

Reimplemented from gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 246 of file jointTargetedInference_tpl.h.

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

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

◆ posterior() [2/2]

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

Computes and returns the posterior of a node.

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

Reimplemented from gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 256 of file jointTargetedInference_tpl.h.

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

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

◆ posterior_()

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

returns the posterior of a given variable

Parameters
idThe variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

◆ prepareInference()

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

prepare the internal inference structures for the next inference

Definition at line 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::ShaferShenoyInference< GUM_SCALAR >::produceMessage__ ( NodeId  from_id,
NodeId  to_id 
)
private

creates the message sent by clique from_id to clique to_id

◆ removeBarrenVariables__()

template<typename GUM_SCALAR>
PotentialSet__ gum::ShaferShenoyInference< GUM_SCALAR >::removeBarrenVariables__ ( PotentialSet__ pot_list,
Set< const DiscreteVariable * > &  del_vars 
)
private

◆ setBN()

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

assigns a new BN to the inference engine

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

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

Definition at line 66 of file BayesNetInference_tpl.h.

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

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

◆ setCombinationFunction__()

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

sets the operator for performing the combinations

◆ setFindBarrenNodesType()

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

sets how we determine barren nodes

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

◆ setModel_()

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

Definition at line 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::ShaferShenoyInference< 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::MarginalTargetedInference< GUM_SCALAR >::setTargetedMode_ ( )
protectedinherited

Definition at line 336 of file marginalTargetedInference_tpl.h.

336  {
337  if (!targeted_mode__) {
338  targets__.clear();
339  targeted_mode__ = true;
340  }
341  }
bool targeted_mode__
whether the actual targets are default
NodeSet targets__
the set of marginal targets
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:374

◆ setTriangulation()

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

◆ targets()

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

returns the list of marginal targets

Definition at line 211 of file marginalTargetedInference_tpl.h.

211  {
212  return targets__;
213  }
NodeSet targets__
the set of marginal targets

◆ unnormalizedJointPosterior_() [1/2]

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

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

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ unnormalizedJointPosterior_() [2/2]

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

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

Implements gum::JointTargetedInference< GUM_SCALAR >.

◆ updateOutdatedPotentials_()

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

Implements gum::GraphicalModelInference< GUM_SCALAR >.

◆ updateOutdatedStructure_()

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

prepares inference when the latter is in OutdatedStructure state

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

Implements gum::GraphicalModelInference< GUM_SCALAR >.

◆ VI() [1/2]

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

Variation of information between X and Y.

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

Definition at line 334 of file jointTargetedInference_tpl.h.

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

334  {
335  return this->H(X) + this->H(Y) - 2 * I(X, Y);
336  }
GUM_SCALAR I(NodeId X, NodeId Y)
Mutual information between X and Y.
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon&#39;s entropy of a node given the observation.
+ Here is the call graph for this function:

◆ VI() [2/2]

template<typename GUM_SCALAR >
GUM_SCALAR gum::JointTargetedInference< GUM_SCALAR >::VI ( const std::string &  Xname,
const std::string &  Yname 
)
inherited

Variation of information between X and Y.

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

Definition at line 270 of file jointTargetedInference_tpl.h.

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

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

Member Data Documentation

◆ barren_nodes_type__

template<typename GUM_SCALAR>
FindBarrenNodesType gum::ShaferShenoyInference< GUM_SCALAR >::barren_nodes_type__
private

the type of barren nodes computation we wish

Definition at line 227 of file ShaferShenoyInference.h.

◆ clique_potentials__

template<typename GUM_SCALAR>
NodeProperty< PotentialSet__ > gum::ShaferShenoyInference< GUM_SCALAR >::clique_potentials__
private

the list of all potentials stored in the cliques

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

Definition at line 289 of file ShaferShenoyInference.h.

◆ clique_ss_potential__

template<typename GUM_SCALAR>
NodeProperty< const Potential< GUM_SCALAR >* > gum::ShaferShenoyInference< GUM_SCALAR >::clique_ss_potential__
private

the potentials stored into the cliques by Shafer-Shenoy

For a given clique, there is an entry in clique_ss_potential__ 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__.

Definition at line 296 of file ShaferShenoyInference.h.

◆ combination_op__

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

the operator for performing the combinations

Definition at line 235 of file ShaferShenoyInference.h.

236  {
static INLINE Potential< GUM_SCALAR > * SSNewmultiPotential(const Potential< GUM_SCALAR > &t1, const Potential< GUM_SCALAR > &t2)

◆ constants__

template<typename GUM_SCALAR>
NodeProperty< GUM_SCALAR > gum::ShaferShenoyInference< GUM_SCALAR >::constants__
private

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

Definition at line 323 of file ShaferShenoyInference.h.

◆ created_potentials__

template<typename GUM_SCALAR>
ArcProperty< PotentialSet__ > gum::ShaferShenoyInference< GUM_SCALAR >::created_potentials__
private

the set of potentials created for the last inference messages

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

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

Definition at line 309 of file ShaferShenoyInference.h.

◆ evidence_changes__

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

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

Definition at line 361 of file ShaferShenoyInference.h.

◆ graph__

template<typename GUM_SCALAR>
UndiGraph gum::ShaferShenoyInference< GUM_SCALAR >::graph__
private

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

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

Definition at line 252 of file ShaferShenoyInference.h.

◆ hard_ev_nodes__

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

the hard evidence nodes which were projected in CPTs

Definition at line 349 of file ShaferShenoyInference.h.

◆ hard_ev_projected_CPTs__

template<typename GUM_SCALAR>
NodeProperty< const Potential< GUM_SCALAR >* > gum::ShaferShenoyInference< GUM_SCALAR >::hard_ev_projected_CPTs__
private

the CPTs that were projected due to hard evidence nodes

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

Warning
These potentials are owned by LayPropagation.

Definition at line 346 of file ShaferShenoyInference.h.

◆ is_new_jt_needed__

template<typename GUM_SCALAR>
bool gum::ShaferShenoyInference< 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 264 of file ShaferShenoyInference.h.

◆ joint_target_posteriors__

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

the set of set target posteriors computed during the last inference

the posteriors are owned by ShaferShenoyInference.

Definition at line 317 of file ShaferShenoyInference.h.

◆ joint_target_to_clique__

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

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

Definition at line 279 of file ShaferShenoyInference.h.

◆ JT__

template<typename GUM_SCALAR>
JoinTree* gum::ShaferShenoyInference< GUM_SCALAR >::JT__ {nullptr}
private

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

Definition at line 255 of file ShaferShenoyInference.h.

◆ junctionTree__

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

the junction tree to answer the last inference query

Definition at line 258 of file ShaferShenoyInference.h.

◆ messages_computed__

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

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

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

Definition at line 330 of file ShaferShenoyInference.h.

◆ node_to_clique__

template<typename GUM_SCALAR>
HashTable< NodeId, NodeId > gum::ShaferShenoyInference< GUM_SCALAR >::node_to_clique__
private

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

Definition at line 276 of file ShaferShenoyInference.h.

◆ node_to_soft_evidence__

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

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

This variable is useful for method 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 ShaferShenoyInference, they are only referenced by it. Only the cliques that contain evidence are filled in this structure.

Definition at line 339 of file ShaferShenoyInference.h.

◆ one_minus_epsilon__

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

for comparisons with 1 - epsilon

Definition at line 364 of file ShaferShenoyInference.h.

◆ projection_op__

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

the operator for performing the projections

Definition at line 230 of file ShaferShenoyInference.h.

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

◆ roots__

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

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

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

Warning
roots__ should be computed only when evidenceProbability is called.

Definition at line 273 of file ShaferShenoyInference.h.

◆ separator_potentials__

template<typename GUM_SCALAR>
ArcProperty< PotentialSet__ > gum::ShaferShenoyInference< 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 301 of file ShaferShenoyInference.h.

◆ target_posteriors__

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

the set of single posteriors computed during the last inference

the posteriors are owned by ShaferShenoyInference.

Definition at line 313 of file ShaferShenoyInference.h.

◆ triangulation__

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

the triangulation class creating the junction tree used for inference

Definition at line 237 of file ShaferShenoyInference.h.

◆ use_binary_join_tree__

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

indicates whether we should transform junction trees into binary join trees

Definition at line 244 of file ShaferShenoyInference.h.


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