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

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

#include <GibbsSampling.h>

Inheritance diagram for gum::GibbsSampling< GUM_SCALAR >:
Collaboration diagram for gum::GibbsSampling< GUM_SCALAR >:

Public Types

enum class  StateOfInference { OutdatedStructure , OutdatedTensors , ReadyForInference , Done }
 current state of the inference More...
enum class  ApproximationSchemeSTATE : char {
  Undefined , Continue , Epsilon , Rate ,
  Limit , TimeLimit , Stopped
}
 The different state of an approximation scheme. More...

Public Member Functions

 GibbsSampling (const IBayesNet< GUM_SCALAR > *bn)
 Default constructor.
 ~GibbsSampling () override
 Destructor.
void setBurnIn (Size b)
 Number of burn in for one iteration.
Size burnIn () const
 Returns the number of burn in.
virtual void contextualize ()
 Simplifying the Bayesian network with relevance reasonning to lighten the computational charge.
Tensor< GUM_SCALAR > evidenceImpact (NodeId target, const NodeSet &evs)
 Create a gum::Tensor for P(target|evs) (for all instantiation of target and evs).
Tensor< GUM_SCALAR > evidenceImpact (std::string_view target, const std::vector< std::string > &evs)
 Create a gum::Tensor for P(target|evs) (for all instantiation of target and evs).
Size nbrDrawnVar () const
 Getters and setters.
void setNbrDrawnVar (Size nbr)
bool isDrawnAtRandom () const
void setDrawnAtRandom (bool atRandom)
Instantiation monteCarloSample ()
 draws a Monte Carlo sample
Instantiation nextSample (Instantiation prev)
 draws next sample of Gibbs sampling
Constructors / Destructors
const Tensor< GUM_SCALAR > & currentPosterior (NodeId id)
 Computes and returns the actual estimation of the posterior of a node.
const Tensor< GUM_SCALAR > & currentPosterior (std::string_view name)
 Computes and returns the actual estimation of the posterior of a node by its name.
Probability computations
const IBayesNet< GUM_SCALAR > & samplingBN ()
 get the BayesNet which is used to really perform the sampling
const Tensor< GUM_SCALAR > & posterior_ (NodeId id) override
 Computes and returns the posterior of a node.
Estimator objects initializing
virtual void setEstimatorFromBN_ ()
 Initializes the estimators object linked to the simulation.
virtual void setEstimatorFromLBP_ (LoopyBeliefPropagation< GUM_SCALAR > *lbp, GUM_SCALAR virtualLBPSize)
 Initializes the estimators object linked to the simulation.
Probability computations
virtual const Tensor< GUM_SCALAR > & posterior (NodeId node)
 Computes and returns the posterior of a node.
virtual const Tensor< GUM_SCALAR > & posterior (std::string_view nodeName)
 Computes and returns the posterior of a node.
Targets
virtual void eraseAllTargets ()
 Clear all previously defined targets.
virtual void addAllTargets () final
 adds all nodes as targets
virtual void addTarget (NodeId target) final
 Add a marginal target to the list of targets.
virtual void addTarget (std::string_view nodeName) final
 Add a marginal target to the list of targets.
virtual void eraseTarget (NodeId target) final
 removes an existing (marginal) target
virtual void eraseTarget (std::string_view nodeName) final
 removes an existing (marginal) target
virtual bool isTarget (NodeId node) const final
 return true if variable is a (marginal) target
virtual bool isTarget (std::string_view nodeName) const final
 return true if variable is a (marginal) target
virtual Size nbrTargets () const noexcept final
 returns the number of marginal targets
virtual const NodeSettargets () const noexcept final
 returns the list of marginal targets
virtual bool isInTargetMode () const noexcept final
 indicates whether the inference is in a target mode
Information Theory related functions
virtual GUM_SCALAR H (NodeId X) final
 Entropy Compute Shanon's entropy of a node given the observation.
virtual GUM_SCALAR H (std::string_view nodeName) final
 Entropy Compute Shanon's entropy of a node given the observation.
Accessors / Modifiers
virtual void setBN (const IBayesNet< GUM_SCALAR > *bn)
 assigns a new BN to the inference engine
virtual const IBayesNet< GUM_SCALAR > & BN () const final
 Returns a constant reference over the IBayesNet referenced by this class.
Accessors / Modifiers
virtual const GraphicalModelmodel () const final
 Returns a constant reference over the IBayesNet referenced by this class.
virtual const NodeProperty< Size > & domainSizes () const final
 get the domain sizes of the random variables of the model
virtual bool isInferenceReady () const noexcept final
 returns whether the inference object is in a ready state
virtual bool isInferenceOutdatedStructure () const noexcept final
 returns whether the inference object is in a OutdatedStructure state
virtual bool isInferenceOutdatedTensors () const noexcept final
 returns whether the inference object is in a OutdatedTensor state
virtual bool isInferenceDone () const noexcept final
 returns whether the inference object is in a InferenceDone state
virtual void prepareInference () final
 prepare the internal inference structures for the next inference
virtual void makeInference () final
 perform the heavy computations needed to compute the targets' posteriors
virtual void clear ()
 clears all the data structures allocated for the last inference
virtual StateOfInference state () const noexcept final
 returns the state of the inference engine
Evidence
virtual void addEvidence (NodeId id, const Idx val) final
 adds a new hard evidence on node id
virtual void addEvidence (std::string_view nodeName, const Idx val) final
 adds a new hard evidence on node named nodeName
virtual void addEvidence (NodeId id, std::string_view label) final
 adds a new hard evidence on node id
virtual void addEvidence (std::string_view nodeName, std::string_view label) final
 adds a new hard evidence on node named nodeName
virtual void addEvidence (NodeId id, const std::vector< GUM_SCALAR > &vals) final
 adds a new evidence on node id (might be soft or hard)
virtual void addEvidence (std::string_view nodeName, const std::vector< GUM_SCALAR > &vals) final
 adds a new evidence on node named nodeName (might be soft or hard)
virtual void addEvidence (const Tensor< GUM_SCALAR > &pot) final
 adds a new evidence on node id (might be soft or hard)
virtual void addEvidence (Tensor< GUM_SCALAR > &&pot) final
 adds a new evidence on node id (might be soft or hard)
virtual void addSetOfEvidence (const Set< const Tensor< GUM_SCALAR > * > &potset) final
 adds a new set of evidence
virtual void addListOfEvidence (const List< const Tensor< GUM_SCALAR > * > &potlist) final
 adds a new list of evidence
virtual void chgEvidence (NodeId id, const Idx val) final
 change the value of an already existing hard evidence
virtual void chgEvidence (std::string_view nodeName, const Idx val) final
 change the value of an already existing hard evidence
virtual void chgEvidence (NodeId id, std::string_view label) final
 change the value of an already existing hard evidence
virtual void chgEvidence (std::string_view nodeName, std::string_view label) final
 change the value of an already existing hard evidence
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)
virtual void chgEvidence (std::string_view nodeName, const std::vector< GUM_SCALAR > &vals) final
 change the value of an already existing evidence (might be soft or hard)
virtual void chgEvidence (const Tensor< GUM_SCALAR > &pot) final
 change the value of an already existing evidence (might be soft or hard)
virtual void eraseAllEvidence () final
 removes all the evidence entered into the network
virtual void eraseEvidence (NodeId id) final
 removed the evidence, if any, corresponding to node id
virtual void eraseEvidence (std::string_view nodeName) final
 removed the evidence, if any, corresponding to node of name nodeName
virtual bool hasEvidence () const final
 indicates whether some node(s) have received evidence
virtual bool hasEvidence (NodeId id) const final
 indicates whether node id has received an evidence
virtual bool hasEvidence (std::string_view nodeName) const final
 indicates whether node id has received an evidence
virtual bool hasHardEvidence (NodeId id) const final
 indicates whether node id has received a hard evidence
virtual bool hasHardEvidence (std::string_view nodeName) const final
 indicates whether node id has received a hard evidence
virtual bool hasSoftEvidence (NodeId id) const final
 indicates whether node id has received a soft evidence
virtual bool hasSoftEvidence (std::string_view nodeName) const final
 indicates whether node id has received a soft evidence
virtual Size nbrEvidence () const final
 returns the number of evidence entered into the Bayesian network
virtual Size nbrHardEvidence () const final
 returns the number of hard evidence entered into the Bayesian network
virtual Size nbrSoftEvidence () const final
 returns the number of soft evidence entered into the Bayesian network
const NodeProperty< const Tensor< GUM_SCALAR > * > & evidence () const
 returns the set of evidence
const NodeSetsoftEvidenceNodes () const
 returns the set of nodes with soft evidence
const NodeSethardEvidenceNodes () const
 returns the set of nodes with hard evidence
const NodeProperty< Idx > & hardEvidence () const
 indicate for each node with hard evidence which value it took
Getters and setters
void setEpsilon (double eps) override
 Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
double epsilon () const override
 Returns the value of epsilon.
void disableEpsilon () override
 Disable stopping criterion on epsilon.
void enableEpsilon () override
 Enable stopping criterion on epsilon.
bool isEnabledEpsilon () const override
 Returns true if stopping criterion on epsilon is enabled, false otherwise.
void setMinEpsilonRate (double rate) override
 Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
double minEpsilonRate () const override
 Returns the value of the minimal epsilon rate.
void disableMinEpsilonRate () override
 Disable stopping criterion on epsilon rate.
void enableMinEpsilonRate () override
 Enable stopping criterion on epsilon rate.
bool isEnabledMinEpsilonRate () const override
 Returns true if stopping criterion on epsilon rate is enabled, false otherwise.
void setMaxIter (Size max) override
 Stopping criterion on number of iterations.
Size maxIter () const override
 Returns the criterion on number of iterations.
void disableMaxIter () override
 Disable stopping criterion on max iterations.
void enableMaxIter () override
 Enable stopping criterion on max iterations.
bool isEnabledMaxIter () const override
 Returns true if stopping criterion on max iterations is enabled, false otherwise.
void setMaxTime (double timeout) override
 Stopping criterion on timeout.
double maxTime () const override
 Returns the timeout (in seconds).
double currentTime () const override
 Returns the current running time in second.
void disableMaxTime () override
 Disable stopping criterion on timeout.
void enableMaxTime () override
 Enable stopping criterion on timeout.
bool isEnabledMaxTime () const override
 Returns true if stopping criterion on timeout is enabled, false otherwise.
void setPeriodSize (Size p) override
 How many samples between two stopping is enable.
Size periodSize () const override
 Returns the period size.
void setVerbosity (bool v) override
 Set the verbosity on (true) or off (false).
bool verbosity () const override
 Returns true if verbosity is enabled.
ApproximationSchemeSTATE stateApproximationScheme () const override
 Returns the approximation scheme state.
Size nbrIterations () const override
 Returns the number of iterations.
const std::vector< double > & history () const override
 Returns the scheme history.
void initApproximationScheme ()
 Initialise the scheme.
bool startOfPeriod () const
 Returns true if we are at the beginning of a period (compute error is mandatory).
void updateApproximationScheme (unsigned int incr=1)
 Update the scheme w.r.t the new error and increment steps.
Size remainingBurnIn () const
 Returns the remaining burn in.
void stopApproximationScheme ()
 Stop the approximation scheme.
bool continueApproximationScheme (double error)
 Update the scheme w.r.t the new error.
Getters and setters
std::string messageApproximationScheme () const
 Returns the approximation scheme message.

Public Attributes

Signaler< Size, double, doubleonProgress
 Progression, error and time.
Signaler< std::string_view > onStop
 Criteria messageApproximationScheme.

Protected Member Functions

Instantiation burnIn_ () override
 draws a defined number of samples without updating the estimators
Instantiation draw_ (GUM_SCALAR *w, Instantiation prev) override
 draws a sample given previous one according to Gibbs sampling
Instantiation monteCarloSample_ ()
 draws a Monte Carlo sample
void makeInference_ () override
 makes the inference by generating samples
void loopApproxInference_ ()
virtual void addVarSample_ (NodeId nod, Instantiation *I)
 adds a node to current instantiation
virtual void onContextualize_ (BayesNetFragment< GUM_SCALAR > *bn)
 fired when Bayesian network is contextualized
void onEvidenceAdded_ (const NodeId id, bool isHardEvidence) override
 fired after a new evidence is inserted
void onEvidenceErased_ (const NodeId id, bool isHardEvidence) override
 fired before an evidence is removed
void onAllEvidenceErased_ (bool contains_hard_evidence) override
 fired before all the evidence are erased
void onEvidenceChanged_ (const NodeId id, bool hasChangedSoftHard) override
 fired after an evidence is changed, in particular when its status (soft/hard) changes
void onModelChanged_ (const GraphicalModel *bn) override
 fired after a new Bayes net has been assigned to the engine
void updateOutdatedStructure_ () override
 prepares inference when the latter is in OutdatedStructure state
void updateOutdatedTensors_ () override
 prepares inference when the latter is in OutdatedTensors state
void onMarginalTargetAdded_ (const NodeId id) override
 fired after a new marginal target is inserted
void onMarginalTargetErased_ (const NodeId id) override
 fired before a marginal target is removed
void onAllMarginalTargetsAdded_ () override
 fired after all the nodes of the BN are added as marginal targets
void onAllMarginalTargetsErased_ () override
 fired before a all marginal targets are removed
void onStateChanged_ () override
 fired when the stage is changed
void setTargetedMode_ ()
bool isTargetedMode_ () const
void setOutdatedStructureState_ ()
 put the inference into an outdated model structure state
void setOutdatedTensorsState_ ()
 puts the inference into an OutdatedTensors state if it is not already in an OutdatedStructure state
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).
void setModel_ (const GraphicalModel *model)
void setModelDuringConstruction_ (const GraphicalModel *model)
 assigns a model during the inference engine construction
bool hasNoModel_ () const
void updateSamplingNodes_ ()

Protected Attributes

Estimator< GUM_SCALAR > _estimator_
 Estimator object designed to approximate target posteriors.
bool isSetEstimator = false
 whether the Estimator object has been initialized
bool isContextualized = false
 whether the referenced Bayesian network has been "contextualized"
double current_epsilon_
 Current epsilon.
double last_epsilon_
 Last epsilon value.
double current_rate_
 Current rate.
Size current_step_
 The current step.
Timer timer_
 The timer.
ApproximationSchemeSTATE current_state_
 The current state.
std::vector< doublehistory_
 The scheme history, used only if verbosity == true.
double eps_
 Threshold for convergence.
bool enabled_eps_
 If true, the threshold convergence is enabled.
double min_rate_eps_
 Threshold for the epsilon rate.
bool enabled_min_rate_eps_
 If true, the minimal threshold for epsilon rate is enabled.
double max_time_
 The timeout.
bool enabled_max_time_
 If true, the timeout is enabled.
Size max_iter_
 The maximum iterations.
bool enabled_max_iter_
 If true, the maximum iterations stopping criterion is enabled.
Size burn_in_
 Number of iterations before checking stopping criteria.
Size period_size_
 Checking criteria frequency.
bool verbosity_
 If true, verbosity is enabled.
Size counting_
const IBayesNet< GUM_SCALAR > & samplingBn_
const NodeProperty< Idx > * hardEv_
Sequence< NodeIdsamplingNodes_
Size nbr_
bool atRandom_

Private Member Functions

void _setAllMarginalTargets_ ()
 sets all the nodes of the Bayes net as targets
void stopScheme_ (ApproximationSchemeSTATE new_state)
 Stop the scheme given a new state.
void _drawVarMonteCarlo_ (NodeId nod, Instantiation *I)
void _GibbsSample_ (NodeId id, Instantiation *I)
 change in Instantiation I a new drawn value for id

Private Attributes

BayesNetFragment< GUM_SCALAR > * _samplingBN_
bool _targeted_mode_
 whether the actual targets are default
NodeSet _targets_
 the set of marginal targets

Detailed Description

template<GUM_Numeric GUM_SCALAR>
class gum::GibbsSampling< GUM_SCALAR >

<agrum/BN/inference/gibbsSampling.h>

class for making Gibbs sampling inference in Bayesian networks.

This class overrides pure function declared in the inherited class ApproximateInference. It defines the way Gibbs sampling draws a sample. It also inherits GibbsOperator which contains Gibbs sampling methods.

Definition at line 72 of file GibbsSampling.h.

Member Enumeration Documentation

◆ ApproximationSchemeSTATE

The different state of an approximation scheme.

Enumerator
Undefined 
Continue 
Epsilon 
Rate 
Limit 
TimeLimit 
Stopped 

Definition at line 87 of file IApproximationSchemeConfiguration.h.

87 : char {
88 Undefined,
89 Continue,
90 Epsilon,
91 Rate,
92 Limit,
93 TimeLimit,
94 Stopped
95 };

◆ StateOfInference

template<GUM_Numeric GUM_SCALAR>
enum class 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.
  • OutdatedTensors: in this state, the structure of the model remains unchanged, only some tensors stored in it have changed. Therefore, the inference probably just needs to invalidate some already computed tensors 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 tensors we need.
Enumerator
OutdatedStructure 
OutdatedTensors 
ReadyForInference 
Done 

Definition at line 127 of file graphicalModelInference.h.

127{ OutdatedStructure, OutdatedTensors, ReadyForInference, Done };

Constructor & Destructor Documentation

◆ GibbsSampling()

template<GUM_Numeric GUM_SCALAR>
gum::GibbsSampling< GUM_SCALAR >::GibbsSampling ( const IBayesNet< GUM_SCALAR > * bn)
explicit

Default constructor.

default constructor

Definition at line 64 of file GibbsSampling_tpl.h.

64 :
67 &this->hardEvidence(),
68 1 + (bn->size() * GIBBS_SAMPLING_POURCENT_DRAWN_SAMPLE / 100),
71
75 }
void setMinEpsilonRate(double rate) override
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
void setEpsilon(double eps) override
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
GibbsOperator(const IBayesNet< GUM_SCALAR > &BN, const NodeProperty< Idx > *hardEv, Size nbr=1, bool atRandom=false)
constructor
<agrum/BN/inference/gibbsSampling.h>
void setBurnIn(Size b)
Number of burn in for one iteration.
GibbsSampling(const IBayesNet< GUM_SCALAR > *bn)
Default constructor.
const NodeProperty< Idx > & hardEvidence() const
indicate for each node with hard evidence which value it took
SamplingInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor

References gum::GibbsOperator< GUM_SCALAR >::GibbsOperator(), GibbsSampling(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), GIBBS_SAMPLING_DEFAULT_BURNIN, GIBBS_SAMPLING_DEFAULT_EPSILON, GIBBS_SAMPLING_DEFAULT_MIN_EPSILON_RATE, GIBBS_SAMPLING_DRAWN_AT_RANDOM, GIBBS_SAMPLING_POURCENT_DRAWN_SAMPLE, gum::GraphicalModelInference< GUM_SCALAR >::hardEvidence(), setBurnIn(), gum::ApproximationScheme::setEpsilon(), and gum::ApproximationScheme::setMinEpsilonRate().

Referenced by GibbsSampling(), and ~GibbsSampling().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~GibbsSampling()

template<GUM_Numeric GUM_SCALAR>
gum::GibbsSampling< GUM_SCALAR >::~GibbsSampling ( )
override

Destructor.

destructor

Definition at line 79 of file GibbsSampling_tpl.h.

79 {
81 }

References GibbsSampling().

Here is the call graph for this function:

Member Function Documentation

◆ _drawVarMonteCarlo_()

template<GUM_Numeric GUM_SCALAR>
void gum::GibbsOperator< GUM_SCALAR >::_drawVarMonteCarlo_ ( NodeId nod,
Instantiation * I )
privateinherited

Definition at line 103 of file gibbsOperator_tpl.h.

103 {
105 Itop.erase(samplingBn_.variable(nod));
106 I->chgVal(samplingBn_.variable(nod), samplingBn_.cpt(nod).extract(Itop).draw());
107 }
class containing all variables and methods required for Gibbssampling
const IBayesNet< GUM_SCALAR > & samplingBn_

References gum::Instantiation::chgVal(), gum::Instantiation::erase(), and samplingBn_.

Referenced by monteCarloSample().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _GibbsSample_()

template<GUM_Numeric GUM_SCALAR>
void gum::GibbsOperator< GUM_SCALAR >::_GibbsSample_ ( NodeId id,
Instantiation * I )
privateinherited

change in Instantiation I a new drawn value for id

Definition at line 123 of file gibbsOperator_tpl.h.

123 {
125 Itop.erase(samplingBn_.variable(id));
126 gum::Tensor< GUM_SCALAR > p = samplingBn_.cpt(id).extract(Itop);
127 for (const auto nod: samplingBn_.children(id))
128 p *= samplingBn_.cpt(nod).extract(Itop);
129 GUM_ASSERT(p.nbrDim() == 1);
130 if (p.sum() != 0) {
131 p.normalize();
132 I->chgVal(samplingBn_.variable(id), p.draw());
133 }
134 }

References gum::Instantiation::chgVal(), gum::Tensor< GUM_SCALAR >::draw(), gum::Instantiation::erase(), gum::MultiDimDecorator< GUM_ELEMENT >::nbrDim(), gum::Tensor< GUM_SCALAR >::normalize(), samplingBn_, and gum::Tensor< GUM_SCALAR >::sum().

Referenced by nextSample().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _setAllMarginalTargets_()

template<GUM_Numeric GUM_SCALAR>
void gum::MarginalTargetedInference< GUM_SCALAR >::_setAllMarginalTargets_ ( )
privateinherited

sets all the nodes of the Bayes net as targets

Definition at line 232 of file marginalTargetedInference_tpl.h.

232 {
233 _targets_.clear();
234 if (!this->hasNoModel_()) {
235 _targets_ = this->BN().internalDag().asNodeSet();
237 }
238 }
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
NodeSet _targets_
the set of marginal targets
virtual void onAllMarginalTargetsAdded_()=0
fired after all the nodes of the BN are added as marginal targets

References _targets_, gum::BayesNetInference< GUM_SCALAR >::BN(), gum::GraphicalModelInference< GUM_SCALAR >::hasNoModel_(), and onAllMarginalTargetsAdded_().

Referenced by onModelChanged_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addAllTargets()

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

adds all nodes as targets

Definition at line 147 of file marginalTargetedInference_tpl.h.

147 {
148 // check if the node belongs to the Bayesian network
149 if (this->hasNoModel_())
151 "No Bayes net has been assigned to the "
152 "inference algorithm");
153
154
155 setTargetedMode_(); // does nothing if already in targeted mode
156 for (const auto target: this->BN().internalDag()) {
157 if (!_targets_.contains(target)) {
158 _targets_.insert(target);
161 }
162 }
163 }
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i....
<agrum/BN/inference/marginalTargetedInference.h>
virtual void onMarginalTargetAdded_(const NodeId id)=0
fired after a new marginal target is inserted
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References _targets_, gum::BayesNetInference< GUM_SCALAR >::BN(), GUM_ERROR, gum::GraphicalModelInference< GUM_SCALAR >::hasNoModel_(), onMarginalTargetAdded_(), gum::GraphicalModelInference< GUM_SCALAR >::OutdatedStructure, gum::GraphicalModelInference< GUM_SCALAR >::setState_(), and setTargetedMode_().

Here is the call graph for this function:

◆ addEvidence() [1/8]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::addEvidence ( const Tensor< GUM_SCALAR > & pot)
finalvirtualinherited

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

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

Definition at line 323 of file graphicalModelInference_tpl.h.

323 {
326 }
<agrum/base/graphicalModels/graphicalModel.h>
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id

References addEvidence().

Here is the call graph for this function:

◆ addEvidence() [2/8]

template<GUM_Numeric GUM_SCALAR>
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 230 of file graphicalModelInference_tpl.h.

230 {
232 }
Tensor< GUM_SCALAR > _createHardEvidence_(NodeId id, Idx val) const
create the internal structure for a hard evidence

References _createHardEvidence_(), and addEvidence().

Referenced by addEvidence(), addEvidence(), addEvidence(), addEvidence(), addEvidence(), addEvidence(), addEvidence(), addListOfEvidence(), addSetOfEvidence(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::counterfactualModel(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::JointTargetedMRFInference< GUM_SCALAR >::evidenceJointImpact(), and gum::LoopySamplingInference< GUM_SCALAR, APPROX >::makeInference_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addEvidence() [3/8]

template<GUM_Numeric 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 257 of file graphicalModelInference_tpl.h.

258 {
259 // checks that the evidence is meaningful
260 if (_model_ == nullptr)
262 "No Bayes net has been assigned to the "
263 "inference algorithm");
264
265 if (!_model_->exists(id)) { GUM_ERROR(UndefinedElement, id << " is not a NodeId in the model") }
266
267 if (_model_->variable(id).domainSize() != vals.size()) {
269 "node " << _model_->variable(id)
270 << " and its evidence vector have different sizes.");
271 }
272
274 pot.add(_model_->variable(id));
275 pot.fillWith(vals);
277 }
const GraphicalModel * _model_
the Bayes net on which we perform inferences

References _model_, addEvidence(), and GUM_ERROR.

Here is the call graph for this function:

◆ addEvidence() [4/8]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::addEvidence ( NodeId id,
std::string_view 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 243 of file graphicalModelInference_tpl.h.

243 {
244 addEvidence(id, this->model().variable(id)[label]);
245 }
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.

References addEvidence(), and model().

Here is the call graph for this function:

◆ addEvidence() [5/8]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::addEvidence ( std::string_view 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 236 of file graphicalModelInference_tpl.h.

237 {
239 }

References addEvidence(), and model().

Here is the call graph for this function:

◆ addEvidence() [6/8]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::addEvidence ( std::string_view 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 281 of file graphicalModelInference_tpl.h.

282 {
284 }

References addEvidence(), and model().

Here is the call graph for this function:

◆ addEvidence() [7/8]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::addEvidence ( std::string_view nodeName,
std::string_view 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 249 of file graphicalModelInference_tpl.h.

250 {
251 const NodeId id = this->model().idFromName(nodeName);
252 addEvidence(id, this->model().variable(id)[label]);
253 }
virtual NodeId idFromName(std::string_view name) const =0
Getter by name.

References addEvidence(), and model().

Here is the call graph for this function:

◆ addEvidence() [8/8]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::addEvidence ( Tensor< GUM_SCALAR > && pot)
finalvirtualinherited

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

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

Definition at line 288 of file graphicalModelInference_tpl.h.

288 {
289 // check if the tensor corresponds to an evidence
290 if (pot.nbrDim() != 1) { GUM_ERROR(InvalidArgument, pot << " is not mono-dimensional.") }
291 if (_model_ == nullptr)
293 "No Bayes net has been assigned to the "
294 "inference algorithm");
295
296 NodeId id = _model_->nodeId(pot.variable(0));
297
298 if (hasEvidence(id)) {
300 " node " << id << " already has an evidence. Please use chgEvidence().");
301 }
302
303 // check whether we have a hard evidence (and also check whether the
304 // tensor only contains 0 (in this case, this will automatically raise
305 // an exception) )
306 Idx val = 0;
308
309 // insert the evidence
311 if (is_hard_evidence) { // pot is deterministic
312 _hard_evidence_.insert(id, val);
313 _hard_evidence_nodes_.insert(id);
314 } else {
315 _soft_evidence_nodes_.insert(id);
316 }
319 }
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
NodeProperty< const Tensor< GUM_SCALAR > * > _evidence_
the set of evidence entered into the network
bool _isHardEvidence_(const Tensor< GUM_SCALAR > &pot, Idx &val) const
checks whether a tensor corresponds to a hard evidence or not
NodeSet _soft_evidence_nodes_
the set of nodes that received soft evidence
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
NodeProperty< Idx > _hard_evidence_
assign to each node with a hard evidence the index of its observed value

References _evidence_, _hard_evidence_, _hard_evidence_nodes_, _isHardEvidence_(), _model_, _soft_evidence_nodes_, GUM_ERROR, hasEvidence(), onEvidenceAdded_(), OutdatedStructure, and setState_().

Here is the call graph for this function:

◆ addListOfEvidence()

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::addListOfEvidence ( const List< const Tensor< GUM_SCALAR > * > & potlist)
finalvirtualinherited

adds a new list of evidence

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

Definition at line 330 of file graphicalModelInference_tpl.h.

331 {
332 for (const auto pot: potlist)
334 }

References addEvidence().

Here is the call graph for this function:

◆ addSetOfEvidence()

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::addSetOfEvidence ( const Set< const Tensor< GUM_SCALAR > * > & potset)
finalvirtualinherited

adds a new set of evidence

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

Definition at line 338 of file graphicalModelInference_tpl.h.

339 {
340 for (const auto pot: potset)
342 }

References addEvidence().

Here is the call graph for this function:

◆ addTarget() [1/2]

template<GUM_Numeric 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 125 of file marginalTargetedInference_tpl.h.

125 {
126 // check if the node belongs to the Bayesian network
127 if (this->hasNoModel_())
129 "No Bayes net has been assigned to the "
130 "inference algorithm");
131
132 if (!this->BN().internalDag().exists(target)) {
133 GUM_ERROR(UndefinedElement, target << " is not a NodeId in the bn")
134 }
135
136 setTargetedMode_(); // does nothing if already in targeted mode
137 // add the new target
138 if (!_targets_.contains(target)) {
139 _targets_.insert(target);
142 }
143 }

References _targets_, gum::BayesNetInference< GUM_SCALAR >::BN(), GUM_ERROR, gum::GraphicalModelInference< GUM_SCALAR >::hasNoModel_(), onMarginalTargetAdded_(), gum::GraphicalModelInference< GUM_SCALAR >::OutdatedStructure, gum::GraphicalModelInference< GUM_SCALAR >::setState_(), and setTargetedMode_().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addTarget() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::MarginalTargetedInference< GUM_SCALAR >::addTarget ( std::string_view 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 167 of file marginalTargetedInference_tpl.h.

167 {
168 // check if the node belongs to the Bayesian network
169 if (this->hasNoModel_())
171 "No Bayes net has been assigned to the "
172 "inference algorithm");
173
175 }
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.

References addTarget(), gum::BayesNetInference< GUM_SCALAR >::BN(), GUM_ERROR, and gum::GraphicalModelInference< GUM_SCALAR >::hasNoModel_().

Here is the call graph for this function:

◆ addVarSample_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::addVarSample_ ( NodeId nod,
Instantiation * I )
protectedvirtualinherited

adds a node to current instantiation

Parameters
nodthe node to add to the sample
Ithe current sample

generates random value based on the BN's CPT's and adds the node to the Instantiation with that value

Definition at line 196 of file samplingInference_tpl.h.

196 {
198
199 I->add(samplingBN().variable(nod));
201 }
<agrum/BN/inference/samplingInference.h>
const IBayesNet< GUM_SCALAR > & samplingBN()
get the BayesNet which is used to really perform the sampling

References gum::Instantiation::add(), gum::Instantiation::chgVal(), and samplingBN().

Referenced by gum::ImportanceSampling< GUM_SCALAR >::draw_(), gum::MonteCarloSampling< GUM_SCALAR >::draw_(), and gum::WeightedSampling< GUM_SCALAR >::draw_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BN()

template<GUM_Numeric GUM_SCALAR>
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 76 of file BayesNetInference_tpl.h.

76 {
77 return static_cast< const IBayesNet< GUM_SCALAR >& >(this->model());
78 }
<agrum/BN/inference/BayesNetInference.h>

References gum::GraphicalModelInference< GUM_SCALAR >::model().

Referenced by gum::LazyPropagation< GUM_SCALAR >::LazyPropagation(), gum::ShaferShenoyInference< GUM_SCALAR >::ShaferShenoyInference(), gum::VariableElimination< GUM_SCALAR >::VariableElimination(), gum::MarginalTargetedInference< GUM_SCALAR >::_setAllMarginalTargets_(), gum::MarginalTargetedInference< GUM_SCALAR >::addAllTargets(), gum::JointTargetedInference< GUM_SCALAR >::addJointTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), gum::SamplingInference< GUM_SCALAR >::contextualize(), gum::SamplingInference< GUM_SCALAR >::currentPosterior(), gum::SamplingInference< GUM_SCALAR >::currentPosterior(), gum::ImportanceSampling< GUM_SCALAR >::draw_(), gum::MonteCarloSampling< GUM_SCALAR >::draw_(), gum::WeightedSampling< GUM_SCALAR >::draw_(), gum::JointTargetedInference< GUM_SCALAR >::eraseJointTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::MarginalTargetedInference< GUM_SCALAR >::H(), gum::JointTargetedInference< GUM_SCALAR >::isJointTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::isTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::isTarget(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedInference< GUM_SCALAR >::posterior(), gum::MarginalTargetedInference< GUM_SCALAR >::posterior(), gum::SamplingInference< GUM_SCALAR >::posterior_(), gum::SamplingInference< GUM_SCALAR >::samplingBN(), and gum::Estimator< GUM_SCALAR >::setFromLBP().

Here is the call graph for this function:

◆ burnIn()

template<GUM_Numeric GUM_SCALAR>
Size gum::GibbsSampling< GUM_SCALAR >::burnIn ( ) const

Returns the number of burn in.

Returns
Returns the number of burn in.

Definition at line 119 of file GibbsSampling_tpl.h.

119 {
120 return this->burn_in_;
121 }
Size burn_in_
Number of iterations before checking stopping criteria.

References gum::ApproximationScheme::burn_in_.

Referenced by burnIn_().

Here is the caller graph for this function:

◆ burnIn_()

template<GUM_Numeric GUM_SCALAR>
Instantiation gum::GibbsSampling< GUM_SCALAR >::burnIn_ ( )
overrideprotectedvirtual

draws a defined number of samples without updating the estimators

Implements gum::SamplingInference< GUM_SCALAR >.

Definition at line 89 of file GibbsSampling_tpl.h.

89 {
90 // we initialize the nodes with hard evidence
91 // hypothesis : burnIn_ is called at the beginning of makeInference
93
95 if (this->burnIn() == 0) return Ip;
96
97 GUM_SCALAR w = 1.0f;
99 for (Size i = 1; i < this->burnIn(); i++)
100 Ip = this->draw_(&w, Ip);
101
102 return Ip;
103 }
Instantiation draw_(GUM_SCALAR *w, Instantiation prev) override
draws a sample given previous one according to Gibbs sampling
Instantiation monteCarloSample_()
draws a Monte Carlo sample
Size burnIn() const
Returns the number of burn in.

References burnIn(), draw_(), monteCarloSample_(), and gum::GibbsOperator< GUM_SCALAR >::updateSamplingNodes_().

Here is the call graph for this function:

◆ chgEvidence() [1/7]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::chgEvidence ( const Tensor< GUM_SCALAR > & pot)
finalvirtualinherited

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

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

Definition at line 446 of file graphicalModelInference_tpl.h.

446 {
447 // check if the tensor corresponds to an evidence
448 if (pot.nbrDim() != 1) {
449 GUM_ERROR(InvalidArgument, pot << " is not a mono-dimensional tensor.")
450 }
451 if (_model_ == nullptr)
453 "No Bayes net has been assigned to the "
454 "inference algorithm");
455
456 NodeId id = _model_->nodeId(pot.variable(0));
457
458 if (!hasEvidence(id)) {
459 GUM_ERROR(InvalidArgument, id << " has no evidence. Please use addEvidence().")
460 }
461
462 // check whether we have a hard evidence (and also check whether the
463 // tensor only contains 0 (in this case, this will automatically raise
464 // an exception) )
465 Idx val;
467
468 // modify the evidence already stored
471 for (I.setFirst(); !I.end(); I.inc()) {
472 localPot->set(I, pot[I]);
473 }
474
475 // the inference state will be different
476 // whether evidence change from Hard to Soft or not.
477 bool hasChangedSoftHard = false;
478
479 if (is_hard_evidence) {
480 if (!hasHardEvidence(id)) {
481 hasChangedSoftHard = true;
482 _hard_evidence_.insert(id, val);
483 _hard_evidence_nodes_.insert(id);
484 _soft_evidence_nodes_.erase(id);
485 } else {
487 }
488 } else {
489 if (hasHardEvidence(id)) { // evidence was hard
490 _hard_evidence_.erase(id);
491 _hard_evidence_nodes_.erase(id);
492 _soft_evidence_nodes_.insert(id);
493 hasChangedSoftHard = true;
494 }
495 }
496
497 if (hasChangedSoftHard) {
499 } else {
501 }
502
504 }
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 hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
virtual bool isInferenceOutdatedStructure() const noexcept final
returns whether the inference object is in a OutdatedStructure state

References _evidence_, _hard_evidence_, _hard_evidence_nodes_, _isHardEvidence_(), _model_, _soft_evidence_nodes_, gum::Instantiation::end(), GUM_ERROR, hasEvidence(), hasHardEvidence(), gum::Instantiation::inc(), isInferenceOutdatedStructure(), onEvidenceChanged_(), OutdatedStructure, OutdatedTensors, gum::Instantiation::setFirst(), and setState_().

Here is the call graph for this function:

◆ chgEvidence() [2/7]

template<GUM_Numeric GUM_SCALAR>
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 388 of file graphicalModelInference_tpl.h.

388 {
390 }
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence

References _createHardEvidence_(), and chgEvidence().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chgEvidence() [3/7]

template<GUM_Numeric GUM_SCALAR>
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 415 of file graphicalModelInference_tpl.h.

416 {
417 // check whether this corresponds to an evidence
418 if (_model_ == nullptr)
420 "No Bayes net has been assigned to the "
421 "inference algorithm");
422
423 if (!_model_->exists(id)) { GUM_ERROR(UndefinedElement, id << " is not a NodeId in the model") }
424
425 if (_model_->variable(id).domainSize() != vals.size()) {
427 "node " << _model_->variable(id) << " and its evidence have different sizes.");
428 }
429
430 // create the tensor corresponding to vals
432 pot.add(_model_->variable(id));
433 pot.fillWith(vals);
435 }

References _model_, chgEvidence(), and GUM_ERROR.

Here is the call graph for this function:

◆ chgEvidence() [4/7]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::chgEvidence ( NodeId id,
std::string_view 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 401 of file graphicalModelInference_tpl.h.

401 {
402 chgEvidence(id, this->model().variable(id)[label]);
403 }

References chgEvidence(), and model().

Here is the call graph for this function:

◆ chgEvidence() [5/7]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::chgEvidence ( std::string_view 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 394 of file graphicalModelInference_tpl.h.

395 {
397 }

References chgEvidence(), and model().

Here is the call graph for this function:

◆ chgEvidence() [6/7]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::chgEvidence ( std::string_view 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 439 of file graphicalModelInference_tpl.h.

440 {
442 }

References chgEvidence(), and model().

Here is the call graph for this function:

◆ chgEvidence() [7/7]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::chgEvidence ( std::string_view nodeName,
std::string_view 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 407 of file graphicalModelInference_tpl.h.

408 {
409 NodeId id = this->model().idFromName(nodeName);
410 chgEvidence(id, this->model().variable(id)[label]);
411 }

References chgEvidence(), and model().

Here is the call graph for this function:

◆ clear()

template<GUM_Numeric GUM_SCALAR>
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 156 of file graphicalModelInference_tpl.h.

156 {
159 }
virtual void eraseAllEvidence() final
removes all the evidence entered into the network

References eraseAllEvidence(), OutdatedStructure, and setState_().

Referenced by setModel_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contextualize()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::contextualize ( )
virtualinherited

Simplifying the Bayesian network with relevance reasonning to lighten the computational charge.

Sets the reference Bayesian network as a BayesNetFragment after having eliminated nodes that are idle for simulation and computation, such as barren or d-separated nodes. Eliminates the arcs from evidence nodes to it's children, after setting new CPT's for them.

Definition at line 127 of file samplingInference_tpl.h.

127 {
128 // Finding Barren nodes
129
131 barr_nodes.setTargets(&this->targets());
132 barr_nodes.setEvidence(&this->hardEvidenceNodes());
133 const NodeSet& barren = barr_nodes.barrenNodes();
134
135 // creating BN fragment
137 for (const auto elmt: this->BN().internalDag().asNodeSet() - barren)
138 _samplingBN_->installNode(elmt);
139
140 // D-separated nodes
141
144 dsep.requisiteNodes(this->BN().internalDag(),
145 this->BN().nodes().asNodeSet(), // no target for approximateInference
146 this->hardEvidenceNodes(),
147 this->softEvidenceNodes(), // should be empty
148 requisite);
149 requisite += this->hardEvidenceNodes();
150
151 auto nonRequisite = this->BN().internalDag().asNodeSet() - requisite;
152
153 for (const auto elmt: nonRequisite)
154 _samplingBN_->uninstallNode(elmt);
155 for (const auto hard: this->hardEvidenceNodes()) {
157 I.add(this->BN().variable(hard));
158 I.chgVal(this->BN().variable(hard), this->hardEvidence()[hard]);
159
160 for (const auto& child: this->BN().children(hard)) {
161 _samplingBN_->installCPT(child, this->BN().cpt(child).extract(I));
162 }
163 }
164
165 this->isContextualized = true;
167 }
const NodeSet & softEvidenceNodes() const
returns the set of nodes with soft evidence
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
bool isContextualized
whether the referenced Bayesian network has been "contextualized"
virtual void onContextualize_(BayesNetFragment< GUM_SCALAR > *bn)
fired when Bayesian network is contextualized
BayesNetFragment< GUM_SCALAR > * _samplingBN_

References _samplingBN_, gum::Instantiation::add(), gum::BarrenNodesFinder::barrenNodes(), gum::BayesNetInference< GUM_SCALAR >::BN(), gum::Instantiation::chgVal(), gum::GraphicalModelInference< GUM_SCALAR >::hardEvidence(), gum::GraphicalModelInference< GUM_SCALAR >::hardEvidenceNodes(), isContextualized, onContextualize_(), gum::dSeparationAlgorithm::requisiteNodes(), gum::BarrenNodesFinder::setEvidence(), gum::BarrenNodesFinder::setTargets(), gum::GraphicalModelInference< GUM_SCALAR >::softEvidenceNodes(), and gum::MarginalTargetedInference< GUM_SCALAR >::targets().

Referenced by loopApproxInference_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ continueApproximationScheme()

bool gum::ApproximationScheme::continueApproximationScheme ( double error)
inherited

Update the scheme w.r.t the new error.

Test the stopping criterion that are enabled.

Parameters
errorThe new error value.
Returns
false if state become != ApproximationSchemeSTATE::Continue
Exceptions
OperationNotAllowedRaised if state != ApproximationSchemeSTATE::Continue.

Definition at line 69 of file approximationScheme.cpp.

69 {
70 // For coherence, we fix the time used in the method
71
72 double timer_step = timer_.step();
73
75 if (timer_step > max_time_) {
77 return false;
78 }
79 }
80
81 if (!startOfPeriod()) { return true; }
82
85 OperationNotAllowed,
86 "state of the approximation scheme is not correct : " << messageApproximationScheme());
87 }
88
89 if (verbosity()) { history_.push_back(error); }
90
92 if (current_step_ >= max_iter_) {
94 return false;
95 }
96 }
97
99 current_epsilon_ = error; // eps rate isEnabled needs it so affectation was
100 // moved from eps isEnabled below
101
102 if (enabled_eps_) {
103 if (current_epsilon_ <= eps_) {
105 return false;
106 }
107 }
108
109 if (last_epsilon_ >= 0.) {
110 if (current_epsilon_ > .0) {
111 // ! current_epsilon_ can be 0. AND epsilon
112 // isEnabled can be disabled !
114 }
115 // limit with current eps ---> 0 is | 1 - ( last_eps / 0 ) | --->
116 // infinity the else means a return false if we isEnabled the rate below,
117 // as we would have returned false if epsilon isEnabled was enabled
118 else {
120 }
121
125 return false;
126 }
127 }
128 }
129
131 if (onProgress.hasListener()) {
133 }
134
135 return true;
136 } else {
137 return false;
138 }
139 }
Size current_step_
The current step.
double current_epsilon_
Current epsilon.
double last_epsilon_
Last epsilon value.
double eps_
Threshold for convergence.
bool enabled_max_time_
If true, the timeout is enabled.
Size max_iter_
The maximum iterations.
bool enabled_eps_
If true, the threshold convergence is enabled.
ApproximationSchemeSTATE current_state_
The current state.
double min_rate_eps_
Threshold for the epsilon rate.
std::vector< double > history_
The scheme history, used only if verbosity == true.
double current_rate_
Current rate.
ApproximationSchemeSTATE stateApproximationScheme() const override
Returns the approximation scheme state.
bool startOfPeriod() const
Returns true if we are at the beginning of a period (compute error is mandatory).
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
void stopScheme_(ApproximationSchemeSTATE new_state)
Stop the scheme given a new state.
bool verbosity() const override
Returns true if verbosity is enabled.
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
Signaler< Size, double, double > onProgress
Progression, error and time.
std::string messageApproximationScheme() const
Returns the approximation scheme message.
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition signaler.h:291

References gum::IApproximationSchemeConfiguration::Continue, current_epsilon_, current_rate_, current_state_, current_step_, enabled_eps_, enabled_max_iter_, enabled_max_time_, enabled_min_rate_eps_, eps_, gum::IApproximationSchemeConfiguration::Epsilon, GUM_EMIT3, GUM_ERROR, history_, last_epsilon_, gum::IApproximationSchemeConfiguration::Limit, max_iter_, max_time_, gum::IApproximationSchemeConfiguration::messageApproximationScheme(), min_rate_eps_, gum::IApproximationSchemeConfiguration::onProgress, gum::IApproximationSchemeConfiguration::Rate, startOfPeriod(), stateApproximationScheme(), stopScheme_(), gum::IApproximationSchemeConfiguration::TimeLimit, timer_, and verbosity().

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::GreedyThickThinning::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), gum::SamplingInference< GUM_SCALAR >::loopApproxInference_(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceByOrderedArcs_(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceByRandomOrder_(), and gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceNodeToNeighbours_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ currentPosterior() [1/2]

template<GUM_Numeric GUM_SCALAR>
const Tensor< GUM_SCALAR > & gum::SamplingInference< GUM_SCALAR >::currentPosterior ( NodeId id)
inherited

Computes and returns the actual estimation of the posterior of a node.

Returns
a const ref to the posterior probability of the node.
Parameters
idthe node for which we need a posterior probability
Warning
for efficiency reasons, the tensor is returned by reference. In order to ensure that the tensor may still exist even if the Inference object is destroyed, the user has to copy it explicitly.
Exceptions
UndefinedElementif node is not in the set of targets.
NotFoundif node is not in the BN.

Definition at line 111 of file samplingInference_tpl.h.

111 {
112 return _estimator_.posterior(this->BN().variable(id));
113 }
Estimator< GUM_SCALAR > _estimator_
Estimator object designed to approximate target posteriors.

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

Referenced by currentPosterior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ currentPosterior() [2/2]

template<GUM_Numeric GUM_SCALAR>
const Tensor< GUM_SCALAR > & gum::SamplingInference< GUM_SCALAR >::currentPosterior ( std::string_view name)
inherited

Computes and returns the actual estimation of the posterior of a node by its name.

Returns
a const ref to the posterior probability of the node referred by name.
Parameters
namethe name of the node for which we need a posterior probability
Warning
for efficiency reasons, the tensor is returned by reference. In order to ensure that the tensor may still exist even if the Inference object is destroyed, the user has to copy it explicitly.
Exceptions
UndefinedElementif node corresponding to name is not in the set of targets.
NotFoundif node corresponding to name is not in the BN.

Definition at line 117 of file samplingInference_tpl.h.

117 {
118 return currentPosterior(this->BN().idFromName(name));
119 }
const Tensor< GUM_SCALAR > & currentPosterior(NodeId id)
Computes and returns the actual estimation of the posterior of a node.

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

Here is the call graph for this function:

◆ currentTime()

INLINE double gum::ApproximationScheme::currentTime ( ) const
overridevirtualinherited

Returns the current running time in second.

Returns
Returns the current running time in second.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 137 of file approximationScheme_inl.h.

137{ return timer_.step(); }

References timer_.

◆ disableEpsilon()

INLINE void gum::ApproximationScheme::disableEpsilon ( )
overridevirtualinherited

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 75 of file approximationScheme_inl.h.

75{ enabled_eps_ = false; }

References enabled_eps_.

Referenced by gum::learning::EMApproximationScheme::EMApproximationScheme(), and gum::learning::EMApproximationScheme::setMinEpsilonRate().

Here is the caller graph for this function:

◆ disableMaxIter()

INLINE void gum::ApproximationScheme::disableMaxIter ( )
overridevirtualinherited

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 116 of file approximationScheme_inl.h.

116{ enabled_max_iter_ = false; }

References enabled_max_iter_.

Referenced by gum::learning::GreedyHillClimbing::GreedyHillClimbing(), and gum::learning::GreedyThickThinning::GreedyThickThinning().

Here is the caller graph for this function:

◆ disableMaxTime()

INLINE void gum::ApproximationScheme::disableMaxTime ( )
overridevirtualinherited

Disable stopping criterion on timeout.

Returns
Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 140 of file approximationScheme_inl.h.

140{ enabled_max_time_ = false; }

References enabled_max_time_.

Referenced by gum::learning::GreedyHillClimbing::GreedyHillClimbing(), and gum::learning::GreedyThickThinning::GreedyThickThinning().

Here is the caller graph for this function:

◆ disableMinEpsilonRate()

INLINE void gum::ApproximationScheme::disableMinEpsilonRate ( )
overridevirtualinherited

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 96 of file approximationScheme_inl.h.

96{ enabled_min_rate_eps_ = false; }

References enabled_min_rate_eps_.

Referenced by gum::learning::GreedyHillClimbing::GreedyHillClimbing(), gum::learning::GreedyThickThinning::GreedyThickThinning(), gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), and gum::learning::EMApproximationScheme::setEpsilon().

Here is the caller graph for this function:

◆ domainSizes()

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

get the domain sizes of the random variables of the model

Definition at line 174 of file graphicalModelInference_tpl.h.

174 {
175 return _domain_sizes_;
176 }
NodeProperty< Size > _domain_sizes_
the domain sizes of the random variables

References _domain_sizes_.

◆ draw_()

template<GUM_Numeric GUM_SCALAR>
Instantiation gum::GibbsSampling< GUM_SCALAR >::draw_ ( GUM_SCALAR * w,
Instantiation prev )
overrideprotectedvirtual

draws a sample given previous one according to Gibbs sampling

draws next sample for gibbs sampling

Parameters
wthe weight of sample being generated
prevthe previous sample generated
bnthe Bayesian network containing the evidence
hardEvNodeshard evidence nodes
hardEvhard evidences values

Uses the Gibbs sampling method to generate a new sample given the previous one. The method is implemented in the inherited class GibbsOperator. This function only makes the call to it. It consists of choosing one node x to sample, given the instantiation of all other nodes. It requires computing of P( x \given instantiation_markovblanket(x)).

Implements gum::SamplingInference< GUM_SCALAR >.

Definition at line 108 of file GibbsSampling_tpl.h.

108 {
109 *w = 1.0;
111 }
Instantiation nextSample(Instantiation prev)
draws next sample of Gibbs sampling

References gum::GibbsOperator< GUM_SCALAR >::nextSample().

Referenced by burnIn_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enableEpsilon()

INLINE void gum::ApproximationScheme::enableEpsilon ( )
overridevirtualinherited

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 78 of file approximationScheme_inl.h.

78{ enabled_eps_ = true; }

References enabled_eps_.

◆ enableMaxIter()

INLINE void gum::ApproximationScheme::enableMaxIter ( )
overridevirtualinherited

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 119 of file approximationScheme_inl.h.

119{ enabled_max_iter_ = true; }

References enabled_max_iter_.

◆ enableMaxTime()

INLINE void gum::ApproximationScheme::enableMaxTime ( )
overridevirtualinherited

Enable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 143 of file approximationScheme_inl.h.

143{ enabled_max_time_ = true; }

References enabled_max_time_.

◆ enableMinEpsilonRate()

INLINE void gum::ApproximationScheme::enableMinEpsilonRate ( )
overridevirtualinherited

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 99 of file approximationScheme_inl.h.

99{ enabled_min_rate_eps_ = true; }

References enabled_min_rate_eps_.

Referenced by gum::learning::EMApproximationScheme::EMApproximationScheme(), and gum::GibbsBNdistance< GUM_SCALAR >::computeKL_().

Here is the caller graph for this function:

◆ epsilon()

INLINE double gum::ApproximationScheme::epsilon ( ) const
overridevirtualinherited

Returns the value of epsilon.

Returns
Returns the value of epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 72 of file approximationScheme_inl.h.

72{ return eps_; }

References eps_.

Referenced by gum::ImportanceSampling< GUM_SCALAR >::onContextualize_(), and gum::ImportanceSampling< GUM_SCALAR >::unsharpenBN_().

Here is the caller graph for this function:

◆ eraseAllEvidence()

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

removes all the evidence entered into the network

Definition at line 534 of file graphicalModelInference_tpl.h.

534 {
535 bool has_hard_evidence = !_hard_evidence_.empty();
537
538 for (const auto& pair: _evidence_) {
539 if (pair.second != nullptr) { delete (pair.second); }
540 }
541
542 _evidence_.clear();
543 _hard_evidence_.clear();
544 _hard_evidence_nodes_.clear();
545 _soft_evidence_nodes_.clear();
546
547 if (has_hard_evidence) {
549 } else {
551 }
552 }
virtual void onAllEvidenceErased_(bool contains_hard_evidence)=0
fired before all the evidence are erased

References _evidence_, _hard_evidence_, _hard_evidence_nodes_, _soft_evidence_nodes_, isInferenceOutdatedStructure(), onAllEvidenceErased_(), OutdatedStructure, OutdatedTensors, and setState_().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseAllTargets()

template<GUM_Numeric GUM_SCALAR>
void gum::MarginalTargetedInference< GUM_SCALAR >::eraseAllTargets ( )
virtualinherited

Clear all previously defined targets.

Reimplemented in gum::JointTargetedInference< GUM_SCALAR >.

Definition at line 114 of file marginalTargetedInference_tpl.h.

114 {
116
117 _targets_.clear();
118 setTargetedMode_(); // does nothing if already in targeted mode
119
121 }
virtual void onAllMarginalTargetsErased_()=0
fired before a all marginal targets are removed

References _targets_, onAllMarginalTargetsErased_(), gum::GraphicalModelInference< GUM_SCALAR >::OutdatedStructure, gum::GraphicalModelInference< GUM_SCALAR >::setState_(), and setTargetedMode_().

Referenced by gum::JointTargetedInference< GUM_SCALAR >::eraseAllMarginalTargets(), and evidenceImpact().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseEvidence() [1/2]

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

removed the evidence, if any, corresponding to node id

Definition at line 508 of file graphicalModelInference_tpl.h.

508 {
509 if (hasEvidence(id)) {
510 if (hasHardEvidence(id)) {
511 onEvidenceErased_(id, true);
512 _hard_evidence_.erase(id);
513 _hard_evidence_nodes_.erase(id);
515 } else {
516 onEvidenceErased_(id, false);
517 _soft_evidence_nodes_.erase(id);
519 }
520
521 delete (_evidence_[id]);
522 _evidence_.erase(id);
523 }
524 }
virtual void onEvidenceErased_(const NodeId id, bool isHardEvidence)=0
fired before an evidence is removed

References _evidence_, _hard_evidence_, _hard_evidence_nodes_, _soft_evidence_nodes_, hasEvidence(), hasHardEvidence(), isInferenceOutdatedStructure(), onEvidenceErased_(), OutdatedStructure, OutdatedTensors, and setState_().

Referenced by eraseEvidence().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseEvidence() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::eraseEvidence ( std::string_view nodeName)
finalvirtualinherited

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

Definition at line 528 of file graphicalModelInference_tpl.h.

528 {
530 }
virtual void eraseEvidence(NodeId id) final
removed the evidence, if any, corresponding to node id

References eraseEvidence(), and model().

Here is the call graph for this function:

◆ eraseTarget() [1/2]

template<GUM_Numeric 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 179 of file marginalTargetedInference_tpl.h.

179 {
180 // check if the node belongs to the Bayesian network
181 if (this->hasNoModel_())
183 "No Bayes net has been assigned to the "
184 "inference algorithm");
185
186 if (!this->BN().internalDag().exists(target)) {
187 GUM_ERROR(UndefinedElement, target << " is not a NodeId in the bn")
188 }
189
190
191 if (_targets_.contains(target)) {
192 _targeted_mode_ = true; // we do not use setTargetedMode_ because we do not
193 // want to clear the targets
195 _targets_.erase(target);
197 }
198 }
virtual void onMarginalTargetErased_(const NodeId id)=0
fired before a marginal target is removed
bool _targeted_mode_
whether the actual targets are default

References _targeted_mode_, _targets_, gum::BayesNetInference< GUM_SCALAR >::BN(), GUM_ERROR, gum::GraphicalModelInference< GUM_SCALAR >::hasNoModel_(), onMarginalTargetErased_(), gum::GraphicalModelInference< GUM_SCALAR >::OutdatedStructure, and gum::GraphicalModelInference< GUM_SCALAR >::setState_().

Referenced by eraseTarget().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseTarget() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget ( std::string_view 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 202 of file marginalTargetedInference_tpl.h.

202 {
203 // check if the node belongs to the Bayesian network
204 if (this->hasNoModel_())
206 "No Bayes net has been assigned to the "
207 "inference algorithm");
208
210 }
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target

References gum::BayesNetInference< GUM_SCALAR >::BN(), eraseTarget(), GUM_ERROR, and gum::GraphicalModelInference< GUM_SCALAR >::hasNoModel_().

Here is the call graph for this function:

◆ evidence()

template<GUM_Numeric GUM_SCALAR>
const NodeProperty< const Tensor< GUM_SCALAR > * > & gum::GraphicalModelInference< GUM_SCALAR >::evidence ( ) const
inherited

returns the set of evidence

Definition at line 581 of file graphicalModelInference_tpl.h.

581 {
582 return _evidence_;
583 }

References _evidence_.

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

Here is the caller graph for this function:

◆ evidenceImpact() [1/2]

template<GUM_Numeric GUM_SCALAR>
Tensor< GUM_SCALAR > gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact ( NodeId target,
const NodeSet & evs )
inherited

Create a gum::Tensor for P(target|evs) (for all instantiation of target and evs).

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

Definition at line 283 of file marginalTargetedInference_tpl.h.

284 {
285 const auto& vtarget = this->BN().variable(target);
286
287 if (evs.contains(target)) {
289 "Target <" << vtarget.name() << "> (" << target << ") can not be in evs (" << evs
290 << ").");
291 }
292 auto condset = this->BN().minimalCondSet(target, evs);
293
295 this->eraseAllTargets();
296 this->eraseAllEvidence();
297 res.add(this->BN().variable(target));
298 this->addTarget(target);
299 for (const auto& n: condset) {
300 res.add(this->BN().variable(n));
301 this->addEvidence(n, 0);
302 }
303
305 for (inst.setFirst(); !inst.end(); inst.incNotVar(vtarget)) {
306 // inferring
307 for (const auto& n: condset)
308 this->chgEvidence(n, inst.val(this->BN().variable(n)));
309 this->makeInference();
310 // populate res
311 const auto& pot = this->posterior(target);
312 for (inst.setFirstVar(vtarget); !inst.end(); inst.incVar(vtarget)) {
313 res.set(inst, pot[inst]);
314 }
315 inst.setFirstVar(vtarget); // remove inst.end() flag
316 }
317
318 return res;
319 }
virtual void makeInference() final
perform the heavy computations needed to compute the targets' posteriors
virtual const Tensor< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
virtual void eraseAllTargets()
Clear all previously defined targets.

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

Referenced by evidenceImpact().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ evidenceImpact() [2/2]

template<GUM_Numeric GUM_SCALAR>
Tensor< GUM_SCALAR > gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact ( std::string_view target,
const std::vector< std::string > & evs )
inherited

Create a gum::Tensor for P(target|evs) (for all instantiation of target and evs).

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

Definition at line 322 of file marginalTargetedInference_tpl.h.

324 {
325 const auto& bn = this->BN();
326 return evidenceImpact(bn.idFromName(target), bn.nodeset(evs));
327 }
Tensor< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet &evs)
Create a gum::Tensor for P(target|evs) (for all instantiation of target and evs).

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

Here is the call graph for this function:

◆ H() [1/2]

template<GUM_Numeric GUM_SCALAR>
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 270 of file marginalTargetedInference_tpl.h.

270 {
271 return posterior(X).entropy();
272 }

References posterior().

Referenced by H().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ H() [2/2]

template<GUM_Numeric GUM_SCALAR>
GUM_SCALAR gum::MarginalTargetedInference< GUM_SCALAR >::H ( std::string_view 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 278 of file marginalTargetedInference_tpl.h.

278 {
279 return H(this->BN().idFromName(nodeName));
280 }
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon's entropy of a node given the observation.

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

Here is the call graph for this function:

◆ hardEvidence()

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

indicate for each node with hard evidence which value it took

Definition at line 574 of file graphicalModelInference_tpl.h.

574 {
575 return _hard_evidence_;
576 }

References _hard_evidence_.

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

Here is the caller graph for this function:

◆ hardEvidenceNodes()

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

◆ hasEvidence() [1/3]

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

indicates whether some node(s) have received evidence

Definition at line 346 of file graphicalModelInference_tpl.h.

346 {
347 return !_evidence_.empty();
348 }

References _evidence_.

Referenced by addEvidence(), chgEvidence(), eraseEvidence(), and hasEvidence().

Here is the caller graph for this function:

◆ hasEvidence() [2/3]

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

indicates whether node id has received an evidence

Definition at line 352 of file graphicalModelInference_tpl.h.

352 {
353 return _evidence_.exists(id);
354 }

References _evidence_.

◆ hasEvidence() [3/3]

template<GUM_Numeric GUM_SCALAR>
bool gum::GraphicalModelInference< GUM_SCALAR >::hasEvidence ( std::string_view nodeName) const
finalvirtualinherited

indicates whether node id has received an evidence

Definition at line 370 of file graphicalModelInference_tpl.h.

370 {
371 return hasEvidence(this->model().idFromName(nodeName));
372 }

References hasEvidence(), and model().

Here is the call graph for this function:

◆ hasHardEvidence() [1/2]

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

indicates whether node id has received a hard evidence

Definition at line 358 of file graphicalModelInference_tpl.h.

358 {
359 return _hard_evidence_nodes_.exists(id);
360 }

References _hard_evidence_nodes_.

Referenced by chgEvidence(), gum::ImportanceSampling< GUM_SCALAR >::draw_(), eraseEvidence(), hasHardEvidence(), and gum::JointTargetedMRFInference< GUM_SCALAR >::jointPosterior().

Here is the caller graph for this function:

◆ hasHardEvidence() [2/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::GraphicalModelInference< GUM_SCALAR >::hasHardEvidence ( std::string_view nodeName) const
finalvirtualinherited

indicates whether node id has received a hard evidence

Definition at line 376 of file graphicalModelInference_tpl.h.

376 {
377 return hasHardEvidence(this->model().idFromName(nodeName));
378 }

References hasHardEvidence(), and model().

Here is the call graph for this function:

◆ hasNoModel_()

template<GUM_Numeric GUM_SCALAR>
bool gum::GraphicalModelInference< GUM_SCALAR >::hasNoModel_ ( ) const
protectedinherited

Definition at line 643 of file graphicalModelInference_tpl.h.

643 {
644 return _model_ == nullptr;
645 }

References _model_.

Referenced by gum::EvidenceInference< GUM_SCALAR >::EvidenceInference(), gum::EvidenceMRFInference< GUM_SCALAR >::EvidenceMRFInference(), gum::JointTargetedInference< GUM_SCALAR >::JointTargetedInference(), gum::JointTargetedMRFInference< GUM_SCALAR >::JointTargetedMRFInference(), gum::MarginalTargetedInference< GUM_SCALAR >::MarginalTargetedInference(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::MarginalTargetedMRFInference(), _computeDomainSizes_(), gum::MarginalTargetedInference< GUM_SCALAR >::_setAllMarginalTargets_(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::_setAllMarginalTargets_(), gum::MarginalTargetedInference< GUM_SCALAR >::addAllTargets(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::addAllTargets(), gum::JointTargetedInference< GUM_SCALAR >::addJointTarget(), gum::JointTargetedMRFInference< GUM_SCALAR >::addJointTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::addTarget(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::addTarget(), gum::JointTargetedInference< GUM_SCALAR >::eraseJointTarget(), gum::JointTargetedMRFInference< GUM_SCALAR >::eraseJointTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::eraseTarget(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::eraseTarget(), gum::JointTargetedInference< GUM_SCALAR >::isJointTarget(), gum::JointTargetedMRFInference< GUM_SCALAR >::isJointTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::isTarget(), and gum::MarginalTargetedMRFInference< GUM_SCALAR >::isTarget().

Here is the caller graph for this function:

◆ hasSoftEvidence() [1/2]

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

indicates whether node id has received a soft evidence

Definition at line 364 of file graphicalModelInference_tpl.h.

364 {
365 return _soft_evidence_nodes_.exists(id);
366 }

References _soft_evidence_nodes_.

Referenced by hasSoftEvidence().

Here is the caller graph for this function:

◆ hasSoftEvidence() [2/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::GraphicalModelInference< GUM_SCALAR >::hasSoftEvidence ( std::string_view nodeName) const
finalvirtualinherited

indicates whether node id has received a soft evidence

Definition at line 382 of file graphicalModelInference_tpl.h.

382 {
383 return hasSoftEvidence(this->model().idFromName(nodeName));
384 }
virtual bool hasSoftEvidence(NodeId id) const final
indicates whether node id has received a soft evidence

References hasSoftEvidence(), and model().

Here is the call graph for this function:

◆ history()

INLINE const std::vector< double > & gum::ApproximationScheme::history ( ) const
overridevirtualinherited

Returns the scheme history.

Returns
Returns the scheme history.
Exceptions
OperationNotAllowedRaised if the scheme did not performed or if verbosity is set to false.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 179 of file approximationScheme_inl.h.

179 {
181 GUM_ERROR(OperationNotAllowed, "state of the approximation scheme is udefined")
182 }
183
184 if (!verbosity()) GUM_ERROR(OperationNotAllowed, "No history when verbosity=false")
185
186 return history_;
187 }

References GUM_ERROR, stateApproximationScheme(), and gum::IApproximationSchemeConfiguration::Undefined.

Here is the call graph for this function:

◆ initApproximationScheme()

INLINE void gum::ApproximationScheme::initApproximationScheme ( )
inherited

Initialise the scheme.

Definition at line 190 of file approximationScheme_inl.h.

190 {
192 current_step_ = 0;
194 history_.clear();
195 timer_.reset();
196 }

References ApproximationScheme(), gum::IApproximationSchemeConfiguration::Continue, current_state_, current_step_, and initApproximationScheme().

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), initApproximationScheme(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::GreedyThickThinning::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), gum::SamplingInference< GUM_SCALAR >::loopApproxInference_(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInference(), and gum::SamplingInference< GUM_SCALAR >::onStateChanged_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDrawnAtRandom()

template<GUM_Numeric GUM_SCALAR>
bool gum::GibbsOperator< GUM_SCALAR >::isDrawnAtRandom ( ) const
inherited

Definition at line 147 of file gibbsOperator_tpl.h.

147 {
148 return atRandom_;
149 }

References atRandom_.

◆ isEnabledEpsilon()

INLINE bool gum::ApproximationScheme::isEnabledEpsilon ( ) const
overridevirtualinherited

Returns true if stopping criterion on epsilon is enabled, false otherwise.

Returns
Returns true if stopping criterion on epsilon is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 82 of file approximationScheme_inl.h.

82{ return enabled_eps_; }

References enabled_eps_.

◆ isEnabledMaxIter()

INLINE bool gum::ApproximationScheme::isEnabledMaxIter ( ) const
overridevirtualinherited

Returns true if stopping criterion on max iterations is enabled, false otherwise.

Returns
Returns true if stopping criterion on max iterations is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 123 of file approximationScheme_inl.h.

123{ return enabled_max_iter_; }

References enabled_max_iter_.

◆ isEnabledMaxTime()

INLINE bool gum::ApproximationScheme::isEnabledMaxTime ( ) const
overridevirtualinherited

Returns true if stopping criterion on timeout is enabled, false otherwise.

Returns
Returns true if stopping criterion on timeout is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 147 of file approximationScheme_inl.h.

147{ return enabled_max_time_; }

References enabled_max_time_.

◆ isEnabledMinEpsilonRate()

INLINE bool gum::ApproximationScheme::isEnabledMinEpsilonRate ( ) const
overridevirtualinherited

Returns true if stopping criterion on epsilon rate is enabled, false otherwise.

Returns
Returns true if stopping criterion on epsilon rate is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 103 of file approximationScheme_inl.h.

103{ return enabled_min_rate_eps_; }

References enabled_min_rate_eps_.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::computeKL_().

Here is the caller graph for this function:

◆ isInferenceDone()

template<GUM_Numeric GUM_SCALAR>
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 105 of file graphicalModelInference_tpl.h.

105 {
107 }
StateOfInference _state_
the current state of the inference (outdated/ready/done)

References _state_, and Done.

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

Here is the caller graph for this function:

◆ isInferenceOutdatedStructure()

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

returns whether the inference object is in a OutdatedStructure state

Definition at line 93 of file graphicalModelInference_tpl.h.

93 {
95 }

References _state_, and OutdatedStructure.

Referenced by chgEvidence(), eraseAllEvidence(), and eraseEvidence().

Here is the caller graph for this function:

◆ isInferenceOutdatedTensors()

template<GUM_Numeric GUM_SCALAR>
bool gum::GraphicalModelInference< GUM_SCALAR >::isInferenceOutdatedTensors ( ) const
finalvirtualnoexceptinherited

returns whether the inference object is in a OutdatedTensor state

Definition at line 99 of file graphicalModelInference_tpl.h.

99 {
101 }

References _state_, and OutdatedTensors.

◆ isInferenceReady()

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

returns whether the inference object is in a ready state

Definition at line 87 of file graphicalModelInference_tpl.h.

References _state_, and ReadyForInference.

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

Here is the caller graph for this function:

◆ isInTargetMode()

template<GUM_Numeric GUM_SCALAR>
bool gum::MarginalTargetedInference< GUM_SCALAR >::isInTargetMode ( ) const
finalvirtualnoexceptinherited

indicates whether the inference is in a target mode

Definition at line 226 of file marginalTargetedInference_tpl.h.

226 {
227 return _targeted_mode_;
228 }

References _targeted_mode_.

◆ isTarget() [1/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::MarginalTargetedInference< GUM_SCALAR >::isTarget ( NodeId node) const
finalvirtualinherited

return true if variable is a (marginal) target

Definition at line 93 of file marginalTargetedInference_tpl.h.

93 {
94 // check that the variable belongs to the bn
95 if (this->hasNoModel_())
97 "No Bayes net has been assigned to the "
98 "inference algorithm");
99 if (!this->BN().internalDag().exists(node)) {
100 GUM_ERROR(UndefinedElement, node << " is not a NodeId in the bn")
101 }
102
103 return _targets_.contains(node);
104 }

References _targets_, gum::BayesNetInference< GUM_SCALAR >::BN(), GUM_ERROR, and gum::GraphicalModelInference< GUM_SCALAR >::hasNoModel_().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isTarget() [2/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::MarginalTargetedInference< GUM_SCALAR >::isTarget ( std::string_view nodeName) const
finalvirtualinherited

return true if variable is a (marginal) target

Definition at line 108 of file marginalTargetedInference_tpl.h.

108 {
109 return isTarget(this->BN().idFromName(nodeName));
110 }
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target

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

Here is the call graph for this function:

◆ isTargetedMode_()

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

Definition at line 330 of file marginalTargetedInference_tpl.h.

330 {
331 return _targeted_mode_;
332 }

References _targeted_mode_.

◆ loopApproxInference_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::loopApproxInference_ ( )
protectedinherited

Definition at line 176 of file samplingInference_tpl.h.

176 {
177 //@todo This should be in _prepareInference_
178 if (!isContextualized) { this->contextualize(); }
179
182 GUM_SCALAR w = .0; //
183
184 // Burn in
185 Ip = this->burnIn_();
186 do {
187 Ip = this->draw_(&w, Ip);
188 _estimator_.update(Ip, w);
190 } while (this->continueApproximationScheme(_estimator_.confidence()));
191
192 this->isSetEstimator = false;
193 }
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
void initApproximationScheme()
Initialise the scheme.
virtual void contextualize()
Simplifying the Bayesian network with relevance reasonning to lighten the computational charge.
virtual Instantiation draw_(GUM_SCALAR *w, Instantiation prev)=0
draws a sample in the Bayesian network given a previous one
virtual Instantiation burnIn_()=0
draws samples without updating the estimators
bool isSetEstimator
whether the Estimator object has been initialized

References _estimator_, burnIn_(), contextualize(), gum::ApproximationScheme::continueApproximationScheme(), draw_(), gum::ApproximationScheme::initApproximationScheme(), isContextualized, isSetEstimator, and gum::ApproximationScheme::updateApproximationScheme().

Referenced by makeInference_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeInference()

template<GUM_Numeric GUM_SCALAR>
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 632 of file graphicalModelInference_tpl.h.

632 {
633 if (isInferenceDone()) { return; }
634
636
638
640 }
virtual void prepareInference() final
prepare the internal inference structures for the next inference
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
virtual bool isInferenceReady() const noexcept final
returns whether the inference object is in a ready state
virtual void makeInference_()=0
called when the inference has to be performed effectively

References Done, isInferenceDone(), isInferenceReady(), makeInference_(), prepareInference(), and setState_().

Referenced by gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::Counterfactual< GUM_ELEMENT >::counterFactualModel(), gum::counterfactualModel(), gum::ASTjointProba< GUM_SCALAR >::eval(), gum::ASTposteriorProba< GUM_SCALAR >::eval(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::JointTargetedMRFInference< GUM_SCALAR >::evidenceJointImpact(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedInference< GUM_SCALAR >::jointPosterior(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointPosterior(), gum::LoopySamplingInference< GUM_SCALAR, APPROX >::makeInference_(), gum::MarginalTargetedInference< GUM_SCALAR >::posterior(), and gum::MarginalTargetedMRFInference< GUM_SCALAR >::posterior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeInference_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::makeInference_ ( )
overrideprotectedvirtualinherited

makes the inference by generating samples

Implements gum::GraphicalModelInference< GUM_SCALAR >.

Definition at line 170 of file samplingInference_tpl.h.

170 {
173 }
virtual void setEstimatorFromBN_()
Initializes the estimators object linked to the simulation.

References isSetEstimator, loopApproxInference_(), and setEstimatorFromBN_().

Here is the call graph for this function:

◆ maxIter()

INLINE Size gum::ApproximationScheme::maxIter ( ) const
overridevirtualinherited

Returns the criterion on number of iterations.

Returns
Returns the criterion on number of iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 113 of file approximationScheme_inl.h.

113{ return max_iter_; }

References max_iter_.

◆ maxTime()

INLINE double gum::ApproximationScheme::maxTime ( ) const
overridevirtualinherited

Returns the timeout (in seconds).

Returns
Returns the timeout (in seconds).

Implements gum::IApproximationSchemeConfiguration.

Definition at line 134 of file approximationScheme_inl.h.

134{ return max_time_; }

References max_time_.

◆ messageApproximationScheme()

std::string gum::IApproximationSchemeConfiguration::messageApproximationScheme ( ) const
inherited

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 64 of file IApproximationSchemeConfiguration.cpp.

64 {
65 switch (stateApproximationScheme()) {
66 case ApproximationSchemeSTATE::Continue : return "in progress";
67
69 return std::format("stopped with epsilon={}", epsilon());
70
72 return std::format("stopped with rate={}", minEpsilonRate());
73
75 return std::format("stopped with max iteration={}", maxIter());
76
78 return std::format("stopped with timeout={}", maxTime());
79
80 case ApproximationSchemeSTATE::Stopped : return "stopped on request";
81
82 case ApproximationSchemeSTATE::Undefined : return "undefined state";
83 }
84 return {};
85 }
virtual double epsilon() const =0
Returns the value of epsilon.
virtual ApproximationSchemeSTATE stateApproximationScheme() const =0
Returns the approximation scheme state.
virtual double minEpsilonRate() const =0
Returns the value of the minimal epsilon rate.
virtual Size maxIter() const =0
Returns the criterion on number of iterations.
virtual double maxTime() const =0
Returns the timeout (in seconds).

References Continue, Epsilon, epsilon(), Limit, maxIter(), maxTime(), minEpsilonRate(), Rate, stateApproximationScheme(), Stopped, TimeLimit, and Undefined.

Referenced by gum::ApproximationScheme::continueApproximationScheme(), gum::credal::InferenceEngine< GUM_SCALAR >::getApproximationSchemeMsg(), and gum::credal::MultipleInferenceEngine< GUM_SCALAR, LazyPropagation< GUM_SCALAR > >::isEnabledMaxIter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ minEpsilonRate()

INLINE double gum::ApproximationScheme::minEpsilonRate ( ) const
overridevirtualinherited

Returns the value of the minimal epsilon rate.

Returns
Returns the value of the minimal epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 93 of file approximationScheme_inl.h.

93{ return min_rate_eps_; }

References min_rate_eps_.

◆ model()

template<GUM_Numeric GUM_SCALAR>
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 127 of file graphicalModelInference_tpl.h.

127 {
128 if (_model_ == nullptr)
130 "No Bayes net has been assigned to "
131 "the inference algorithm.");
132 return *_model_;
133 }

References _model_, and GUM_ERROR.

Referenced by GraphicalModelInference(), addEvidence(), addEvidence(), addEvidence(), addEvidence(), gum::BayesNetInference< GUM_SCALAR >::BN(), chgEvidence(), chgEvidence(), chgEvidence(), chgEvidence(), eraseEvidence(), hasEvidence(), hasHardEvidence(), hasSoftEvidence(), gum::MRFInference< GUM_SCALAR >::MRF(), onModelChanged_(), gum::ShaferShenoyLIMIDInference< GUM_SCALAR >::onModelChanged_(), setModel_(), and setModelDuringConstruction_().

Here is the caller graph for this function:

◆ monteCarloSample()

template<GUM_Numeric GUM_SCALAR>
Instantiation gum::GibbsOperator< GUM_SCALAR >::monteCarloSample ( )
inherited

draws a Monte Carlo sample

returns a MC sample This is not a really sample since we take into account evidence without care about parent of evidence, etc. This is just a not-so-bad first sample for GibbsSampler

Definition at line 88 of file gibbsOperator_tpl.h.

88 {
90
91 for (const auto nod: samplingBn_.topologicalOrder()) {
92 I.add(samplingBn_.variable(nod));
93 if (hardEv_ != nullptr && hardEv_->exists(nod)) {
94 I.chgVal(samplingBn_.variable(nod), (*hardEv_)[nod]);
95 } else {
97 }
98 }
99 return I;
100 }
void _drawVarMonteCarlo_(NodeId nod, Instantiation *I)
const NodeProperty< Idx > * hardEv_

References _drawVarMonteCarlo_(), gum::Instantiation::add(), gum::Instantiation::chgVal(), hardEv_, and samplingBn_.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), and gum::GibbsSampling< GUM_SCALAR >::monteCarloSample_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ monteCarloSample_()

template<GUM_Numeric GUM_SCALAR>
Instantiation gum::GibbsSampling< GUM_SCALAR >::monteCarloSample_ ( )
protected

draws a Monte Carlo sample

Parameters
bnthe reference Bayesian network

This Monte Carlo sample generates a good starting point for Gibbs sampling, because it returns a sample consistent with the evidence, but it differs from the one implemented in the inherited class Approximate Inference because it also initializes attributes needed for Gibbs sampling.

Definition at line 84 of file GibbsSampling_tpl.h.

84 {
86 }
Instantiation monteCarloSample()
draws a Monte Carlo sample

References gum::GibbsOperator< GUM_SCALAR >::monteCarloSample().

Referenced by burnIn_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nbrDrawnVar()

template<GUM_Numeric GUM_SCALAR>
Size gum::GibbsOperator< GUM_SCALAR >::nbrDrawnVar ( ) const
inherited

Getters and setters.

Definition at line 137 of file gibbsOperator_tpl.h.

137 {
138 return nbr_;
139 }

References nbr_.

◆ nbrEvidence()

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

returns the number of evidence entered into the Bayesian network

Definition at line 556 of file graphicalModelInference_tpl.h.

556 {
557 return _evidence_.size();
558 }

References _evidence_.

◆ nbrHardEvidence()

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

returns the number of hard evidence entered into the Bayesian network

Definition at line 562 of file graphicalModelInference_tpl.h.

562 {
563 return _hard_evidence_nodes_.size();
564 }

References _hard_evidence_nodes_.

◆ nbrIterations()

INLINE Size gum::ApproximationScheme::nbrIterations ( ) const
overridevirtualinherited

Returns the number of iterations.

Returns
Returns the number of iterations.
Exceptions
OperationNotAllowedRaised if the scheme did not perform.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 170 of file approximationScheme_inl.h.

170 {
172 GUM_ERROR(OperationNotAllowed, "state of the approximation scheme is undefined")
173 }
174
175 return current_step_;
176 }

References current_step_, GUM_ERROR, stateApproximationScheme(), and gum::IApproximationSchemeConfiguration::Undefined.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::computeKL_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nbrSoftEvidence()

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

returns the number of soft evidence entered into the Bayesian network

Definition at line 568 of file graphicalModelInference_tpl.h.

568 {
569 return _soft_evidence_nodes_.size();
570 }

References _soft_evidence_nodes_.

◆ nbrTargets()

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

returns the number of marginal targets

Definition at line 220 of file marginalTargetedInference_tpl.h.

220 {
221 return _targets_.size();
222 }

References _targets_.

◆ nextSample()

template<GUM_Numeric GUM_SCALAR>
Instantiation gum::GibbsOperator< GUM_SCALAR >::nextSample ( Instantiation prev)
inherited

draws next sample of Gibbs sampling

Definition at line 110 of file gibbsOperator_tpl.h.

110 {
111 for (Idx i = 0; i < nbr_; i++) {
112 auto pos
115 counting_++;
116 }
117 return prev;
118 }
void _GibbsSample_(NodeId id, Instantiation *I)
change in Instantiation I a new drawn value for id
Sequence< NodeId > samplingNodes_
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.

References _GibbsSample_(), atRandom_, counting_, nbr_, gum::randomValue(), and samplingNodes_.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), and gum::GibbsSampling< GUM_SCALAR >::draw_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onAllEvidenceErased_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onAllEvidenceErased_ ( bool contains_hard_evidence)
overrideprotectedvirtualinherited

fired before all the evidence are erased

Implements gum::GraphicalModelInference< GUM_SCALAR >.

Definition at line 217 of file samplingInference_tpl.h.

217{}

◆ onAllMarginalTargetsAdded_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onAllMarginalTargetsAdded_ ( )
overrideprotectedvirtualinherited

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

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 243 of file samplingInference_tpl.h.

243{}

◆ onAllMarginalTargetsErased_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onAllMarginalTargetsErased_ ( )
overrideprotectedvirtualinherited

fired before a all marginal targets are removed

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 246 of file samplingInference_tpl.h.

246{}

◆ onContextualize_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onContextualize_ ( BayesNetFragment< GUM_SCALAR > * bn)
protectedvirtualinherited

fired when Bayesian network is contextualized

Parameters
bnthe contextualized BayesNetFragment
targetsinference target variables
hardEvNodeshard evidence nodes
hardEvhard evidences values

Reimplemented in gum::ImportanceSampling< GUM_SCALAR >.

Definition at line 204 of file samplingInference_tpl.h.

204{}

Referenced by contextualize().

Here is the caller graph for this function:

◆ onEvidenceAdded_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onEvidenceAdded_ ( const NodeId id,
bool isHardEvidence )
overrideprotectedvirtualinherited

fired after a new evidence is inserted

Implements gum::GraphicalModelInference< GUM_SCALAR >.

Definition at line 207 of file samplingInference_tpl.h.

207 {
208 if (!isHardEvidence) {
209 GUM_ERROR(FatalError, "Approximated inference only accept hard evidence")
210 }
211 }

References GUM_ERROR.

◆ onEvidenceChanged_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onEvidenceChanged_ ( const NodeId id,
bool hasChangedSoftHard )
overrideprotectedvirtualinherited

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 >.

Definition at line 220 of file samplingInference_tpl.h.

221 {
222 if (hasChangedSoftHard) {
223 GUM_ERROR(FatalError, "Approximated inference only accept hard evidence")
224 }
225 }

References GUM_ERROR.

◆ onEvidenceErased_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onEvidenceErased_ ( const NodeId id,
bool isHardEvidence )
overrideprotectedvirtualinherited

fired before an evidence is removed

Implements gum::GraphicalModelInference< GUM_SCALAR >.

Definition at line 214 of file samplingInference_tpl.h.

214{}

◆ onMarginalTargetAdded_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onMarginalTargetAdded_ ( const NodeId id)
overrideprotectedvirtualinherited

fired after a new marginal target is inserted

Parameters
idThe target variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 237 of file samplingInference_tpl.h.

237{}

◆ onMarginalTargetErased_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onMarginalTargetErased_ ( const NodeId id)
overrideprotectedvirtualinherited

fired before a marginal target is removed

Parameters
idThe target variable's id.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 240 of file samplingInference_tpl.h.

240{}

◆ onModelChanged_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onModelChanged_ ( const GraphicalModel * bn)
overrideprotectedvirtualinherited

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

Reimplemented from gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 228 of file samplingInference_tpl.h.

228{}

◆ onStateChanged_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::onStateChanged_ ( )
overrideprotectedvirtualinherited

fired when the stage is changed

Implements gum::GraphicalModelInference< GUM_SCALAR >.

Definition at line 249 of file samplingInference_tpl.h.

249 {
250 if (this->isInferenceReady()) {
251 _estimator_.clear();
253 }
254 }

References _estimator_, gum::ApproximationScheme::initApproximationScheme(), and gum::GraphicalModelInference< GUM_SCALAR >::isInferenceReady().

Here is the call graph for this function:

◆ periodSize()

INLINE Size gum::ApproximationScheme::periodSize ( ) const
overridevirtualinherited

Returns the period size.

Returns
Returns the period size.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 156 of file approximationScheme_inl.h.

156{ return period_size_; }
Size period_size_
Checking criteria frequency.

References period_size_.

◆ posterior() [1/2]

template<GUM_Numeric GUM_SCALAR>
const Tensor< GUM_SCALAR > & gum::MarginalTargetedInference< GUM_SCALAR >::posterior ( NodeId node)
virtualinherited

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 tensor is stored into the inference engine and is returned by reference. In order to ensure that the tensor 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 in gum::JointTargetedInference< GUM_SCALAR >.

Definition at line 246 of file marginalTargetedInference_tpl.h.

246 {
247 if (this->hardEvidenceNodes().contains(node)) { return *(this->evidence()[node]); }
248
249 if (!isTarget(node)) {
250 // throws UndefinedElement if var is not a target
251 GUM_ERROR(UndefinedElement, node << " is not a target node")
252 }
253
254 if (!this->isInferenceDone()) { this->makeInference(); }
255
256 return posterior_(node);
257 }
const NodeProperty< const Tensor< GUM_SCALAR > * > & evidence() const
returns the set of evidence
virtual const Tensor< GUM_SCALAR > & posterior_(NodeId id)=0
asks derived classes for the posterior of a given variable

References gum::contains(), gum::GraphicalModelInference< GUM_SCALAR >::evidence(), GUM_ERROR, gum::GraphicalModelInference< GUM_SCALAR >::hardEvidenceNodes(), gum::GraphicalModelInference< GUM_SCALAR >::isInferenceDone(), isTarget(), gum::GraphicalModelInference< GUM_SCALAR >::makeInference(), and posterior_().

Referenced by evidenceImpact(), H(), gum::JointTargetedInference< GUM_SCALAR >::posterior(), posterior(), and gum::Estimator< GUM_SCALAR >::setFromLBP().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ posterior() [2/2]

template<GUM_Numeric GUM_SCALAR>
const Tensor< GUM_SCALAR > & gum::MarginalTargetedInference< GUM_SCALAR >::posterior ( std::string_view nodeName)
virtualinherited

Computes and returns the posterior of a node.

Returns
a const ref to the posterior probability of the node.
Parameters
nodeNamethe name of the node for which we need a posterior probability
Warning
for efficiency reasons, the tensor is stored into the inference engine and is returned by reference. In order to ensure that the tensor 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 in gum::JointTargetedInference< GUM_SCALAR >.

Definition at line 262 of file marginalTargetedInference_tpl.h.

262 {
263 return posterior(this->BN().idFromName(nodeName));
264 }

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

Here is the call graph for this function:

◆ posterior_()

template<GUM_Numeric GUM_SCALAR>
const Tensor< GUM_SCALAR > & gum::SamplingInference< GUM_SCALAR >::posterior_ ( NodeId id)
overridevirtualinherited

Computes and returns the posterior of a node.

Returns
a const ref to the posterior probability of the node.
Parameters
idthe node for which we need a posterior probability
Warning
for efficiency reasons, the tensor is returned by reference. In order to ensure that the tensor may still exist even if the Inference object is destroyed, the user has to copy it explicitly.
Exceptions
UndefinedElementif node is not in the set of targets.
NotFoundif node is not in the BN.

Implements gum::MarginalTargetedInference< GUM_SCALAR >.

Definition at line 122 of file samplingInference_tpl.h.

122 {
123 return _estimator_.posterior(this->BN().variable(id));
124 }

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

Here is the call graph for this function:

◆ prepareInference()

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

prepare the internal inference structures for the next inference

Definition at line 616 of file graphicalModelInference_tpl.h.

616 {
617 if (isInferenceReady() || isInferenceDone()) { return; }
618
619 if (_model_ == nullptr)
621 "No model been assigned to the "
622 "inference algorithm");
623
626
628 }
virtual void updateOutdatedTensors_()=0
prepares inference when the latter is in OutdatedTensors state
virtual void updateOutdatedStructure_()=0
prepares inference when the latter is in OutdatedStructure state

References _model_, _state_, GUM_ERROR, isInferenceDone(), isInferenceReady(), OutdatedStructure, ReadyForInference, setState_(), updateOutdatedStructure_(), and updateOutdatedTensors_().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remainingBurnIn()

INLINE Size gum::ApproximationScheme::remainingBurnIn ( ) const
inherited

Returns the remaining burn in.

Returns
Returns the remaining burn in.

Definition at line 213 of file approximationScheme_inl.h.

213 {
214 if (burn_in_ > current_step_) {
215 return burn_in_ - current_step_;
216 } else {
217 return 0;
218 }
219 }

References burn_in_, and current_step_.

◆ samplingBN()

template<GUM_Numeric GUM_SCALAR>
const IBayesNet< GUM_SCALAR > & gum::SamplingInference< GUM_SCALAR >::samplingBN ( )
inherited

get the BayesNet which is used to really perform the sampling

Definition at line 90 of file samplingInference_tpl.h.

90 {
91 this->prepareInference();
92 if (_samplingBN_ == nullptr) return this->BN();
93 else return *_samplingBN_;
94 }

References _samplingBN_, gum::BayesNetInference< GUM_SCALAR >::BN(), and gum::GraphicalModelInference< GUM_SCALAR >::prepareInference().

Referenced by addVarSample_(), gum::ImportanceSampling< GUM_SCALAR >::draw_(), and setEstimatorFromBN_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBN()

template<GUM_Numeric 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 82 of file BayesNetInference_tpl.h.

82 {
83 this->setModel_(bn);
84 }
void setModel_(const GraphicalModel *model)

References gum::GraphicalModelInference< GUM_SCALAR >::setModel_().

Here is the call graph for this function:

◆ setBurnIn()

template<GUM_Numeric GUM_SCALAR>
void gum::GibbsSampling< GUM_SCALAR >::setBurnIn ( Size b)

Number of burn in for one iteration.

Parameters
bThe number of burn in.
Exceptions
OutOfBoundsRaised if b < 1.

Definition at line 114 of file GibbsSampling_tpl.h.

114 {
115 this->burn_in_ = b;
116 }

References gum::ApproximationScheme::burn_in_.

Referenced by GibbsSampling().

Here is the caller graph for this function:

◆ setDrawnAtRandom()

template<GUM_Numeric GUM_SCALAR>
void gum::GibbsOperator< GUM_SCALAR >::setDrawnAtRandom ( bool atRandom)
inherited

Definition at line 152 of file gibbsOperator_tpl.h.

152 {
154 }

References atRandom_.

◆ setEpsilon()

INLINE void gum::ApproximationScheme::setEpsilon ( double eps)
overridevirtualinherited

Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.

If the criterion was disabled it will be enabled.

Parameters
epsThe new epsilon value.
Exceptions
OutOfBoundsRaised if eps < 0.

Implements gum::IApproximationSchemeConfiguration.

Reimplemented in gum::learning::EMApproximationScheme.

Definition at line 64 of file approximationScheme_inl.h.

64 {
65 if (eps < 0.) { GUM_ERROR(OutOfBounds, "eps should be >=0") }
66
67 eps_ = eps;
68 enabled_eps_ = true;
69 }

References enabled_eps_, eps_, and GUM_ERROR.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsSampling< GUM_SCALAR >::GibbsSampling(), gum::learning::GreedyHillClimbing::GreedyHillClimbing(), gum::learning::GreedyThickThinning::GreedyThickThinning(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), and gum::learning::EMApproximationScheme::setEpsilon().

Here is the caller graph for this function:

◆ setEstimatorFromBN_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::setEstimatorFromBN_ ( )
virtualinherited

Initializes the estimators object linked to the simulation.

Initializes the estimator object by creating a hashtable between non evidence nodes and a 0-filled tensor which will approximate the node's posterior

Definition at line 97 of file samplingInference_tpl.h.

97 {
98 _estimator_.setFromBN(&samplingBN(), this->hardEvidenceNodes());
99 this->isSetEstimator = true;
100 }

References _estimator_, gum::GraphicalModelInference< GUM_SCALAR >::hardEvidenceNodes(), isSetEstimator, and samplingBN().

Referenced by makeInference_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEstimatorFromLBP_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::setEstimatorFromLBP_ ( LoopyBeliefPropagation< GUM_SCALAR > * lbp,
GUM_SCALAR virtualLBPSize )
virtualinherited

Initializes the estimators object linked to the simulation.

Parameters
lbpa LoopyBeliefPropagation object
virtualLBPSizethe size of the equivalent sampling by LBP

Initializes the estimator object by creating a hashtable between non evidence nodes and the current approximation of the node's posterior obtained by running LoopyBeliefPropagation algorithm

Definition at line 103 of file samplingInference_tpl.h.

105 {
106 _estimator_.setFromLBP(lbp, this->hardEvidenceNodes(), virtualLBPSize);
107 this->isSetEstimator = true;
108 }

References _estimator_, gum::GraphicalModelInference< GUM_SCALAR >::hardEvidenceNodes(), and isSetEstimator.

Here is the call graph for this function:

◆ setMaxIter()

INLINE void gum::ApproximationScheme::setMaxIter ( Size max)
overridevirtualinherited

Stopping criterion on number of iterations.

If the criterion was disabled it will be enabled.

Parameters
maxThe maximum number of iterations.
Exceptions
OutOfBoundsRaised if max <= 1.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 106 of file approximationScheme_inl.h.

106 {
107 if (max < 1) { GUM_ERROR(OutOfBounds, "max should be >=1") }
108 max_iter_ = max;
109 enabled_max_iter_ = true;
110 }

References enabled_max_iter_, GUM_ERROR, and max_iter_.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), and gum::SamplingInference< GUM_SCALAR >::SamplingInference().

Here is the caller graph for this function:

◆ setMaxTime()

INLINE void gum::ApproximationScheme::setMaxTime ( double timeout)
overridevirtualinherited

Stopping criterion on timeout.

If the criterion was disabled it will be enabled.

Parameters
timeoutThe timeout value in seconds.
Exceptions
OutOfBoundsRaised if timeout <= 0.0.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 127 of file approximationScheme_inl.h.

127 {
128 if (timeout <= 0.) { GUM_ERROR(OutOfBounds, "timeout should be >0.") }
129 max_time_ = timeout;
130 enabled_max_time_ = true;
131 }

References enabled_max_time_, GUM_ERROR, and max_time_.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), and gum::SamplingInference< GUM_SCALAR >::SamplingInference().

Here is the caller graph for this function:

◆ setMinEpsilonRate()

INLINE void gum::ApproximationScheme::setMinEpsilonRate ( double rate)
overridevirtualinherited

Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).

If the criterion was disabled it will be enabled

Parameters
rateThe minimal epsilon rate.
Exceptions
OutOfBoundsif rate<0

Implements gum::IApproximationSchemeConfiguration.

Reimplemented in gum::learning::EMApproximationScheme.

Definition at line 85 of file approximationScheme_inl.h.

85 {
86 if (rate < 0) { GUM_ERROR(OutOfBounds, "rate should be >=0") }
87
88 min_rate_eps_ = rate;
90 }

References enabled_min_rate_eps_, GUM_ERROR, and min_rate_eps_.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsSampling< GUM_SCALAR >::GibbsSampling(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), and gum::learning::EMApproximationScheme::setMinEpsilonRate().

Here is the caller graph for this function:

◆ setModel_()

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

Definition at line 137 of file graphicalModelInference_tpl.h.

137 {
138 clear();
139 _model_ = model;
143 }
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 void clear()
clears all the data structures allocated for the last inference

References _computeDomainSizes_(), _model_, clear(), model(), onModelChanged_(), OutdatedStructure, and setState_().

Referenced by gum::BayesNetInference< GUM_SCALAR >::setBN(), and gum::MRFInference< GUM_SCALAR >::setMRF().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setModelDuringConstruction_()

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

assigns a model during the inference engine construction

Definition at line 147 of file graphicalModelInference_tpl.h.

References _computeDomainSizes_(), _model_, model(), OutdatedStructure, and setState_().

Referenced by gum::BayesNetInference< GUM_SCALAR >::_setBayesNetDuringConstruction_(), and gum::MRFInference< GUM_SCALAR >::_setMRFDuringConstruction_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setNbrDrawnVar()

template<GUM_Numeric GUM_SCALAR>
void gum::GibbsOperator< GUM_SCALAR >::setNbrDrawnVar ( Size nbr)
inherited

Definition at line 142 of file gibbsOperator_tpl.h.

142 {
143 nbr_ = nbr;
144 }

References nbr_.

◆ setOutdatedStructureState_()

template<GUM_Numeric GUM_SCALAR>
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 OutdatedTensors 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 tensors 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 603 of file graphicalModelInference_tpl.h.

References OutdatedStructure, and setState_().

Referenced by makeInference_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setOutdatedTensorsState_()

template<GUM_Numeric GUM_SCALAR>
void gum::GraphicalModelInference< GUM_SCALAR >::setOutdatedTensorsState_ ( )
protectedinherited

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

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

Definition at line 610 of file graphicalModelInference_tpl.h.

References OutdatedTensors, and setState_().

Referenced by makeInference_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPeriodSize()

INLINE void gum::ApproximationScheme::setPeriodSize ( Size p)
overridevirtualinherited

How many samples between two stopping is enable.

Parameters
pThe new period value.
Exceptions
OutOfBoundsRaised if p < 1.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 150 of file approximationScheme_inl.h.

150 {
151 if (p < 1) { GUM_ERROR(OutOfBounds, "p should be >=1") }
152
153 period_size_ = p;
154 }

References GUM_ERROR.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), and gum::SamplingInference< GUM_SCALAR >::SamplingInference().

Here is the caller graph for this function:

◆ setState_()

template<GUM_Numeric GUM_SCALAR>
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 118 of file graphicalModelInference_tpl.h.

118 {
119 if (_state_ != state) {
120 _state_ = state;
122 }
123 }
virtual void onStateChanged_()=0
fired when the stage is changed
virtual StateOfInference state() const noexcept final
returns the state of the inference engine

References _state_, onStateChanged_(), and state().

Referenced by gum::MarginalTargetedInference< GUM_SCALAR >::addAllTargets(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::addAllTargets(), addEvidence(), gum::JointTargetedInference< GUM_SCALAR >::addJointTarget(), gum::JointTargetedMRFInference< GUM_SCALAR >::addJointTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::addTarget(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::addTarget(), chgEvidence(), clear(), eraseAllEvidence(), gum::JointTargetedInference< GUM_SCALAR >::eraseAllJointTargets(), gum::JointTargetedMRFInference< GUM_SCALAR >::eraseAllJointTargets(), gum::MarginalTargetedInference< GUM_SCALAR >::eraseAllTargets(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::eraseAllTargets(), eraseEvidence(), gum::JointTargetedInference< GUM_SCALAR >::eraseJointTarget(), gum::JointTargetedMRFInference< GUM_SCALAR >::eraseJointTarget(), gum::MarginalTargetedInference< GUM_SCALAR >::eraseTarget(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::eraseTarget(), makeInference(), prepareInference(), setModel_(), setModelDuringConstruction_(), setOutdatedStructureState_(), and setOutdatedTensorsState_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTargetedMode_()

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

Definition at line 335 of file marginalTargetedInference_tpl.h.

335 {
336 if (!_targeted_mode_) {
337 _targets_.clear();
338 _targeted_mode_ = true;
339 }
340 }

References _targeted_mode_, and _targets_.

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

Here is the caller graph for this function:

◆ setVerbosity()

INLINE void gum::ApproximationScheme::setVerbosity ( bool v)
overridevirtualinherited

Set the verbosity on (true) or off (false).

Parameters
vIf true, then verbosity is turned on.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 159 of file approximationScheme_inl.h.

159{ verbosity_ = v; }
bool verbosity_
If true, verbosity is enabled.

References verbosity_.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), and gum::SamplingInference< GUM_SCALAR >::SamplingInference().

Here is the caller graph for this function:

◆ softEvidenceNodes()

template<GUM_Numeric GUM_SCALAR>
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 587 of file graphicalModelInference_tpl.h.

587 {
589 }

References _soft_evidence_nodes_.

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

Here is the caller graph for this function:

◆ startOfPeriod()

INLINE bool gum::ApproximationScheme::startOfPeriod ( ) const
inherited

Returns true if we are at the beginning of a period (compute error is mandatory).

Returns
Returns true if we are at the beginning of a period (compute error is mandatory).

Definition at line 200 of file approximationScheme_inl.h.

200 {
201 if (current_step_ < burn_in_) { return false; }
202
203 if (period_size_ == 1) { return true; }
204
205 return ((current_step_ - burn_in_) % period_size_ == 0);
206 }

Referenced by continueApproximationScheme().

Here is the caller graph for this function:

◆ state()

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

returns the state of the inference engine

Definition at line 112 of file graphicalModelInference_tpl.h.

112 {
113 return _state_;
114 }

References _state_.

Referenced by setState_().

Here is the caller graph for this function:

◆ stateApproximationScheme()

INLINE IApproximationSchemeConfiguration::ApproximationSchemeSTATE gum::ApproximationScheme::stateApproximationScheme ( ) const
overridevirtualinherited

Returns the approximation scheme state.

Returns
Returns the approximation scheme state.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 165 of file approximationScheme_inl.h.

165 {
166 return current_state_;
167 }

Referenced by continueApproximationScheme(), history(), and nbrIterations().

Here is the caller graph for this function:

◆ stopApproximationScheme()

INLINE void gum::ApproximationScheme::stopApproximationScheme ( )
inherited

Stop the approximation scheme.

Definition at line 222 of file approximationScheme_inl.h.

Referenced by gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::GreedyThickThinning::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), and gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceNodeToNeighbours_().

Here is the caller graph for this function:

◆ stopScheme_()

INLINE void gum::ApproximationScheme::stopScheme_ ( ApproximationSchemeSTATE new_state)
privateinherited

Stop the scheme given a new state.

Parameters
new_stateThe scheme new state.

Definition at line 231 of file approximationScheme_inl.h.

231 {
232 if (new_state == ApproximationSchemeSTATE::Continue) { return; }
233
234 if (new_state == ApproximationSchemeSTATE::Undefined) { return; }
235
236 current_state_ = new_state;
237 timer_.pause();
238
239 if (onStop.hasListener()) { GUM_EMIT1(onStop, messageApproximationScheme()); }
240 }
Signaler< std::string_view > onStop
Criteria messageApproximationScheme.
#define GUM_EMIT1(signal, arg1)
Definition signaler.h:289

References gum::IApproximationSchemeConfiguration::Continue, and gum::IApproximationSchemeConfiguration::Undefined.

Referenced by continueApproximationScheme(), and gum::credal::MultipleInferenceEngine< GUM_SCALAR, LazyPropagation< GUM_SCALAR > >::disableMaxIter().

Here is the caller graph for this function:

◆ targets()

◆ updateApproximationScheme()

INLINE void gum::ApproximationScheme::updateApproximationScheme ( unsigned int incr = 1)
inherited

◆ updateOutdatedStructure_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::updateOutdatedStructure_ ( )
overrideprotectedvirtualinherited

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 >.

Definition at line 231 of file samplingInference_tpl.h.

231{}

◆ updateOutdatedTensors_()

template<GUM_Numeric GUM_SCALAR>
void gum::SamplingInference< GUM_SCALAR >::updateOutdatedTensors_ ( )
overrideprotectedvirtualinherited

prepares inference when the latter is in OutdatedTensors state

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

Implements gum::GraphicalModelInference< GUM_SCALAR >.

Definition at line 234 of file samplingInference_tpl.h.

234{}

◆ updateSamplingNodes_()

template<GUM_Numeric GUM_SCALAR>
void gum::GibbsOperator< GUM_SCALAR >::updateSamplingNodes_ ( )
protectedinherited

Definition at line 73 of file gibbsOperator_tpl.h.

73 {
74 samplingNodes_.clear();
75 for (const auto node: samplingBn_.nodes())
76 if (hardEv_ == nullptr || !hardEv_->exists(node)) { samplingNodes_.insert(node); }
77 if (samplingNodes_.size() == 0) {
78 GUM_ERROR(InvalidArgument, "No node to sample (too many nodes or too much evidence)!")
79 }
80 if (nbr_ > samplingNodes_.size()) nbr_ = samplingNodes_.size();
81 }

References GUM_ERROR, hardEv_, nbr_, samplingBn_, and samplingNodes_.

Referenced by gum::GibbsSampling< GUM_SCALAR >::burnIn_(), and gum::GibbsBNdistance< GUM_SCALAR >::computeKL_().

Here is the caller graph for this function:

◆ verbosity()

INLINE bool gum::ApproximationScheme::verbosity ( ) const
overridevirtualinherited

Returns true if verbosity is enabled.

Returns
Returns true if verbosity is enabled.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 161 of file approximationScheme_inl.h.

161{ return verbosity_; }

References verbosity_.

Referenced by ApproximationScheme(), gum::learning::EMApproximationScheme::EMApproximationScheme(), and continueApproximationScheme().

Here is the caller graph for this function:

Member Data Documentation

◆ _estimator_

template<GUM_Numeric GUM_SCALAR>
Estimator< GUM_SCALAR > gum::SamplingInference< GUM_SCALAR >::_estimator_
protectedinherited

Estimator object designed to approximate target posteriors.

Definition at line 196 of file samplingInference.h.

Referenced by SamplingInference(), currentPosterior(), loopApproxInference_(), onStateChanged_(), posterior_(), setEstimatorFromBN_(), and setEstimatorFromLBP_().

◆ _samplingBN_

template<GUM_Numeric GUM_SCALAR>
BayesNetFragment< GUM_SCALAR >* gum::SamplingInference< GUM_SCALAR >::_samplingBN_
privateinherited

◆ _targeted_mode_

template<GUM_Numeric GUM_SCALAR>
bool gum::MarginalTargetedInference< GUM_SCALAR >::_targeted_mode_
privateinherited

whether the actual targets are default

Definition at line 262 of file marginalTargetedInference.h.

Referenced by MarginalTargetedInference(), eraseTarget(), isInTargetMode(), isTargetedMode_(), onModelChanged_(), and setTargetedMode_().

◆ _targets_

template<GUM_Numeric GUM_SCALAR>
NodeSet gum::MarginalTargetedInference< GUM_SCALAR >::_targets_
privateinherited

◆ atRandom_

template<GUM_Numeric GUM_SCALAR>
bool gum::GibbsOperator< GUM_SCALAR >::atRandom_
protectedinherited

Definition at line 104 of file gibbsOperator.h.

Referenced by GibbsOperator(), isDrawnAtRandom(), nextSample(), and setDrawnAtRandom().

◆ burn_in_

Size gum::ApproximationScheme::burn_in_
protectedinherited

◆ counting_

template<GUM_Numeric GUM_SCALAR>
Size gum::GibbsOperator< GUM_SCALAR >::counting_
protectedinherited

Definition at line 98 of file gibbsOperator.h.

Referenced by GibbsOperator(), and nextSample().

◆ current_epsilon_

double gum::ApproximationScheme::current_epsilon_
protectedinherited

Current epsilon.

Definition at line 378 of file approximationScheme.h.

Referenced by continueApproximationScheme().

◆ current_rate_

double gum::ApproximationScheme::current_rate_
protectedinherited

Current rate.

Definition at line 384 of file approximationScheme.h.

Referenced by continueApproximationScheme().

◆ current_state_

ApproximationSchemeSTATE gum::ApproximationScheme::current_state_
protectedinherited

The current state.

Definition at line 393 of file approximationScheme.h.

Referenced by ApproximationScheme(), continueApproximationScheme(), and initApproximationScheme().

◆ current_step_

◆ enabled_eps_

bool gum::ApproximationScheme::enabled_eps_
protectedinherited

If true, the threshold convergence is enabled.

Definition at line 402 of file approximationScheme.h.

Referenced by ApproximationScheme(), continueApproximationScheme(), disableEpsilon(), enableEpsilon(), isEnabledEpsilon(), and setEpsilon().

◆ enabled_max_iter_

bool gum::ApproximationScheme::enabled_max_iter_
protectedinherited

If true, the maximum iterations stopping criterion is enabled.

Definition at line 420 of file approximationScheme.h.

Referenced by ApproximationScheme(), continueApproximationScheme(), disableMaxIter(), enableMaxIter(), isEnabledMaxIter(), and setMaxIter().

◆ enabled_max_time_

bool gum::ApproximationScheme::enabled_max_time_
protectedinherited

If true, the timeout is enabled.

Definition at line 414 of file approximationScheme.h.

Referenced by ApproximationScheme(), continueApproximationScheme(), disableMaxTime(), enableMaxTime(), isEnabledMaxTime(), and setMaxTime().

◆ enabled_min_rate_eps_

bool gum::ApproximationScheme::enabled_min_rate_eps_
protectedinherited

If true, the minimal threshold for epsilon rate is enabled.

Definition at line 408 of file approximationScheme.h.

Referenced by ApproximationScheme(), continueApproximationScheme(), disableMinEpsilonRate(), enableMinEpsilonRate(), isEnabledMinEpsilonRate(), and setMinEpsilonRate().

◆ eps_

double gum::ApproximationScheme::eps_
protectedinherited

Threshold for convergence.

Definition at line 399 of file approximationScheme.h.

Referenced by ApproximationScheme(), continueApproximationScheme(), epsilon(), and setEpsilon().

◆ hardEv_

template<GUM_Numeric GUM_SCALAR>
const NodeProperty< Idx >* gum::GibbsOperator< GUM_SCALAR >::hardEv_
protectedinherited

Definition at line 100 of file gibbsOperator.h.

Referenced by GibbsOperator(), monteCarloSample(), and updateSamplingNodes_().

◆ history_

std::vector< double > gum::ApproximationScheme::history_
protectedinherited

The scheme history, used only if verbosity == true.

Definition at line 396 of file approximationScheme.h.

Referenced by continueApproximationScheme().

◆ isContextualized

template<GUM_Numeric GUM_SCALAR>
bool gum::SamplingInference< GUM_SCALAR >::isContextualized = false
protectedinherited

whether the referenced Bayesian network has been "contextualized"

Definition at line 202 of file samplingInference.h.

Referenced by ~SamplingInference(), contextualize(), and loopApproxInference_().

◆ isSetEstimator

template<GUM_Numeric GUM_SCALAR>
bool gum::SamplingInference< GUM_SCALAR >::isSetEstimator = false
protectedinherited

whether the Estimator object has been initialized

Definition at line 199 of file samplingInference.h.

Referenced by loopApproxInference_(), makeInference_(), setEstimatorFromBN_(), and setEstimatorFromLBP_().

◆ last_epsilon_

double gum::ApproximationScheme::last_epsilon_
protectedinherited

Last epsilon value.

Definition at line 381 of file approximationScheme.h.

Referenced by continueApproximationScheme().

◆ max_iter_

Size gum::ApproximationScheme::max_iter_
protectedinherited

The maximum iterations.

Definition at line 417 of file approximationScheme.h.

Referenced by ApproximationScheme(), continueApproximationScheme(), maxIter(), and setMaxIter().

◆ max_time_

double gum::ApproximationScheme::max_time_
protectedinherited

The timeout.

Definition at line 411 of file approximationScheme.h.

Referenced by ApproximationScheme(), continueApproximationScheme(), maxTime(), and setMaxTime().

◆ min_rate_eps_

double gum::ApproximationScheme::min_rate_eps_
protectedinherited

Threshold for the epsilon rate.

Definition at line 405 of file approximationScheme.h.

Referenced by ApproximationScheme(), continueApproximationScheme(), minEpsilonRate(), and setMinEpsilonRate().

◆ nbr_

template<GUM_Numeric GUM_SCALAR>
Size gum::GibbsOperator< GUM_SCALAR >::nbr_
protectedinherited

◆ onProgress

◆ onStop

Signaler< std::string_view > gum::IApproximationSchemeConfiguration::onStop
inherited

Criteria messageApproximationScheme.

Definition at line 84 of file IApproximationSchemeConfiguration.h.

Referenced by gum::learning::IBNLearner::distributeStop().

◆ period_size_

Size gum::ApproximationScheme::period_size_
protectedinherited

Checking criteria frequency.

Definition at line 426 of file approximationScheme.h.

Referenced by ApproximationScheme(), and periodSize().

◆ samplingBn_

template<GUM_Numeric GUM_SCALAR>
const IBayesNet< GUM_SCALAR >& gum::GibbsOperator< GUM_SCALAR >::samplingBn_
protectedinherited

◆ samplingNodes_

template<GUM_Numeric GUM_SCALAR>
Sequence< NodeId > gum::GibbsOperator< GUM_SCALAR >::samplingNodes_
protectedinherited

Definition at line 101 of file gibbsOperator.h.

Referenced by nextSample(), and updateSamplingNodes_().

◆ timer_

◆ verbosity_

bool gum::ApproximationScheme::verbosity_
protectedinherited

If true, verbosity is enabled.

Definition at line 429 of file approximationScheme.h.

Referenced by ApproximationScheme(), setVerbosity(), and verbosity().


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