aGrUM 3.2.0
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

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.

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_
 Current epsilon.
double last_epsilon_
 Last epsilon value.
double current_rate_
 Current rate.
Size current_step_
 The current step.
Timer timer_
 The timer.
ApproximationSchemeSTATE current_state_
 The current state.
std::vector< 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 1197 of file inferenceEngine_tpl.h.

1197 {
1198 const auto id = this->credalNet_->current_bn().idFromName(pot.variable(0).name());
1199 std::vector< GUM_SCALAR > vals(this->credalNet_->current_bn().variable(id).domainSize(), 0);
1201 for (I.setFirst(); !I.end(); I.inc()) {
1202 vals[I.val(0)] = pot[I];
1203 }
1204 addEvidence(id, vals);
1205 }
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 1164 of file inferenceEngine_tpl.h.

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

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

1155 {
1156 evidence_.insert(id, vals);
1157 // forces the computation of the begin iterator to avoid subsequent data races
1158 // @TODO make HashTableConstIterator constructors thread safe
1159 evidence_.begin();
1160 }
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 1178 of file inferenceEngine_tpl.h.

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

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

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

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

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

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

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

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

979 {
980 // compute the number of threads and prepare for the result
982 ? this->threadRanges_.size() - 1
983 : 1; // no nested multithreading
985
986 // create the function to be executed by the threads
987 auto threadedEps = [this, &tEps](const std::size_t this_thread,
990 auto& this_tEps = tEps[this_thread];
992
993 // below, we will loop over indices i and j of marginalMin_ and
994 // marginalMax_. Index i represents nodes and j allow to parse their
995 // domain. To parse all the domains of all the nodes, we should theorically
996 // use 2 loops. However, here, we will use one loop: we start with node i
997 // and parse its domain with index j. When this is done, we move to the
998 // next node, and so on. The underlying idea is that, by doing so, we
999 // need not parse in this function the whole domain of a node: we can start
1000 // the loop at a given value of node i and complete the loop on another
1001 // value of another node. These values are computed in Vector threadRanges_
1002 // by Method dispatchMarginalsToThreads_(), which dispatches the loops
1003 // among threads
1004 auto i = ranges[this_thread].first;
1005 auto j = ranges[this_thread].second;
1006 auto domain_size = this->marginalMax_[i].size();
1007 const auto end_i = ranges[this_thread + 1].first;
1008 auto end_j = ranges[this_thread + 1].second;
1009 const auto marginalMax_size = this->marginalMax_.size();
1010
1011 while ((i < end_i) || (j < end_j)) {
1012 // on min
1014 delta = (delta < 0) ? (-delta) : delta;
1016
1017 // on max
1019 delta = (delta < 0) ? (-delta) : delta;
1021
1024
1025 if (++j == domain_size) {
1026 j = 0;
1027 ++i;
1028 if (i < marginalMax_size) domain_size = this->marginalMax_[i].size();
1029 }
1030 }
1031 };
1032
1033 // launch the threads
1035 nb_threads,
1037 (nb_threads == 1)
1038 ? std::vector< std::pair< NodeId, Idx > >{{0, 0}, {this->marginalMin_.size(), 0}}
1039 : this->threadRanges_);
1040
1041 // aggregate all the results
1042 GUM_SCALAR eps = tEps[0];
1043 for (const auto nb: tEps)
1044 if (eps < nb) eps = nb;
1045
1046 return eps;
1047 }
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 69 of file approximationScheme.cpp.

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

82 {
83 return *credalNet_;
84 }

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

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

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

1094 {
1095 // we compute the number of elements in the 2 loops (over i,j in marginalMin_[i][j])
1096 Size nb_elements = 0;
1097 const auto marginalMin_size = this->marginalMin_.size();
1098 for (const auto& marg_i: this->marginalMin_)
1099 nb_elements += marg_i.second.size();
1100
1101 // distribute evenly the elements among the threads
1104
1105 // the result that we return is a vector of pairs (NodeId, Idx). For thread number i, the
1106 // pair at index i is the beginning of the range that the thread will have to process: this
1107 // is the part of the marginal distribution vector of node NodeId starting at index Idx.
1108 // The pair at index i+1 is the end of this range (not included)
1109 threadRanges_.clear();
1110 threadRanges_.reserve(nb_threads + 1);
1111
1112 // try to balance the number of elements among the threads
1115
1116 NodeId current_node = 0;
1118 Size current_domain_size = this->marginalMin_[0].size();
1120
1121 for (Idx i = Idx(0); i < nb_threads; ++i) {
1122 // compute the end of the threads, assuming that the current node has a domain
1123 // sufficiently large
1125 if (rest_elts != Idx(0)) {
1127 --rest_elts;
1128 }
1129
1130 // if the current node is not sufficient to hold all the elements that
1131 // the current thread should process. So we should add elements of the
1132 // next nodes
1135 ++current_node;
1139 }
1140 }
1141
1142 // now we can store the range if elements
1144
1145 // compute the next begin_node
1147 ++current_node;
1149 }
1150 }
1151 }
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 702 of file inferenceEngine_tpl.h.

702 {
704 }
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 707 of file inferenceEngine_tpl.h.

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

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

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

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

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

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

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

Returns the value of epsilon.

Returns
Returns the value of epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 72 of file approximationScheme_inl.h.

72{ return eps_; }

References eps_.

Referenced by gum::learning::IBNLearner::EMEpsilon(), gum::learning::IBNLearner::epsilon(), gum::ImportanceSampling< GUM_SCALAR >::onContextualize_(), and gum::ImportanceSampling< GUM_SCALAR >::unsharpenBN_().

Here is the caller graph for this function:

◆ eraseAllEvidence()

template<GUM_Numeric GUM_SCALAR>
void gum::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 473 of file inferenceEngine_tpl.h.

473 {
474 return expectationMax_[id];
475 }

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

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

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

468 {
469 return expectationMin_[id];
470 }

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

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

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

1208 {
1209 return this->messageApproximationScheme();
1210 }

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

968 {
969 return t0_;
970 }
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 974 of file inferenceEngine_tpl.h.

974 {
975 return t1_;
976 }
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 164 of file inferenceEngine_tpl.h.

164 {
165 return &dbnOpt_;
166 }
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, stateApproximationScheme(), and gum::IApproximationSchemeConfiguration::Undefined.

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 ApproximationScheme(), gum::IApproximationSchemeConfiguration::Continue, current_state_, current_step_, and initApproximationScheme().

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

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

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

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

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

644 {
645 marginalMin_.clear();
646 marginalMax_.clear();
647 oldMarginalMin_.clear();
648 oldMarginalMax_.clear();
649
650 for (auto node: credalNet_->current_bn().nodes()) {
651 auto dSize = credalNet_->current_bn().variable(node).domainSize();
654
657 }
658
659 // now that we know the sizes of marginalMin_ and marginalMax_, we can
660 // dispatch their processes to the threads
662 }
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 665 of file inferenceEngine_tpl.h.

665 {
666 marginalSets_.clear();
667
668 if (!storeVertices_) return;
669
670 for (auto node: credalNet_->current_bn().nodes())
672 }
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 268 of file inferenceEngine_tpl.h.

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

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

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

References credalNet_, and 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 216 of file inferenceEngine_tpl.h.

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

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

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

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

References query_.

Referenced by makeInference().

Here is the caller graph for this function:

◆ insertQueryFile()

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

Insert query variables states from file.

Parameters
pathThe path to the query file.

Definition at line 358 of file inferenceEngine_tpl.h.

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

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

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

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

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

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

435 {
436 return marginalMax(credalNet_->current_bn().idFromName(varName));
437 }
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 440 of file inferenceEngine_tpl.h.

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

References credalNet_, and marginalMin_.

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

429 {
430 return marginalMin(credalNet_->current_bn().idFromName(varName));
431 }
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 }

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

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

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

◆ periodSize()

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

Returns the period size.

Returns
Returns the period size.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 156 of file approximationScheme_inl.h.

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

References period_size_.

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

Here is the caller graph for this function:

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

References burn_in_, and current_step_.

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

143 {
144 return repetitiveInd_;
145 }
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 763 of file inferenceEngine_tpl.h.

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

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

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

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

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

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

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

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::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::MCBNDistance< GUM_SCALAR >::MCBNDistance(), gum::MCBNDistance< GUM_SCALAR >::MCBNDistance(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), gum::learning::IBNLearner::EMsetMaxIter(), 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::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::MCBNDistance< GUM_SCALAR >::MCBNDistance(), gum::MCBNDistance< GUM_SCALAR >::MCBNDistance(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), gum::learning::IBNLearner::EMsetMaxTime(), 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::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsSampling< GUM_SCALAR >::GibbsSampling(), gum::MCBNDistance< GUM_SCALAR >::MCBNDistance(), gum::MCBNDistance< GUM_SCALAR >::MCBNDistance(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), 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.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::MCBNDistance< GUM_SCALAR >::MCBNDistance(), gum::MCBNDistance< GUM_SCALAR >::MCBNDistance(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), gum::learning::IBNLearner::EMsetPeriodSize(), 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 134 of file inferenceEngine_tpl.h.

134 {
137
138 // do not compute clusters more than once
140 }
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::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::MCBNDistance< GUM_SCALAR >::MCBNDistance(), gum::MCBNDistance< GUM_SCALAR >::MCBNDistance(), gum::SamplingInference< GUM_SCALAR >::SamplingInference(), gum::learning::IBNLearner::EMsetVerbosity(), and gum::learning::IBNLearner::setVerbosity().

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

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

159 {
160 return storeBNOpt_;
161 }
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 122 of file inferenceEngine_tpl.h.

122 {
124 }

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

154 {
155 return storeVertices_;
156 }

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

127 {
129
131 }
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 585 of file inferenceEngine_tpl.h.

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

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

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

References marginalSets_.

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

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

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

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

References verbosity_.

Referenced by ApproximationScheme(), gum::learning::EMApproximationScheme::EMApproximationScheme(), continueApproximationScheme(), gum::learning::IBNLearner::EMVerbosity(), 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 513 of file inferenceEngine_tpl.h.

513 {
514 return marginalSets_[id];
515 }

References marginalSets_.

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

Current epsilon.

Definition at line 378 of file approximationScheme.h.

Referenced by continueApproximationScheme().

◆ current_rate_

double gum::ApproximationScheme::current_rate_
protectedinherited

Current rate.

Definition at line 384 of file approximationScheme.h.

Referenced by continueApproximationScheme().

◆ current_state_

ApproximationSchemeSTATE gum::ApproximationScheme::current_state_
protectedinherited

The current state.

Definition at line 393 of file approximationScheme.h.

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

◆ current_step_

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

◆ enabled_eps_

bool gum::ApproximationScheme::enabled_eps_
protectedinherited

If true, the threshold convergence is enabled.

Definition at line 402 of file approximationScheme.h.

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

◆ enabled_max_iter_

bool gum::ApproximationScheme::enabled_max_iter_
protectedinherited

If true, the maximum iterations stopping criterion is enabled.

Definition at line 420 of file approximationScheme.h.

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

◆ enabled_max_time_

bool gum::ApproximationScheme::enabled_max_time_
protectedinherited

If true, the timeout is enabled.

Definition at line 414 of file approximationScheme.h.

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

◆ enabled_min_rate_eps_

bool gum::ApproximationScheme::enabled_min_rate_eps_
protectedinherited

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

Definition at line 408 of file approximationScheme.h.

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

◆ eps_

double gum::ApproximationScheme::eps_
protectedinherited

Threshold for convergence.

Definition at line 399 of file approximationScheme.h.

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

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

Referenced by continueApproximationScheme().

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

Last epsilon value.

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

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

◆ max_time_

double gum::ApproximationScheme::max_time_
protectedinherited

The timeout.

Definition at line 411 of file approximationScheme.h.

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

◆ min_rate_eps_

double gum::ApproximationScheme::min_rate_eps_
protectedinherited

Threshold for the epsilon rate.

Definition at line 405 of file approximationScheme.h.

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

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

Referenced by ApproximationScheme(), and periodSize().

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

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

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


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