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

<agrum/CN/CNLoopyPropagation.h> More...

#include <CNLoopyPropagation.h>

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

Public Types

enum class  InferenceType : char { nodeToNeighbours , ordered , randomOrder }
 Inference type to be used by the algorithm. More...
using msg = std::vector< Tensor< GUM_SCALAR >* >
using cArcP = const class gum::Arc*
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)
Public algorithm methods
void makeInference () override
 Starts the inference.
void insertEvidenceFile (std::string_view path) override
 Starts the inference.
Getters and setters
void inferenceType (InferenceType inft)
 Set the inference type.
InferenceType inferenceType ()
 Get the inference type.
Post-inference methods
void eraseAllEvidence () override
 Erase all inference related data to perform another one.
void saveInference (std::string_view path)
Constructors / Destructors
 CNLoopyPropagation (const CredalNet< GUM_SCALAR > &credalNet)
 Constructor.
 ~CNLoopyPropagation () override
 Destructor.
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.
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
void initialize_ ()
 Topological forward propagation to initialize old marginals & messages.
Protected algorithm methods
void makeInferenceNodeToNeighbours_ ()
 Starts the inference with this inference type.
void makeInferenceByOrderedArcs_ ()
 Starts the inference with this inference type.
void makeInferenceByRandomOrder_ ()
 Starts the inference with this inference type.
void updateMarginals_ ()
 Compute marginals from up-to-date messages.
void msgL_ (const NodeId X, const NodeId demanding_parent)
 Sends a message to one's parent, i.e.
void compute_ext_ (GUM_SCALAR &msg_l_min, GUM_SCALAR &msg_l_max, std::vector< GUM_SCALAR > &lx, GUM_SCALAR &num_min, GUM_SCALAR &num_max, GUM_SCALAR &den_min, GUM_SCALAR &den_max)
 Used by msgL_.
void compute_ext_ (std::vector< std::vector< GUM_SCALAR > > &combi_msg_p, const NodeId &id, GUM_SCALAR &msg_l_min, GUM_SCALAR &msg_l_max, std::vector< GUM_SCALAR > &lx, const Idx &pos)
 Used by msgL_.
void enum_combi_ (std::vector< std::vector< std::vector< GUM_SCALAR > > > &msgs_p, const NodeId &id, GUM_SCALAR &msg_l_min, GUM_SCALAR &msg_l_max, std::vector< GUM_SCALAR > &lx, const Idx &pos)
 Used by msgL_.
void msgP_ (const NodeId X, const NodeId demanding_child)
 Sends a message to one's child, i.e.
void enum_combi_ (std::vector< std::vector< std::vector< GUM_SCALAR > > > &msgs_p, const NodeId &id, GUM_SCALAR &msg_p_min, GUM_SCALAR &msg_p_max)
 Used by msgP_.
void compute_ext_ (std::vector< std::vector< GUM_SCALAR > > &combi_msg_p, const NodeId &id, GUM_SCALAR &msg_p_min, GUM_SCALAR &msg_p_max)
 Used by msgP_.
void refreshLMsPIs_ (bool refreshIndic=false)
 Get the last messages from one's parents and children.
GUM_SCALAR calculateEpsilon_ ()
 Compute epsilon.
Post-inference protected methods
void computeExpectations_ ()
 Since the network is binary, expectations can be computed from the final marginals which give us the credal set vertices.
void updateIndicatrices_ ()
 Only update indicatrices variables at the end of computations ( calls msgP_ ).
Protected initialization methods
void repetitiveInit_ ()
 Initialize t0_ and t1_ clusters.
void initExpectations_ ()
 Initialize lower and upper expectations before inference, with the lower expectation being initialized on the highest modality and the upper expectation being initialized on the lowest modality.
void initMarginals_ ()
 Initialize lower and upper old marginals and marginals before inference, with the lower marginal being 1 and the upper 0.
void dispatchMarginalsToThreads_ ()
 computes Vector threadRanges_, that assigns some part of marginalMin_ and marginalMax_ to the threads
void initMarginalSets_ ()
 Initialize credal set vertices with empty sets.
Protected algorithms methods
virtual const GUM_SCALAR computeEpsilon_ ()
 Compute approximation scheme epsilon using the old marginals and the new ones.
void updateExpectations_ (const NodeId &id, const std::vector< GUM_SCALAR > &vertex)
 Given a node id and one of it's possible vertex obtained during inference, update this node lower and upper expectations.
void updateCredalSets_ (const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund=false)
 Given a node id and one of it's possible vertex, update it's credal set.
Proptected post-inference methods
void dynamicExpectations_ ()
 Rearrange lower and upper expectations to suit dynamic networks.

Static Protected Member Functions

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

Protected Attributes

NodeProperty< bool > update_p_
 Used to keep track of which node needs to update it's information coming from it's parents.
NodeProperty< bool > update_l_
 Used to keep track of which node needs to update it's information coming from it's children.
NodeSet active_nodes_set_
 The current node-set to iterate through at this current step.
NodeSet next_active_nodes_set_
 The next node-set, i.e.
NodeProperty< NodeSet * > msg_l_sent_
 Used to keep track of one's messages sent to it's parents.
ArcProperty< GUM_SCALAR > ArcsL_min_
 "Lower" information \( \Lambda \) coming from one's children.
ArcProperty< GUM_SCALAR > ArcsP_min_
 "Lower" information \( \pi \) coming from one's parent.
NodeProperty< GUM_SCALAR > NodesL_min_
 "Lower" node information \( \Lambda \) obtained by combinaison of children messages.
NodeProperty< GUM_SCALAR > NodesP_min_
 "Lower" node information \( \pi \) obtained by combinaison of parent's messages.
ArcProperty< GUM_SCALAR > ArcsL_max_
 "Upper" information \( \Lambda \) coming from one's children.
ArcProperty< GUM_SCALAR > ArcsP_max_
 "Upper" information \( \pi \) coming from one's parent.
NodeProperty< GUM_SCALAR > NodesL_max_
 "Upper" node information \( \Lambda \) obtained by combinaison of children messages.
NodeProperty< GUM_SCALAR > NodesP_max_
 "Upper" node information \( \pi \) obtained by combinaison of parent's messages.
bool inference_up_to_date_
 TRUE if inference has already been performed, FALSE otherwise.
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 credalSet = NodeProperty< std::vector< std::vector< GUM_SCALAR > > >
using margi = NodeProperty< std::vector< GUM_SCALAR > >
using expe = NodeProperty< GUM_SCALAR >
using dynExpe = typename gum::HashTable< std::string, std::vector< GUM_SCALAR > >
using query = NodeProperty< std::vector< bool > >
using cluster = NodeProperty< std::vector< NodeId > >

Private Member Functions

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

Private Attributes

InferenceType _inferenceType_
 The chosen inference type.
const CredalNet< GUM_SCALAR > * _cn_
 A pointer to the CredalNet to be used.
const IBayesNet< GUM_SCALAR > * _bnet_
 A pointer to it's IBayesNet used as a DAG.
Size _nb_threads_ {0}
 the max number of threads used by the class

Detailed Description

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

<agrum/CN/CNLoopyPropagation.h>

Class implementing loopy-propagation with binary networks - L2U algorithm.

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

Definition at line 75 of file CNLoopyPropagation.h.

Member Typedef Documentation

◆ _infE_

template<GUM_Numeric GUM_SCALAR>
using gum::credal::CNLoopyPropagation< GUM_SCALAR >::_infE_ = InferenceEngine< GUM_SCALAR >
private

To easily access InferenceEngine< GUM_SCALAR > methods.

Definition at line 384 of file CNLoopyPropagation.h.

◆ cArcP

template<GUM_Numeric GUM_SCALAR>
using gum::credal::CNLoopyPropagation< GUM_SCALAR >::cArcP = const class gum::Arc*

Definition at line 78 of file CNLoopyPropagation.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.

◆ msg

template<GUM_Numeric GUM_SCALAR>
using gum::credal::CNLoopyPropagation< GUM_SCALAR >::msg = std::vector< Tensor< GUM_SCALAR >* >

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

◆ InferenceType

template<GUM_Numeric GUM_SCALAR>
enum class gum::credal::CNLoopyPropagation::InferenceType : char
strong

Inference type to be used by the algorithm.

Enumerator
nodeToNeighbours 

Uses a node-set so we don't iterate on nodes that can't send a new message.

Should be the fastest inference type. A step is going through the node-set.

ordered 

Chooses an arc ordering and sends messages accordingly at all steps.

Avoid it since it can give slightly worse results than other inference types. A step is going through all arcs.

randomOrder 

Chooses a random arc ordering and sends messages accordingly.

A new order is set at each step. A step is going through all arcs.

Definition at line 83 of file CNLoopyPropagation.h.

83 : char {
84 nodeToNeighbours,
88
89 ordered,
94
95 randomOrder
99 };

Constructor & Destructor Documentation

◆ CNLoopyPropagation()

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

Constructor.

Parameters
cnetThe CredalNet to be used with this algorithm.

Definition at line 1480 of file CNLoopyPropagation_tpl.h.

1480 :
1482 if (!credalNet.isSeparatelySpecified()) {
1484 "CNLoopyPropagation is only available "
1485 "with separately specified nets");
1486 }
1487
1488 // test for binary cn
1489 for (auto node: credalNet.current_bn().nodes())
1490 if (credalNet.current_bn().variable(node).domainSize() != 2) {
1492 "CNLoopyPropagation is only available "
1493 "with binary credal networks")
1494 }
1495
1496 // test if compute CPTMinMax has been called
1497 if (!credalNet.hasComputedBinaryCPTMinMax()) {
1499 "CNLoopyPropagation only works when "
1500 "\"computeBinaryCPTMinMax()\" has been called for "
1501 "this credal net")
1502 }
1503
1504 _cn_ = &credalNet;
1505 _bnet_ = &credalNet.current_bn();
1506
1508 inference_up_to_date_ = false;
1509
1511 }
<agrum/CN/CNLoopyPropagation.h>
InferenceType _inferenceType_
The chosen inference type.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it's IBayesNet used as a DAG.
@ nodeToNeighbours
Uses a node-set so we don't iterate on nodes that can't send a new message.
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
CNLoopyPropagation(const CredalNet< GUM_SCALAR > &credalNet)
Constructor.
bool inference_up_to_date_
TRUE if inference has already been performed, FALSE otherwise.
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.
const CredalNet< GUM_SCALAR > & credalNet() const
Get this credal network.

References CNLoopyPropagation(), gum::credal::InferenceEngine< GUM_SCALAR >::InferenceEngine(), _bnet_, _cn_, _inferenceType_, gum::credal::InferenceEngine< GUM_SCALAR >::credalNet(), gum::credal::CredalNet< GUM_SCALAR >::current_bn(), gum::credal::CredalNet< GUM_SCALAR >::hasComputedBinaryCPTMinMax(), inference_up_to_date_, gum::credal::CredalNet< GUM_SCALAR >::isSeparatelySpecified(), and nodeToNeighbours.

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

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

◆ ~CNLoopyPropagation()

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

Destructor.

Definition at line 1514 of file CNLoopyPropagation_tpl.h.

1514 {
1515 inference_up_to_date_ = false;
1516
1517 for (auto& [node, pset]: msg_l_sent_) {
1518 delete pset;
1519 }
1520
1522 }
NodeProperty< NodeSet * > msg_l_sent_
Used to keep track of one's messages sent to it's parents.

References CNLoopyPropagation(), inference_up_to_date_, and msg_l_sent_.

Here is the call graph for this function:

Member Function Documentation

◆ addEvidence() [1/7]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence ( const Tensor< GUM_SCALAR > & pot)
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:

◆ calculateEpsilon_()

template<GUM_Numeric GUM_SCALAR>
GUM_SCALAR gum::credal::CNLoopyPropagation< GUM_SCALAR >::calculateEpsilon_ ( )
protected

Compute epsilon.

Returns
Epsilon.

Definition at line 1434 of file CNLoopyPropagation_tpl.h.

1434 {
1437
1438 return _infE_::computeEpsilon_();
1439 }
void refreshLMsPIs_(bool refreshIndic=false)
Get the last messages from one's parents and children.
void updateMarginals_()
Compute marginals from up-to-date messages.
virtual const GUM_SCALAR computeEpsilon_()
Compute approximation scheme epsilon using the old marginals and the new ones.

References gum::credal::InferenceEngine< GUM_SCALAR >::computeEpsilon_(), refreshLMsPIs_(), and updateMarginals_().

Referenced by makeInferenceByOrderedArcs_(), makeInferenceByRandomOrder_(), and makeInferenceNodeToNeighbours_().

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

◆ compute_ext_() [1/3]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::compute_ext_ ( GUM_SCALAR & msg_l_min,
GUM_SCALAR & msg_l_max,
std::vector< GUM_SCALAR > & lx,
GUM_SCALAR & num_min,
GUM_SCALAR & num_max,
GUM_SCALAR & den_min,
GUM_SCALAR & den_max )
protected

Used by msgL_.

pour les fonctions suivantes, les GUM_SCALAR min/max doivent etre initialises (min a 1 et max a 0) pour comparer avec les resultats intermediaires

Compute the final message for the given parent's message and likelihood (children's messages), numerators & denominators.

Parameters
msg_l_minThe reference to the current lower value of the message to be sent.
msg_l_maxThe reference to the current upper value of the message to be sent.
lxThe lower and upper likelihood.
num_minThe reference to the previously computed lower numerator.
num_maxThe reference to the previously computed upper numerator.
den_minThe reference to the previously computed lower denominator.
den_maxThe reference to the previously computed upper denominator.

une fois les cpts marginalises sur X et Ui, on calcul le min/max,

Definition at line 196 of file CNLoopyPropagation_tpl.h.

202 {
207
208 GUM_SCALAR res_min = 1.0;
209 GUM_SCALAR res_max = 0.0;
210
211 auto lsize = lx.size();
212
213 for (decltype(lsize) i = 0; i < lsize; i++) {
214 bool non_defini_min = false;
215 bool non_defini_max = false;
216
217 if (lx[i] == INF_) {
222 } else if (lx[i] == (GUM_SCALAR)1.) {
227 } else if (lx[i] > (GUM_SCALAR)1.) {
228 GUM_SCALAR li = GUM_SCALAR(1.) / (lx[i] - GUM_SCALAR(1.));
233 } else if (lx[i] < (GUM_SCALAR)1.) {
234 GUM_SCALAR li = GUM_SCALAR(1.) / (lx[i] - GUM_SCALAR(1.));
239 }
240
241 if (den_min_tmp == 0. && num_min_tmp == 0.) {
242 non_defini_min = true;
243 } else if (den_min_tmp == 0. && num_min_tmp != 0.) {
244 res_min = INF_;
245 } else if (den_min_tmp != INF_ || num_min_tmp != INF_) {
247 }
248
249 if (den_max_tmp == 0. && num_max_tmp == 0.) {
250 non_defini_max = true;
251 } else if (den_max_tmp == 0. && num_max_tmp != 0.) {
252 res_max = INF_;
253 } else if (den_max_tmp != INF_ || num_max_tmp != INF_) {
255 }
256
258 std::cout << "undefined msg" << std::endl;
259 continue;
260 } else if (non_defini_min && !non_defini_max) {
262 } else if (non_defini_max && !non_defini_min) {
264 }
265
266 if (res_min < 0.) { res_min = 0.; }
267
268 if (res_max < 0.) { res_max = 0.; }
269
270 if (msg_l_min == msg_l_max && msg_l_min == -2.) {
273 }
274
275 if (res_max > msg_l_max) { msg_l_max = res_max; }
276
277 if (res_min < msg_l_min) { msg_l_min = res_min; }
278
279 } // end of : for each lx
280 }

References INF_.

Referenced by compute_ext_(), enum_combi_(), and enum_combi_().

Here is the caller graph for this function:

◆ compute_ext_() [2/3]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::compute_ext_ ( std::vector< std::vector< GUM_SCALAR > > & combi_msg_p,
const NodeId & id,
GUM_SCALAR & msg_l_min,
GUM_SCALAR & msg_l_max,
std::vector< GUM_SCALAR > & lx,
const Idx & pos )
protected

Used by msgL_.

extremes pour une combinaison des parents, message vers parent

Compute the numerators & denominators for the given parent's message and likelihood (children's messages). Marginalisation.

Parameters
combi_msg_pThe parent's chosen message.
idThe constant id of the node sending the message.
msg_l_minThe reference to the current lower value of the message to be sent.
msg_l_maxThe reference to the current upper value of the message to be sent.
lxThe lower and upper likelihood.
posThe position of the parent node to receive the message in the CPT of the one sending the message ( first parent, second ... ).

Definition at line 286 of file CNLoopyPropagation_tpl.h.

292 {
293 GUM_SCALAR num_min = 0.;
294 GUM_SCALAR num_max = 0.;
295 GUM_SCALAR den_min = 0.;
296 GUM_SCALAR den_max = 0.;
297
298 auto taille = combi_msg_p.size();
299
301
302 for (decltype(taille) i = 0; i < taille; i++) {
303 it[i] = combi_msg_p[i].begin();
304 }
305
306 Size pp = pos;
307
308 Size combi_den = 0;
309 Size combi_num = pp;
310
311 // marginalisation
312 while (it[taille - 1] != combi_msg_p[taille - 1].end()) {
313 GUM_SCALAR prod = 1.;
314
315 for (decltype(taille) k = 0; k < taille; k++) {
316 prod *= *it[k];
317 }
318
319 den_min += (_cn_->get_binaryCPT_min()[id][combi_den] * prod);
320 den_max += (_cn_->get_binaryCPT_max()[id][combi_den] * prod);
321
322 num_min += (_cn_->get_binaryCPT_min()[id][combi_num] * prod);
323 num_max += (_cn_->get_binaryCPT_max()[id][combi_num] * prod);
324
325 combi_den++;
326 combi_num++;
327
328 if (pp != 0) {
329 if (combi_den % pp == 0) {
330 combi_den += pp;
331 combi_num += pp;
332 }
333 }
334
335 // incrementation
336 ++it[0];
337
338 for (decltype(taille) i = 0; (i < taille - 1) && (it[i] == combi_msg_p[i].end()); ++i) {
339 it[i] = combi_msg_p[i].begin();
340 ++it[i + 1];
341 }
342 } // end of : marginalisation
343
345 }
void compute_ext_(GUM_SCALAR &msg_l_min, GUM_SCALAR &msg_l_max, std::vector< GUM_SCALAR > &lx, GUM_SCALAR &num_min, GUM_SCALAR &num_max, GUM_SCALAR &den_min, GUM_SCALAR &den_max)
Used by msgL_.

References _cn_, and compute_ext_().

Here is the call graph for this function:

◆ compute_ext_() [3/3]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::compute_ext_ ( std::vector< std::vector< GUM_SCALAR > > & combi_msg_p,
const NodeId & id,
GUM_SCALAR & msg_p_min,
GUM_SCALAR & msg_p_max )
protected

Used by msgP_.

extremes pour une combinaison des parents, message vers enfant marginalisation cpts

Marginalisation.

Parameters
combi_msg_pThe parent's chosen message.
idThe constant id of the node sending the message.
msg_p_minThe reference to the current lower value of the message to be sent.
msg_p_maxThe reference to the current upper value of the message to be sent.

Definition at line 352 of file CNLoopyPropagation_tpl.h.

356 {
357 GUM_SCALAR min = 0.;
358 GUM_SCALAR max = 0.;
359
360 auto taille = combi_msg_p.size();
361
363
364 for (decltype(taille) i = 0; i < taille; i++) {
365 it[i] = combi_msg_p[i].begin();
366 }
367
368 int combi = 0;
369 auto theEnd = combi_msg_p[taille - 1].end();
370
371 while (it[taille - 1] != theEnd) {
372 GUM_SCALAR prod = 1.;
373
374 for (decltype(taille) k = 0; k < taille; k++) {
375 prod *= *it[k];
376 }
377
378 min += (_cn_->get_binaryCPT_min()[id][combi] * prod);
379 max += (_cn_->get_binaryCPT_max()[id][combi] * prod);
380
381 combi++;
382
383 // incrementation
384 ++it[0];
385
386 for (decltype(taille) i = 0; (i < taille - 1) && (it[i] == combi_msg_p[i].end()); ++i) {
387 it[i] = combi_msg_p[i].begin();
388 ++it[i + 1];
389 }
390 }
391
392 if (min < msg_p_min) { msg_p_min = min; }
393
394 if (max > msg_p_max) { msg_p_max = max; }
395 }

References _cn_.

◆ computeEpsilon_()

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

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

Highest delta on either lower or upper marginal is epsilon.

Also updates oldMarginals to current marginals.

Returns
Epsilon.

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

Definition at line 981 of file inferenceEngine_tpl.h.

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

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

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

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

◆ computeExpectations_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::computeExpectations_ ( )
protected

Since the network is binary, expectations can be computed from the final marginals which give us the credal set vertices.

Definition at line 1456 of file CNLoopyPropagation_tpl.h.

1456 {
1457 if (_infE_::modal_.empty()) { return; }
1458
1460
1461 for (auto node: _bnet_->nodes()) {
1464
1467
1468 for (auto vertex = 0, vend = 2; vertex != vend; vertex++) {
1470 // test credal sets vertices elim
1471 // remove with L2U since variables are binary
1472 // but does the user know that ?
1474 vertices[vertex]); // no redundancy elimination with 2 vertices
1475 }
1476 }
1477 }
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...
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.
const std::vector< std::vector< GUM_SCALAR > > & vertices(const NodeId id) const
Get the vertice of a given node id.
dynExpe modal_
Variables modalities used to compute expectations.

References _bnet_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin_, gum::credal::InferenceEngine< GUM_SCALAR >::modal_, gum::credal::InferenceEngine< GUM_SCALAR >::updateCredalSets_(), gum::credal::InferenceEngine< GUM_SCALAR >::updateExpectations_(), and gum::credal::InferenceEngine< GUM_SCALAR >::vertices().

Referenced by makeInference().

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

◆ enum_combi_() [1/2]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::enum_combi_ ( std::vector< std::vector< std::vector< GUM_SCALAR > > > & msgs_p,
const NodeId & id,
GUM_SCALAR & msg_l_min,
GUM_SCALAR & msg_l_max,
std::vector< GUM_SCALAR > & lx,
const Idx & pos )
protected

Used by msgL_.

comme precedemment mais pour message parent, vraisemblance prise en compte

Enumerate parent's messages.

Parameters
msgs_pAll the messages from the parents which will be enumerated.
idThe constant id of the node sending the message.
msg_l_minThe reference to the current lower value of the message to be sent.
msg_l_maxThe reference to the current upper value of the message to be sent.
lxThe lower and upper likelihood.
posThe position of the parent node to receive the message in the CPT of the one sending the message ( first parent, second ... ).

Definition at line 471 of file CNLoopyPropagation_tpl.h.

477 {
480
481 auto taille = msgs_p.size();
482
483 // one parent node, the one receiving the message
484 if (taille == 0) {
485 GUM_SCALAR num_min = _cn_->get_binaryCPT_min()[id][1];
486 GUM_SCALAR num_max = _cn_->get_binaryCPT_max()[id][1];
487 GUM_SCALAR den_min = _cn_->get_binaryCPT_min()[id][0];
488 GUM_SCALAR den_max = _cn_->get_binaryCPT_max()[id][0];
489
491
494 return;
495 }
496
497 Size msgPerm = 1;
498 for (Size i = 0; i < taille; i++) {
499 msgPerm *= msgs_p[i].size();
500 }
501
502 // dispatch the messages among the threads and prepare the data
503 // they will process
505 ? this->getNumberOfThreads()
506 : 1; // no nested multithreading
508 if (nb_threads < 1) nb_threads = 1;
509
510 const auto ranges = gum::dispatchRangeToThreads(0, msgPerm, (unsigned int)(nb_threads));
511 const auto real_nb_threads = ranges.size();
514
515 // create the function to be executed by the threads
516 auto threadedExec = [this, &msg_lmin, &msg_lmax, msgs_p, taille, ranges, id, &lx, pos](
518 const std::size_t nb_threads) {
520
521 const auto& [first, second] = ranges[this_thread];
522 for (Idx j = first; j < second; ++j) {
523 // get jth msg :
524 auto jvalue = j;
525
526 for (Idx i = 0; i < taille; i++) {
527 if (msgs_p[i].size() == 2) {
528 combi_msg_p[i] = (jvalue & 1) ? msgs_p[i][1] : msgs_p[i][0];
529 jvalue /= 2;
530 } else {
531 combi_msg_p[i] = msgs_p[i][0];
532 }
533 }
535 }
536 };
537
538 // launch the threads
540
541 for (Idx j = 0; j < real_nb_threads; ++j) {
542 if ((msg_l_min > msg_lmin[j] || msg_l_min == -2) && msg_lmin[j] > 0) {
544 }
545 if ((msg_l_max < msg_lmax[j] || msg_l_max == -2) && msg_lmax[j] > 0) {
547 }
548 }
549
552 }
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
virtual Size getNumberOfThreads() const =0
returns the current max number of threads of the scheduler

References _cn_, compute_ext_(), gum::dispatchRangeToThreads(), gum::threadsSTL::ThreadExecutor::execute(), gum::ThreadNumberManager::getNumberOfThreads(), gum::threadsSTL::ThreadExecutor::nbRunningThreadsExecutors(), and gum::credal::InferenceEngine< GUM_SCALAR >::threadMinimalNbOps_.

Referenced by initialize_(), msgL_(), msgP_(), and refreshLMsPIs_().

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

◆ enum_combi_() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::enum_combi_ ( std::vector< std::vector< std::vector< GUM_SCALAR > > > & msgs_p,
const NodeId & id,
GUM_SCALAR & msg_p_min,
GUM_SCALAR & msg_p_max )
protected

Used by msgP_.

enumerate combinations messages parents, pour message vers enfant

Enumerate parent's messages.

Parameters
msgs_pAll the messages from the parents which will be enumerated.
idThe constant id of the node sending the message.
msg_p_minThe reference to the current lower value of the message to be sent.
msg_p_maxThe reference to the current upper value of the message to be sent.

Definition at line 401 of file CNLoopyPropagation_tpl.h.

405 {
406 auto taille = msgs_p.size();
407
408 // source node
409 if (taille == 0) {
410 msg_p_min = _cn_->get_binaryCPT_min()[id][0];
411 msg_p_max = _cn_->get_binaryCPT_max()[id][0];
412 return;
413 }
414
415 Size msgPerm = 1;
416 for (Size i = 0; i < taille; i++) {
417 msgPerm *= msgs_p[i].size();
418 }
419
420 // dispatch the messages among the threads and prepare the data
421 // they will process
423 ? this->getNumberOfThreads()
424 : 1; // no nested multithreading
426 if (nb_threads < 1) nb_threads = 1;
427
428 const auto ranges = gum::dispatchRangeToThreads(0, msgPerm, (unsigned int)(nb_threads));
429 const auto real_nb_threads = ranges.size();
432
433 // create the function to be executed by the threads
434 auto threadedExec
436 const std::size_t nb_threads) {
438
439 const auto& [first, second] = ranges[this_thread];
440 for (Idx j = first; j < second; ++j) {
441 // get jth msg :
442 auto jvalue = j;
443
444 for (Idx i = 0; i < taille; i++) {
445 if (msgs_p[i].size() == 2) {
446 combi_msg_p[i] = (jvalue & 1) ? msgs_p[i][1] : msgs_p[i][0];
447 jvalue /= 2;
448 } else {
449 combi_msg_p[i] = msgs_p[i][0];
450 }
451 }
452
454 }
455 };
456
457 // launch the threads
459
460 for (Idx j = 0; j < real_nb_threads; ++j) {
461 if (msg_p_min > msg_pmin[j]) { msg_p_min = msg_pmin[j]; }
462 if (msg_p_max < msg_pmax[j]) { msg_p_max = msg_pmax[j]; }
463 }
464 }

References _cn_, compute_ext_(), gum::dispatchRangeToThreads(), gum::threadsSTL::ThreadExecutor::execute(), gum::ThreadNumberManager::getNumberOfThreads(), gum::threadsSTL::ThreadExecutor::nbRunningThreadsExecutors(), and gum::credal::InferenceEngine< GUM_SCALAR >::threadMinimalNbOps_.

Here is the call graph for this function:

◆ epsilon()

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

◆ eraseAllEvidence()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::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 579 of file CNLoopyPropagation_tpl.h.

579 {
581
582 ArcsL_min_.clear();
583 ArcsL_max_.clear();
584 ArcsP_min_.clear();
585 ArcsP_max_.clear();
586 NodesL_min_.clear();
587 NodesL_max_.clear();
588 NodesP_min_.clear();
589 NodesP_max_.clear();
590
591 inference_up_to_date_ = false;
592
593 if (!msg_l_sent_.empty()) {
594 for (auto node: _bnet_->nodes()) {
595 delete msg_l_sent_[node];
596 }
597 }
598
599 msg_l_sent_.clear();
600 update_l_.clear();
601 update_p_.clear();
602
603 active_nodes_set_.clear();
605 }
NodeProperty< GUM_SCALAR > NodesL_min_
"Lower" node information obtained by combinaison of children messages.
NodeProperty< GUM_SCALAR > NodesP_min_
"Lower" node information obtained by combinaison of parent's messages.
NodeProperty< GUM_SCALAR > NodesL_max_
"Upper" node information obtained by combinaison of children messages.
NodeProperty< bool > update_p_
Used to keep track of which node needs to update it's information coming from it's parents.
NodeProperty< bool > update_l_
Used to keep track of which node needs to update it's information coming from it's children.
ArcProperty< GUM_SCALAR > ArcsP_min_
"Lower" information coming from one's parent.
ArcProperty< GUM_SCALAR > ArcsL_max_
"Upper" information coming from one's children.
NodeProperty< GUM_SCALAR > NodesP_max_
"Upper" node information obtained by combinaison of parent's messages.
NodeSet active_nodes_set_
The current node-set to iterate through at this current step.
NodeSet next_active_nodes_set_
The next node-set, i.e.
ArcProperty< GUM_SCALAR > ArcsL_min_
"Lower" information coming from one's children.
ArcProperty< GUM_SCALAR > ArcsP_max_
"Upper" information coming from one's parent.
virtual void eraseAllEvidence()
removes all the evidence entered into the network

References _bnet_, active_nodes_set_, ArcsL_max_, ArcsL_min_, ArcsP_max_, ArcsP_min_, gum::credal::InferenceEngine< GUM_SCALAR >::eraseAllEvidence(), inference_up_to_date_, msg_l_sent_, next_active_nodes_set_, NodesL_max_, NodesL_min_, NodesP_max_, NodesP_min_, update_l_, and update_p_.

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

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

◆ inferenceType() [1/2]

template<GUM_Numeric GUM_SCALAR>
CNLoopyPropagation< GUM_SCALAR >::InferenceType gum::credal::CNLoopyPropagation< GUM_SCALAR >::inferenceType ( )

Get the inference type.

Returns
The inference type.

Definition at line 1531 of file CNLoopyPropagation_tpl.h.

1531 {
1532 return _inferenceType_;
1533 }

References _inferenceType_.

◆ inferenceType() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::inferenceType ( InferenceType inft)

Set the inference type.

Parameters
inftThe chosen InferenceType.

Definition at line 1525 of file CNLoopyPropagation_tpl.h.

1525 {
1527 }

References _inferenceType_.

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

◆ initialize_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::initialize_ ( )
protected

Topological forward propagation to initialize old marginals & messages.

Definition at line 608 of file CNLoopyPropagation_tpl.h.

608 {
609 const DAG& graphe = _bnet_->dag();
610
611 // use const iterators with cbegin when available
612 for (auto node: _bnet_->topologicalOrder()) {
613 update_p_.set(node, false);
614 update_l_.set(node, false);
615 auto parents_ = new NodeSet();
617
618 // accelerer init pour evidences
620 if (_infE_::evidence_[node][1] != 0. && _infE_::evidence_[node][1] != 1.) {
621 GUM_ERROR(OperationNotAllowed, "CNLoopyPropagation can only handle HARD evidences")
622 }
623
624 active_nodes_set_.insert(node);
625 update_l_.set(node, true);
626 update_p_.set(node, true);
627
628 if (_infE_::evidence_[node][1] == (GUM_SCALAR)1.) {
629 NodesL_min_.set(node, INF_);
630 NodesP_min_.set(node, (GUM_SCALAR)1.);
631 } else if (_infE_::evidence_[node][1] == (GUM_SCALAR)0.) {
632 NodesL_min_.set(node, (GUM_SCALAR)0.);
633 NodesP_min_.set(node, (GUM_SCALAR)0.);
634 }
635
637 marg[1] = NodesP_min_[node];
638 marg[0] = 1 - marg[1];
639
642
643 continue;
644 }
645
646 NodeSet par_ = graphe.parents(node);
647 NodeSet enf_ = graphe.children(node);
648
649 if (par_.empty()) {
650 active_nodes_set_.insert(node);
651 update_p_.set(node, true);
652 update_l_.set(node, true);
653 }
654
655 if (enf_.empty()) {
656 active_nodes_set_.insert(node);
657 update_p_.set(node, true);
658 update_l_.set(node, true);
659 }
660
665 const auto parents = &_bnet_->cpt(node).variablesSequence();
666
670
671 // +1 from start to avoid counting_ itself
672 // use const iterators when available with cbegin
673 for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd; ++jt) {
674 // compute probability distribution to avoid doing it multiple times
675 // (at
676 // each combination of messages)
677 distri[1] = NodesP_min_[_bnet_->nodeId(**jt)];
678 distri[0] = (GUM_SCALAR)1. - distri[1];
679 msg_p.push_back(distri);
680
681 if (NodesP_max_.exists(_bnet_->nodeId(**jt))) {
682 distri[1] = NodesP_max_[_bnet_->nodeId(**jt)];
683 distri[0] = (GUM_SCALAR)1. - distri[1];
684 msg_p.push_back(distri);
685 }
686
687 msgs_p.push_back(msg_p);
688 msg_p.clear();
689 }
690
693
694 if (_cn_->currentNodeType(node) != CredalNet< GUM_SCALAR >::NodeType::Indic) {
696 }
697
698 if (msg_p_min <= (GUM_SCALAR)0.) { msg_p_min = (GUM_SCALAR)0.; }
699
700 if (msg_p_max <= (GUM_SCALAR)0.) { msg_p_max = (GUM_SCALAR)0.; }
701
704 marg[1] = msg_p_min;
705 marg[0] = 1 - msg_p_min;
706
708
709 if (msg_p_min != msg_p_max) {
710 marg[1] = msg_p_max;
711 marg[0] = 1 - msg_p_max;
712 NodesP_max_.insert(node, msg_p_max);
713 }
714
716
717 NodesL_min_.set(node, (GUM_SCALAR)1.);
718 }
719
720 for (auto arc: _bnet_->arcs()) {
721 ArcsP_min_.set(arc, NodesP_min_[arc.tail()]);
722
723 if (NodesP_max_.exists(arc.tail())) { ArcsP_max_.set(arc, NodesP_max_[arc.tail()]); }
724
725 ArcsL_min_.set(arc, NodesL_min_[arc.tail()]);
726 }
727 }
void enum_combi_(std::vector< std::vector< std::vector< GUM_SCALAR > > > &msgs_p, const NodeId &id, GUM_SCALAR &msg_l_min, GUM_SCALAR &msg_l_max, std::vector< GUM_SCALAR > &lx, const Idx &pos)
Used by msgL_.

References _bnet_, _cn_, active_nodes_set_, ArcsL_min_, ArcsP_max_, ArcsP_min_, gum::ArcGraphPart::children(), gum::Set< Key >::empty(), enum_combi_(), gum::credal::InferenceEngine< GUM_SCALAR >::evidence_, GUM_ERROR, gum::credal::CredalNet< GUM_SCALAR >::Indic, INF_, msg_l_sent_, NodesL_min_, NodesP_max_, NodesP_min_, gum::credal::InferenceEngine< GUM_SCALAR >::oldMarginalMax_, gum::credal::InferenceEngine< GUM_SCALAR >::oldMarginalMin_, gum::ArcGraphPart::parents(), update_l_, and update_p_.

Referenced by makeInference().

Here is the call graph for this function:
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 }
bool storeVertices_
True if credal sets vertices are stored, False otherwise.
credalSet marginalSets_
Credal sets vertices, if enabled.

References credalNet_, marginalSets_, and storeVertices_.

Referenced by eraseAllEvidence(), and storeVertices().

Here is the caller graph for this function:

◆ insertEvidence() [1/2]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::insertEvidence ( const NodeProperty< std::vector< GUM_SCALAR > > & evidence)
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::CNLoopyPropagation< GUM_SCALAR >::insertEvidenceFile ( std::string_view path)
overridevirtual

Starts the inference.

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

Definition at line 1536 of file CNLoopyPropagation_tpl.h.

1536 {
1538 }
virtual void insertEvidenceFile(std::string_view path)
Insert evidence from file.

References gum::credal::InferenceEngine< GUM_SCALAR >::insertEvidenceFile().

Here is the call 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>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInference ( )
overridevirtual

Starts the inference.

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

Definition at line 555 of file CNLoopyPropagation_tpl.h.

555 {
556 if (inference_up_to_date_) { return; }
557
558 initialize_();
559
561
562 switch (_inferenceType_) {
564
566
568 }
569
570 //_updateMarginals();
571 updateIndicatrices_(); // will call updateMarginals_()
572
574
576 }
void initApproximationScheme()
Initialise the scheme.
void makeInferenceNodeToNeighbours_()
Starts the inference with this inference type.
void initialize_()
Topological forward propagation to initialize old marginals & messages.
void makeInferenceByRandomOrder_()
Starts the inference with this inference type.
@ randomOrder
Chooses a random arc ordering and sends messages accordingly.
@ ordered
Chooses an arc ordering and sends messages accordingly at all steps.
void computeExpectations_()
Since the network is binary, expectations can be computed from the final marginals which give us the ...
void makeInferenceByOrderedArcs_()
Starts the inference with this inference type.
void updateIndicatrices_()
Only update indicatrices variables at the end of computations ( calls msgP_ ).

References _inferenceType_, computeExpectations_(), inference_up_to_date_, gum::ApproximationScheme::initApproximationScheme(), initialize_(), makeInferenceByOrderedArcs_(), makeInferenceByRandomOrder_(), makeInferenceNodeToNeighbours_(), nodeToNeighbours, ordered, randomOrder, and updateIndicatrices_().

Here is the call graph for this function:

◆ makeInferenceByOrderedArcs_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceByOrderedArcs_ ( )
protected

Starts the inference with this inference type.

Definition at line 813 of file CNLoopyPropagation_tpl.h.

813 {
814 Size nbrArcs = _bnet_->dag().sizeArcs();
815
817 seq.reserve(nbrArcs);
818
819 for (const auto& arc: _bnet_->arcs()) {
820 seq.push_back(&arc);
821 }
822
824 // validate TestSuite
826
827 do {
828 for (const auto it: seq) {
829 if (_cn_->currentNodeType(it->tail()) == CredalNet< GUM_SCALAR >::NodeType::Indic
830 || _cn_->currentNodeType(it->head()) == CredalNet< GUM_SCALAR >::NodeType::Indic) {
831 continue;
832 }
833
834 msgP_(it->tail(), it->head());
835 msgL_(it->head(), it->tail());
836 }
837
839
841
843 }
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
void msgL_(const NodeId X, const NodeId demanding_parent)
Sends a message to one's parent, i.e.
GUM_SCALAR calculateEpsilon_()
Compute epsilon.
void msgP_(const NodeId X, const NodeId demanding_child)
Sends a message to one's child, i.e.

References _bnet_, _cn_, calculateEpsilon_(), gum::ApproximationScheme::continueApproximationScheme(), gum::credal::CredalNet< GUM_SCALAR >::Indic, msgL_(), msgP_(), and gum::ApproximationScheme::updateApproximationScheme().

Referenced by makeInference().

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

◆ makeInferenceByRandomOrder_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceByRandomOrder_ ( )
protected

Starts the inference with this inference type.

Definition at line 768 of file CNLoopyPropagation_tpl.h.

768 {
769 Size nbrArcs = _bnet_->dag().sizeArcs();
770
772 seq.reserve(nbrArcs);
773
774 for (const auto& arc: _bnet_->arcs()) {
775 seq.push_back(&arc);
776 }
777
779 // validate TestSuite
781
782 do {
783 for (Size j = 0, theEnd = nbrArcs / 2; j < theEnd; j++) {
784 auto w1 = randomValue(nbrArcs);
785 auto w2 = randomValue(nbrArcs);
786
787 if (w1 == w2) { continue; }
788
789 std::swap(seq[w1], seq[w2]);
790 }
791
792 for (const auto it: seq) {
793 if (_cn_->currentNodeType(it->tail()) == CredalNet< GUM_SCALAR >::NodeType::Indic
794 || _cn_->currentNodeType(it->head()) == CredalNet< GUM_SCALAR >::NodeType::Indic) {
795 continue;
796 }
797
798 msgP_(it->tail(), it->head());
799 msgL_(it->head(), it->tail());
800 }
801
803
805
807 }

References _bnet_, _cn_, calculateEpsilon_(), gum::ApproximationScheme::continueApproximationScheme(), gum::credal::CredalNet< GUM_SCALAR >::Indic, msgL_(), msgP_(), gum::randomValue(), and gum::ApproximationScheme::updateApproximationScheme().

Referenced by makeInference().

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

◆ makeInferenceNodeToNeighbours_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceNodeToNeighbours_ ( )
protected

Starts the inference with this inference type.

Definition at line 730 of file CNLoopyPropagation_tpl.h.

730 {
731 const DAG& graphe = _bnet_->dag();
732
734 // to validate TestSuite
736
737 do {
738 for (auto node: active_nodes_set_) {
739 for (auto chil: graphe.children(node)) {
740 if (_cn_->currentNodeType(chil) == CredalNet< GUM_SCALAR >::NodeType::Indic) { continue; }
741
742 msgP_(node, chil);
743 }
744
745 for (auto par: graphe.parents(node)) {
746 if (_cn_->currentNodeType(node) == CredalNet< GUM_SCALAR >::NodeType::Indic) { continue; }
747
748 msgL_(node, par);
749 }
750 }
751
753
755
756 active_nodes_set_.clear();
759
761
762 _infE_::stopApproximationScheme(); // just to be sure of the
763 // approximationScheme has been notified of
764 // the end of looop
765 }
void stopApproximationScheme()
Stop the approximation scheme.

References _bnet_, _cn_, active_nodes_set_, calculateEpsilon_(), gum::ArcGraphPart::children(), gum::ApproximationScheme::continueApproximationScheme(), gum::credal::CredalNet< GUM_SCALAR >::Indic, msgL_(), msgP_(), next_active_nodes_set_, gum::ArcGraphPart::parents(), gum::ApproximationScheme::stopApproximationScheme(), and gum::ApproximationScheme::updateApproximationScheme().

Referenced by makeInference().

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

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

◆ msgL_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::msgL_ ( const NodeId X,
const NodeId demanding_parent )
protected

Sends a message to one's parent, i.e.

X is sending a message to a demanding_parent.

Parameters
XThe constant node id of the node sending the message.
demanding_parentThe constant node id of the node receiving the message.

Definition at line 846 of file CNLoopyPropagation_tpl.h.

846 {
847 NodeSet const& children = _bnet_->children(Y);
848 NodeSet const& parents_ = _bnet_->parents(Y);
849
850 const auto parents = &_bnet_->cpt(Y).variablesSequence();
851
852 if (((children.size() + parents->size() - 1) == 1) && (!_infE_::evidence_.exists(Y))) {
853 return;
854 }
855
856 bool update_l = update_l_[Y];
857 bool update_p = update_p_[Y];
858
859 if (!update_p && !update_l) { return; }
860
861 msg_l_sent_[Y]->insert(X);
862
863 // for future refresh LM/PI
864 if (msg_l_sent_[Y]->size() == parents_.size()) {
865 msg_l_sent_[Y]->clear();
866 update_l_[Y] = false;
867 }
868
869 // refresh LM_part
870 if (update_l) {
871 if (!children.empty() && !_infE_::evidence_.exists(Y)) {
872 GUM_SCALAR lmin = 1.;
873 GUM_SCALAR lmax = 1.;
874
875 for (const NodeId chil: children) {
876 const Arc arc_YC{Y, chil};
878
879 if (ArcsL_max_.exists(arc_YC)) {
881 } else {
883 }
884 }
885
886 lmin = lmax;
887
888 if (lmax != lmax && lmin == lmin) { lmax = lmin; }
889
890 if (lmax != lmax && lmin != lmin) {
891 std::cout << "no likelihood defined [lmin, lmax] (incompatibles "
892 "evidence ?)"
893 << std::endl;
894 }
895
896 if (lmin < 0.) { lmin = 0.; }
897
898 if (lmax < 0.) { lmax = 0.; }
899
900 // no need to update nodeL if evidence since nodeL will never be used
901
902 NodesL_min_[Y] = lmin;
903
904 if (lmin != lmax) {
905 NodesL_max_.set(Y, lmax);
906 } else if (NodesL_max_.exists(Y)) {
907 NodesL_max_.erase(Y);
908 }
909
910 } // end of : node has children & no evidence
911
912 } // end of : if update_l
913
916
917 if (NodesL_max_.exists(Y)) {
918 lmax = NodesL_max_[Y];
919 } else {
920 lmax = lmin;
921 }
922
926
927 const Arc arc_XY{X, Y};
928 if (lmin == lmax && lmin == 1.) {
930
931 if (ArcsL_max_.exists(arc_XY)) { ArcsL_max_.erase(arc_XY); }
932
933 return;
934 }
935
936 // garder pour chaque noeud un table des parents maj, une fois tous maj,
937 // stop
938 // jusque notification msg L ou P
939
940 if (update_p || update_l) {
944
945 Idx pos;
946
947 // +1 from start to avoid counting_ itself
948 // use const iterators with cbegin when available
949 for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd; ++jt) {
950 if (_bnet_->nodeId(**jt) == X) {
951 // retirer la variable courante de la taille
952 pos = parents->pos(*jt) - 1;
953 continue;
954 }
955
956 // compute probability distribution to avoid doing it multiple times
957 // (at each combination of messages)
958 const Arc arc_PY{_bnet_->nodeId(**jt), Y};
960 distri[0] = GUM_SCALAR(1.) - distri[1];
961 msg_p.push_back(distri);
962
963 if (ArcsP_max_.exists(arc_PY)) {
965 distri[0] = GUM_SCALAR(1.) - distri[1];
966 msg_p.push_back(distri);
967 }
968
969 msgs_p.push_back(msg_p);
970 msg_p.clear();
971 }
972
973 GUM_SCALAR min = -2.;
974 GUM_SCALAR max = -2.;
975
977 lx.push_back(lmin);
978
979 if (lmin != lmax) { lx.push_back(lmax); }
980
982
983 if (min == -2. || max == -2.) {
984 if (min != -2.) {
985 max = min;
986 } else if (max != -2.) {
987 min = max;
988 } else {
990 std::cout << "!!!! pas de message L calculable !!!!" << std::endl;
991 return;
992 }
993 }
994
995 if (min < 0.) { min = 0.; }
996
997 if (max < 0.) { max = 0.; }
998
999 bool update = false;
1000
1001 if (min != ArcsL_min_[arc_XY]) {
1003 update = true;
1004 }
1005
1006 if (ArcsL_max_.exists(arc_XY)) {
1007 if (max != ArcsL_max_[arc_XY]) {
1008 if (max != min) {
1010 } else { // if ( max == min )
1011 ArcsL_max_.erase(arc_XY);
1012 }
1013
1014 update = true;
1015 }
1016 } else {
1017 if (max != min) {
1018 ArcsL_max_.insert(arc_XY, max);
1019 update = true;
1020 }
1021 }
1022
1023 if (update) {
1024 update_l_.set(X, true);
1025 next_active_nodes_set_.insert(X);
1026 }
1027
1028 } // end of update_p || update_l
1029 }

References _bnet_, ArcsL_max_, ArcsL_min_, ArcsP_max_, ArcsP_min_, gum::Set< Key >::empty(), enum_combi_(), gum::credal::InferenceEngine< GUM_SCALAR >::evidence_, gum::Set< Key >::insert(), msg_l_sent_, next_active_nodes_set_, NodesL_max_, NodesL_min_, gum::Set< Key >::size(), update_l_, and update_p_.

Referenced by makeInferenceByOrderedArcs_(), makeInferenceByRandomOrder_(), and makeInferenceNodeToNeighbours_().

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

◆ msgP_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::msgP_ ( const NodeId X,
const NodeId demanding_child )
protected

Sends a message to one's child, i.e.

X is sending a message to a demanding_child.

Parameters
XThe constant node id of the node sending the message.
demanding_childThe constant node id of the node receiving the message.

Definition at line 1032 of file CNLoopyPropagation_tpl.h.

1032 {
1033 NodeSet const& children = _bnet_->children(X);
1034
1035 const auto parents = &_bnet_->cpt(X).variablesSequence();
1036
1037 if (((children.size() + parents->size() - 1) == 1) && (!_infE_::evidence_.exists(X))) {
1038 return;
1039 }
1040
1041 // LM_part ---- from all children but one --- the lonely one will get the
1042 // message
1043
1044 const Arc arc_XDC{X, demanding_child};
1045 if (_infE_::evidence_.exists(X)) {
1047
1048 if (ArcsP_max_.exists(arc_XDC)) { ArcsP_max_.erase(arc_XDC); }
1049
1050 return;
1051 }
1052
1053 bool update_l = update_l_[X];
1054 bool update_p = update_p_[X];
1055
1056 if (!update_p && !update_l) { return; }
1057
1058 GUM_SCALAR lmin = 1.;
1059 GUM_SCALAR lmax = 1.;
1060
1061 // use cbegin if available
1062 for (auto chil: children) {
1063 if (chil == demanding_child) { continue; }
1064
1065 const Arc arc_XC{X, chil};
1067
1068 if (ArcsL_max_.exists(arc_XC)) {
1070 } else {
1072 }
1073 }
1074
1075 if (lmin != lmin && lmax == lmax) { lmin = lmax; }
1076
1077 if (lmax != lmax && lmin == lmin) { lmax = lmin; }
1078
1079 if (lmax != lmax && lmin != lmin) {
1080 std::cout << "pas de vraisemblance definie [lmin, lmax] (observations "
1081 "incompatibles ?)"
1082 << std::endl;
1083 return;
1084 }
1085
1086 if (lmin < 0.) { lmin = 0.; }
1087
1088 if (lmax < 0.) { lmax = 0.; }
1089
1090 // refresh PI_part
1092 GUM_SCALAR max = 0.;
1093
1094 if (update_p) {
1098
1099 // +1 from start to avoid counting_ itself
1100 // use const_iterators if available
1101 for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd; ++jt) {
1102 // compute probability distribution to avoid doing it multiple times
1103 // (at each combination of messages)
1104 const Arc arc_PX{_bnet_->nodeId(**jt), X};
1105 distri[1] = ArcsP_min_[arc_PX];
1106 distri[0] = GUM_SCALAR(1.) - distri[1];
1107 msg_p.push_back(distri);
1108
1109 if (ArcsP_max_.exists(arc_PX)) {
1110 distri[1] = ArcsP_max_[arc_PX];
1111 distri[0] = GUM_SCALAR(1.) - distri[1];
1112 msg_p.push_back(distri);
1113 }
1114
1115 msgs_p.push_back(msg_p);
1116 msg_p.clear();
1117 }
1118
1120
1121 if (min < 0.) { min = 0.; }
1122
1123 if (max < 0.) { max = 0.; }
1124
1125 if (min == INF_ || max == INF_) {
1126 std::cout << " ERREUR msg P min = max = INF " << std::endl;
1127 std::cout.flush();
1128 return;
1129 }
1130
1131 NodesP_min_[X] = min;
1132
1133 if (min != max) {
1134 NodesP_max_.set(X, max);
1135 } else if (NodesP_max_.exists(X)) {
1136 NodesP_max_.erase(X);
1137 }
1138
1139 update_p_.set(X, false);
1140
1141 } // end of update_p
1142 else {
1143 min = NodesP_min_[X];
1144
1145 if (NodesP_max_.exists(X)) {
1146 max = NodesP_max_[X];
1147 } else {
1148 max = min;
1149 }
1150 }
1151
1152 if (update_p || update_l) {
1155
1156 // cas limites sur min
1157 if (min == INF_ && lmin == 0.) {
1158 std::cout << "MESSAGE P ERR (negatif) : pi = inf, l = 0" << std::endl;
1159 }
1160
1161 if (lmin == INF_) { // cas infini
1162 msg_p_min = GUM_SCALAR(1.);
1163 } else if (min == 0. || lmin == 0.) {
1164 msg_p_min = 0;
1165 } else {
1166 msg_p_min = GUM_SCALAR(1. / (1. + ((1. / min - 1.) * 1. / lmin)));
1167 }
1168
1169 // cas limites sur max
1170 if (max == INF_ && lmax == 0.) {
1171 std::cout << "MESSAGE P ERR (negatif) : pi = inf, l = 0" << std::endl;
1172 }
1173
1174 if (lmax == INF_) { // cas infini
1175 msg_p_max = GUM_SCALAR(1.);
1176 } else if (max == 0. || lmax == 0.) {
1177 msg_p_max = 0;
1178 } else {
1179 msg_p_max = GUM_SCALAR(1. / (1. + ((1. / max - 1.) * 1. / lmax)));
1180 }
1181
1182 if (msg_p_min != msg_p_min && msg_p_max == msg_p_max) {
1185 std::cout << "msg_p_min is NaN" << std::endl;
1186 }
1187
1188 if (msg_p_max != msg_p_max && msg_p_min == msg_p_min) {
1191 std::cout << "msg_p_max is NaN" << std::endl;
1192 }
1193
1194 if (msg_p_max != msg_p_max && msg_p_min != msg_p_min) {
1196 std::cout << "pas de message P calculable (verifier observations)" << std::endl;
1197 return;
1198 }
1199
1200 if (msg_p_min < 0.) { msg_p_min = 0.; }
1201
1202 if (msg_p_max < 0.) { msg_p_max = 0.; }
1203
1204 bool update = false;
1205
1206 if (msg_p_min != ArcsP_min_[arc_XDC]) {
1208 update = true;
1209 }
1210
1211 if (ArcsP_max_.exists(arc_XDC)) {
1212 if (msg_p_max != ArcsP_max_[arc_XDC]) {
1213 if (msg_p_max != msg_p_min) {
1215 } else { // if ( msg_p_max == msg_p_min )
1216 ArcsP_max_.erase(arc_XDC);
1217 }
1218
1219 update = true;
1220 }
1221 } else {
1222 if (msg_p_max != msg_p_min) {
1223 ArcsP_max_.insert(arc_XDC, msg_p_max);
1224 update = true;
1225 }
1226 }
1227
1228 if (update) {
1229 update_p_.set(demanding_child, true);
1231 }
1232
1233 } // end of : update_l || update_p
1234 }

References _bnet_, ArcsL_max_, ArcsL_min_, ArcsP_max_, ArcsP_min_, enum_combi_(), gum::credal::InferenceEngine< GUM_SCALAR >::evidence_, INF_, next_active_nodes_set_, NodesP_max_, NodesP_min_, gum::Set< Key >::size(), update_l_, and update_p_.

Referenced by makeInferenceByOrderedArcs_(), makeInferenceByRandomOrder_(), makeInferenceNodeToNeighbours_(), and updateIndicatrices_().

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

◆ nbrIterations()

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

Returns the number of iterations.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 170 of file approximationScheme_inl.h.

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

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

Here is the caller graph for this function:

◆ periodSize()

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

Returns the period size.

Returns
Returns the period size.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 156 of file approximationScheme_inl.h.

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

References period_size_.

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

Here is the caller graph for this function:

◆ refreshLMsPIs_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::refreshLMsPIs_ ( bool refreshIndic = false)
protected

Get the last messages from one's parents and children.

Definition at line 1237 of file CNLoopyPropagation_tpl.h.

1237 {
1238 for (auto node: _bnet_->nodes()) {
1239 if ((!refreshIndic)
1240 && _cn_->currentNodeType(node) == CredalNet< GUM_SCALAR >::NodeType::Indic) {
1241 continue;
1242 }
1243
1244 NodeSet const& children = _bnet_->children(node);
1245
1246 auto parents = &_bnet_->cpt(node).variablesSequence();
1247
1248 if (update_l_[node]) {
1249 GUM_SCALAR lmin = 1.;
1250 GUM_SCALAR lmax = 1.;
1251
1252 if (!children.empty() && !_infE_::evidence_.exists(node)) {
1253 for (auto chil: children) {
1254 const Arc arc_NC{node, chil};
1256
1257 if (ArcsL_max_.exists(arc_NC)) {
1259 } else {
1261 }
1262 }
1263
1264 if (lmin != lmin && lmax == lmax) { lmin = lmax; }
1265
1266 lmax = lmin;
1267
1268 if (lmax != lmax && lmin != lmin) {
1269 std::cout << "pas de vraisemblance definie [lmin, lmax] (observations "
1270 "incompatibles ?)"
1271 << std::endl;
1272 return;
1273 }
1274
1275 if (lmin < 0.) { lmin = 0.; }
1276
1277 if (lmax < 0.) { lmax = 0.; }
1278
1280
1281 if (lmin != lmax) {
1282 NodesL_max_.set(node, lmax);
1283 } else if (NodesL_max_.exists(node)) {
1284 NodesL_max_.erase(node);
1285 }
1286 }
1287
1288 } // end of : update_l
1289
1290 if (update_p_[node]) {
1291 if ((parents->size() - 1) > 0 && !_infE_::evidence_.exists(node)) {
1295
1296 // +1 from start to avoid counting_ itself
1297 // cbegin
1298 for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd; ++jt) {
1299 // compute probability distribution to avoid doing it multiple
1300 // times (at each combination of messages)
1301 const Arc arc_PN{_bnet_->nodeId(**jt), node};
1302 distri[1] = ArcsP_min_[arc_PN];
1303 distri[0] = GUM_SCALAR(1.) - distri[1];
1304 msg_p.push_back(distri);
1305
1306 if (ArcsP_max_.exists(arc_PN)) {
1307 distri[1] = ArcsP_max_[arc_PN];
1308 distri[0] = GUM_SCALAR(1.) - distri[1];
1309 msg_p.push_back(distri);
1310 }
1311
1312 msgs_p.push_back(msg_p);
1313 msg_p.clear();
1314 }
1315
1317 GUM_SCALAR max = 0.;
1318
1320
1321 if (min < 0.) { min = 0.; }
1322
1323 if (max < 0.) { max = 0.; }
1324
1325 NodesP_min_[node] = min;
1326
1327 if (min != max) {
1328 NodesP_max_.set(node, max);
1329 } else if (NodesP_max_.exists(node)) {
1330 NodesP_max_.erase(node);
1331 }
1332
1333 update_p_[node] = false;
1334 }
1335 } // end of update_p
1336
1337 } // end of : for each node
1338 }

References _bnet_, _cn_, ArcsL_max_, ArcsL_min_, ArcsP_max_, ArcsP_min_, gum::Set< Key >::empty(), enum_combi_(), gum::credal::InferenceEngine< GUM_SCALAR >::evidence_, gum::credal::CredalNet< GUM_SCALAR >::Indic, INF_, NodesL_max_, NodesL_min_, NodesP_max_, NodesP_min_, update_l_, and update_p_.

Referenced by calculateEpsilon_(), and updateIndicatrices_().

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

◆ remainingBurnIn()

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

Returns the remaining burn in.

Returns
Returns the remaining burn in.

Definition at line 213 of file approximationScheme_inl.h.

213 {
214 if (burn_in_ > current_step_) {
215 return burn_in_ - current_step_;
216 } else {
217 return 0;
218 }
219 }
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:

◆ saveInference()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::saveInference ( std::string_view path)
Deprecated
Use saveMarginals() from InferenceEngine instead. This one is easier to read but harder for scripts to parse.
Parameters
pathThe path to the file to save marginals.

Definition at line 49 of file CNLoopyPropagation_tpl.h.

49 {
50 const std::string spath(path);
51 std::string path_name = spath.substr(0, spath.size() - 4);
52 path_name = path_name + ".res";
53
55
56 if (!res.good()) {
58 "CNLoopyPropagation<GUM_SCALAR>::saveInference(std::"
59 "string & path) : could not open file : "
60 + path_name)
61 }
62
63
64 if (std::string ext = spath.substr(spath.size() - 3, spath.size());
65 std::strcmp(ext.c_str(), "evi") == 0) {
68
69 if (!evi.good()) {
71 "CNLoopyPropagation<GUM_SCALAR>::saveInference(std::"
72 "string & path) : could not open file : "
73 + ext)
74 }
75
76 while (evi.good()) {
78 res << ligne << "\n";
79 }
80
81 evi.close();
82 }
83
84 res << "[RESULTATS]"
85 << "\n";
86
87 for (auto node: _bnet_->nodes()) {
88 // calcul distri posteriori
91
92 // cas evidence, calcul immediat
94 if (_infE_::evidence_[node][1] == 0.) {
95 msg_p_min = 0.;
96 } else if (_infE_::evidence_[node][1] == 1.) {
97 msg_p_min = 1.;
98 }
99
101 }
102 // sinon depuis node P et node L
103 else {
106
107 if (NodesP_max_.exists(node)) {
109 } else {
110 max = min;
111 }
112
115
116 if (NodesL_max_.exists(node)) {
118 } else {
119 lmax = lmin;
120 }
121
122 // cas limites sur min
123 if (min == INF_ && lmin == 0.) {
124 std::cout << "proba ERR (negatif) : pi = inf, l = 0" << std::endl;
125 }
126
127 if (lmin == INF_) { // cas infini
128 msg_p_min = GUM_SCALAR(1.);
129 } else if (min == 0. || lmin == 0.) {
130 msg_p_min = GUM_SCALAR(0.);
131 } else {
132 msg_p_min = GUM_SCALAR(1. / (1. + ((1. / min - 1.) * 1. / lmin)));
133 }
134
135 // cas limites sur max
136 if (max == INF_ && lmax == 0.) {
137 std::cout << "proba ERR (negatif) : pi = inf, l = 0" << std::endl;
138 }
139
140 if (lmax == INF_) { // cas infini
141 msg_p_max = GUM_SCALAR(1.);
142 } else if (max == 0. || lmax == 0.) {
143 msg_p_max = GUM_SCALAR(0.);
144 } else {
145 msg_p_max = GUM_SCALAR(1. / (1. + ((1. / max - 1.) * 1. / lmax)));
146 }
147 }
148
150
152
153 if (msg_p_max != msg_p_max && msg_p_min != msg_p_min) {
155 std::cout << "pas de proba calculable (verifier observations)" << std::endl;
156 }
157
158 res << "P(" << _bnet_->variable(node).name() << " | e) = ";
159
161 res << "(observe)" << std::endl;
162 } else {
163 res << std::endl;
164 }
165
166 res << "\t\t" << _bnet_->variable(node).label(0) << " [ " << (GUM_SCALAR)1. - msg_p_max;
167
168 if (msg_p_min != msg_p_max) {
169 res << ", " << (GUM_SCALAR)1. - msg_p_min << " ] | ";
170 } else {
171 res << " ] | ";
172 }
173
174 res << _bnet_->variable(node).label(1) << " [ " << msg_p_min;
175
176 if (msg_p_min != msg_p_max) {
177 res << ", " << msg_p_max << " ]" << std::endl;
178 } else {
179 res << " ]" << std::endl;
180 }
181 } // end of : for each node
182
183 res.close();
184 }

References _bnet_, gum::credal::InferenceEngine< GUM_SCALAR >::evidence_, GUM_ERROR, INF_, NodesL_max_, NodesL_min_, NodesP_max_, and NodesP_min_.

◆ 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 }
bool storeBNOpt_
Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling.

References storeBNOpt_.

◆ storeBNOpt() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::storeBNOpt ( const bool value)
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 }
double epsilon() const override
Returns the value of epsilon.

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

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

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

◆ updateExpectations_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::InferenceEngine< GUM_SCALAR >::updateExpectations_ ( const NodeId & id,
const std::vector< GUM_SCALAR > & vertex )
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:

◆ updateIndicatrices_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::updateIndicatrices_ ( )
protected

Only update indicatrices variables at the end of computations ( calls msgP_ ).

Definition at line 1442 of file CNLoopyPropagation_tpl.h.

1442 {
1443 for (auto node: _bnet_->nodes()) {
1444 if (_cn_->currentNodeType(node) != CredalNet< GUM_SCALAR >::NodeType::Indic) { continue; }
1445
1446 for (auto pare: _bnet_->parents(node)) {
1447 msgP_(pare, node);
1448 }
1449 }
1450
1451 refreshLMsPIs_(true);
1453 }

References _bnet_, _cn_, gum::credal::CredalNet< GUM_SCALAR >::Indic, msgP_(), refreshLMsPIs_(), and updateMarginals_().

Referenced by makeInference().

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

◆ updateMarginals_()

template<GUM_Numeric GUM_SCALAR>
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::updateMarginals_ ( )
protected

Compute marginals from up-to-date messages.

Definition at line 1341 of file CNLoopyPropagation_tpl.h.

1341 {
1342 for (auto node: _bnet_->nodes()) {
1343 GUM_SCALAR msg_p_min = 1.;
1344 GUM_SCALAR msg_p_max = 0.;
1345
1347 if (_infE_::evidence_[node][1] == 0.) {
1348 msg_p_min = (GUM_SCALAR)0.;
1349 } else if (_infE_::evidence_[node][1] == 1.) {
1350 msg_p_min = 1.;
1351 }
1352
1354 } else {
1357
1358 if (NodesP_max_.exists(node)) {
1359 max = NodesP_max_[node];
1360 } else {
1361 max = min;
1362 }
1363
1366 if (NodesL_max_.exists(node)) {
1368 } else {
1369 lmax = lmin;
1370 }
1371
1372 if (min == INF_ || max == INF_) {
1373 std::cout << " min ou max === INF_ !!!!!!!!!!!!!!!!!!!!!!!!!! " << std::endl;
1374 return;
1375 }
1376
1377 if (min == INF_ && lmin == 0.) {
1378 std::cout << "proba ERR (negatif) : pi = inf, l = 0" << std::endl;
1379 return;
1380 }
1381
1382 if (lmin == INF_) {
1383 msg_p_min = GUM_SCALAR(1.);
1384 } else if (min == 0. || lmin == 0.) {
1385 msg_p_min = GUM_SCALAR(0.);
1386 } else {
1387 msg_p_min = GUM_SCALAR(1. / (1. + ((1. / min - 1.) * 1. / lmin)));
1388 }
1389
1390 if (max == INF_ && lmax == 0.) {
1391 std::cout << "proba ERR (negatif) : pi = inf, l = 0" << std::endl;
1392 return;
1393 }
1394
1395 if (lmax == INF_) {
1396 msg_p_max = GUM_SCALAR(1.);
1397 } else if (max == 0. || lmax == 0.) {
1398 msg_p_max = GUM_SCALAR(0.);
1399 } else {
1400 msg_p_max = GUM_SCALAR(1. / (1. + ((1. / max - 1.) * 1. / lmax)));
1401 }
1402 }
1403
1404 if (msg_p_min != msg_p_min && msg_p_max == msg_p_max) {
1407 std::cout << "msg_p_min is NaN" << std::endl;
1408 }
1409
1410 if (msg_p_max != msg_p_max && msg_p_min == msg_p_min) {
1413 std::cout << "msg_p_max is NaN" << std::endl;
1414 }
1415
1416 if (msg_p_max != msg_p_max && msg_p_min != msg_p_min) {
1418 std::cout << "Please check the observations (no proba can be computed)" << std::endl;
1419 return;
1420 }
1421
1422 if (msg_p_min < 0.) { msg_p_min = 0.; }
1423
1424 if (msg_p_max < 0.) { msg_p_max = 0.; }
1425
1430 }
1431 }

References _bnet_, gum::credal::InferenceEngine< GUM_SCALAR >::evidence_, INF_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax_, gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin_, NodesL_max_, NodesL_min_, NodesP_max_, and NodesP_min_.

Referenced by calculateEpsilon_(), and updateIndicatrices_().

Here is the caller graph for this function:

◆ verbosity()

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

Returns true if verbosity is enabled.

Returns
Returns true if verbosity is enabled.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 161 of file approximationScheme_inl.h.

161{ return verbosity_; }

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

Here is the caller graph for this function:

◆ vertices()

template<GUM_Numeric GUM_SCALAR>
const std::vector< std::vector< GUM_SCALAR > > & gum::credal::InferenceEngine< GUM_SCALAR >::vertices ( const NodeId id) const
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:

Member Data Documentation

◆ _bnet_

◆ _cn_

◆ _inferenceType_

template<GUM_Numeric GUM_SCALAR>
InferenceType gum::credal::CNLoopyPropagation< GUM_SCALAR >::_inferenceType_
private

The chosen inference type.

nodeToNeighbours by Default.

Definition at line 387 of file CNLoopyPropagation.h.

Referenced by CNLoopyPropagation(), inferenceType(), inferenceType(), and makeInference().

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

◆ active_nodes_set_

template<GUM_Numeric GUM_SCALAR>
NodeSet gum::credal::CNLoopyPropagation< GUM_SCALAR >::active_nodes_set_
protected

The current node-set to iterate through at this current step.

Definition at line 345 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), initialize_(), and makeInferenceNodeToNeighbours_().

◆ ArcsL_max_

template<GUM_Numeric GUM_SCALAR>
ArcProperty< GUM_SCALAR > gum::credal::CNLoopyPropagation< GUM_SCALAR >::ArcsL_max_
protected

"Upper" information \( \Lambda \) coming from one's children.

Definition at line 367 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), msgL_(), msgP_(), and refreshLMsPIs_().

◆ ArcsL_min_

template<GUM_Numeric GUM_SCALAR>
ArcProperty< GUM_SCALAR > gum::credal::CNLoopyPropagation< GUM_SCALAR >::ArcsL_min_
protected

"Lower" information \( \Lambda \) coming from one's children.

Definition at line 355 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), initialize_(), msgL_(), msgP_(), and refreshLMsPIs_().

◆ ArcsP_max_

template<GUM_Numeric GUM_SCALAR>
ArcProperty< GUM_SCALAR > gum::credal::CNLoopyPropagation< GUM_SCALAR >::ArcsP_max_
protected

"Upper" information \( \pi \) coming from one's parent.

Definition at line 369 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), initialize_(), msgL_(), msgP_(), and refreshLMsPIs_().

◆ ArcsP_min_

template<GUM_Numeric GUM_SCALAR>
ArcProperty< GUM_SCALAR > gum::credal::CNLoopyPropagation< GUM_SCALAR >::ArcsP_min_
protected

"Lower" information \( \pi \) coming from one's parent.

Definition at line 357 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), initialize_(), msgL_(), msgP_(), and refreshLMsPIs_().

◆ 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

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

◆ inference_up_to_date_

template<GUM_Numeric GUM_SCALAR>
bool gum::credal::CNLoopyPropagation< GUM_SCALAR >::inference_up_to_date_
protected

TRUE if inference has already been performed, FALSE otherwise.

Definition at line 380 of file CNLoopyPropagation.h.

Referenced by CNLoopyPropagation(), ~CNLoopyPropagation(), eraseAllEvidence(), and makeInference().

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

◆ msg_l_sent_

template<GUM_Numeric GUM_SCALAR>
NodeProperty< NodeSet* > gum::credal::CNLoopyPropagation< GUM_SCALAR >::msg_l_sent_
protected

Used to keep track of one's messages sent to it's parents.

Definition at line 352 of file CNLoopyPropagation.h.

Referenced by ~CNLoopyPropagation(), eraseAllEvidence(), initialize_(), and msgL_().

◆ next_active_nodes_set_

template<GUM_Numeric GUM_SCALAR>
NodeSet gum::credal::CNLoopyPropagation< GUM_SCALAR >::next_active_nodes_set_
protected

The next node-set, i.e.

the nodes that will send messages at the next step.

Definition at line 349 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), makeInferenceNodeToNeighbours_(), msgL_(), and msgP_().

◆ NodesL_max_

template<GUM_Numeric GUM_SCALAR>
NodeProperty< GUM_SCALAR > gum::credal::CNLoopyPropagation< GUM_SCALAR >::NodesL_max_
protected

"Upper" node information \( \Lambda \) obtained by combinaison of children messages.

Definition at line 372 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), msgL_(), refreshLMsPIs_(), saveInference(), and updateMarginals_().

◆ NodesL_min_

template<GUM_Numeric GUM_SCALAR>
NodeProperty< GUM_SCALAR > gum::credal::CNLoopyPropagation< GUM_SCALAR >::NodesL_min_
protected

"Lower" node information \( \Lambda \) obtained by combinaison of children messages.

Definition at line 360 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), initialize_(), msgL_(), refreshLMsPIs_(), saveInference(), and updateMarginals_().

◆ NodesP_max_

template<GUM_Numeric GUM_SCALAR>
NodeProperty< GUM_SCALAR > gum::credal::CNLoopyPropagation< GUM_SCALAR >::NodesP_max_
protected

"Upper" node information \( \pi \) obtained by combinaison of parent's messages.

Definition at line 376 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), initialize_(), msgP_(), refreshLMsPIs_(), saveInference(), and updateMarginals_().

◆ NodesP_min_

template<GUM_Numeric GUM_SCALAR>
NodeProperty< GUM_SCALAR > gum::credal::CNLoopyPropagation< GUM_SCALAR >::NodesP_min_
protected

"Lower" node information \( \pi \) obtained by combinaison of parent's messages.

Definition at line 364 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), initialize_(), msgP_(), refreshLMsPIs_(), saveInference(), and updateMarginals_().

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

◆ update_l_

template<GUM_Numeric GUM_SCALAR>
NodeProperty< bool > gum::credal::CNLoopyPropagation< GUM_SCALAR >::update_l_
protected

Used to keep track of which node needs to update it's information coming from it's children.

Definition at line 342 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), initialize_(), msgL_(), msgP_(), and refreshLMsPIs_().

◆ update_p_

template<GUM_Numeric GUM_SCALAR>
NodeProperty< bool > gum::credal::CNLoopyPropagation< GUM_SCALAR >::update_p_
protected

Used to keep track of which node needs to update it's information coming from it's parents.

Definition at line 338 of file CNLoopyPropagation.h.

Referenced by eraseAllEvidence(), initialize_(), msgL_(), msgP_(), and refreshLMsPIs_().

◆ verbosity_

bool gum::ApproximationScheme::verbosity_
protectedinherited

If true, verbosity is enabled.

Definition at line 470 of file approximationScheme.h.

Referenced by ApproximationScheme(), and setVerbosity().


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