aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
gum::credal::InferenceEngine< GUM_SCALAR > Class Template Referenceabstract

Abstract class template representing a CredalNet inference engine. More...

#include <agrum/CN/inferenceEngine.h>

Inheritance diagram for gum::credal::InferenceEngine< GUM_SCALAR >:
[legend]
Collaboration diagram for gum::credal::InferenceEngine< GUM_SCALAR >:
[legend]

Public Types

enum class  ApproximationSchemeSTATE : char {
  Undefined , Continue , Epsilon , Rate ,
  Limit , TimeLimit , Stopped
}
 The different state of an approximation scheme. More...

Public Member Functions

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 eraseAllEvidence ()
 removes all the evidence entered into the network
Constructors / Destructors
 InferenceEngine (const CredalNet< GUM_SCALAR > &credalNet)
 Construtor.
 ~InferenceEngine () override
 Destructor.
Pure virtual methods
virtual void makeInference ()=0
 To be redefined by each credal net algorithm.
Getters and setters
VarMod2BNsMap< GUM_SCALAR > * getVarMod2BNsMap ()
 Get optimum IBayesNet.
const CredalNet< GUM_SCALAR > & credalNet () const
 Get this credal network.
const NodeProperty< std::vector< NodeId > > & getT0Cluster () const
 Get the t0_ cluster.
const NodeProperty< std::vector< NodeId > > & getT1Cluster () const
 Get the t1_ cluster.
void setRepetitiveInd (const bool repetitive)
void storeVertices (const bool value)
void storeBNOpt (const bool value)
bool repetitiveInd () const
 Get the current independence status.
bool storeVertices () const
 Get the number of iterations without changes used to stop some algorithms.
bool storeBNOpt () const
Pre-inference initialization methods
void insertModalsFile (std::string_view path)
 Insert variables modalities from file to compute expectations.
void insertModals (const std::map< std::string, std::vector< GUM_SCALAR > > &modals)
 Insert variables modalities from map to compute expectations.
virtual void insertEvidenceFile (std::string_view path)
 Insert evidence from file.
void insertEvidence (const std::map< std::string, std::vector< GUM_SCALAR > > &eviMap)
 Insert evidence from map.
void insertEvidence (const NodeProperty< std::vector< GUM_SCALAR > > &evidence)
 Insert evidence from Property.
void insertQueryFile (std::string_view path)
 Insert query variables states from file.
void insertQuery (const NodeProperty< std::vector< bool > > &queryquery)
 Insert query variables and states from Property.
Post-inference methods
Tensor< GUM_SCALAR > marginalMin (const NodeId id) const
 Get the lower marginals of a given node id.
Tensor< GUM_SCALAR > marginalMax (const NodeId id) const
 Get the upper marginals of a given node id.
Tensor< GUM_SCALAR > marginalMin (std::string_view varName) const
 Get the lower marginals of a given variable name.
Tensor< GUM_SCALAR > marginalMax (std::string_view varName) const
 Get the upper marginals of a given variable name.
const GUM_SCALAR & expectationMin (const NodeId id) const
 Get the lower expectation of a given node id.
const GUM_SCALAR & expectationMax (const NodeId id) const
 Get the upper expectation of a given node id.
const GUM_SCALAR & expectationMin (std::string_view varName) const
 Get the lower expectation of a given variable name.
const GUM_SCALAR & expectationMax (std::string_view varName) const
 Get the upper expectation of a given variable name.
const std::vector< GUM_SCALAR > & dynamicExpMin (std::string_view varName) const
 Get the lower dynamic expectation of a given variable prefix (without the time step included, i.e.
const std::vector< GUM_SCALAR > & dynamicExpMax (std::string_view varName) const
 Get the upper dynamic expectation of a given variable prefix (without the time step included, i.e.
const std::vector< std::vector< GUM_SCALAR > > & vertices (const NodeId id) const
 Get the vertice of a given node id.
void saveMarginals (std::string_view path) const
 Saves marginals to file.
void saveExpectations (std::string_view path) const
 Saves expectations to file.
void saveVertices (std::string_view path) const
 Saves vertices to file.
void dynamicExpectations ()
 Compute dynamic expectations.
std::string toString () const
 Print all nodes marginals to standart output.
const std::string getApproximationSchemeMsg ()
 Get approximation scheme state.
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.
Accessors/Modifiers
void setNumberOfThreads (Size nb) override
 sets the number max of threads to be used by the class containing this ThreadNumberManager
Size getNumberOfThreads () const override
 returns the current max number of threads used by the class containing this ThreadNumberManager
bool isGumNumberOfThreadsOverriden () const override
 indicates whether the class containing this ThreadNumberManager set its own number of threads

Public Attributes

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

Protected Member Functions

void setFromConfiguration_ (const std::string &section, bool withMaxTime, bool withVerbosity=true)
 Set the parameters of the scheme from a section of gum::Configuration.
Protected initialization methods
void repetitiveInit_ ()
 Initialize t0_ and t1_ clusters.
void initExpectations_ ()
 Initialize lower and upper expectations before inference, with the lower expectation being initialized on the highest modality and the upper expectation being initialized on the lowest modality.
void initMarginals_ ()
 Initialize lower and upper old marginals and marginals before inference, with the lower marginal being 1 and the upper 0.
void dispatchMarginalsToThreads_ ()
 computes Vector threadRanges_, that assigns some part of marginalMin_ and marginalMax_ to the threads
void initMarginalSets_ ()
 Initialize credal set vertices with empty sets.
Protected algorithms methods
virtual const GUM_SCALAR computeEpsilon_ ()
 Compute approximation scheme epsilon using the old marginals and the new ones.
void updateExpectations_ (const NodeId &id, const std::vector< GUM_SCALAR > &vertex)
 Given a node id and one of it's possible vertex obtained during inference, update this node lower and upper expectations.
void updateCredalSets_ (const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund=false)
 Given a node id and one of it's possible vertex, update it's credal set.
Proptected post-inference methods
void dynamicExpectations_ ()
 Rearrange lower and upper expectations to suit dynamic networks.

Static Protected Member Functions

static Size sizeFromConfiguration_ (const std::string &section, const std::string &key)
 Read a non negative integer key of gum::Configuration.

Protected Attributes

const CredalNet< GUM_SCALAR > * credalNet_
 A pointer to the Credal Net used.
margi oldMarginalMin_
 Old lower marginals used to compute epsilon.
margi oldMarginalMax_
 Old upper marginals used to compute epsilon.
margi marginalMin_
 Lower marginals.
margi marginalMax_
 Upper marginals.
credalSet marginalSets_
 Credal sets vertices, if enabled.
expe expectationMin_
 Lower expectations, if some variables modalities were inserted.
expe expectationMax_
 Upper expectations, if some variables modalities were inserted.
dynExpe dynamicExpMin_
 Lower dynamic expectations.
dynExpe dynamicExpMax_
 Upper dynamic expectations.
dynExpe modal_
 Variables modalities used to compute expectations.
margi evidence_
 Holds observed variables states.
query query_
 Holds the query nodes states.
cluster t0_
 Clusters of nodes used with dynamic networks.
cluster t1_
 Clusters of nodes used with dynamic networks.
bool storeVertices_
 True if credal sets vertices are stored, False otherwise.
bool repetitiveInd_
 True if using repetitive independence ( dynamic network only ), False otherwise.
bool storeBNOpt_
 Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling.
VarMod2BNsMap< GUM_SCALAR > dbnOpt_
 Object used to efficiently store optimal bayes net during inference, for some algorithms.
std::vector< std::pair< NodeId, Idx > > threadRanges_
 the ranges of elements of marginalMin_ and marginalMax_ processed by each thread
int timeSteps_
 The number of time steps of this network (only useful for dynamic networks).
Size threadMinimalNbOps_ {Size(20)}
double current_epsilon_ {-1.}
 Current epsilon.
double last_epsilon_ {-1.}
 Last epsilon value.
double current_rate_ {-1.}
 Current rate.
Size current_step_ {0}
 The current step.
Timer timer_
 The timer.
ApproximationSchemeSTATE current_state_
 The current state.
std::vector< double > history_
 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.

Private Types

using credalSet = NodeProperty< std::vector< std::vector< GUM_SCALAR > > >
using margi = NodeProperty< std::vector< GUM_SCALAR > >
using expe = NodeProperty< GUM_SCALAR >
using dynExpe = typename gum::HashTable< std::string, std::vector< GUM_SCALAR > >
using query = NodeProperty< std::vector< bool > >
using cluster = NodeProperty< std::vector< NodeId > >

Private Member Functions

void stopScheme_ (ApproximationSchemeSTATE new_state)
 Stop the scheme given a new state.

Private Attributes

Size _nb_threads_ {0}
 the max number of threads used by the class

Detailed Description

template<GUM_Numeric GUM_SCALAR>
class gum::credal::InferenceEngine< GUM_SCALAR >

Abstract class template representing a CredalNet inference engine.

Used by credal network inference algorithms such as CNLoopyPropagation (inner multi-threading) or CNMonteCarloSampling (outer multi-threading).

Template Parameters
GUM_SCALARA floating type ( float, double, long double ... ).
Author
Matthieu HOURBRACQ and Pierre-Henri WUILLEMIN(_at_LIP6)

Definition at line 74 of file inferenceEngine.h.

Member Typedef Documentation

◆ cluster

template<GUM_Numeric GUM_SCALAR>
using gum::credal::InferenceEngine< GUM_SCALAR >::cluster = NodeProperty< std::vector< NodeId > >
private

Definition at line 82 of file inferenceEngine.h.

◆ credalSet

template<GUM_Numeric GUM_SCALAR>
using gum::credal::InferenceEngine< GUM_SCALAR >::credalSet = NodeProperty< std::vector< std::vector< GUM_SCALAR > > >
private

Definition at line 75 of file inferenceEngine.h.

◆ dynExpe

template<GUM_Numeric GUM_SCALAR>
using gum::credal::InferenceEngine< GUM_SCALAR >::dynExpe = typename gum::HashTable< std::string, std::vector< GUM_SCALAR > >
private

Definition at line 79 of file inferenceEngine.h.

◆ expe

template<GUM_Numeric GUM_SCALAR>
using gum::credal::InferenceEngine< GUM_SCALAR >::expe = NodeProperty< GUM_SCALAR >
private

Definition at line 77 of file inferenceEngine.h.

◆ margi

template<GUM_Numeric GUM_SCALAR>
using gum::credal::InferenceEngine< GUM_SCALAR >::margi = NodeProperty< std::vector< GUM_SCALAR > >
private

Definition at line 76 of file inferenceEngine.h.

◆ query

template<GUM_Numeric GUM_SCALAR>
using gum::credal::InferenceEngine< GUM_SCALAR >::query = NodeProperty< std::vector< bool > >
private

Definition at line 81 of file inferenceEngine.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 };

Constructor & Destructor Documentation

◆ InferenceEngine()

template<GUM_Numeric GUM_SCALAR>
gum::credal::InferenceEngine< GUM_SCALAR >::InferenceEngine ( const CredalNet< GUM_SCALAR > & credalNet)
explicit

Construtor.

Parameters
credalNetThe credal net to be used with this inference engine.

Definition at line 66 of file inferenceEngine_tpl.h.

66 :
69
70 dbnOpt_.setCNet(credalNet);
71
73
75 }
ApproximationScheme()
Build a scheme whose parameters are read from the configuration.
Abstract class template representing a CredalNet inference engine.
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
const CredalNet< GUM_SCALAR > & credalNet() const
Get this credal network.
void initMarginals_()
Initialize lower and upper old marginals and marginals before inference, with the lower marginal bein...
VarMod2BNsMap< GUM_SCALAR > dbnOpt_
Object used to efficiently store optimal bayes net during inference, for some algorithms.

References gum::ApproximationScheme::ApproximationScheme(), InferenceEngine(), credalNet(), credalNet_, dbnOpt_, and initMarginals_().

Referenced by gum::credal::CNLoopyPropagation< GUM_SCALAR >::CNLoopyPropagation(), InferenceEngine(), gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::MultipleInferenceEngine(), ~InferenceEngine(), and dynamicExpMax().

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

◆ ~InferenceEngine()

template<GUM_Numeric GUM_SCALAR>
gum::credal::InferenceEngine< GUM_SCALAR >::~InferenceEngine ( )
override

Destructor.

Definition at line 78 of file inferenceEngine_tpl.h.

References InferenceEngine().

Here is the call graph for this function:

Member Function Documentation

◆ addEvidence() [1/7]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence ( const Tensor< GUM_SCALAR > & pot)
finalvirtual

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 1199 of file inferenceEngine_tpl.h.

1199 {
1200 const auto id = this->credalNet_->current_bn().idFromName(pot.variable(0).name());
1201 std::vector< GUM_SCALAR > vals(this->credalNet_->current_bn().variable(id).domainSize(), 0);
1203 for (I.setFirst(); !I.end(); I.inc()) {
1204 vals[I.val(0)] = pot[I];
1205 }
1206 addEvidence(id, vals);
1207 }
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id

References addEvidence(), credalNet_, gum::Instantiation::end(), gum::Instantiation::inc(), gum::Instantiation::setFirst(), and gum::Instantiation::val().

Here is the call graph for this function:

◆ addEvidence() [2/7]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence ( NodeId id,
const Idx val )
finalvirtual

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 1166 of file inferenceEngine_tpl.h.

1166 {
1167 std::vector< GUM_SCALAR > vals(this->credalNet_->current_bn().variable(id).domainSize(), 0);
1168 vals[val] = 1;
1169 addEvidence(id, vals);
1170 }

References addEvidence(), and credalNet_.

Referenced by addEvidence(), addEvidence(), addEvidence(), addEvidence(), addEvidence(), addEvidence(), and makeInference().

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

◆ addEvidence() [3/7]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence ( NodeId id,
const std::vector< GUM_SCALAR > & vals )
finalvirtual

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 1156 of file inferenceEngine_tpl.h.

1157 {
1158 evidence_.insert(id, vals);
1159 // forces the computation of the begin iterator to avoid subsequent data races
1160 // @TODO make HashTableConstIterator constructors thread safe
1161 evidence_.begin();
1162 }
margi evidence_
Holds observed variables states.

References evidence_.

◆ addEvidence() [4/7]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence ( NodeId id,
std::string_view label )
finalvirtual

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 1180 of file inferenceEngine_tpl.h.

1180 {
1181 addEvidence(id, this->credalNet_->current_bn().variable(id)[label]);
1182 }

References addEvidence(), and credalNet_.

Here is the call graph for this function:

◆ addEvidence() [5/7]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence ( std::string_view nodeName,
const Idx val )
finalvirtual

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 1174 of file inferenceEngine_tpl.h.

1174 {
1175 addEvidence(this->credalNet_->current_bn().idFromName(nodeName), val);
1176 }

References addEvidence(), and credalNet_.

Here is the call graph for this function:

◆ addEvidence() [6/7]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence ( std::string_view nodeName,
const std::vector< GUM_SCALAR > & vals )
finalvirtual

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 1193 of file inferenceEngine_tpl.h.

1194 {
1195 addEvidence(this->credalNet_->current_bn().idFromName(nodeName), vals);
1196 }

References addEvidence(), and credalNet_.

Here is the call graph for this function:

◆ addEvidence() [7/7]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence ( std::string_view nodeName,
std::string_view label )
finalvirtual

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 1186 of file inferenceEngine_tpl.h.

1187 {
1188 const NodeId id = this->credalNet_->current_bn().idFromName(nodeName);
1189 addEvidence(id, this->credalNet_->current_bn().variable(id)[label]);
1190 }

References addEvidence(), and credalNet_.

Here is the call graph for this function:

◆ computeEpsilon_()

template<GUM_Numeric GUM_SCALAR>
const GUM_SCALAR gum::credal::InferenceEngine< GUM_SCALAR >::computeEpsilon_ ( )
protectedvirtual

Compute approximation scheme epsilon using the old marginals and the new ones.

Highest delta on either lower or upper marginal is epsilon.

Also updates oldMarginals to current marginals.

Returns
Epsilon.

Reimplemented in gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >, and gum::credal::MultipleInferenceEngine< GUM_SCALAR, LazyPropagation< GUM_SCALAR > >.

Definition at line 981 of file inferenceEngine_tpl.h.

981 {
982 // compute the number of threads and prepare for the result
984 ? this->threadRanges_.size() - 1
985 : 1; // no nested multithreading
987
988 // create the function to be executed by the threads
989 auto threadedEps = [this, &tEps](const std::size_t this_thread,
992 auto& this_tEps = tEps[this_thread];
994
995 // below, we will loop over indices i and j of marginalMin_ and
996 // marginalMax_. Index i represents nodes and j allow to parse their
997 // domain. To parse all the domains of all the nodes, we should theorically
998 // use 2 loops. However, here, we will use one loop: we start with node i
999 // and parse its domain with index j. When this is done, we move to the
1000 // next node, and so on. The underlying idea is that, by doing so, we
1001 // need not parse in this function the whole domain of a node: we can start
1002 // the loop at a given value of node i and complete the loop on another
1003 // value of another node. These values are computed in Vector threadRanges_
1004 // by Method dispatchMarginalsToThreads_(), which dispatches the loops
1005 // among threads
1006 auto i = ranges[this_thread].first;
1007 auto j = ranges[this_thread].second;
1008 auto domain_size = this->marginalMax_[i].size();
1009 const auto end_i = ranges[this_thread + 1].first;
1010 auto end_j = ranges[this_thread + 1].second;
1011 const auto marginalMax_size = this->marginalMax_.size();
1012
1013 while ((i < end_i) || (j < end_j)) {
1014 // on min
1016 delta = (delta < 0) ? (-delta) : delta;
1018
1019 // on max
1021 delta = (delta < 0) ? (-delta) : delta;
1023
1026
1027 if (++j == domain_size) {
1028 j = 0;
1029 ++i;
1030 if (i < marginalMax_size) domain_size = this->marginalMax_[i].size();
1031 }
1032 }
1033 };
1034
1035 // launch the threads
1037 nb_threads,
1039 (nb_threads == 1)
1040 ? std::vector< std::pair< NodeId, Idx > >{{0, 0}, {this->marginalMin_.size(), 0}}
1041 : this->threadRanges_);
1042
1043 // aggregate all the results
1044 GUM_SCALAR eps = tEps[0];
1045 for (const auto nb: tEps)
1046 if (eps < nb) eps = nb;
1047
1048 return eps;
1049 }
margi oldMarginalMax_
Old upper marginals used to compute epsilon.
margi marginalMax_
Upper marginals.
margi oldMarginalMin_
Old lower marginals used to compute epsilon.
margi marginalMin_
Lower marginals.
std::vector< std::pair< NodeId, Idx > > threadRanges_
the ranges of elements of marginalMin_ and marginalMax_ processed by each thread
static void execute(std::size_t nb_threads, FUNCTION exec_func, ARGS &&... func_args)
executes a function using several threads
static int nbRunningThreadsExecutors()
indicates how many threadExecutors are currently running

References gum::threadsSTL::ThreadExecutor::execute(), marginalMax_, marginalMin_, gum::threadsSTL::ThreadExecutor::nbRunningThreadsExecutors(), oldMarginalMax_, oldMarginalMin_, and threadRanges_.

Referenced by gum::credal::CNLoopyPropagation< GUM_SCALAR >::calculateEpsilon_().

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 107 of file approximationScheme.cpp.

107 {
108 // For coherence, we fix the time used in the method
109
110 double timer_step = timer_.step();
111
112 if (enabled_max_time_) {
113 if (timer_step > max_time_) {
115 return false;
116 }
117 }
118
119 if (!startOfPeriod()) { return true; }
120
122 GUM_ERROR(
123 OperationNotAllowed,
124 "state of the approximation scheme is not correct : " << messageApproximationScheme());
125 }
126
127 if (verbosity()) { history_.push_back(error); }
128
129 if (enabled_max_iter_) {
130 if (current_step_ >= max_iter_) {
132 return false;
133 }
134 }
135
137 current_epsilon_ = error; // eps rate isEnabled needs it so affectation was
138 // moved from eps isEnabled below
139
140 if (enabled_eps_) {
141 if (current_epsilon_ <= eps_) {
143 return false;
144 }
145 }
146
147 if (last_epsilon_ >= 0.) {
148 if (current_epsilon_ > .0) {
149 // ! current_epsilon_ can be 0. AND epsilon
150 // isEnabled can be disabled !
152 }
153 // limit with current eps ---> 0 is | 1 - ( last_eps / 0 ) | --->
154 // infinity the else means a return false if we isEnabled the rate below,
155 // as we would have returned false if epsilon isEnabled was enabled
156 else {
158 }
159
163 return false;
164 }
165 }
166 }
167
169 if (onProgress.hasListener()) {
171 }
172
173 return true;
174 } else {
175 return false;
176 }
177 }
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.
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition timer_inl.h:72
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
#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, gum::__sig__::BasicSignaler< Args... >::hasListener(), history_, last_epsilon_, gum::IApproximationSchemeConfiguration::Limit, max_iter_, max_time_, gum::IApproximationSchemeConfiguration::messageApproximationScheme(), min_rate_eps_, gum::IApproximationSchemeConfiguration::onProgress, gum::IApproximationSchemeConfiguration::Rate, startOfPeriod(), stateApproximationScheme(), gum::Timer::step(), stopScheme_(), gum::IApproximationSchemeConfiguration::TimeLimit, timer_, and verbosity().

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), gum::MCBNDistance< 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:

◆ credalNet()

template<GUM_Numeric GUM_SCALAR>
const CredalNet< GUM_SCALAR > & gum::credal::InferenceEngine< GUM_SCALAR >::credalNet ( ) const

Get this credal network.

Returns
A constant reference to this CredalNet.

Definition at line 83 of file inferenceEngine_tpl.h.

83 {
84 return *credalNet_;
85 }

References credalNet_.

Referenced by gum::credal::CNLoopyPropagation< GUM_SCALAR >::CNLoopyPropagation(), InferenceEngine(), gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::MultipleInferenceEngine(), and makeInference().

Here is the caller 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 gum::Timer::step(), and timer_.

Referenced by gum::learning::IBNLearner::currentTime(), and gum::learning::IBNLearner::EMCurrentTime().

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

◆ 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(), gum::learning::LocalSearchWithTabuList::LocalSearchWithTabuList(), gum::learning::IBNLearner::disableEpsilon(), gum::learning::IBNLearner::EMdisableEpsilon(), gum::SamplingInference< GUM_SCALAR >::loopApproxInference_(), 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(), gum::learning::GreedyThickThinning::GreedyThickThinning(), gum::learning::LocalSearchWithTabuList::LocalSearchWithTabuList(), gum::learning::IBNLearner::disableMaxIter(), and gum::learning::IBNLearner::EMdisableMaxIter().

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 ApproximationScheme(), gum::learning::GreedyHillClimbing::GreedyHillClimbing(), gum::learning::GreedyThickThinning::GreedyThickThinning(), gum::learning::LocalSearchWithTabuList::LocalSearchWithTabuList(), gum::learning::IBNLearner::disableMaxTime(), and gum::learning::IBNLearner::EMdisableMaxTime().

Here is the caller graph for this function:

◆ disableMinEpsilonRate()

◆ dispatchMarginalsToThreads_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::dispatchMarginalsToThreads_ ( )
protected

computes Vector threadRanges_, that assigns some part of marginalMin_ and marginalMax_ to the threads

Definition at line 1096 of file inferenceEngine_tpl.h.

1096 {
1097 // we compute the number of elements in the 2 loops (over i,j in marginalMin_[i][j])
1098 Size nb_elements = 0;
1099 const auto marginalMin_size = this->marginalMin_.size();
1100 for (const auto& marg_i: this->marginalMin_)
1101 nb_elements += marg_i.second.size();
1102
1103 // distribute evenly the elements among the threads
1106
1107 // the result that we return is a vector of pairs (NodeId, Idx). For thread number i, the
1108 // pair at index i is the beginning of the range that the thread will have to process: this
1109 // is the part of the marginal distribution vector of node NodeId starting at index Idx.
1110 // The pair at index i+1 is the end of this range (not included)
1111 threadRanges_.clear();
1112 threadRanges_.reserve(nb_threads + 1);
1113
1114 // try to balance the number of elements among the threads
1117
1118 NodeId current_node = 0;
1120 Size current_domain_size = this->marginalMin_[0].size();
1122
1123 for (Idx i = Idx(0); i < nb_threads; ++i) {
1124 // compute the end of the threads, assuming that the current node has a domain
1125 // sufficiently large
1127 if (rest_elts != Idx(0)) {
1129 --rest_elts;
1130 }
1131
1132 // if the current node is not sufficient to hold all the elements that
1133 // the current thread should process. So we should add elements of the
1134 // next nodes
1137 ++current_node;
1141 }
1142 }
1143
1144 // now we can store the range if elements
1146
1147 // compute the next begin_node
1149 ++current_node;
1151 }
1152 }
1153 }
Size getNumberOfThreads() const override
returns the current max number of threads used by the class containing this ThreadNumberManager

References gum::ThreadNumberManager::getNumberOfThreads(), and threadRanges_.

Referenced by initMarginals_().

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

◆ dynamicExpectations()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpectations ( )

Compute dynamic expectations.

See also
dynamicExpectations_ Only call this if an algorithm does not call it by itself.

Definition at line 703 of file inferenceEngine_tpl.h.

703 {
705 }
void dynamicExpectations_()
Rearrange lower and upper expectations to suit dynamic networks.

References dynamicExpectations_().

Referenced by makeInference().

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

◆ dynamicExpectations_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpectations_ ( )
protected

Rearrange lower and upper expectations to suit dynamic networks.

Definition at line 708 of file inferenceEngine_tpl.h.

708 {
709 // no modals, no expectations computed during inference
710 if (expectationMin_.empty() || modal_.empty()) return;
711
712 // already called by the algorithm or the user
713 if (dynamicExpMax_.size() > 0 && dynamicExpMin_.size() > 0) return;
714
716
718
719
720 // if non dynamic, directly save expectationMin_ et Max (same but faster)
722
723 for (const auto& elt: expectationMin_) {
725
726 var_name = credalNet_->current_bn().variable(elt.first).name();
727 auto delim = var_name.find_first_of("_");
728 time_step = var_name.substr(delim + 1, var_name.size());
729 var_name = var_name.substr(0, delim);
730
731 // to be sure (don't store not monitored variables' expectations)
732 // although it
733 // should be taken care of before this point
734 if (!modal_.exists(var_name)) continue;
735
736 expectationsMin.getWithDefault(var_name, innerMap())
737 .getWithDefault(atoi(time_step.c_str()), 0)
738 = elt.second; // we iterate with min iterators
739 expectationsMax.getWithDefault(var_name, innerMap())
740 .getWithDefault(atoi(time_step.c_str()), 0) = expectationMax_[elt.first];
741 }
742
743 for (const auto& elt: expectationsMin) {
744 typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
745
746 for (const auto& elt2: elt.second)
747 dynExp[elt2.first] = elt2.second;
748
749 dynamicExpMin_.insert(elt.first, dynExp);
750 }
751
752 for (const auto& elt: expectationsMax) {
753 typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
754
755 for (const auto& elt2: elt.second) {
756 dynExp[elt2.first] = elt2.second;
757 }
758
759 dynamicExpMax_.insert(elt.first, dynExp);
760 }
761 }
dynExpe dynamicExpMin_
Lower dynamic expectations.
dynExpe dynamicExpMax_
Upper dynamic expectations.
expe expectationMax_
Upper expectations, if some variables modalities were inserted.
dynExpe modal_
Variables modalities used to compute expectations.
expe expectationMin_
Lower expectations, if some variables modalities were inserted.

References credalNet_, dynamicExpMax_, dynamicExpMin_, expectationMax_, expectationMin_, and modal_.

Referenced by dynamicExpectations().

Here is the caller graph for this function:

◆ dynamicExpMax()

template<GUM_Numeric GUM_SCALAR>
const std::vector< GUM_SCALAR > & gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpMax ( std::string_view varName) const

Get the upper dynamic expectation of a given variable prefix (without the time step included, i.e.

call with "temp" to get "temp_0", ..., "temp_T").

Parameters
varNameThe variable name prefix which upper expectation we want.
Returns
A constant reference to the variable upper expectation over all time steps.

Definition at line 497 of file inferenceEngine_tpl.h.

497 {
498 std::string errTxt = "const std::vector< GUM_SCALAR > & InferenceEngine< "
499 "GUM_SCALAR >::dynamicExpMax ( const std::string & "
500 "varName ) const : ";
501
502 if (dynamicExpMax_.empty())
503 GUM_ERROR(OperationNotAllowed, errTxt + "_dynamicExpectations() needs to be called before")
504
506 if (!p /*dynamicExpMin_.find(varName) == dynamicExpMin_.end()*/)
507 GUM_ERROR(NotFound, errTxt + "variable name not found : " << varName)
508
509 return *p;
510 }

References InferenceEngine(), and dynamicExpMax().

Referenced by dynamicExpMax(), and makeInference().

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

◆ dynamicExpMin()

template<GUM_Numeric GUM_SCALAR>
const std::vector< GUM_SCALAR > & gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpMin ( std::string_view varName) const

Get the lower dynamic expectation of a given variable prefix (without the time step included, i.e.

call with "temp" to get "temp_0", ..., "temp_T").

Parameters
varNameThe variable name prefix which lower expectation we want.
Returns
A constant reference to the variable lower expectation over all time steps.

Definition at line 480 of file inferenceEngine_tpl.h.

480 {
481 std::string errTxt = "const std::vector< GUM_SCALAR > & InferenceEngine< "
482 "GUM_SCALAR >::dynamicExpMin ( const std::string & "
483 "varName ) const : ";
484
485 if (dynamicExpMin_.empty())
486 GUM_ERROR(OperationNotAllowed, errTxt + "_dynamicExpectations() needs to be called before")
487
489 if (!p /*dynamicExpMin_.find(varName) == dynamicExpMin_.end()*/)
490 GUM_ERROR(NotFound, errTxt + "variable name not found : " << varName)
491
492 return *p;
493 }

References dynamicExpMin_, and GUM_ERROR.

Referenced by makeInference().

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

Referenced by gum::learning::IBNLearner::EMenableEpsilon(), gum::learning::IBNLearner::enableEpsilon(), and gum::SamplingInference< GUM_SCALAR >::loopApproxInference_().

Here is the caller graph for this function:

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

Referenced by gum::learning::IBNLearner::EMenableMaxIter(), and gum::learning::IBNLearner::enableMaxIter().

Here is the caller graph for this function:

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

Referenced by gum::learning::IBNLearner::EMenableMaxTime(), and gum::learning::IBNLearner::enableMaxTime().

Here is the caller graph for this function:

◆ 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(), gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), gum::MCBNDistance< GUM_SCALAR >::computeKL_(), gum::learning::IBNLearner::EMenableMinEpsilonRate(), gum::learning::IBNLearner::enableMinEpsilonRate(), and gum::SamplingInference< GUM_SCALAR >::loopApproxInference_().

Here is the caller graph for this function:

◆ epsilon()

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

◆ eraseAllEvidence()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::eraseAllEvidence ( )
virtual

removes all the evidence entered into the network

Reimplemented in gum::credal::CNLoopyPropagation< GUM_SCALAR >, gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >, and gum::credal::MultipleInferenceEngine< GUM_SCALAR, LazyPropagation< GUM_SCALAR > >.

Definition at line 88 of file inferenceEngine_tpl.h.

88 {
89 evidence_.clear();
90 query_.clear();
91 /*
92 marginalMin_.clear();
93 marginalMax_.clear();
94 oldMarginalMin_.clear();
95 oldMarginalMax_.clear();
96 */
98 /*
99 expectationMin_.clear();
100 expectationMax_.clear();
101 */
103
104 // marginalSets_.clear();
106
107 dynamicExpMin_.clear();
108 dynamicExpMax_.clear();
109
110 //_modal.clear();
111
112 //_t0.clear();
113 //_t1.clear();
114 }
void initExpectations_()
Initialize lower and upper expectations before inference, with the lower expectation being initialize...
void initMarginalSets_()
Initialize credal set vertices with empty sets.
query query_
Holds the query nodes states.

References dynamicExpMax_, dynamicExpMin_, evidence_, initExpectations_(), initMarginals_(), initMarginalSets_(), and query_.

Referenced by gum::credal::CNLoopyPropagation< GUM_SCALAR >::eraseAllEvidence(), gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::eraseAllEvidence(), and makeInference().

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

◆ expectationMax() [1/2]

template<GUM_Numeric GUM_SCALAR>
const GUM_SCALAR & gum::credal::InferenceEngine< GUM_SCALAR >::expectationMax ( const NodeId id) const

Get the upper expectation of a given node id.

Parameters
idThe node id which upper expectation we want.
Returns
A constant reference to this node upper expectation.

Definition at line 474 of file inferenceEngine_tpl.h.

474 {
475 return expectationMax_[id];
476 }

References expectationMax_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ expectationMax() [2/2]

template<GUM_Numeric GUM_SCALAR>
const GUM_SCALAR & gum::credal::InferenceEngine< GUM_SCALAR >::expectationMax ( std::string_view varName) const

Get the upper expectation of a given variable name.

Parameters
varNameThe variable name which upper expectation we want.
Returns
A constant reference to this variable upper expectation.

Definition at line 464 of file inferenceEngine_tpl.h.

464 {
465 return expectationMax_[credalNet_->current_bn().idFromName(varName)];
466 }

References credalNet_, and expectationMax_.

◆ expectationMin() [1/2]

template<GUM_Numeric GUM_SCALAR>
const GUM_SCALAR & gum::credal::InferenceEngine< GUM_SCALAR >::expectationMin ( const NodeId id) const

Get the lower expectation of a given node id.

Parameters
idThe node id which lower expectation we want.
Returns
A constant reference to this node lower expectation.

Definition at line 469 of file inferenceEngine_tpl.h.

469 {
470 return expectationMin_[id];
471 }

References expectationMin_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ expectationMin() [2/2]

template<GUM_Numeric GUM_SCALAR>
const GUM_SCALAR & gum::credal::InferenceEngine< GUM_SCALAR >::expectationMin ( std::string_view varName) const

Get the lower expectation of a given variable name.

Parameters
varNameThe variable name which lower expectation we want.
Returns
A constant reference to this variable lower expectation.

Definition at line 458 of file inferenceEngine_tpl.h.

458 {
459 return expectationMin_[credalNet_->current_bn().idFromName(varName)];
460 }

References credalNet_, and expectationMin_.

◆ getApproximationSchemeMsg()

template<GUM_Numeric GUM_SCALAR>
const std::string gum::credal::InferenceEngine< GUM_SCALAR >::getApproximationSchemeMsg ( )

Get approximation scheme state.

Returns
A constant string about approximation scheme state.

Definition at line 1210 of file inferenceEngine_tpl.h.

1210 {
1211 return this->messageApproximationScheme();
1212 }

References gum::IApproximationSchemeConfiguration::messageApproximationScheme().

Referenced by makeInference().

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

◆ getNumberOfThreads()

◆ getT0Cluster()

template<GUM_Numeric GUM_SCALAR>
const NodeProperty< std::vector< NodeId > > & gum::credal::InferenceEngine< GUM_SCALAR >::getT0Cluster ( ) const

Get the t0_ cluster.

Returns
A constant reference to the t0_ cluster.

Definition at line 970 of file inferenceEngine_tpl.h.

970 {
971 return t0_;
972 }
cluster t0_
Clusters of nodes used with dynamic networks.

References t0_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ getT1Cluster()

template<GUM_Numeric GUM_SCALAR>
const NodeProperty< std::vector< NodeId > > & gum::credal::InferenceEngine< GUM_SCALAR >::getT1Cluster ( ) const

Get the t1_ cluster.

Returns
A constant reference to the t1_ cluster.

Definition at line 976 of file inferenceEngine_tpl.h.

976 {
977 return t1_;
978 }
cluster t1_
Clusters of nodes used with dynamic networks.

References t1_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ getVarMod2BNsMap()

template<GUM_Numeric GUM_SCALAR>
VarMod2BNsMap< GUM_SCALAR > * gum::credal::InferenceEngine< GUM_SCALAR >::getVarMod2BNsMap ( )

Get optimum IBayesNet.

Returns
A pointer to the optimal net object.

Definition at line 165 of file inferenceEngine_tpl.h.

165 {
166 return &dbnOpt_;
167 }

References dbnOpt_.

Referenced by makeInference().

Here is the caller 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, history_, stateApproximationScheme(), gum::IApproximationSchemeConfiguration::Undefined, and verbosity().

Referenced by gum::learning::IBNLearner::EMHistory(), and gum::learning::IBNLearner::history().

Here is the call graph for this function:
Here is the caller 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 }
void reset()
Reset the timer.
Definition timer_inl.h:53

References gum::IApproximationSchemeConfiguration::Continue, current_epsilon_, current_rate_, current_state_, current_step_, history_, gum::Timer::reset(), and timer_.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), gum::MCBNDistance< 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 >::makeInference(), and gum::SamplingInference< GUM_SCALAR >::onStateChanged_().

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

◆ initExpectations_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::initExpectations_ ( )
protected

Initialize lower and upper expectations before inference, with the lower expectation being initialized on the highest modality and the upper expectation being initialized on the lowest modality.

Definition at line 681 of file inferenceEngine_tpl.h.

681 {
682 expectationMin_.clear();
683 expectationMax_.clear();
684
685 if (modal_.empty()) return;
686
687 for (auto node: credalNet_->current_bn().nodes()) {
689
690 var_name = credalNet_->current_bn().variable(node).name();
691 auto delim = var_name.find_first_of("_");
692 var_name = var_name.substr(0, delim);
693
694 auto p_modal = modal_.tryGet(var_name);
695 if (!p_modal) continue;
696
697 expectationMin_.insert(node, p_modal->back());
698 expectationMax_.insert(node, p_modal->front());
699 }
700 }

References credalNet_, expectationMax_, expectationMin_, and modal_.

Referenced by eraseAllEvidence().

Here is the caller graph for this function:

◆ initMarginals_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::initMarginals_ ( )
protected

Initialize lower and upper old marginals and marginals before inference, with the lower marginal being 1 and the upper 0.

Definition at line 645 of file inferenceEngine_tpl.h.

645 {
646 marginalMin_.clear();
647 marginalMax_.clear();
648 oldMarginalMin_.clear();
649 oldMarginalMax_.clear();
650
651 for (auto node: credalNet_->current_bn().nodes()) {
652 auto dSize = credalNet_->current_bn().variable(node).domainSize();
655
658 }
659
660 // now that we know the sizes of marginalMin_ and marginalMax_, we can
661 // dispatch their processes to the threads
663 }
void dispatchMarginalsToThreads_()
computes Vector threadRanges_, that assigns some part of marginalMin_ and marginalMax_ to the threads

References credalNet_, dispatchMarginalsToThreads_(), marginalMax_, marginalMin_, oldMarginalMax_, and oldMarginalMin_.

Referenced by InferenceEngine(), and eraseAllEvidence().

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

◆ initMarginalSets_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::initMarginalSets_ ( )
protected

Initialize credal set vertices with empty sets.

Definition at line 666 of file inferenceEngine_tpl.h.

666 {
667 marginalSets_.clear();
668
669 if (!storeVertices_) return;
670
671 for (auto node: credalNet_->current_bn().nodes())
673 }
bool storeVertices_
True if credal sets vertices are stored, False otherwise.
credalSet marginalSets_
Credal sets vertices, if enabled.

References credalNet_, marginalSets_, and storeVertices_.

Referenced by eraseAllEvidence(), and storeVertices().

Here is the caller graph for this function:

◆ insertEvidence() [1/2]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::insertEvidence ( const NodeProperty< std::vector< GUM_SCALAR > > & evidence)

Insert evidence from Property.

Parameters
evidenceThe on nodes Property containing likelihoods.

Definition at line 269 of file inferenceEngine_tpl.h.

270 {
271 if (!evidence_.empty()) evidence_.clear();
272
273 // use cbegin() to get const_iterator when available in aGrUM hashtables
274 for (const auto& elt: evidence) {
275 if (!credalNet_->current_bn().exists(elt.first)) continue;
276
277 evidence_.insert(elt.first, elt.second);
278 }
279
280 // forces the computation of the begin iterator to avoid subsequent data races
281 // @TODO make HashTableConstIterator constructors thread safe
282 evidence_.begin();
283 }

References credalNet_, and evidence_.

◆ insertEvidence() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::insertEvidence ( const std::map< std::string, std::vector< GUM_SCALAR > > & eviMap)

Insert evidence from map.

Parameters
eviMapThe map variable name - likelihood.

Definition at line 248 of file inferenceEngine_tpl.h.

249 {
250 if (!evidence_.empty()) evidence_.clear();
251
252 for (auto it = eviMap.cbegin(), theEnd = eviMap.cend(); it != theEnd; ++it) {
253 if (!credalNet_->current_bn().exists(it->first)) continue;
254
255 NodeId id = credalNet_->current_bn().idFromName(it->first);
256
257 evidence_.insert(id, it->second);
258 }
259
260 // forces the computation of the begin iterator to avoid subsequent data races
261 // @TODO make HashTableConstIterator constructors thread safe
262 evidence_.begin();
263 }

References evidence_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ insertEvidenceFile()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::insertEvidenceFile ( std::string_view path)
virtual

Insert evidence from file.

Parameters
pathThe path to the evidence file.

Reimplemented in gum::credal::CNLoopyPropagation< GUM_SCALAR >, and gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >.

Definition at line 286 of file inferenceEngine_tpl.h.

286 {
288
289 if (!evi_stream.good()) {
291 "void InferenceEngine< GUM_SCALAR "
292 ">::insertEvidence(const std::string & path) : could not "
293 "open input file : "
294 << path);
295 }
296
297 if (!evidence_.empty()) evidence_.clear();
298
300 char * cstr, *p;
301
302 while (evi_stream.good() && std::strcmp(line.c_str(), "[EVIDENCE]") != 0) {
304 }
305
306 while (evi_stream.good()) {
308
309 if (std::strcmp(line.c_str(), "[QUERY]") == 0) break;
310
311 if (line.size() == 0) continue;
312
313 cstr = new char[line.size() + 1];
314 strcpy(cstr, line.c_str());
315
316 p = strtok(cstr, " ");
317 tmp = p;
318
319 // if user input is wrong
320 NodeId node = -1;
321
322 if (!credalNet_->current_bn().exists(tmp)) continue;
323 node = credalNet_->current_bn().idFromName(tmp);
324
326 p = strtok(nullptr, " ");
327
328 while (p != nullptr) {
329 values.push_back(GUM_SCALAR(atof(p)));
330 p = strtok(nullptr, " ");
331 } // end of : line
332
333 evidence_.insert(node, values);
334
335 delete[] p;
336 delete[] cstr;
337 } // end of : file
338
339 evi_stream.close();
340
341 // forces the computation of the begin iterator to avoid subsequent data races
342 // @TODO make HashTableConstIterator constructors thread safe
343 evidence_.begin();
344 }

References GUM_ERROR.

Referenced by gum::credal::CNLoopyPropagation< GUM_SCALAR >::insertEvidenceFile(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::insertEvidenceFile(), and makeInference().

Here is the caller graph for this function:

◆ insertModals()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::insertModals ( const std::map< std::string, std::vector< GUM_SCALAR > > & modals)

Insert variables modalities from map to compute expectations.

Parameters
modalsThe map variable name - modalities.

Definition at line 217 of file inferenceEngine_tpl.h.

218 {
219 if (!modal_.empty()) modal_.clear();
220
221 for (auto it = modals.cbegin(), theEnd = modals.cend(); it != theEnd; ++it) {
222 if (!credalNet_->current_bn().exists(it->first)) continue;
223
224 NodeId id = credalNet_->current_bn().idFromName(it->first);
225
226 // check that modals are net compatible
227 auto dSize = credalNet_->current_bn().variable(id).domainSize();
228
229 if (dSize != it->second.size()) continue;
230
231 // GUM_ERROR(OperationNotAllowed, "void InferenceEngine< GUM_SCALAR
232 // >::insertModals( const std::map< std::string, std::vector< GUM_SCALAR
233 // > >
234 // &modals) : modalities does not respect variable cardinality : " <<
235 // credalNet_->current_bn().variable( id ).name() << " : " << dSize << "
236 // != "
237 // << it->second.size());
238
239 modal_.insert(it->first, it->second); //[ it->first ] = it->second;
240 }
241
242 //_modal = modals;
243
245 }

References credalNet_, and modal_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ insertModalsFile()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::insertModalsFile ( std::string_view path)

Insert variables modalities from file to compute expectations.

Parameters
pathThe path to the modalities file.

Definition at line 170 of file inferenceEngine_tpl.h.

170 {
172
173 if (!mod_stream.good()) {
175 "void InferenceEngine< GUM_SCALAR "
176 ">::insertModals(const std::string & path) : "
177 "could not open input file : "
178 << path);
179 }
180
181 if (!modal_.empty()) modal_.clear();
182
184 char * cstr, *p;
185
186 while (mod_stream.good()) {
188
189 if (line.size() == 0) continue;
190
191 cstr = new char[line.size() + 1];
192 strcpy(cstr, line.c_str());
193
194 p = strtok(cstr, " ");
195 tmp = p;
196
198 p = strtok(nullptr, " ");
199
200 while (p != nullptr) {
201 values.push_back(GUM_SCALAR(atof(p)));
202 p = strtok(nullptr, " ");
203 } // end of : line
204
205 modal_.insert(tmp, values); //[tmp] = values;
206
207 delete[] p;
208 delete[] cstr;
209 } // end of : file
210
211 mod_stream.close();
212
214 }

References GUM_ERROR, and modal_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ insertQuery()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::insertQuery ( const NodeProperty< std::vector< bool > > & query)

Insert query variables and states from Property.

Parameters
queryThe on nodes Property containing queried variables states.

Definition at line 347 of file inferenceEngine_tpl.h.

348 {
349 if (!query_.empty()) query_.clear();
350
351 for (const auto& elt: query) {
352 if (!credalNet_->current_bn().exists(elt.first)) continue;
353
354 query_.insert(elt.first, elt.second);
355 }
356 }
NodeProperty< std::vector< bool > > query

Referenced by makeInference().

Here is the caller graph for this function:

◆ insertQueryFile()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::insertQueryFile ( std::string_view path)

Insert query variables states from file.

Parameters
pathThe path to the query file.

Definition at line 359 of file inferenceEngine_tpl.h.

359 {
361
362 if (!evi_stream.good()) {
364 "void InferenceEngine< GUM_SCALAR >::insertQuery(const "
365 "std::string & path) : could not open input file : "
366 << path);
367 }
368
369 if (!query_.empty()) query_.clear();
370
372 char * cstr, *p;
373
374 while (evi_stream.good() && std::strcmp(line.c_str(), "[QUERY]") != 0) {
376 }
377
378 while (evi_stream.good()) {
380
381 if (std::strcmp(line.c_str(), "[EVIDENCE]") == 0) break;
382
383 if (line.size() == 0) continue;
384
385 cstr = new char[line.size() + 1];
386 strcpy(cstr, line.c_str());
387
388 p = strtok(cstr, " ");
389 tmp = p;
390
391 // if user input is wrong
392 NodeId node = -1;
393
394 if (!credalNet_->current_bn().exists(tmp)) continue;
395 node = credalNet_->current_bn().idFromName(tmp);
396
397 auto dSize = credalNet_->current_bn().variable(node).domainSize();
398
399 p = strtok(nullptr, " ");
400
401 if (p == nullptr) {
402 query_.insert(node, std::vector< bool >(dSize, true));
403 } else {
405
406 while (p != nullptr) {
407 if ((Size)atoi(p) >= dSize)
409 "void InferenceEngine< GUM_SCALAR "
410 ">::insertQuery(const std::string & path) : "
411 "query modality is higher or equal to "
412 "cardinality");
413
414 values[atoi(p)] = true;
415 p = strtok(nullptr, " ");
416 } // end of : line
417
418 query_.insert(node, values);
419 }
420
421 delete[] p;
422 delete[] cstr;
423 } // end of : file
424
425 evi_stream.close();
426 }

References GUM_ERROR.

Referenced by makeInference().

Here is the caller graph for this function:

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

Referenced by gum::learning::IBNLearner::EMisEnabledEpsilon(), gum::learning::IBNLearner::isEnabledEpsilon(), and gum::SamplingInference< GUM_SCALAR >::loopApproxInference_().

Here is the caller graph for this function:

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

Referenced by gum::learning::IBNLearner::EMisEnabledMaxIter(), and gum::learning::IBNLearner::isEnabledMaxIter().

Here is the caller graph for this function:

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

Referenced by gum::learning::IBNLearner::EMisEnabledMaxTime(), and gum::learning::IBNLearner::isEnabledMaxTime().

Here is the caller graph for this function:

◆ 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_(), gum::MCBNDistance< GUM_SCALAR >::computeKL_(), gum::learning::IBNLearner::EMisEnabledMinEpsilonRate(), gum::learning::IBNLearner::isEnabledMinEpsilonRate(), and gum::SamplingInference< GUM_SCALAR >::loopApproxInference_().

Here is the caller graph for this function:

◆ isGumNumberOfThreadsOverriden()

bool gum::ThreadNumberManager::isGumNumberOfThreadsOverriden ( ) const
nodiscardoverridevirtualinherited

indicates whether the class containing this ThreadNumberManager set its own number of threads

Implements gum::IThreadNumberManager.

Referenced by gum::learning::IBNLearner::createParamEstimator_(), gum::learning::IBNLearner::createScore_(), gum::ScheduledInference::operator=(), and gum::ScheduledInference::operator=().

Here is the caller graph for this function:

◆ makeInference()

◆ marginalMax() [1/2]

template<GUM_Numeric GUM_SCALAR>
gum::Tensor< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax ( const NodeId id) const

Get the upper marginals of a given node id.

Parameters
idThe node id which upper marginals we want.
Returns
A constant reference to this node upper marginals.

Definition at line 449 of file inferenceEngine_tpl.h.

449 {
451 res.add(credalNet_->current_bn().variable(id));
452 res.fillWith(marginalMax_[id]);
453 return res;
454 }

Referenced by makeInference(), and marginalMax().

Here is the caller graph for this function:

◆ marginalMax() [2/2]

template<GUM_Numeric GUM_SCALAR>
Tensor< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax ( std::string_view varName) const

Get the upper marginals of a given variable name.

Parameters
varNameThe variable name which upper marginals we want.
Returns
A constant reference to this variable upper marginals.

Definition at line 436 of file inferenceEngine_tpl.h.

436 {
437 return marginalMax(credalNet_->current_bn().idFromName(varName));
438 }
Tensor< GUM_SCALAR > marginalMax(const NodeId id) const
Get the upper marginals of a given node id.

References credalNet_, and marginalMax().

Here is the call graph for this function:

◆ marginalMin() [1/2]

template<GUM_Numeric GUM_SCALAR>
gum::Tensor< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin ( const NodeId id) const

Get the lower marginals of a given node id.

Parameters
idThe node id which lower marginals we want.
Returns
A constant reference to this node lower marginals.

Definition at line 441 of file inferenceEngine_tpl.h.

441 {
443 res.add(credalNet_->current_bn().variable(id));
444 res.fillWith(marginalMin_[id]);
445 return res;
446 }

References credalNet_.

Referenced by makeInference(), and marginalMin().

Here is the caller graph for this function:

◆ marginalMin() [2/2]

template<GUM_Numeric GUM_SCALAR>
Tensor< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin ( std::string_view varName) const

Get the lower marginals of a given variable name.

Parameters
varNameThe variable name which lower marginals we want.
Returns
A constant reference to this variable lower marginals.

Definition at line 430 of file inferenceEngine_tpl.h.

430 {
431 return marginalMin(credalNet_->current_bn().idFromName(varName));
432 }
Tensor< GUM_SCALAR > marginalMin(const NodeId id) const
Get the lower marginals of a given node id.

References credalNet_, and marginalMin().

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

Referenced by gum::learning::IBNLearner::EMMaxIter(), and gum::learning::IBNLearner::maxIter().

Here is the caller graph for this function:

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

Referenced by gum::learning::IBNLearner::EMMaxTime(), and gum::learning::IBNLearner::maxTime().

Here is the caller graph for this function:

◆ 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::learning::IBNLearner::EMStateMessage(), and gum::credal::InferenceEngine< GUM_SCALAR >::getApproximationSchemeMsg().

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

Referenced by gum::learning::IBNLearner::EMMinEpsilonRate(), and gum::learning::IBNLearner::minEpsilonRate().

Here is the caller graph for this function:

◆ 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 }

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), gum::MCBNDistance< GUM_SCALAR >::computeKL_(), gum::learning::IBNLearner::EMnbrIterations(), and gum::learning::IBNLearner::nbrIterations().

Here is the caller 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_.

Referenced by gum::learning::IBNLearner::EMPeriodSize(), and gum::learning::IBNLearner::periodSize().

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 }
Size burn_in_
Number of iterations before checking stopping criteria.

◆ repetitiveInd()

template<GUM_Numeric GUM_SCALAR>
bool gum::credal::InferenceEngine< GUM_SCALAR >::repetitiveInd ( ) const

Get the current independence status.

Returns
True if repetitive, False otherwise.

Definition at line 144 of file inferenceEngine_tpl.h.

144 {
145 return repetitiveInd_;
146 }
bool repetitiveInd_
True if using repetitive independence ( dynamic network only ), False otherwise.

References repetitiveInd_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ repetitiveInit_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::repetitiveInit_ ( )
protected

Initialize t0_ and t1_ clusters.

Definition at line 764 of file inferenceEngine_tpl.h.

764 {
765 timeSteps_ = 0;
766 t0_.clear();
767 t1_.clear();
768
769 // t = 0 vars belongs to t0_ as keys
770 for (auto node: credalNet_->current_bn().internalDag().nodes()) {
771 std::string var_name = credalNet_->current_bn().variable(node).name();
772 auto delim = var_name.find_first_of("_");
773
774 if (delim > var_name.size()) {
776 "void InferenceEngine< GUM_SCALAR "
777 ">::repetitiveInit_() : the network does not "
778 "appear to be dynamic");
779 }
780
781 std::string time_step = var_name.substr(delim + 1, 1);
782
783 if (time_step.compare("0") == 0) t0_.insert(node, std::vector< NodeId >());
784 }
785
786 // t = 1 vars belongs to either t0_ as member value or t1_ as keys
787 for (const auto& node: credalNet_->current_bn().internalDag().nodes()) {
788 std::string var_name = credalNet_->current_bn().variable(node).name();
789 auto delim = var_name.find_first_of("_");
790 std::string time_step = var_name.substr(delim + 1, var_name.size());
791 var_name = var_name.substr(0, delim);
792 delim = time_step.find_first_of("_");
793 time_step = time_step.substr(0, delim);
794
795 if (time_step.compare("1") == 0) {
796 bool found = false;
797
798 for (const auto& elt: t0_) {
799 std::string var_0_name = credalNet_->current_bn().variable(elt.first).name();
800 delim = var_0_name.find_first_of("_");
801 var_0_name = var_0_name.substr(0, delim);
802
803 if (var_name.compare(var_0_name) == 0) {
804 const Tensor< GUM_SCALAR >* tensor(&credalNet_->current_bn().cpt(node));
805 const Tensor< GUM_SCALAR >* tensor2(&credalNet_->current_bn().cpt(elt.first));
806
807 if (tensor->domainSize() == tensor2->domainSize()) t0_[elt.first].push_back(node);
808 else t1_.insert(node, std::vector< NodeId >());
809
810 found = true;
811 break;
812 }
813 }
814
815 if (!found) { t1_.insert(node, std::vector< NodeId >()); }
816 }
817 }
818
819 // t > 1 vars belongs to either t0_ or t1_ as member value
820 // remember timeSteps_
821 for (auto node: credalNet_->current_bn().internalDag().nodes()) {
822 std::string var_name = credalNet_->current_bn().variable(node).name();
823 auto delim = var_name.find_first_of("_");
824 std::string time_step = var_name.substr(delim + 1, var_name.size());
825 var_name = var_name.substr(0, delim);
826 delim = time_step.find_first_of("_");
827 time_step = time_step.substr(0, delim);
828
829 if (time_step.compare("0") != 0 && time_step.compare("1") != 0) {
830 // keep max time_step
831 if (atoi(time_step.c_str()) > timeSteps_) timeSteps_ = atoi(time_step.c_str());
832
834 bool found = false;
835
836 for (const auto& elt: t0_) {
837 std::string var_0_name = credalNet_->current_bn().variable(elt.first).name();
838 delim = var_0_name.find_first_of("_");
839 var_0_name = var_0_name.substr(0, delim);
840
841 if (var_name.compare(var_0_name) == 0) {
842 const Tensor< GUM_SCALAR >* tensor(&credalNet_->current_bn().cpt(node));
843 const Tensor< GUM_SCALAR >* tensor2(&credalNet_->current_bn().cpt(elt.first));
844
845 if (tensor->domainSize() == tensor2->domainSize()) {
846 t0_[elt.first].push_back(node);
847 found = true;
848 break;
849 }
850 }
851 }
852
853 if (!found) {
854 for (const auto& elt: t1_) {
855 std::string var_0_name = credalNet_->current_bn().variable(elt.first).name();
856 auto delim = var_0_name.find_first_of("_");
857 var_0_name = var_0_name.substr(0, delim);
858
859 if (var_name.compare(var_0_name) == 0) {
860 const Tensor< GUM_SCALAR >* tensor(&credalNet_->current_bn().cpt(node));
861 const Tensor< GUM_SCALAR >* tensor2(&credalNet_->current_bn().cpt(elt.first));
862
863 if (tensor->domainSize() == tensor2->domainSize()) {
864 t1_[elt.first].push_back(node);
865 break;
866 }
867 }
868 }
869 }
870 }
871 }
872 }
int timeSteps_
The number of time steps of this network (only useful for dynamic networks).

References gum::HashTable< Key, Val >::clear(), credalNet_, GUM_ERROR, t0_, t1_, and timeSteps_.

Referenced by setRepetitiveInd().

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

◆ saveExpectations()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::saveExpectations ( std::string_view path) const

Saves expectations to file.

Parameters
pathThe path to the file to be used.

Definition at line 542 of file inferenceEngine_tpl.h.

542 {
543 if (dynamicExpMin_.empty()) //_modal.empty())
544 return;
545
546 // else not here, to keep the const (natural with a saving process)
547 // else if(dynamicExpMin_.empty() || dynamicExpMax_.empty())
548 //_dynamicExpectations(); // works with or without a dynamic network
549
551
552 if (!m_stream.good()) {
554 "void InferenceEngine< GUM_SCALAR "
555 ">::saveExpectations(const std::string & path) : could "
556 "not open output file : "
557 << path);
558 }
559
560 for (const auto& elt: dynamicExpMin_) {
561 m_stream << elt.first; // it->first;
562
563 // iterates over a vector
564 for (const auto& elt2: elt.second) {
565 m_stream << " " << elt2;
566 }
567
569 }
570
571 for (const auto& elt: dynamicExpMax_) {
572 m_stream << elt.first;
573
574 // iterates over a vector
575 for (const auto& elt2: elt.second) {
576 m_stream << " " << elt2;
577 }
578
580 }
581
582 m_stream.close();
583 }

Referenced by makeInference().

Here is the caller graph for this function:

◆ saveMarginals()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::saveMarginals ( std::string_view path) const

Saves marginals to file.

Parameters
pathThe path to the file to be used.

Definition at line 519 of file inferenceEngine_tpl.h.

519 {
521
522 if (!m_stream.good()) {
524 "void InferenceEngine< GUM_SCALAR >::saveMarginals(const "
525 "std::string & path) const : could not open output file "
526 ": " << path);
527 }
528
529 for (const auto& elt: marginalMin_) {
530 Size esize = Size(elt.second.size());
531
532 for (Size mod = 0; mod < esize; mod++) {
533 m_stream << credalNet_->current_bn().variable(elt.first).name() << " " << mod << " "
534 << (elt.second)[mod] << " " << marginalMax_[elt.first][mod] << std::endl;
535 }
536 }
537
538 m_stream.close();
539 }

Referenced by makeInference().

Here is the caller graph for this function:

◆ saveVertices()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::saveVertices ( std::string_view path) const

Saves vertices to file.

Parameters
pathThe path to the file to be used.

Definition at line 614 of file inferenceEngine_tpl.h.

614 {
616
617 if (!m_stream.good()) {
619 "void InferenceEngine< GUM_SCALAR >::saveVertices(const "
620 "std::string & path) : could not open outpul file : "
621 << path);
622 }
623
624 for (const auto& elt: marginalSets_) {
625 m_stream << credalNet_->current_bn().variable(elt.first).name() << std::endl;
626
627 for (const auto& elt2: elt.second) {
628 m_stream << "[";
629 bool first = true;
630
631 for (const auto& elt3: elt2) {
632 if (!first) { m_stream << ","; }
633 first = false;
634 m_stream << elt3;
635 }
636
637 m_stream << "]\n";
638 }
639 }
640
641 m_stream.close();
642 }

References credalNet_, GUM_ERROR, and marginalSets_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ 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::GibbsSampling< GUM_SCALAR >::GibbsSampling(), gum::learning::GreedyHillClimbing::GreedyHillClimbing(), gum::learning::GreedyThickThinning::GreedyThickThinning(), gum::learning::EMApproximationScheme::setEpsilon(), gum::learning::IBNLearner::setEpsilon(), and setFromConfiguration_().

Here is the caller graph for this function:

◆ setFromConfiguration_()

void gum::ApproximationScheme::setFromConfiguration_ ( const std::string & section,
bool withMaxTime,
bool withVerbosity = true )
protectedinherited

Set the parameters of the scheme from a section of gum::Configuration.

The keys epsilon, minEpsilonRate, maxIter and periodSize of the section are read (and maxTime if withMaxTime is true, verbosity if withVerbosity is true, burnIn if the section has this key) and applied through the corresponding setters, which enable the matching stopping criteria and check the values.

Parameters
sectionThe name of the section of the configuration.
withMaxTimeIf true, the key maxTime is read and the timeout is enabled.
withVerbosityIf true, the key verbosity is read ; otherwise the verbosity is left unchanged.
Exceptions
OutOfBoundsRaised if a value of the section is not valid for its setter.

Definition at line 90 of file approximationScheme.cpp.

92 {
93 const auto& conf = Configuration::instance();
94
95 setEpsilon(conf.typed< double >(section, "epsilon"));
96 setMinEpsilonRate(conf.typed< double >(section, "minEpsilonRate"));
97 setMaxIter(sizeFromConfiguration_(section, "maxIter"));
98 setPeriodSize(sizeFromConfiguration_(section, "periodSize"));
99 if (withVerbosity) setVerbosity(conf.typed< bool >(section, "verbosity"));
100 if (withMaxTime) setMaxTime(conf.typed< double >(section, "maxTime"));
101 // only some sections have a burn-in (approximation, gibbs, gibbsKL)
102 if (conf.has(section, "burnIn")) burn_in_ = sizeFromConfiguration_(section, "burnIn");
103 }
static Size sizeFromConfiguration_(const std::string &section, const std::string &key)
Read a non negative integer key of gum::Configuration.
void setMaxIter(Size max) override
Stopping criterion on number of iterations.
void setMaxTime(double timeout) override
Stopping criterion on timeout.
void setMinEpsilonRate(double rate) override
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
void setPeriodSize(Size p) override
How many samples between two stopping is enable.
void setVerbosity(bool v) override
Set the verbosity on (true) or off (false).
void setEpsilon(double eps) override
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
static Configuration & instance()
The global configuration.

References burn_in_, gum::Configuration::instance(), setEpsilon(), setMaxIter(), setMaxTime(), setMinEpsilonRate(), setPeriodSize(), setVerbosity(), and sizeFromConfiguration_().

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

Here is the call graph for this function:
Here is the caller 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::learning::IBNLearner::EMsetMaxIter(), setFromConfiguration_(), and gum::learning::IBNLearner::setMaxIter().

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::learning::IBNLearner::EMsetMaxTime(), setFromConfiguration_(), and gum::learning::IBNLearner::setMaxTime().

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::GibbsSampling< GUM_SCALAR >::GibbsSampling(), setFromConfiguration_(), gum::learning::EMApproximationScheme::setMinEpsilonRate(), and gum::learning::IBNLearner::setMinEpsilonRate().

Here is the caller graph for this function:

◆ setNumberOfThreads()

void gum::ThreadNumberManager::setNumberOfThreads ( Size nb)
overridevirtualinherited

sets the number max of threads to be used by the class containing this ThreadNumberManager

Parameters
nbthe number of threads to be used. If this number is set to 0, then it is defaulted to aGrUM's number of threads

Implements gum::IThreadNumberManager.

Referenced by gum::learning::IBNLearner::setNumberOfThreads(), and gum::ScheduledInference::setNumberOfThreads().

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, and period_size_.

Referenced by gum::learning::IBNLearner::EMsetPeriodSize(), setFromConfiguration_(), and gum::learning::IBNLearner::setPeriodSize().

Here is the caller graph for this function:

◆ setRepetitiveInd()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::setRepetitiveInd ( const bool repetitive)
Parameters
repetitiveTrue if repetitive independence is to be used, false otherwise. Only useful with dynamic networks.

Definition at line 135 of file inferenceEngine_tpl.h.

135 {
138
139 // do not compute clusters more than once
141 }
void repetitiveInit_()
Initialize t0_ and t1_ clusters.

References repetitiveInd_, and repetitiveInit_().

Referenced by makeInference().

Here is the call graph for this function:
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::learning::IBNLearner::EMsetVerbosity(), setFromConfiguration_(), and gum::learning::IBNLearner::setVerbosity().

Here is the caller graph for this function:

◆ sizeFromConfiguration_()

Size gum::ApproximationScheme::sizeFromConfiguration_ ( const std::string & section,
const std::string & key )
staticprotectedinherited

Read a non negative integer key of gum::Configuration.

Parameters
sectionThe name of the section of the configuration.
keyThe name of the key of the section.
Returns
The value of the key.
Exceptions
OutOfBoundsRaised if the value is negative.

Definition at line 79 of file approximationScheme.cpp.

80 {
81 const auto value = Configuration::instance().typed< std::int64_t >(section, key);
82 if (value < 0) {
83 GUM_ERROR(OutOfBounds,
84 "The key " << section << "." << key
85 << " of the configuration must not be negative.")
86 }
87 return static_cast< Size >(value);
88 }
T typed(std::string_view section, std::string_view key) const
Value of section.key converted according to its declared type.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

References GUM_ERROR, gum::Configuration::instance(), and gum::Configuration::typed().

Referenced by gum::GibbsSampling< GUM_SCALAR >::GibbsSampling(), and setFromConfiguration_().

Here is the call graph for this function:
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:

◆ 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(), gum::learning::IBNLearner::EMState(), gum::learning::IBNLearner::EMStateApproximationScheme(), history(), and gum::learning::IBNLearner::stateApproximationScheme().

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.

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

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
240 }
Signaler< std::string_view > onStop
Criteria messageApproximationScheme.
double pause()
Pause the timer and return the delta (.
Definition timer_inl.h:75
#define GUM_EMIT1(signal, arg1)
Definition signaler.h:289

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

Referenced by continueApproximationScheme().

Here is the caller graph for this function:

◆ storeBNOpt() [1/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::credal::InferenceEngine< GUM_SCALAR >::storeBNOpt ( ) const
Returns
True if optimal bayes net are stored for each variable and each modality, False otherwise.

Definition at line 160 of file inferenceEngine_tpl.h.

160 {
161 return storeBNOpt_;
162 }
bool storeBNOpt_
Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling.

References storeBNOpt_.

◆ storeBNOpt() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::storeBNOpt ( const bool value)
Parameters
valueTrue if optimal Bayesian networks are to be stored for each variable and each modality.

Definition at line 123 of file inferenceEngine_tpl.h.

123 {
125 }

References storeBNOpt_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ storeVertices() [1/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::credal::InferenceEngine< GUM_SCALAR >::storeVertices ( ) const

Get the number of iterations without changes used to stop some algorithms.

Returns
the number of iterations. int iterStop () const;
True if vertice are stored, False otherwise.

Definition at line 155 of file inferenceEngine_tpl.h.

155 {
156 return storeVertices_;
157 }

References storeVertices_.

◆ storeVertices() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::storeVertices ( const bool value)
Parameters
valueTrue if vertices are to be stored, false otherwise.

Definition at line 128 of file inferenceEngine_tpl.h.

128 {
130
132 }

References initMarginalSets_(), and storeVertices_.

Referenced by makeInference().

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

◆ toString()

template<GUM_Numeric GUM_SCALAR>
std::string gum::credal::InferenceEngine< GUM_SCALAR >::toString ( ) const

Print all nodes marginals to standart output.

Definition at line 586 of file inferenceEngine_tpl.h.

586 {
588 output << std::endl;
589
590 // use cbegin() when available
591 for (const auto& elt: marginalMin_) {
592 Size esize = Size(elt.second.size());
593
594 for (Size mod = 0; mod < esize; mod++) {
595 output << "P(" << credalNet_->current_bn().variable(elt.first).name() << "=" << mod
596 << "|e) = [ ";
597 output << marginalMin_[elt.first][mod] << ", " << marginalMax_[elt.first][mod] << " ]";
598
599 if (!query_.empty()) {
600 if (auto p_query = query_.tryGet(elt.first); p_query && (*p_query)[mod])
601 output << " QUERY";
602 }
603
604 output << std::endl;
605 }
606
607 output << std::endl;
608 }
609
610 return output.str();
611 }

Referenced by makeInference().

Here is the caller graph for this function:

◆ updateApproximationScheme()

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

◆ updateCredalSets_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::updateCredalSets_ ( const NodeId & id,
const std::vector< GUM_SCALAR > & vertex,
const bool & elimRedund = false )
inlineprotected

Given a node id and one of it's possible vertex, update it's credal set.

To maximise efficiency, don't pass a vertex we know is inside the polytope (i.e. not at an extreme value for any modality)

Parameters
idThe id of the node to be updated
vertexA (tensor) vertex of the node credal set
elimRedundremove redundant vertex (inside a facet)

Definition at line 897 of file inferenceEngine_tpl.h.

899 {
901 auto dsize = vertex.size();
902
903 bool eq = true;
904 const double epsilon = config().epsilonStandard();
905
906 for (auto it = nodeCredalSet.cbegin(), itEnd = nodeCredalSet.cend(); it != itEnd; ++it) {
907 eq = true;
908
909 for (Size i = 0; i < dsize; i++) {
910 if (std::fabs(vertex[i] - (*it)[i]) > epsilon) {
911 eq = false;
912 break;
913 }
914 }
915
916 if (eq) break;
917 }
918
919 if (!eq || nodeCredalSet.size() == 0) {
920 nodeCredalSet.push_back(vertex);
921 } else return;
922
923 // because of next lambda return condition
924 if (nodeCredalSet.size() == 1) return;
925
926 // check that the point and all previously added ones are not inside the
927 // actual
928 // polytope
929 auto itEnd = std::remove_if(
930 nodeCredalSet.begin(),
931 nodeCredalSet.end(),
932 [&](const std::vector< GUM_SCALAR >& v) -> bool {
933 for (auto jt = v.cbegin(),
934 jtEnd = v.cend(),
935 minIt = marginalMin_[id].cbegin(),
936 minItEnd = marginalMin_[id].cend(),
937 maxIt = marginalMax_[id].cbegin(),
938 maxItEnd = marginalMax_[id].cend();
939 jt != jtEnd && minIt != minItEnd && maxIt != maxItEnd;
940 ++jt, ++minIt, ++maxIt) {
941 if ((std::fabs(*jt - *minIt) < epsilon || std::fabs(*jt - *maxIt) < epsilon)
942 && std::fabs(*minIt - *maxIt) > epsilon)
943 return false;
944 }
945 return true;
946 });
947
948 nodeCredalSet.erase(itEnd, nodeCredalSet.end());
949
950 // we need at least 2 points to make a convex combination
951 if (!elimRedund || nodeCredalSet.size() <= 2) return;
952
953 // there may be points not inside the polytope but on one of it's facet,
954 // meaning it's still a convex combination of vertices of this facet. Here
955 // we
956 // need lrs.
958 lrsWrapper.setUpV((unsigned int)dsize, (unsigned int)(nodeCredalSet.size()));
959
960 for (const auto& vtx: nodeCredalSet)
962
963 lrsWrapper.elimRedundVrep();
964
965 marginalSets_[id] = lrsWrapper.getOutput();
966 }
double epsilon() const override
Returns the value of epsilon.

References gum::config(), gum::ApproximationScheme::epsilon(), gum::Configuration::epsilonStandard(), and marginalSets_.

Referenced by gum::credal::CNLoopyPropagation< GUM_SCALAR >::computeExpectations_(), and gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::verticesFusion_().

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

◆ updateExpectations_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::updateExpectations_ ( const NodeId & id,
const std::vector< GUM_SCALAR > & vertex )
inlineprotected

Given a node id and one of it's possible vertex obtained during inference, update this node lower and upper expectations.

Parameters
idThe id of the node to be updated
vertexA (tensor) vertex of the node credal set

Definition at line 875 of file inferenceEngine_tpl.h.

877 {
878 std::string var_name = credalNet_->current_bn().variable(id).name();
879 auto delim = var_name.find_first_of("_");
880
881 var_name = var_name.substr(0, delim);
882
883 if (auto p_modal = modal_.tryGet(var_name)) {
884 GUM_SCALAR exp = 0;
885 auto vsize = vertex.size();
886
887 for (Size mod = 0; mod < vsize; mod++)
888 exp += vertex[mod] * (*p_modal)[mod];
889
891
893 }
894 }

References credalNet_, expectationMax_, expectationMin_, and modal_.

Referenced by gum::credal::CNLoopyPropagation< GUM_SCALAR >::computeExpectations_().

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_; }

Referenced by ApproximationScheme(), gum::learning::EMApproximationScheme::EMApproximationScheme(), continueApproximationScheme(), gum::learning::IBNLearner::EMVerbosity(), history(), and gum::learning::IBNLearner::verbosity().

Here is the caller graph for this function:

◆ vertices()

template<GUM_Numeric GUM_SCALAR>
const std::vector< std::vector< GUM_SCALAR > > & gum::credal::InferenceEngine< GUM_SCALAR >::vertices ( const NodeId id) const

Get the vertice of a given node id.

Parameters
idThe node id which vertice we want.
Returns
A constant reference to this node vertice.

Definition at line 514 of file inferenceEngine_tpl.h.

514 {
515 return marginalSets_[id];
516 }

Referenced by gum::credal::CNLoopyPropagation< GUM_SCALAR >::computeExpectations_(), and makeInference().

Here is the caller graph for this function:

Member Data Documentation

◆ _nb_threads_

Size gum::ThreadNumberManager::_nb_threads_ {0}
privateinherited

the max number of threads used by the class

Definition at line 126 of file threadNumberManager.h.

◆ burn_in_

Size gum::ApproximationScheme::burn_in_
protectedinherited

◆ credalNet_

◆ current_epsilon_

double gum::ApproximationScheme::current_epsilon_ {-1.}
protectedinherited

Current epsilon.

Definition at line 419 of file approximationScheme.h.

Referenced by continueApproximationScheme(), and initApproximationScheme().

◆ current_rate_

double gum::ApproximationScheme::current_rate_ {-1.}
protectedinherited

Current rate.

Definition at line 425 of file approximationScheme.h.

Referenced by continueApproximationScheme(), and initApproximationScheme().

◆ current_state_

ApproximationSchemeSTATE gum::ApproximationScheme::current_state_
protectedinherited

◆ current_step_

◆ dbnOpt_

template<GUM_Numeric GUM_SCALAR>
VarMod2BNsMap< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::dbnOpt_
protected

Object used to efficiently store optimal bayes net during inference, for some algorithms.

Definition at line 160 of file inferenceEngine.h.

Referenced by InferenceEngine(), getVarMod2BNsMap(), and gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::optFusion_().

◆ dynamicExpMax_

template<GUM_Numeric GUM_SCALAR>
dynExpe gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpMax_
protected

Upper dynamic expectations.

If the network if not dynamic it's content is the same as expectationMax_.

Definition at line 113 of file inferenceEngine.h.

Referenced by dynamicExpectations_(), and eraseAllEvidence().

◆ dynamicExpMin_

template<GUM_Numeric GUM_SCALAR>
dynExpe gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpMin_
protected

Lower dynamic expectations.

If the network is not dynamic it's content is the same as expectationMin_.

Definition at line 110 of file inferenceEngine.h.

Referenced by dynamicExpectations_(), dynamicExpMin(), and eraseAllEvidence().

◆ enabled_eps_

bool gum::ApproximationScheme::enabled_eps_
protectedinherited

If true, the threshold convergence is enabled.

Definition at line 443 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 461 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 455 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 449 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 440 of file approximationScheme.h.

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

◆ evidence_

◆ expectationMax_

template<GUM_Numeric GUM_SCALAR>
expe gum::credal::InferenceEngine< GUM_SCALAR >::expectationMax_
protected

◆ expectationMin_

template<GUM_Numeric GUM_SCALAR>
expe gum::credal::InferenceEngine< GUM_SCALAR >::expectationMin_
protected

◆ history_

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

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

Definition at line 437 of file approximationScheme.h.

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

◆ last_epsilon_

double gum::ApproximationScheme::last_epsilon_ {-1.}
protectedinherited

Last epsilon value.

Definition at line 422 of file approximationScheme.h.

Referenced by continueApproximationScheme().

◆ marginalMax_

◆ marginalMin_

◆ marginalSets_

template<GUM_Numeric GUM_SCALAR>
credalSet gum::credal::InferenceEngine< GUM_SCALAR >::marginalSets_
protected

◆ max_iter_

Size gum::ApproximationScheme::max_iter_
protectedinherited

The maximum iterations.

Definition at line 458 of file approximationScheme.h.

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

◆ max_time_

double gum::ApproximationScheme::max_time_
protectedinherited

The timeout.

Definition at line 452 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 446 of file approximationScheme.h.

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

◆ modal_

◆ oldMarginalMax_

◆ oldMarginalMin_

◆ 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 467 of file approximationScheme.h.

Referenced by ApproximationScheme(), periodSize(), and setPeriodSize().

◆ query_

template<GUM_Numeric GUM_SCALAR>
query gum::credal::InferenceEngine< GUM_SCALAR >::query_
protected

Holds the query nodes states.

Definition at line 121 of file inferenceEngine.h.

Referenced by eraseAllEvidence().

◆ repetitiveInd_

template<GUM_Numeric GUM_SCALAR>
bool gum::credal::InferenceEngine< GUM_SCALAR >::repetitiveInd_
protected

◆ storeBNOpt_

◆ storeVertices_

◆ t0_

template<GUM_Numeric GUM_SCALAR>
cluster gum::credal::InferenceEngine< GUM_SCALAR >::t0_
protected

Clusters of nodes used with dynamic networks.

Any node key in t0_ is present at \( t=0 \) and any node belonging to the node set of this key share the same CPT than the key. Used for sampling with repetitive independence.

Definition at line 129 of file inferenceEngine.h.

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_mcThreadDataCopy_(), getT0Cluster(), and repetitiveInit_().

◆ t1_

template<GUM_Numeric GUM_SCALAR>
cluster gum::credal::InferenceEngine< GUM_SCALAR >::t1_
protected

Clusters of nodes used with dynamic networks.

Any node key in t1_ is present at \( t=1 \) and any node belonging to the node set of this key share the same CPT than the key. Used for sampling with repetitive independence.

Definition at line 136 of file inferenceEngine.h.

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_mcThreadDataCopy_(), getT1Cluster(), and repetitiveInit_().

◆ threadMinimalNbOps_

template<GUM_Numeric GUM_SCALAR>
Size gum::credal::InferenceEngine< GUM_SCALAR >::threadMinimalNbOps_ {Size(20)}
protected

◆ threadRanges_

template<GUM_Numeric GUM_SCALAR>
std::vector< std::pair< NodeId, Idx > > gum::credal::InferenceEngine< GUM_SCALAR >::threadRanges_
protected

the ranges of elements of marginalMin_ and marginalMax_ processed by each thread

these ranges are stored into a vector of pairs (NodeId, Idx). For thread number i, the pair at index i is the beginning of the range that the thread will have to process: this is the part of the marginal distribution vector of node NodeId starting at index Idx. The pair at index i+1 is the end of this range (not included).

Warning
the size of threadRanges_ is the number of threads + 1.

Definition at line 172 of file inferenceEngine.h.

Referenced by computeEpsilon_(), gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::computeEpsilon_(), dispatchMarginalsToThreads_(), and gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::updateMarginals_().

◆ timer_

◆ timeSteps_

template<GUM_Numeric GUM_SCALAR>
int gum::credal::InferenceEngine< GUM_SCALAR >::timeSteps_
protected

The number of time steps of this network (only useful for dynamic networks).

Deprecated

Definition at line 179 of file inferenceEngine.h.

Referenced by repetitiveInit_().

◆ verbosity_

bool gum::ApproximationScheme::verbosity_
protectedinherited

If true, verbosity is enabled.

Definition at line 470 of file approximationScheme.h.

Referenced by ApproximationScheme(), and setVerbosity().


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