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

Class template representing a CredalNet inference engine using one or more IBayesNet inference engines such as LazyPropagation. More...

#include <multipleInferenceEngine.h>

Inheritance diagram for gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >:
[legend]
Collaboration diagram for gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >:
[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)
Constructors / Destructors
 MultipleInferenceEngine (const CredalNet< GUM_SCALAR > &credalNet)
 Constructor.
 ~MultipleInferenceEngine () override
 Destructor.
Post-inference methods
void eraseAllEvidence () override
 Erase all inference related data to perform another one.
Pure virtual methods
void makeInference () override=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)
bool storeVertices () const
 Get the number of iterations without changes used to stop some algorithms.
void storeBNOpt (const bool value)
bool storeBNOpt () const
bool repetitiveInd () const
 Get the current independence status.
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 > marginalMin (std::string_view varName) const
 Get the lower marginals of a given variable name.
Tensor< GUM_SCALAR > marginalMax (const NodeId id) const
 Get the upper marginals of a given node id.
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 & expectationMin (std::string_view varName) const
 Get the lower expectation of a given variable name.
const GUM_SCALAR & expectationMax (const NodeId id) const
 Get the upper expectation of a given node id.
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

Fusion of threads optimal IBayesNet.

void initThreadsData_ (const Size &num_threads, const bool _storeVertices_, const bool _storeBNOpt_)
 Initialize threads data.
Protected algorithms methods
bool updateThread_ (Size this_thread, const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund=false)
 Update thread information (marginals, expectations, IBayesNet, vertices) for a given node id.
void updateMarginals_ ()
 Fusion of threads marginals.
const GUM_SCALAR computeEpsilon_ () override
 Compute epsilon and update old marginals.
void updateOldMarginals_ ()
 Update old marginals (from current marginals).
Proptected post-inference methods
void optFusion_ ()
 Fusion of threads optimal IBayesNet.
void expFusion_ ()
 Fusion of threads expectations.
void verticesFusion_ ()
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
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

_margis_ l_marginalMin_
 Threads lower marginals, one per thread.
_margis_ l_marginalMax_
 Threads upper marginals, one per thread.
_expes_ l_expectationMin_
 Threads lower expectations, one per thread.
_expes_ l_expectationMax_
 Threads upper expectations, one per thread.
_modals_ l_modal_
 Threads modalities.
_credalSets_ l_marginalSets_
 Threads vertices.
_margis_ l_evidence_
 Threads evidence.
_clusters_ l_clusters_
 Threads clusters.
std::vector< _bnet_ * > workingSet_
 Threads IBayesNet.
std::vector< List< const Tensor< GUM_SCALAR > * > * > workingSetE_
 Threads evidence.
std::vector< BNInferenceEngine * > l_inferenceEngine_
 Threads BNInferenceEngine.
std::vector< VarMod2BNsMap< GUM_SCALAR > * > l_optimalNet_
 Threads optimal IBayesNet.
std::vector< std::mt19937 > generators_
 the generators used for computing random values
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 _infE_ = InferenceEngine< GUM_SCALAR >
 To easily access InferenceEngine< GUM_SCALAR > methods.
using _cluster_ = NodeProperty< std::vector< NodeId > >
using _credalSet_ = NodeProperty< std::vector< std::vector< GUM_SCALAR > > >
using _margi_ = NodeProperty< std::vector< GUM_SCALAR > >
using _expe_ = NodeProperty< GUM_SCALAR >
using _bnet_ = IBayesNet< GUM_SCALAR >
using _margis_ = std::vector< _margi_ >
using _expes_ = std::vector< _expe_ >
using _credalSets_ = std::vector< _credalSet_ >
using _clusters_ = std::vector< std::vector< _cluster_ > >
using _modals_ = std::vector< HashTable< std::string, std::vector< GUM_SCALAR > > >
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 _updateThreadCredalSets_ (Size this_thread, const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund)
 Ask for redundancy elimination of a node credal set of a calling thread.
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 BNInferenceEngine>
class gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >

Class template representing a CredalNet inference engine using one or more IBayesNet inference engines such as LazyPropagation.

Extends InferenceEngine< GUM_SCALAR >. Used for outer multi-threading such as CNMonteCarloSampling.

Template Parameters
GUM_SCALARA floating type ( float, double, long double ... ).
BNInferenceEngineA IBayesNet inference engine such as LazyPropagation.
Author
Matthieu HOURBRACQ and Pierre-Henri WUILLEMIN(_at_LIP6)

Definition at line 74 of file multipleInferenceEngine.h.

Member Typedef Documentation

◆ _bnet_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_bnet_ = IBayesNet< GUM_SCALAR >
private

Definition at line 84 of file multipleInferenceEngine.h.

◆ _cluster_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_cluster_ = NodeProperty< std::vector< NodeId > >
private

Definition at line 79 of file multipleInferenceEngine.h.

◆ _clusters_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_clusters_ = std::vector< std::vector< _cluster_ > >
private

Definition at line 88 of file multipleInferenceEngine.h.

◆ _credalSet_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_credalSet_ = NodeProperty< std::vector< std::vector< GUM_SCALAR > > >
private

Definition at line 80 of file multipleInferenceEngine.h.

◆ _credalSets_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_credalSets_ = std::vector< _credalSet_ >
private

Definition at line 87 of file multipleInferenceEngine.h.

◆ _expe_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_expe_ = NodeProperty< GUM_SCALAR >
private

Definition at line 82 of file multipleInferenceEngine.h.

◆ _expes_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_expes_ = std::vector< _expe_ >
private

Definition at line 86 of file multipleInferenceEngine.h.

◆ _infE_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_infE_ = InferenceEngine< GUM_SCALAR >
private

To easily access InferenceEngine< GUM_SCALAR > methods.

Definition at line 77 of file multipleInferenceEngine.h.

◆ _margi_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_margi_ = NodeProperty< std::vector< GUM_SCALAR > >
private

Definition at line 81 of file multipleInferenceEngine.h.

◆ _margis_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_margis_ = std::vector< _margi_ >
private

Definition at line 85 of file multipleInferenceEngine.h.

◆ _modals_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
using gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_modals_ = std::vector< HashTable< std::string, std::vector< GUM_SCALAR > > >
private

Definition at line 90 of file multipleInferenceEngine.h.

◆ cluster

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

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

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

Definition at line 79 of file inferenceEngine.h.

◆ expe

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

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

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

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

◆ MultipleInferenceEngine()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::MultipleInferenceEngine ( const CredalNet< GUM_SCALAR > & credalNet)
explicit

Constructor.

Parameters
credalNetThe CredalNet to be used.

Definition at line 52 of file multipleInferenceEngine_tpl.h.

53 :
56 }
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.
const CredalNet< GUM_SCALAR > & credalNet() const
Get this credal network.
Class template representing a CredalNet inference engine using one or more IBayesNet inference engine...
MultipleInferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Constructor.

References gum::credal::InferenceEngine< GUM_SCALAR >::InferenceEngine(), MultipleInferenceEngine(), and gum::credal::InferenceEngine< GUM_SCALAR >::credalNet().

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

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

◆ ~MultipleInferenceEngine()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::~MultipleInferenceEngine ( )
override

Destructor.

Definition at line 59 of file multipleInferenceEngine_tpl.h.

References MultipleInferenceEngine().

Here is the call graph for this function:

Member Function Documentation

◆ _updateThreadCredalSets_()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
void gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::_updateThreadCredalSets_ ( Size this_thread,
const NodeId & id,
const std::vector< GUM_SCALAR > & vertex,
const bool & elimRedund )
inlineprivate

Ask for redundancy elimination of a node credal set of a calling thread.

Called by updateThread_ if vertices are stored.

Parameters
this_threadthe id of the thread executing this method
idA constant reference to the node id whose credal set is to be checked for redundancy.
vertexThe vertex to add to the credal set.
elimRedundtrue if redundancy elimination is to be performed, false otherwise and by default.

Definition at line 219 of file multipleInferenceEngine_tpl.h.

223 {
225 Size dsize = Size(vertex.size());
226
227 bool eq = true;
228 const double epsilon = config().epsilonStandard();
229
230 for (auto it = nodeCredalSet.cbegin(), itEnd = nodeCredalSet.cend(); it != itEnd; ++it) {
231 eq = true;
232
233 for (Size i = 0; i < dsize; i++) {
234 if (std::fabs(vertex[i] - (*it)[i]) > epsilon) {
235 eq = false;
236 break;
237 }
238 }
239
240 if (eq) break;
241 }
242
243 if (!eq || nodeCredalSet.size() == 0) {
244 nodeCredalSet.push_back(vertex);
245 return;
246 } else return;
247
250 if (nodeCredalSet.size() == 1) return;
251
252 // check that the point and all previously added ones are not inside the
253 // actual
254 // polytope
255 auto itEnd = std::remove_if(
256 nodeCredalSet.begin(),
257 nodeCredalSet.end(),
258 [&](const std::vector< GUM_SCALAR >& v) -> bool {
259 for (auto jt = v.cbegin(),
260 jtEnd = v.cend(),
261 minIt = l_marginalMin_[tId][id].cbegin(),
262 minItEnd = l_marginalMin_[tId][id].cend(),
263 maxIt = l_marginalMax_[tId][id].cbegin(),
264 maxItEnd = l_marginalMax_[tId][id].cend();
265 jt != jtEnd && minIt != minItEnd && maxIt != maxItEnd;
266 ++jt, ++minIt, ++maxIt) {
267 if ((std::fabs(*jt - *minIt) < epsilon || std::fabs(*jt - *maxIt) < epsilon)
268 && std::fabs(*minIt - *maxIt) > epsilon)
269 return false;
270 }
271 return true;
272 });
273
274 nodeCredalSet.erase(itEnd, nodeCredalSet.end());
275
276 // we need at least 2 points to make a convex combination
277 if (!elimRedund || nodeCredalSet.size() <= 2) return;
278
279 // there may be points not inside the polytope but on one of it's facet,
280 // meaning it's still a convex combination of vertices of this facet. Here
281 // we need lrs.
282 Size setSize = Size(nodeCredalSet.size());
283
285 lrsWrapper.setUpV(dsize, setSize);
286
287 for (const auto& vtx: nodeCredalSet)
288 lrsWrapper.fillV(vtx);
289
290 lrsWrapper.elimRedundVrep();
291
292 l_marginalSets_[tId][id] = lrsWrapper.getOutput();
293 }
double epsilon() const override
Returns the value of epsilon.
_credalSets_ l_marginalSets_
Threads vertices.

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

Here is the call graph for this function:

◆ addEvidence() [1/7]

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

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

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

Definition at line 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 }
Abstract class template representing a CredalNet inference engine.
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
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 )
finalvirtualinherited

adds a new hard evidence on node id

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif id already has an evidence

Definition at line 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 )
finalvirtualinherited

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

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif id already has an evidence
FatalErrorif vals=[0,0,...,0]
InvalidArgumentif the size of vals is different from the domain size of node id

Definition at line 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 )
finalvirtualinherited

adds a new hard evidence on node id

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif id already has an evidence

Definition at line 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 )
finalvirtualinherited

adds a new hard evidence on node named nodeName

Exceptions
UndefinedElementif nodeName does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif nodeName already has an evidence

Definition at line 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 )
finalvirtualinherited

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

Exceptions
UndefinedElementif id does not belong to the Bayesian network
InvalidArgumentif nodeName already has an evidence
FatalErrorif vals=[0,0,...,0]
InvalidArgumentif the size of vals is different from the domain size of node nodeName

Definition at line 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 )
finalvirtualinherited

adds a new hard evidence on node named nodeName

Exceptions
UndefinedElementif nodeName does not belong to the Bayesian network
InvalidArgumentif val is not a value for id
InvalidArgumentif nodeName already has an evidence

Definition at line 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, class BNInferenceEngine>
const GUM_SCALAR gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::computeEpsilon_ ( )
inlineoverrideprotectedvirtual

Compute epsilon and update old marginals.

Returns
Epsilon.

Reimplemented from gum::credal::InferenceEngine< GUM_SCALAR >.

Definition at line 371 of file multipleInferenceEngine_tpl.h.

371 {
372 // compute the number of threads (avoid nested threads)
374 ? this->threadRanges_.size() - 1
375 : 1; // no nested multithreading
376
378
379 // create the function to be executed by the threads
380 auto threadedExec = [this, &tEps](const std::size_t this_thread,
383 auto& this_tEps = tEps[this_thread];
384 GUM_SCALAR delta = 0;
385
386 auto i = this->threadRanges_[this_thread].first;
387 auto j = this->threadRanges_[this_thread].second;
388 auto domain_size = this->marginalMax_[i].size();
389 const auto end_i = this->threadRanges_[this_thread + 1].first;
390 auto end_j = this->threadRanges_[this_thread + 1].second;
391 const auto marginalMax_size = this->marginalMax_.size();
392
393 while ((i < end_i) || (j < end_j)) {
394 // on min
395 delta = this->marginalMin_[i][j] - this->oldMarginalMin_[i][j];
396 delta = (delta < 0) ? (-delta) : delta;
398
399 // on max
400 delta = this->marginalMax_[i][j] - this->oldMarginalMax_[i][j];
401 delta = (delta < 0) ? (-delta) : delta;
403
404 this->oldMarginalMin_[i][j] = this->marginalMin_[i][j];
405 this->oldMarginalMax_[i][j] = this->marginalMax_[i][j];
406
407 if (++j == domain_size) {
408 j = 0;
409 ++i;
410 if (i < marginalMax_size) domain_size = this->marginalMax_[i].size();
411 }
412 }
413 };
414
415 // launch the threads
419 (nb_threads == 1)
420 ? std::vector< std::pair< NodeId, Idx > >{{0, 0}, {this->marginalMin_.size(), 0}}
421 : this->threadRanges_);
422
423 // aggregate all the results
424 GUM_SCALAR eps = tEps[0];
425 for (const auto nb: tEps)
426 if (eps < nb) eps = nb;
427
428 return eps;
429 }
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 computeEpsilon_(), gum::threadsSTL::ThreadExecutor::execute(), gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin_, gum::threadsSTL::ThreadExecutor::nbRunningThreadsExecutors(), gum::credal::InferenceEngine< GUM_SCALAR >::oldMarginalMax_, gum::credal::InferenceEngine< GUM_SCALAR >::oldMarginalMin_, and gum::credal::InferenceEngine< GUM_SCALAR >::threadRanges_.

Referenced by computeEpsilon_().

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
inherited

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_ ( )
protectedinherited

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 ( )
inherited

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_ ( )
protectedinherited

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
inherited

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
inherited

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, class BNInferenceEngine>
void gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::eraseAllEvidence ( )
overridevirtual

Erase all inference related data to perform another one.

You need to insert evidence again if needed but modalities are kept. You can insert new ones by using the appropriate method which will delete the old ones.

Reimplemented from gum::credal::InferenceEngine< GUM_SCALAR >.

Definition at line 784 of file multipleInferenceEngine_tpl.h.

784 {
786 Size tsize = Size(workingSet_.size());
787
788 // delete pointers
789 for (Size bn = 0; bn < tsize; bn++) {
791
792 if (workingSet_[bn] != nullptr) delete workingSet_[bn];
793
795 if (l_inferenceEngine_[bn] != nullptr) delete l_optimalNet_[bn];
796
797 if (this->workingSetE_[bn] != nullptr) {
798 for (const auto ev: *workingSetE_[bn])
799 delete ev;
800
801 delete workingSetE_[bn];
802 }
803
804 if (l_inferenceEngine_[bn] != nullptr) delete l_inferenceEngine_[bn];
805 }
806
807 // this is important, those will be resized with the correct number of
808 // threads.
809
810 workingSet_.clear();
811 workingSetE_.clear();
812 l_inferenceEngine_.clear();
813 l_optimalNet_.clear();
814
815 l_marginalMin_.clear();
816 l_marginalMax_.clear();
817 l_expectationMin_.clear();
818 l_expectationMax_.clear();
819 l_modal_.clear();
820 l_marginalSets_.clear();
821 l_evidence_.clear();
822 l_clusters_.clear();
823 }
bool storeBNOpt_
Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling.
bool storeVertices_
True if credal sets vertices are stored, False otherwise.
virtual void eraseAllEvidence()
removes all the evidence entered into the network
_margis_ l_marginalMin_
Threads lower marginals, one per thread.
_expes_ l_expectationMax_
Threads upper expectations, one per thread.
_expes_ l_expectationMin_
Threads lower expectations, one per thread.
std::vector< _bnet_ * > workingSet_
Threads IBayesNet.
std::vector< BNInferenceEngine * > l_inferenceEngine_
Threads BNInferenceEngine.
std::vector< VarMod2BNsMap< GUM_SCALAR > * > l_optimalNet_
Threads optimal IBayesNet.
_margis_ l_marginalMax_
Threads upper marginals, one per thread.
std::vector< List< const Tensor< GUM_SCALAR > * > * > workingSetE_
Threads evidence.

References gum::credal::InferenceEngine< GUM_SCALAR >::eraseAllEvidence(), eraseAllEvidence(), l_clusters_, l_evidence_, l_expectationMax_, l_expectationMin_, l_inferenceEngine_, l_marginalMax_, l_marginalMin_, l_marginalSets_, l_modal_, l_optimalNet_, gum::credal::InferenceEngine< GUM_SCALAR >::storeBNOpt_, gum::credal::InferenceEngine< GUM_SCALAR >::storeVertices_, workingSet_, and workingSetE_.

Referenced by eraseAllEvidence().

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
inherited

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
inherited

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
inherited

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
inherited

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

◆ expFusion_()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
void gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::expFusion_ ( )
protected

Fusion of threads expectations.

Definition at line 578 of file multipleInferenceEngine_tpl.h.

578 {
579 // don't create threads if there are no modalities to compute expectations
580 if (this->modal_.empty()) return;
581
582 // compute the max number of threads to use (avoid nested threads)
585 : 1; // no nested multithreading
586
587 // we can compute expectations from vertices of the final credal set
589 // create the function to be executed by the threads
590 auto threadedExec = [this](const std::size_t this_thread,
595 std::string var_name = workingSet_[work_index]->variable(i).name();
596 auto delim = var_name.find_first_of("_");
597 var_name = var_name.substr(0, delim);
598
599 if (!l_modal_[work_index].exists(var_name)) continue;
600
601 for (const auto& vertex: _infE_::marginalSets_[i]) {
602 GUM_SCALAR exp = 0;
603 Size vsize = Size(vertex.size());
604
605 for (Size mod = 0; mod < vsize; mod++)
607
609
611 }
612 }
613 };
614
615 const Size working_size = workingSet_.size();
617 if (!this->l_modal_[work_index].empty()) {
618 // compute the ranges over which the threads will work
619 const auto nsize = workingSet_[work_index]->size();
621 const auto ranges
624 }
625 }
626
627 return;
628 }
629
630 // create the function to be executed by the threads
631 auto threadedExec = [this](const std::size_t this_thread,
636 std::string var_name = workingSet_[work_index]->variable(i).name();
637 auto delim = var_name.find_first_of("_");
638 var_name = var_name.substr(0, delim);
639
640 if (!l_modal_[work_index].exists(var_name)) continue;
641
643
644 for (Idx tId = 0; tId < tsize; tId++) {
645 if (l_expectationMax_[tId][i] > this->expectationMax_[i])
647
648 if (l_expectationMin_[tId][i] < this->expectationMin_[i])
650 } // end of : each thread
651 } // end of : each variable
652 };
653
654 const Size working_size = workingSet_.size();
656 if (!this->l_modal_[work_index].empty()) {
657 const auto nsize = Size(workingSet_[work_index]->size());
659 const auto ranges
662 }
663 }
664 }
credalSet marginalSets_
Credal sets vertices, if enabled.
std::vector< std::pair< Idx, Idx > > dispatchRangeToThreads(const Idx beg, const Idx end, const unsigned int nb_threads)
returns a vector equally splitting elements of a range among threads
Definition threads.cpp:76

References gum::dispatchRangeToThreads(), gum::threadsSTL::ThreadExecutor::execute(), gum::credal::InferenceEngine< GUM_SCALAR >::expectationMax_, gum::credal::InferenceEngine< GUM_SCALAR >::expectationMin_, expFusion_(), gum::ThreadNumberManager::getNumberOfThreads(), l_expectationMax_, l_expectationMin_, l_modal_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalSets_, gum::credal::InferenceEngine< GUM_SCALAR >::modal_, gum::threadsSTL::ThreadExecutor::nbRunningThreadsExecutors(), gum::credal::InferenceEngine< GUM_SCALAR >::storeVertices_, and workingSet_.

Referenced by expFusion_().

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

◆ getApproximationSchemeMsg()

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

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
inherited

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
inherited

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 ( )
inherited

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 }
VarMod2BNsMap< GUM_SCALAR > dbnOpt_
Object used to efficiently store optimal bayes net during inference, for some algorithms.

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_ ( )
protectedinherited

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_ ( )
protectedinherited

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_ ( )
protectedinherited

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 }

References credalNet_, marginalSets_, and storeVertices_.

Referenced by eraseAllEvidence(), and storeVertices().

Here is the caller graph for this function:

◆ initThreadsData_()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
void gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::initThreadsData_ ( const Size & num_threads,
const bool _storeVertices_,
const bool _storeBNOpt_ )
protected

Initialize threads data.

Parameters
num_threadsThe number of threads.
_storeVertices_True if vertices should be stored, False otherwise.
_storeBNOpt_True if optimal IBayesNet should be stored, false otherwise.

Definition at line 64 of file multipleInferenceEngine_tpl.h.

67 {
68 workingSet_.clear();
69 workingSet_.resize(num_threads, nullptr);
70 workingSetE_.clear();
71 workingSetE_.resize(num_threads, nullptr);
72
73 l_marginalMin_.clear();
75 l_marginalMax_.clear();
77 l_expectationMin_.clear();
79 l_expectationMax_.clear();
81
82 l_clusters_.clear();
84
85 if (_storeVertices_) {
86 l_marginalSets_.clear();
88 }
89
90 if (_storeBNOpt_) {
91 for (Size ptr = 0; ptr < this->l_optimalNet_.size(); ptr++)
92 if (this->l_optimalNet_[ptr] != nullptr) delete l_optimalNet_[ptr];
93
94 l_optimalNet_.clear();
96 }
97
98 l_modal_.clear();
99 l_modal_.resize(num_threads);
100
102 this->oldMarginalMin_ = this->marginalMin_;
103 this->oldMarginalMax_.clear();
104 this->oldMarginalMax_ = this->marginalMax_;
105
106 // init the random number generators
107 generators_.clear();
108 generators_.resize(num_threads);
110 for (auto& generator: generators_) {
111 generator.seed(seed);
112 seed = generator();
113 }
114 }
std::vector< std::mt19937 > generators_
the generators used for computing random values

References l_clusters_, l_expectationMax_, l_expectationMin_, l_marginalMax_, l_marginalMin_, l_marginalSets_, l_modal_, l_optimalNet_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin_, gum::credal::InferenceEngine< GUM_SCALAR >::oldMarginalMax_, gum::credal::InferenceEngine< GUM_SCALAR >::oldMarginalMin_, workingSet_, and workingSetE_.

◆ insertEvidence() [1/2]

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

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)
inherited

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)
virtualinherited

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)
inherited

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 }
void initExpectations_()
Initialize lower and upper expectations before inference, with the lower expectation being initialize...

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)
inherited

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)
inherited

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
query query_
Holds the query nodes states.

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)
inherited

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()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
void gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::makeInference ( )
overridepure virtual

To be redefined by each credal net algorithm.

Starts the inference.

Implements gum::credal::InferenceEngine< GUM_SCALAR >.

Implemented in gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >.

◆ marginalMax() [1/2]

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

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
inherited

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
inherited

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
inherited

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:

◆ optFusion_()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
void gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::optFusion_ ( )
protected

Fusion of threads optimal IBayesNet.

Definition at line 737 of file multipleInferenceEngine_tpl.h.

737 {
738 using dBN = std::vector< bool >;
739
740 Size nsize = Size(workingSet_[0]->size());
741
742 // no parallel insert in hash-tables (OptBN)
743 for (Idx i = 0; i < nsize; i++) {
744 // we don't store anything for observed variables
745 if (_infE_::evidence_.exists(i)) continue;
746
748
749 for (Size j = 0; j < dSize; j++) {
750 // go through all threads
752 keymin[0] = i;
753 keymin[1] = j;
754 keymin[2] = 0;
756 keymax[2] = 1;
757
758 Size tsize = Size(l_marginalMin_.size());
759
760 for (Size tId = 0; tId < tsize; tId++) {
761 if (l_marginalMin_[tId][i][j] == this->marginalMin_[i][j]) {
762 const std::vector< dBN* >& tOpts = l_optimalNet_[tId]->getBNOptsFromKey(keymin);
763 Size osize = Size(tOpts.size());
764
765 for (Size bn = 0; bn < osize; bn++) {
766 _infE_::dbnOpt_.insert(*tOpts[bn], keymin);
767 }
768 }
769
770 if (l_marginalMax_[tId][i][j] == this->marginalMax_[i][j]) {
771 const std::vector< dBN* >& tOpts = l_optimalNet_[tId]->getBNOptsFromKey(keymax);
772 Size osize = Size(tOpts.size());
773
774 for (Size bn = 0; bn < osize; bn++) {
775 _infE_::dbnOpt_.insert(*tOpts[bn], keymax);
776 }
777 }
778 } // end of : all threads
779 } // end of : all modalities
780 } // end of : all variables
781 }

References gum::credal::InferenceEngine< GUM_SCALAR >::dbnOpt_, gum::credal::InferenceEngine< GUM_SCALAR >::evidence_, l_marginalMax_, l_marginalMin_, l_optimalNet_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin_, optFusion_(), and workingSet_.

Referenced by optFusion_().

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

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_ ( )
protectedinherited

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
inherited

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
inherited

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
inherited

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)
inherited
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
inherited
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 }

References storeBNOpt_.

◆ storeBNOpt() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::storeBNOpt ( const bool value)
inherited
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
inherited

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)
inherited
Parameters
valueTrue if vertices are to be stored, false otherwise.

Definition at line 128 of file inferenceEngine_tpl.h.

128 {
130
132 }
void initMarginalSets_()
Initialize credal set vertices with empty sets.

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
inherited

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 )
inlineprotectedinherited

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 }

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 )
inlineprotectedinherited

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:

◆ updateMarginals_()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
void gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::updateMarginals_ ( )
inlineprotected

Fusion of threads marginals.

Definition at line 296 of file multipleInferenceEngine_tpl.h.

296 {
297 // compute the max number of threads to use (avoid nested threads)
299 ? this->threadRanges_.size() - 1
300 : 1; // no nested multithreading
301
302 // create the function to be executed by the threads
303 auto threadedExec = [this](const std::size_t this_thread,
306 auto i = this->threadRanges_[this_thread].first;
307 auto j = this->threadRanges_[this_thread].second;
308 auto domain_size = this->marginalMax_[i].size();
309 const auto end_i = this->threadRanges_[this_thread + 1].first;
310 auto end_j = this->threadRanges_[this_thread + 1].second;
311 const auto marginalMax_size = this->marginalMax_.size();
312 const auto tsize = Size(l_marginalMin_.size());
313
314 while ((i < end_i) || (j < end_j)) {
315 // go through all work indices
316 for (Idx tId = 0; tId < tsize; tId++) {
317 if (l_marginalMin_[tId][i][j] < this->marginalMin_[i][j])
318 this->marginalMin_[i][j] = l_marginalMin_[tId][i][j];
319
320 if (l_marginalMax_[tId][i][j] > this->marginalMax_[i][j])
321 this->marginalMax_[i][j] = l_marginalMax_[tId][i][j];
322 }
323
324 if (++j == domain_size) {
325 j = 0;
326 ++i;
327 if (i < marginalMax_size) domain_size = this->marginalMax_[i].size();
328 }
329 }
330 };
331
332 // launch the threads
336 (nb_threads == 1)
337 ? std::vector< std::pair< NodeId, Idx > >{{0, 0}, {this->marginalMin_.size(), 0}}
338 : this->threadRanges_);
339 }

References gum::threadsSTL::ThreadExecutor::execute(), l_marginalMax_, l_marginalMin_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin_, gum::threadsSTL::ThreadExecutor::nbRunningThreadsExecutors(), gum::credal::InferenceEngine< GUM_SCALAR >::threadRanges_, and updateMarginals_().

Referenced by updateMarginals_().

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

◆ updateOldMarginals_()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
void gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::updateOldMarginals_ ( )
protected

Update old marginals (from current marginals).

Call this once to initialize old marginals (after burn-in for example) and then use computeEpsilon_ which does the same job but compute epsilon too.

Definition at line 475 of file multipleInferenceEngine_tpl.h.

475 {
476#pragma omp parallel
477 {
479 long nsize = long(workingSet_[threadId]->size());
480
481#pragma omp for
482
483 for (long i = 0; i < nsize; i++) {
485
486 for (Size j = 0; j < dSize; j++) {
487 Size tsize = Size(l_marginalMin_.size());
488
489 // go through all threads
490 for (Size tId = 0; tId < tsize; tId++) {
491 if (l_marginalMin_[tId][i][j] < this->oldMarginalMin_[i][j])
492 this->oldMarginalMin_[i][j] = l_marginalMin_[tId][i][j];
493
494 if (l_marginalMax_[tId][i][j] > this->oldMarginalMax_[i][j])
495 this->oldMarginalMax_[i][j] = l_marginalMax_[tId][i][j];
496 } // end of : all threads
497 } // end of : all modalities
498 } // end of : all variables
499 } // end of : parallel region
500 }
unsigned int getThreadNumber()
Get the calling thread id.

References gum::threadsOMP::getThreadNumber(), l_marginalMax_, l_marginalMin_, gum::credal::InferenceEngine< GUM_SCALAR >::oldMarginalMax_, gum::credal::InferenceEngine< GUM_SCALAR >::oldMarginalMin_, updateOldMarginals_(), and workingSet_.

Referenced by updateOldMarginals_().

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

◆ updateThread_()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
bool gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::updateThread_ ( Size this_thread,
const NodeId & id,
const std::vector< GUM_SCALAR > & vertex,
const bool & elimRedund = false )
inlineprotected

Update thread information (marginals, expectations, IBayesNet, vertices) for a given node id.

Parameters
this_threadthe id of the thread executing this method
idThe id of the node to be updated.
vertexThe vertex.
elimRedundtrue if redundancy elimination is to be performed, false otherwise and by default.
Returns
True if the IBayesNet is kept (for now), False otherwise.

Definition at line 117 of file multipleInferenceEngine_tpl.h.

121 {
122 // save E(X) if we don't save vertices
124 std::string var_name = workingSet_[tId]->variable(id).name();
125 auto delim = var_name.find_first_of("_");
126 var_name = var_name.substr(0, delim);
127
128 if (l_modal_[tId].exists(var_name)) {
129 GUM_SCALAR exp = 0;
130 Size vsize = Size(vertex.size());
131
132 for (Size mod = 0; mod < vsize; mod++)
134
136
138 }
139 } // end of : if modal (map) not empty
140
141 bool newOne = false;
142 bool added = false;
143 bool result = false;
144 // for burn in, we need to keep checking on local marginals and not global
145 // ones
146 // (faster inference)
147 // we also don't want to store dbn for observed variables since there will
148 // be a
149 // huge number of them (probably all of them).
150 Size vsize = Size(vertex.size());
151
152 for (Size mod = 0; mod < vsize; mod++) {
153 if (vertex[mod] < l_marginalMin_[tId][id][mod]) {
155 newOne = true;
156
159 key[0] = id;
160 key[1] = mod;
161 key[2] = 0;
162
163 if (l_optimalNet_[tId]->insert(key, true)) result = true;
164 }
165 }
166
167 if (vertex[mod] > l_marginalMax_[tId][id][mod]) {
169 newOne = true;
170
173 key[0] = id;
174 key[1] = mod;
175 key[2] = 1;
176
177 if (l_optimalNet_[tId]->insert(key, true)) result = true;
178 }
179 } else if (vertex[mod] == l_marginalMin_[tId][id][mod]
180 || vertex[mod] == l_marginalMax_[tId][id][mod]) {
181 newOne = true;
182
184 && !_infE_::evidence_.exists(id)) {
186 key[0] = id;
187 key[1] = mod;
188 key[2] = 0;
189
190 if (l_optimalNet_[tId]->insert(key, false)) result = true;
191 }
192
194 && !_infE_::evidence_.exists(id)) {
196 key[0] = id;
197 key[1] = mod;
198 key[2] = 1;
199
200 if (l_optimalNet_[tId]->insert(key, false)) result = true;
201 }
202 }
203
204 // store point to compute credal set vertices.
205 // check for redundancy at each step or at the end ?
208 added = true;
209 }
210 }
211
212 // if all variables didn't get better marginals, we will delete
213 if (_infE_::storeBNOpt_ && result) return true;
214
215 return false;
216 }
void _updateThreadCredalSets_(Size this_thread, const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund)
Ask for redundancy elimination of a node credal set of a calling thread.

References gum::credal::InferenceEngine< GUM_SCALAR >::evidence_, l_expectationMax_, l_expectationMin_, l_marginalMin_, l_modal_, gum::credal::InferenceEngine< GUM_SCALAR >::storeBNOpt_, gum::credal::InferenceEngine< GUM_SCALAR >::storeVertices_, and workingSet_.

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

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:

◆ verticesFusion_()

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
void gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::verticesFusion_ ( )
protected
Deprecated
Fusion of threads vertices.

Definition at line 503 of file multipleInferenceEngine_tpl.h.

503 {
504 // don't create threads if there are no vertices saved
505 if (!_infE_::storeVertices_) return;
506
507 // compute the max number of threads to use (avoid nested threads)
510 : 1; // no nested multithreading
511
512 // create the function to be executed by the threads
513 Size tsize = Size(l_marginalMin_.size());
514 auto threadedExec = [this, tsize](const std::size_t this_thread,
519 // go through all threads
520 for (Size tId = 0; tId < tsize; ++tId) {
522
523 // for each vertex, if we are at any opt marginal, add it to the set
524 for (const auto& vtx: nodeThreadCredalSet) {
525 // we run redundancy elimination at each step because there could
526 // be 100000 threads and the set will be so huge...
527 // BUT not if vertices are of dimension 2 ! opt check and equality
528 // should be enough
529 _infE_::updateCredalSets_(i, vtx, (vtx.size() > 2) ? true : false);
530 } // end of : nodeThreadCredalSet
531 } // end of : all threads
532 } // end of : all variables
533 };
534
535 const Size working_size = workingSet_.size();
537 // compute the ranges over which the threads will work
538 const auto nsize = workingSet_[work_index]->size();
540 const auto ranges = gum::dispatchRangeToThreads(0, nsize, (unsigned int)(real_nb_threads));
542 }
543 }
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.

References gum::dispatchRangeToThreads(), gum::threadsSTL::ThreadExecutor::execute(), gum::ThreadNumberManager::getNumberOfThreads(), l_marginalMin_, l_marginalSets_, gum::threadsSTL::ThreadExecutor::nbRunningThreadsExecutors(), gum::credal::InferenceEngine< GUM_SCALAR >::storeVertices_, gum::credal::InferenceEngine< GUM_SCALAR >::updateCredalSets_(), verticesFusion_(), and workingSet_.

Referenced by verticesFusion_().

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

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

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

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

◆ expectationMin_

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

◆ generators_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
std::vector< std::mt19937 > gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::generators_
protected

the generators used for computing random values

Definition at line 141 of file multipleInferenceEngine.h.

◆ 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().

◆ l_clusters_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
_clusters_ gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::l_clusters_
protected

◆ l_evidence_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
_margis_ gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::l_evidence_
protected

Threads evidence.

Definition at line 125 of file multipleInferenceEngine.h.

Referenced by eraseAllEvidence().

◆ l_expectationMax_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
_expes_ gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::l_expectationMax_
protected

Threads upper expectations, one per thread.

Definition at line 119 of file multipleInferenceEngine.h.

Referenced by eraseAllEvidence(), expFusion_(), initThreadsData_(), and updateThread_().

◆ l_expectationMin_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
_expes_ gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::l_expectationMin_
protected

Threads lower expectations, one per thread.

Definition at line 117 of file multipleInferenceEngine.h.

Referenced by eraseAllEvidence(), expFusion_(), initThreadsData_(), and updateThread_().

◆ l_inferenceEngine_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
std::vector< BNInferenceEngine* > gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::l_inferenceEngine_
protected

Threads BNInferenceEngine.

Definition at line 136 of file multipleInferenceEngine.h.

Referenced by eraseAllEvidence().

◆ l_marginalMax_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
_margis_ gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::l_marginalMax_
protected

Threads upper marginals, one per thread.

Definition at line 115 of file multipleInferenceEngine.h.

Referenced by eraseAllEvidence(), initThreadsData_(), optFusion_(), updateMarginals_(), and updateOldMarginals_().

◆ l_marginalMin_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
_margis_ gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::l_marginalMin_
protected

Threads lower marginals, one per thread.

Definition at line 113 of file multipleInferenceEngine.h.

Referenced by eraseAllEvidence(), initThreadsData_(), optFusion_(), updateMarginals_(), updateOldMarginals_(), updateThread_(), and verticesFusion_().

◆ l_marginalSets_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
_credalSets_ gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::l_marginalSets_
protected

Threads vertices.

Definition at line 123 of file multipleInferenceEngine.h.

Referenced by _updateThreadCredalSets_(), eraseAllEvidence(), initThreadsData_(), and verticesFusion_().

◆ l_modal_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
_modals_ gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::l_modal_
protected

Threads modalities.

Definition at line 121 of file multipleInferenceEngine.h.

Referenced by eraseAllEvidence(), expFusion_(), initThreadsData_(), and updateThread_().

◆ l_optimalNet_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
std::vector< VarMod2BNsMap< GUM_SCALAR >* > gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::l_optimalNet_
protected

Threads optimal IBayesNet.

Definition at line 138 of file multipleInferenceEngine.h.

Referenced by eraseAllEvidence(), initThreadsData_(), and optFusion_().

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

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

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

◆ storeBNOpt_

◆ storeVertices_

◆ t0_

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

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

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)}
protectedinherited

◆ threadRanges_

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

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

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

◆ workingSet_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
std::vector< _bnet_* > gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::workingSet_
protected

◆ workingSetE_

template<GUM_Numeric GUM_SCALAR, class BNInferenceEngine>
std::vector< List< const Tensor< GUM_SCALAR >* >* > gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >::workingSetE_
protected

Threads evidence.

Definition at line 133 of file multipleInferenceEngine.h.

Referenced by eraseAllEvidence(), and initThreadsData_().


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