aGrUM  0.20.3
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 >:
+ Collaboration diagram for gum::credal::CNLoopyPropagation< GUM_SCALAR >:

Public Attributes

Signaler3< Size, double, doubleonProgress
 Progression, error and time. More...
 
Signaler1< std::string > onStop
 Criteria messageApproximationScheme. More...
 

Public Member Functions

virtual void insertEvidenceFile (const std::string &path)
 Insert evidence from file. More...
 
Public algorithm methods
void makeInference ()
 Starts the inference. More...
 
Getters and setters
void inferenceType (InferenceType inft)
 Set the inference type. More...
 
InferenceType inferenceType ()
 Get the inference type. More...
 
Post-inference methods
void eraseAllEvidence ()
 Erase all inference related data to perform another one. More...
 
void saveInference (const std::string &path)
 
Constructors / Destructors
 CNLoopyPropagation (const CredalNet< GUM_SCALAR > &cnet)
 Constructor. More...
 
virtual ~CNLoopyPropagation ()
 Destructor. More...
 
Getters and setters
VarMod2BNsMap< GUM_SCALAR > * getVarMod2BNsMap ()
 Get optimum IBayesNet. More...
 
const CredalNet< GUM_SCALAR > & credalNet () const
 Get this creadal network. More...
 
const NodeProperty< std::vector< NodeId > > & getT0Cluster () const
 Get the t0_ cluster. More...
 
const NodeProperty< std::vector< NodeId > > & getT1Cluster () const
 Get the t1_ cluster. More...
 
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. More...
 
void storeBNOpt (const bool value)
 
bool storeBNOpt () const
 
bool repetitiveInd () const
 Get the current independence status. More...
 
Pre-inference initialization methods
void insertModalsFile (const std::string &path)
 Insert variables modalities from file to compute expectations. More...
 
void insertModals (const std::map< std::string, std::vector< GUM_SCALAR > > &modals)
 Insert variables modalities from map to compute expectations. More...
 
void insertEvidence (const std::map< std::string, std::vector< GUM_SCALAR > > &eviMap)
 Insert evidence from map. More...
 
void insertEvidence (const NodeProperty< std::vector< GUM_SCALAR > > &evidence)
 Insert evidence from Property. More...
 
void insertQueryFile (const std::string &path)
 Insert query variables states from file. More...
 
void insertQuery (const NodeProperty< std::vector< bool > > &query)
 Insert query variables and states from Property. More...
 
Post-inference methods
Potential< GUM_SCALAR > marginalMin (const NodeId id) const
 Get the lower marginals of a given node id. More...
 
Potential< GUM_SCALAR > marginalMin (const std::string &varName) const
 Get the lower marginals of a given variable name. More...
 
Potential< GUM_SCALAR > marginalMax (const NodeId id) const
 Get the upper marginals of a given node id. More...
 
Potential< GUM_SCALAR > marginalMax (const std::string &varName) const
 Get the upper marginals of a given variable name. More...
 
const GUM_SCALAR & expectationMin (const NodeId id) const
 Get the lower expectation of a given node id. More...
 
const GUM_SCALAR & expectationMin (const std::string &varName) const
 Get the lower expectation of a given variable name. More...
 
const GUM_SCALAR & expectationMax (const NodeId id) const
 Get the upper expectation of a given node id. More...
 
const GUM_SCALAR & expectationMax (const std::string &varName) const
 Get the upper expectation of a given variable name. More...
 
const std::vector< GUM_SCALAR > & dynamicExpMin (const std::string &varName) const
 Get the lower dynamic expectation of a given variable prefix (without the time step included, i.e. More...
 
const std::vector< GUM_SCALAR > & dynamicExpMax (const std::string &varName) const
 Get the upper dynamic expectation of a given variable prefix (without the time step included, i.e. More...
 
const std::vector< std::vector< GUM_SCALAR > > & vertices (const NodeId id) const
 Get the vertice of a given node id. More...
 
void saveMarginals (const std::string &path) const
 Saves marginals to file. More...
 
void saveExpectations (const std::string &path) const
 Saves expectations to file. More...
 
void saveVertices (const std::string &path) const
 Saves vertices to file. More...
 
void dynamicExpectations ()
 Compute dynamic expectations. More...
 
std::string toString () const
 Print all nodes marginals to standart output. More...
 
const std::string getApproximationSchemeMsg ()
 Get approximation scheme state. More...
 
Getters and setters
void setEpsilon (double eps)
 Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|. More...
 
double epsilon () const
 Returns the value of epsilon. More...
 
void disableEpsilon ()
 Disable stopping criterion on epsilon. More...
 
void enableEpsilon ()
 Enable stopping criterion on epsilon. More...
 
bool isEnabledEpsilon () const
 Returns true if stopping criterion on epsilon is enabled, false otherwise. More...
 
void setMinEpsilonRate (double rate)
 Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|). More...
 
double minEpsilonRate () const
 Returns the value of the minimal epsilon rate. More...
 
void disableMinEpsilonRate ()
 Disable stopping criterion on epsilon rate. More...
 
void enableMinEpsilonRate ()
 Enable stopping criterion on epsilon rate. More...
 
bool isEnabledMinEpsilonRate () const
 Returns true if stopping criterion on epsilon rate is enabled, false otherwise. More...
 
void setMaxIter (Size max)
 Stopping criterion on number of iterations. More...
 
Size maxIter () const
 Returns the criterion on number of iterations. More...
 
void disableMaxIter ()
 Disable stopping criterion on max iterations. More...
 
void enableMaxIter ()
 Enable stopping criterion on max iterations. More...
 
bool isEnabledMaxIter () const
 Returns true if stopping criterion on max iterations is enabled, false otherwise. More...
 
void setMaxTime (double timeout)
 Stopping criterion on timeout. More...
 
double maxTime () const
 Returns the timeout (in seconds). More...
 
double currentTime () const
 Returns the current running time in second. More...
 
void disableMaxTime ()
 Disable stopping criterion on timeout. More...
 
void enableMaxTime ()
 Enable stopping criterion on timeout. More...
 
bool isEnabledMaxTime () const
 Returns true if stopping criterion on timeout is enabled, false otherwise. More...
 
void setPeriodSize (Size p)
 How many samples between two stopping is enable. More...
 
Size periodSize () const
 Returns the period size. More...
 
void setVerbosity (bool v)
 Set the verbosity on (true) or off (false). More...
 
bool verbosity () const
 Returns true if verbosity is enabled. More...
 
ApproximationSchemeSTATE stateApproximationScheme () const
 Returns the approximation scheme state. More...
 
Size nbrIterations () const
 Returns the number of iterations. More...
 
const std::vector< double > & history () const
 Returns the scheme history. More...
 
void initApproximationScheme ()
 Initialise the scheme. More...
 
bool startOfPeriod ()
 Returns true if we are at the beginning of a period (compute error is mandatory). More...
 
void updateApproximationScheme (unsigned int incr=1)
 Update the scheme w.r.t the new error and increment steps. More...
 
Size remainingBurnIn ()
 Returns the remaining burn in. More...
 
void stopApproximationScheme ()
 Stop the approximation scheme. More...
 
bool continueApproximationScheme (double error)
 Update the scheme w.r.t the new error. More...
 
Getters and setters
std::string messageApproximationScheme () const
 Returns the approximation scheme message. More...
 

Public Types

enum  InferenceType : char { InferenceType::nodeToNeighbours, InferenceType::ordered, InferenceType::randomOrder }
 Inference type to be used by the algorithm. More...
 
using msg = std::vector< Potential< GUM_SCALAR > *>
 
using cArcP = const Arc *
 
enum  ApproximationSchemeSTATE : char {
  ApproximationSchemeSTATE::Undefined, ApproximationSchemeSTATE::Continue, ApproximationSchemeSTATE::Epsilon, ApproximationSchemeSTATE::Rate,
  ApproximationSchemeSTATE::Limit, ApproximationSchemeSTATE::TimeLimit, ApproximationSchemeSTATE::Stopped
}
 The different state of an approximation scheme. More...
 

Protected Attributes

NodeProperty< boolupdate_p_
 Used to keep track of which node needs to update it's information coming from it's parents. More...
 
NodeProperty< boolupdate_l_
 Used to keep track of which node needs to update it's information coming from it's children. More...
 
NodeSet active_nodes_set
 The current node-set to iterate through at this current step. More...
 
NodeSet next_active_nodes_set
 The next node-set, i.e. More...
 
NodeProperty< NodeSet *> msg_l_sent_
 Used to keep track of one's messages sent to it's parents. More...
 
ArcProperty< GUM_SCALAR > ArcsL_min_
 "Lower" information \( \Lambda \) coming from one's children. More...
 
ArcProperty< GUM_SCALAR > ArcsP_min_
 "Lower" information \( \pi \) coming from one's parent. More...
 
NodeProperty< GUM_SCALAR > NodesL_min_
 "Lower" node information \( \Lambda \) obtained by combinaison of children messages. More...
 
NodeProperty< GUM_SCALAR > NodesP_min_
 "Lower" node information \( \pi \) obtained by combinaison of parent's messages. More...
 
ArcProperty< GUM_SCALAR > ArcsL_max_
 "Upper" information \( \Lambda \) coming from one's children. More...
 
ArcProperty< GUM_SCALAR > ArcsP_max_
 "Upper" information \( \pi \) coming from one's parent. More...
 
NodeProperty< GUM_SCALAR > NodesL_max_
 "Upper" node information \( \Lambda \) obtained by combinaison of children messages. More...
 
NodeProperty< GUM_SCALAR > NodesP_max_
 "Upper" node information \( \pi \) obtained by combinaison of parent's messages. More...
 
bool InferenceUpToDate_
 TRUE if inference has already been performed, FALSE otherwise. More...
 
const CredalNet< GUM_SCALAR > * credalNet_
 A pointer to the Credal Net used. More...
 
margi oldMarginalMin_
 Old lower marginals used to compute epsilon. More...
 
margi oldMarginalMax_
 Old upper marginals used to compute epsilon. More...
 
margi marginalMin_
 Lower marginals. More...
 
margi marginalMax_
 Upper marginals. More...
 
credalSet marginalSets_
 Credal sets vertices, if enabled. More...
 
expe expectationMin_
 Lower expectations, if some variables modalities were inserted. More...
 
expe expectationMax_
 Upper expectations, if some variables modalities were inserted. More...
 
dynExpe dynamicExpMin_
 Lower dynamic expectations. More...
 
dynExpe dynamicExpMax_
 Upper dynamic expectations. More...
 
dynExpe modal_
 Variables modalities used to compute expectations. More...
 
margi evidence_
 Holds observed variables states. More...
 
query query_
 Holds the query nodes states. More...
 
cluster t0_
 Clusters of nodes used with dynamic networks. More...
 
cluster t1_
 Clusters of nodes used with dynamic networks. More...
 
bool storeVertices_
 True if credal sets vertices are stored, False otherwise. More...
 
bool repetitiveInd_
 True if using repetitive independence ( dynamic network only ), False otherwise. More...
 
bool storeBNOpt_
 Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling. More...
 
VarMod2BNsMap< GUM_SCALAR > dbnOpt_
 Object used to efficiently store optimal bayes net during inference, for some algorithms. More...
 
int timeSteps_
 The number of time steps of this network (only usefull for dynamic networks). More...
 
double current_epsilon_
 Current epsilon. More...
 
double last_epsilon_
 Last epsilon value. More...
 
double current_rate_
 Current rate. More...
 
Size current_step_
 The current step. More...
 
Timer timer_
 The timer. More...
 
ApproximationSchemeSTATE current_state_
 The current state. More...
 
std::vector< doublehistory_
 The scheme history, used only if verbosity == true. More...
 
double eps_
 Threshold for convergence. More...
 
bool enabled_eps_
 If true, the threshold convergence is enabled. More...
 
double min_rate_eps_
 Threshold for the epsilon rate. More...
 
bool enabled_min_rate_eps_
 If true, the minimal threshold for epsilon rate is enabled. More...
 
double max_time_
 The timeout. More...
 
bool enabled_max_time_
 If true, the timeout is enabled. More...
 
Size max_iter_
 The maximum iterations. More...
 
bool enabled_max_iter_
 If true, the maximum iterations stopping criterion is enabled. More...
 
Size burn_in_
 Number of iterations before checking stopping criteria. More...
 
Size period_size_
 Checking criteria frequency. More...
 
bool verbosity_
 If true, verbosity is enabled. More...
 

Protected Member Functions

Protected initialization methods
void initialize_ ()
 Topological forward propagation to initialize old marginals & messages. More...
 
Protected algorithm methods
void makeInferenceNodeToNeighbours_ ()
 Starts the inference with this inference type. More...
 
void makeInferenceByOrderedArcs_ ()
 Starts the inference with this inference type. More...
 
void makeInferenceByRandomOrder_ ()
 Starts the inference with this inference type. More...
 
void updateMarginals_ ()
 Compute marginals from up-to-date messages. More...
 
void msgL_ (const NodeId X, const NodeId demanding_parent)
 Sends a message to one's parent, i.e. More...
 
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_. More...
 
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_. More...
 
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_. More...
 
void msgP_ (const NodeId X, const NodeId demanding_child)
 Sends a message to one's child, i.e. More...
 
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_. More...
 
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_. More...
 
void refreshLMsPIs_ (bool refreshIndic=false)
 Get the last messages from one's parents and children. More...
 
GUM_SCALAR calculateEpsilon_ ()
 Compute epsilon. More...
 
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. More...
 
void updateIndicatrices_ ()
 Only update indicatrices variables at the end of computations ( calls msgP_ ). More...
 
Protected initialization methods
void repetitiveInit_ ()
 Initialize t0_ and t1_ clusters. More...
 
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. More...
 
void initMarginals_ ()
 Initialize lower and upper old marginals and marginals before inference, with the lower marginal being 1 and the upper 0. More...
 
void initMarginalSets_ ()
 Initialize credal set vertices with empty sets. More...
 
Protected algorithms methods
const GUM_SCALAR computeEpsilon_ ()
 Compute approximation scheme epsilon using the old marginals and the new ones. More...
 
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. More...
 
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. More...
 
Proptected post-inference methods
void dynamicExpectations_ ()
 Rearrange lower and upper expectations to suit dynamic networks. More...
 

Detailed Description

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

Definition at line 57 of file CNLoopyPropagation.h.

Member Typedef Documentation

◆ _infE_

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

To easily access InferenceEngine< GUM_SCALAR > methods.

Definition at line 365 of file CNLoopyPropagation.h.

◆ cArcP

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

Definition at line 60 of file CNLoopyPropagation.h.

◆ msg

template<typename GUM_SCALAR >
using gum::credal::CNLoopyPropagation< GUM_SCALAR >::msg = std::vector< Potential< GUM_SCALAR >* >

Definition at line 59 of file CNLoopyPropagation.h.

Member Enumeration Documentation

◆ ApproximationSchemeSTATE

The different state of an approximation scheme.

Enumerator
Undefined 
Continue 
Epsilon 
Rate 
Limit 
TimeLimit 
Stopped 

Definition at line 64 of file IApproximationSchemeConfiguration.h.

64  : char
65  {
66  Undefined,
67  Continue,
68  Epsilon,
69  Rate,
70  Limit,
71  TimeLimit,
72  Stopped
73  };

◆ InferenceType

template<typename GUM_SCALAR >
enum 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 65 of file CNLoopyPropagation.h.

65  : char
66  {
67  nodeToNeighbours,
72  ordered,
78  randomOrder
82  };

Constructor & Destructor Documentation

◆ CNLoopyPropagation()

template<typename GUM_SCALAR >
gum::credal::CNLoopyPropagation< GUM_SCALAR >::CNLoopyPropagation ( const CredalNet< GUM_SCALAR > &  cnet)
explicit

Constructor.

Parameters
cnetThe CredalNet to be used with this algorithm.

Definition at line 1466 of file CNLoopyPropagation_tpl.h.

1466  :
1468  if (!cnet.isSeparatelySpecified()) {
1469  GUM_ERROR(OperationNotAllowed,
1470  "CNLoopyPropagation is only available "
1471  "with separately specified nets");
1472  }
1473 
1474  // test for binary cn
1475  for (auto node: cnet.current_bn().nodes())
1476  if (cnet.current_bn().variable(node).domainSize() != 2) {
1477  GUM_ERROR(OperationNotAllowed,
1478  "CNLoopyPropagation is only available "
1479  "with binary credal networks");
1480  }
1481 
1482  // test if compute CPTMinMax has been called
1483  if (!cnet.hasComputedBinaryCPTMinMax()) {
1484  GUM_ERROR(OperationNotAllowed,
1485  "CNLoopyPropagation only works when "
1486  "\"computeBinaryCPTMinMax()\" has been called for "
1487  "this credal net");
1488  }
1489 
1490  _cn_ = &cnet;
1491  _bnet_ = &cnet.current_bn();
1492 
1494  InferenceUpToDate_ = false;
1495 
1496  GUM_CONSTRUCTOR(CNLoopyPropagation);
1497  }
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
InferenceType _inferenceType_
The choosen inference type.
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.
CNLoopyPropagation(const CredalNet< GUM_SCALAR > &cnet)
Constructor.
bool InferenceUpToDate_
TRUE if inference has already been performed, FALSE otherwise.
Uses a node-set so we don&#39;t iterate on nodes that can&#39;t send a new message.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ ~CNLoopyPropagation()

template<typename GUM_SCALAR >
gum::credal::CNLoopyPropagation< GUM_SCALAR >::~CNLoopyPropagation ( )
virtual

Destructor.

Definition at line 1500 of file CNLoopyPropagation_tpl.h.

1500  {
1501  InferenceUpToDate_ = false;
1502 
1503  if (msg_l_sent_.size() > 0) {
1504  for (auto node: _bnet_->nodes()) {
1505  delete msg_l_sent_[node];
1506  }
1507  }
1508 
1509  //_msg_l_sent.clear();
1510  //_update_l.clear();
1511  //_update_p.clear();
1512 
1513  GUM_DESTRUCTOR(CNLoopyPropagation);
1514  }
NodeProperty< NodeSet *> msg_l_sent_
Used to keep track of one&#39;s messages sent to it&#39;s parents.
CNLoopyPropagation(const CredalNet< GUM_SCALAR > &cnet)
Constructor.
bool InferenceUpToDate_
TRUE if inference has already been performed, FALSE otherwise.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.

Member Function Documentation

◆ calculateEpsilon_()

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

Compute epsilon.

Returns
Epsilon.

Definition at line 1419 of file CNLoopyPropagation_tpl.h.

1419  {
1420  refreshLMsPIs_();
1421  updateMarginals_();
1422 
1423  return _infE_::computeEpsilon_();
1424  }
void refreshLMsPIs_(bool refreshIndic=false)
Get the last messages from one&#39;s parents and children.
const GUM_SCALAR computeEpsilon_()
Compute approximation scheme epsilon using the old marginals and the new ones.
void updateMarginals_()
Compute marginals from up-to-date messages.

◆ compute_ext_() [1/3]

template<typename 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 174 of file CNLoopyPropagation_tpl.h.

180  {
181  GUM_SCALAR num_min_tmp = 1.;
182  GUM_SCALAR den_min_tmp = 1.;
183  GUM_SCALAR num_max_tmp = 1.;
184  GUM_SCALAR den_max_tmp = 1.;
185 
186  GUM_SCALAR res_min = 1.0, res_max = 0.0;
187 
188  auto lsize = lx.size();
189 
190  for (decltype(lsize) i = 0; i < lsize; i++) {
191  bool non_defini_min = false;
192  bool non_defini_max = false;
193 
194  if (lx[i] == INF_) {
195  num_min_tmp = num_min;
196  den_min_tmp = den_max;
197  num_max_tmp = num_max;
198  den_max_tmp = den_min;
199  } else if (lx[i] == (GUM_SCALAR)1.) {
200  num_min_tmp = GUM_SCALAR(1.);
201  den_min_tmp = GUM_SCALAR(1.);
202  num_max_tmp = GUM_SCALAR(1.);
203  den_max_tmp = GUM_SCALAR(1.);
204  } else if (lx[i] > (GUM_SCALAR)1.) {
205  GUM_SCALAR li = GUM_SCALAR(1.) / (lx[i] - GUM_SCALAR(1.));
206  num_min_tmp = num_min + li;
207  den_min_tmp = den_max + li;
208  num_max_tmp = num_max + li;
209  den_max_tmp = den_min + li;
210  } else if (lx[i] < (GUM_SCALAR)1.) {
211  GUM_SCALAR li = GUM_SCALAR(1.) / (lx[i] - GUM_SCALAR(1.));
212  num_min_tmp = num_max + li;
213  den_min_tmp = den_min + li;
214  num_max_tmp = num_min + li;
215  den_max_tmp = den_max + li;
216  }
217 
218  if (den_min_tmp == 0. && num_min_tmp == 0.) {
219  non_defini_min = true;
220  } else if (den_min_tmp == 0. && num_min_tmp != 0.) {
221  res_min = INF_;
222  } else if (den_min_tmp != INF_ || num_min_tmp != INF_) {
223  res_min = num_min_tmp / den_min_tmp;
224  }
225 
226  if (den_max_tmp == 0. && num_max_tmp == 0.) {
227  non_defini_max = true;
228  } else if (den_max_tmp == 0. && num_max_tmp != 0.) {
229  res_max = INF_;
230  } else if (den_max_tmp != INF_ || num_max_tmp != INF_) {
231  res_max = num_max_tmp / den_max_tmp;
232  }
233 
234  if (non_defini_max && non_defini_min) {
235  std::cout << "undefined msg" << std::endl;
236  continue;
237  } else if (non_defini_min && !non_defini_max) {
238  res_min = res_max;
239  } else if (non_defini_max && !non_defini_min) {
240  res_max = res_min;
241  }
242 
243  if (res_min < 0.) { res_min = 0.; }
244 
245  if (res_max < 0.) { res_max = 0.; }
246 
247  if (msg_l_min == msg_l_max && msg_l_min == -2.) {
248  msg_l_min = res_min;
249  msg_l_max = res_max;
250  }
251 
252  if (res_max > msg_l_max) { msg_l_max = res_max; }
253 
254  if (res_min < msg_l_min) { msg_l_min = res_min; }
255 
256  } // end of : for each lx
257  }
#define INF_

◆ compute_ext_() [2/3]

template<typename 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 choosen 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 263 of file CNLoopyPropagation_tpl.h.

269  {
270  GUM_SCALAR num_min = 0.;
271  GUM_SCALAR num_max = 0.;
272  GUM_SCALAR den_min = 0.;
273  GUM_SCALAR den_max = 0.;
274 
275  auto taille = combi_msg_p.size();
276 
277  std::vector< typename std::vector< GUM_SCALAR >::iterator > it(taille);
278 
279  for (decltype(taille) i = 0; i < taille; i++) {
280  it[i] = combi_msg_p[i].begin();
281  }
282 
283  Size pp = pos;
284 
285  Size combi_den = 0;
286  Size combi_num = pp;
287 
288  // marginalisation
289  while (it[taille - 1] != combi_msg_p[taille - 1].end()) {
290  GUM_SCALAR prod = 1.;
291 
292  for (decltype(taille) k = 0; k < taille; k++) {
293  prod *= *it[k];
294  }
295 
296  den_min += (_cn_->get_binaryCPT_min()[id][combi_den] * prod);
297  den_max += (_cn_->get_binaryCPT_max()[id][combi_den] * prod);
298 
299  num_min += (_cn_->get_binaryCPT_min()[id][combi_num] * prod);
300  num_max += (_cn_->get_binaryCPT_max()[id][combi_num] * prod);
301 
302  combi_den++;
303  combi_num++;
304 
305  if (pp != 0) {
306  if (combi_den % pp == 0) {
307  combi_den += pp;
308  combi_num += pp;
309  }
310  }
311 
312  // incrementation
313  ++it[0];
314 
315  for (decltype(taille) i = 0; (i < taille - 1) && (it[i] == combi_msg_p[i].end()); ++i) {
316  it[i] = combi_msg_p[i].begin();
317  ++it[i + 1];
318  }
319  } // end of : marginalisation
320 
321  compute_ext_(msg_l_min, msg_l_max, lx, num_min, num_max, den_min, den_max);
322  }
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
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_.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

◆ compute_ext_() [3/3]

template<typename 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 choosen 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 329 of file CNLoopyPropagation_tpl.h.

333  {
334  GUM_SCALAR min = 0.;
335  GUM_SCALAR max = 0.;
336 
337  auto taille = combi_msg_p.size();
338 
339  std::vector< typename std::vector< GUM_SCALAR >::iterator > it(taille);
340 
341  for (decltype(taille) i = 0; i < taille; i++) {
342  it[i] = combi_msg_p[i].begin();
343  }
344 
345  int combi = 0;
346  auto theEnd = combi_msg_p[taille - 1].end();
347 
348  while (it[taille - 1] != theEnd) {
349  GUM_SCALAR prod = 1.;
350 
351  for (decltype(taille) k = 0; k < taille; k++) {
352  prod *= *it[k];
353  }
354 
355  min += (_cn_->get_binaryCPT_min()[id][combi] * prod);
356  max += (_cn_->get_binaryCPT_max()[id][combi] * prod);
357 
358  combi++;
359 
360  // incrementation
361  ++it[0];
362 
363  for (decltype(taille) i = 0; (i < taille - 1) && (it[i] == combi_msg_p[i].end()); ++i) {
364  it[i] = combi_msg_p[i].begin();
365  ++it[i + 1];
366  }
367  }
368 
369  if (min < msg_p_min) { msg_p_min = min; }
370 
371  if (max > msg_p_max) { msg_p_max = max; }
372  }
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.

◆ computeEpsilon_()

template<typename GUM_SCALAR >
const GUM_SCALAR gum::credal::InferenceEngine< GUM_SCALAR >::computeEpsilon_ ( )
inlineprotectedinherited

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.

Definition at line 987 of file inferenceEngine_tpl.h.

987  {
988  GUM_SCALAR eps = 0;
989 #pragma omp parallel
990  {
991  GUM_SCALAR tEps = 0;
992  GUM_SCALAR delta;
993 
995  int nsize = int(marginalMin_.size());
996 
997 #pragma omp for
998 
999  for (int i = 0; i < nsize; i++) {
1000  auto dSize = marginalMin_[i].size();
1001 
1002  for (Size j = 0; j < dSize; j++) {
1003  // on min
1004  delta = marginalMin_[i][j] - oldMarginalMin_[i][j];
1005  delta = (delta < 0) ? (-delta) : delta;
1006  tEps = (tEps < delta) ? delta : tEps;
1007 
1008  // on max
1009  delta = marginalMax_[i][j] - oldMarginalMax_[i][j];
1010  delta = (delta < 0) ? (-delta) : delta;
1011  tEps = (tEps < delta) ? delta : tEps;
1012 
1013  oldMarginalMin_[i][j] = marginalMin_[i][j];
1014  oldMarginalMax_[i][j] = marginalMax_[i][j];
1015  }
1016  } // end of : all variables
1017 
1018 #pragma omp critical(epsilon_max)
1019  {
1020 #pragma omp flush(eps)
1021  eps = (eps < tEps) ? tEps : eps;
1022  }
1023  }
1024 
1025  return eps;
1026  }
margi oldMarginalMin_
Old lower marginals used to compute epsilon.
Size size() const noexcept
Returns the number of elements stored into the hashtable.
margi oldMarginalMax_
Old upper marginals used to compute epsilon.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
margi marginalMax_
Upper marginals.
margi marginalMin_
Lower marginals.

◆ computeExpectations_()

template<typename 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 1441 of file CNLoopyPropagation_tpl.h.

1441  {
1442  if (_infE_::modal_.empty()) { return; }
1443 
1444  std::vector< std::vector< GUM_SCALAR > > vertices(2, std::vector< GUM_SCALAR >(2));
1445 
1446  for (auto node: _bnet_->nodes()) {
1447  vertices[0][0] = _infE_::marginalMin_[node][0];
1448  vertices[0][1] = _infE_::marginalMax_[node][1];
1449 
1450  vertices[1][0] = _infE_::marginalMax_[node][0];
1451  vertices[1][1] = _infE_::marginalMin_[node][1];
1452 
1453  for (auto vertex = 0, vend = 2; vertex != vend; vertex++) {
1454  _infE_::updateExpectations_(node, vertices[vertex]);
1455  // test credal sets vertices elim
1456  // remove with L2U since variables are binary
1457  // but does the user know that ?
1459  node,
1460  vertices[vertex]); // no redundancy elimination with 2 vertices
1461  }
1462  }
1463  }
void updateCredalSets_(const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund=false)
Given a node id and one of it&#39;s possible vertex, update it&#39;s credal set.
const std::vector< std::vector< GUM_SCALAR > > & vertices(const NodeId id) const
Get the vertice of a given node id.
void updateExpectations_(const NodeId &id, const std::vector< GUM_SCALAR > &vertex)
Given a node id and one of it&#39;s possible vertex obtained during inference, update this node lower and...
dynExpe modal_
Variables modalities used to compute expectations.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
margi marginalMax_
Upper marginals.
margi marginalMin_
Lower marginals.

◆ continueApproximationScheme()

INLINE 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 208 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

208  {
209  // For coherence, we fix the time used in the method
210 
211  double timer_step = timer_.step();
212 
213  if (enabled_max_time_) {
214  if (timer_step > max_time_) {
216  return false;
217  }
218  }
219 
220  if (!startOfPeriod()) { return true; }
221 
223  GUM_ERROR(OperationNotAllowed,
224  "state of the approximation scheme is not correct : "
226  }
227 
228  if (verbosity()) { history_.push_back(error); }
229 
230  if (enabled_max_iter_) {
231  if (current_step_ > max_iter_) {
233  return false;
234  }
235  }
236 
238  current_epsilon_ = error; // eps rate isEnabled needs it so affectation was
239  // moved from eps isEnabled below
240 
241  if (enabled_eps_) {
242  if (current_epsilon_ <= eps_) {
244  return false;
245  }
246  }
247 
248  if (last_epsilon_ >= 0.) {
249  if (current_epsilon_ > .0) {
250  // ! current_epsilon_ can be 0. AND epsilon
251  // isEnabled can be disabled !
253  }
254  // limit with current eps ---> 0 is | 1 - ( last_eps / 0 ) | --->
255  // infinity the else means a return false if we isEnabled the rate below,
256  // as we would have returned false if epsilon isEnabled was enabled
257  else {
259  }
260 
261  if (enabled_min_rate_eps_) {
262  if (current_rate_ <= min_rate_eps_) {
264  return false;
265  }
266  }
267  }
268 
270  if (onProgress.hasListener()) {
272  }
273 
274  return true;
275  } else {
276  return false;
277  }
278  }
double max_time_
The timeout.
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:41
Signaler3< Size, double, double > onProgress
Progression, error and time.
ApproximationSchemeSTATE current_state_
The current state.
void stopScheme_(ApproximationSchemeSTATE new_state)
Stop the scheme given a new state.
bool startOfPeriod()
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.
double last_epsilon_
Last epsilon value.
double eps_
Threshold for convergence.
double min_rate_eps_
Threshold for the epsilon rate.
bool enabled_max_time_
If true, the timeout is enabled.
double current_rate_
Current rate.
Size max_iter_
The maximum iterations.
double current_epsilon_
Current epsilon.
bool enabled_eps_
If true, the threshold convergence is enabled.
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
std::vector< double > history_
The scheme history, used only if verbosity == true.
bool verbosity() const
Returns true if verbosity is enabled.
std::string messageApproximationScheme() const
Returns the approximation scheme message.
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
Size current_step_
The current step.
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:41
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ credalNet()

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

Get this creadal network.

Returns
A constant reference to this CredalNet.

Definition at line 57 of file inferenceEngine_tpl.h.

57  {
58  return *credalNet_;
59  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.

◆ currentTime()

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

Returns the current running time in second.

Returns
Returns the current running time in second.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 115 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

115 { return timer_.step(); }
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:41
+ Here is the call graph for this function:

◆ disableEpsilon()

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

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 53 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

53 { enabled_eps_ = false; }
bool enabled_eps_
If true, the threshold convergence is enabled.
+ Here is the call graph for this function:

◆ disableMaxIter()

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

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 94 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

94 { enabled_max_iter_ = false; }
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
+ Here is the call graph for this function:

◆ disableMaxTime()

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

Disable stopping criterion on timeout.

Returns
Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 118 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

118 { enabled_max_time_ = false; }
bool enabled_max_time_
If true, the timeout is enabled.
+ Here is the call graph for this function:

◆ disableMinEpsilonRate()

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

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 74 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

74 { enabled_min_rate_eps_ = false; }
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
+ Here is the call graph for this function:

◆ dynamicExpectations()

template<typename 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 699 of file inferenceEngine_tpl.h.

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

◆ dynamicExpectations_()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpectations_ ( )
protectedinherited

Rearrange lower and upper expectations to suit dynamic networks.

Definition at line 704 of file inferenceEngine_tpl.h.

704  {
705  // no modals, no expectations computed during inference
706  if (expectationMin_.empty() || modal_.empty()) return;
707 
708  // already called by the algorithm or the user
709  if (dynamicExpMax_.size() > 0 && dynamicExpMin_.size() > 0) return;
710 
711  // typedef typename std::map< int, GUM_SCALAR > innerMap;
712  using innerMap = typename gum::HashTable< int, GUM_SCALAR >;
713 
714  // typedef typename std::map< std::string, innerMap > outerMap;
715  using outerMap = typename gum::HashTable< std::string, innerMap >;
716 
717  // typedef typename std::map< std::string, std::vector< GUM_SCALAR > >
718  // mod;
719 
720  // si non dynamique, sauver directement expectationMin_ et Max (revient au
721  // meme
722  // mais plus rapide)
723  outerMap expectationsMin, expectationsMax;
724 
725  for (const auto& elt: expectationMin_) {
726  std::string var_name, time_step;
727 
728  var_name = credalNet_->current_bn().variable(elt.first).name();
729  auto delim = var_name.find_first_of("_");
730  time_step = var_name.substr(delim + 1, var_name.size());
731  var_name = var_name.substr(0, delim);
732 
733  // to be sure (don't store not monitored variables' expectations)
734  // although it
735  // should be taken care of before this point
736  if (!modal_.exists(var_name)) continue;
737 
738  expectationsMin.getWithDefault(var_name, innerMap())
739  .getWithDefault(atoi(time_step.c_str()), 0)
740  = elt.second; // we iterate with min iterators
741  expectationsMax.getWithDefault(var_name, innerMap())
742  .getWithDefault(atoi(time_step.c_str()), 0)
743  = expectationMax_[elt.first];
744  }
745 
746  for (const auto& elt: expectationsMin) {
747  typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
748 
749  for (const auto& elt2: elt.second)
750  dynExp[elt2.first] = elt2.second;
751 
752  dynamicExpMin_.insert(elt.first, dynExp);
753  }
754 
755  for (const auto& elt: expectationsMax) {
756  typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
757 
758  for (const auto& elt2: elt.second) {
759  dynExp[elt2.first] = elt2.second;
760  }
761 
762  dynamicExpMax_.insert(elt.first, dynExp);
763  }
764  }
dynExpe dynamicExpMin_
Lower dynamic expectations.
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
The class for generic Hash Tables.
Definition: hashTable.h:666
dynExpe modal_
Variables modalities used to compute 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.
bool empty() const noexcept
Indicates whether the hash table is empty.

◆ dynamicExpMax()

template<typename GUM_SCALAR >
const std::vector< GUM_SCALAR > & gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpMax ( const std::string &  varName) const
inherited

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

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

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

Definition at line 497 of file inferenceEngine_tpl.h.

497  {
498  std::string errTxt = "const std::vector< GUM_SCALAR > & InferenceEngine< "
499  "GUM_SCALAR >::dynamicExpMax ( const std::string & "
500  "varName ) const : ";
501 
502  if (dynamicExpMax_.empty())
503  GUM_ERROR(OperationNotAllowed, errTxt + "_dynamicExpectations() needs to be called before")
504 
505  if (!dynamicExpMax_.exists(varName) /*dynamicExpMin_.find(varName) == dynamicExpMin_.end()*/)
506  GUM_ERROR(NotFound, errTxt + "variable name not found : " << varName)
507 
508  return dynamicExpMax_[varName];
509  }
dynExpe dynamicExpMax_
Upper dynamic expectations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ dynamicExpMin()

template<typename GUM_SCALAR >
const std::vector< GUM_SCALAR > & gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpMin ( const std::string &  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 481 of file inferenceEngine_tpl.h.

481  {
482  std::string errTxt = "const std::vector< GUM_SCALAR > & InferenceEngine< "
483  "GUM_SCALAR >::dynamicExpMin ( const std::string & "
484  "varName ) const : ";
485 
486  if (dynamicExpMin_.empty())
487  GUM_ERROR(OperationNotAllowed, errTxt + "_dynamicExpectations() needs to be called before")
488 
489  if (!dynamicExpMin_.exists(varName) /*dynamicExpMin_.find(varName) == dynamicExpMin_.end()*/)
490  GUM_ERROR(NotFound, errTxt + "variable name not found : " << varName)
491 
492  return dynamicExpMin_[varName];
493  }
dynExpe dynamicExpMin_
Lower dynamic expectations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ enableEpsilon()

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

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 56 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

56 { enabled_eps_ = true; }
bool enabled_eps_
If true, the threshold convergence is enabled.
+ Here is the call graph for this function:

◆ enableMaxIter()

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

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 97 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

97 { enabled_max_iter_ = true; }
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
+ Here is the call graph for this function:

◆ enableMaxTime()

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

Enable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 121 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

121 { enabled_max_time_ = true; }
bool enabled_max_time_
If true, the timeout is enabled.
+ Here is the call graph for this function:

◆ enableMinEpsilonRate()

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

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 77 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

77 { enabled_min_rate_eps_ = true; }
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
+ Here is the call graph for this function:

◆ enum_combi_() [1/2]

template<typename 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 453 of file CNLoopyPropagation_tpl.h.

459  {
460  GUM_SCALAR msg_l_min = real_msg_l_min;
461  GUM_SCALAR msg_l_max = real_msg_l_max;
462 
463  auto taille = msgs_p.size();
464 
465  // one parent node, the one receiving the message
466  if (taille == 0) {
467  GUM_SCALAR num_min = _cn_->get_binaryCPT_min()[id][1];
468  GUM_SCALAR num_max = _cn_->get_binaryCPT_max()[id][1];
469  GUM_SCALAR den_min = _cn_->get_binaryCPT_min()[id][0];
470  GUM_SCALAR den_max = _cn_->get_binaryCPT_max()[id][0];
471 
472  compute_ext_(msg_l_min, msg_l_max, lx, num_min, num_max, den_min, den_max);
473 
474  real_msg_l_min = msg_l_min;
475  real_msg_l_max = msg_l_max;
476  return;
477  }
478 
479  decltype(taille) msgPerm = 1;
480 #pragma omp parallel
481  {
482  GUM_SCALAR msg_lmin = msg_l_min;
483  GUM_SCALAR msg_lmax = msg_l_max;
484  std::vector< std::vector< GUM_SCALAR > > combi_msg_p(taille);
485 
486  decltype(taille) confs = 1;
487 #pragma omp for
488 
489  for (int i = 0; i < int(taille); i++) {
490  confs *= msgs_p[i].size();
491  }
492 
493 #pragma omp atomic
494  msgPerm *= confs;
495 #pragma omp barrier
496 #pragma omp flush(msgPerm)
497 
498 // direct binary representation of config, no need for iterators
499 #pragma omp for
500 
501  for (long j = 0; j < long(msgPerm); j++) {
502  // get jth msg :
503  auto jvalue = j;
504 
505  for (decltype(taille) i = 0; i < taille; i++) {
506  if (msgs_p[i].size() == 2) {
507  combi_msg_p[i] = (jvalue & 1) ? msgs_p[i][1] : msgs_p[i][0];
508  jvalue /= 2;
509  } else {
510  combi_msg_p[i] = msgs_p[i][0];
511  }
512  }
513 
514  compute_ext_(combi_msg_p, id, msg_lmin, msg_lmax, lx, pos);
515  }
516 
517 // there may be more threads here than in the for loop, therefor positive test
518 // is NECESSARY (init is -2)
519 #pragma omp critical(msglminmax)
520  {
521 #pragma omp flush(msg_l_min)
522 #pragma omp flush(msg_l_max)
523 
524  if ((msg_l_min > msg_lmin || msg_l_min == -2) && msg_lmin > 0) { msg_l_min = msg_lmin; }
525 
526  if ((msg_l_max < msg_lmax || msg_l_max == -2) && msg_lmax > 0) { msg_l_max = msg_lmax; }
527  }
528  }
529 
530  real_msg_l_min = msg_l_min;
531  real_msg_l_max = msg_l_max;
532  }
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
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_.

◆ enum_combi_() [2/2]

template<typename 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 378 of file CNLoopyPropagation_tpl.h.

382  {
383  auto taille = msgs_p.size();
384 
385  // source node
386  if (taille == 0) {
387  msg_p_min = _cn_->get_binaryCPT_min()[id][0];
388  msg_p_max = _cn_->get_binaryCPT_max()[id][0];
389  return;
390  }
391 
392  decltype(taille) msgPerm = 1;
393 #pragma omp parallel
394  {
395  GUM_SCALAR msg_pmin = msg_p_min;
396  GUM_SCALAR msg_pmax = msg_p_max;
397 
398  std::vector< std::vector< GUM_SCALAR > > combi_msg_p(taille);
399 
400  decltype(taille) confs = 1;
401 
402 #pragma omp for
403 
404  for (long i = 0; i < long(taille); i++) {
405  confs *= msgs_p[i].size();
406  }
407 
408 #pragma omp atomic
409  msgPerm *= confs;
410 #pragma omp barrier
411 #pragma omp flush // ( msgPerm ) let the compiler choose what to flush (due to mvsc)
412 
413 #pragma omp for
414 
415  for (int j = 0; j < int(msgPerm); j++) {
416  // get jth msg :
417  auto jvalue = j;
418 
419  for (decltype(taille) i = 0; i < taille; i++) {
420  if (msgs_p[i].size() == 2) {
421  combi_msg_p[i] = (jvalue & 1) ? msgs_p[i][1] : msgs_p[i][0];
422  jvalue /= 2;
423  } else {
424  combi_msg_p[i] = msgs_p[i][0];
425  }
426  }
427 
428  compute_ext_(combi_msg_p, id, msg_pmin, msg_pmax);
429  }
430 
431 // since min is INF_ and max is 0 at init, there is no issue having more threads
432 // here
433 // than during for loop
434 #pragma omp critical(msgpminmax)
435  {
436 #pragma omp flush //( msg_p_min )
437  //#pragma omp flush ( msg_p_max ) let the compiler choose what to
438  // flush (due to mvsc)
439 
440  if (msg_p_min > msg_pmin) { msg_p_min = msg_pmin; }
441 
442  if (msg_p_max < msg_pmax) { msg_p_max = msg_pmax; }
443  }
444  }
445  return;
446  }
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
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_.

◆ epsilon()

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

Returns the value of epsilon.

Returns
Returns the value of epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 50 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

50 { return eps_; }
double eps_
Threshold for convergence.
+ Here is the call graph for this function:

◆ eraseAllEvidence()

template<typename GUM_SCALAR >
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::eraseAllEvidence ( )
virtual

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 565 of file CNLoopyPropagation_tpl.h.

565  {
567 
568  ArcsL_min_.clear();
569  ArcsL_max_.clear();
570  ArcsP_min_.clear();
571  ArcsP_max_.clear();
572  NodesL_min_.clear();
573  NodesL_max_.clear();
574  NodesP_min_.clear();
575  NodesP_max_.clear();
576 
577  InferenceUpToDate_ = false;
578 
579  if (msg_l_sent_.size() > 0) {
580  for (auto node: _bnet_->nodes()) {
581  delete msg_l_sent_[node];
582  }
583  }
584 
585  msg_l_sent_.clear();
586  update_l_.clear();
587  update_p_.clear();
588 
591  }
NodeProperty< NodeSet *> msg_l_sent_
Used to keep track of one&#39;s messages sent to it&#39;s parents.
NodeProperty< bool > update_l_
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s children...
ArcProperty< GUM_SCALAR > ArcsP_min_
"Lower" information coming from one&#39;s parent.
NodeSet active_nodes_set
The current node-set to iterate through at this current step.
ArcProperty< GUM_SCALAR > ArcsL_max_
"Upper" information coming from one&#39;s children.
NodeProperty< GUM_SCALAR > NodesL_min_
"Lower" node information obtained by combinaison of children messages.
NodeProperty< GUM_SCALAR > NodesP_max_
"Upper" node information obtained by combinaison of parent&#39;s messages.
NodeProperty< GUM_SCALAR > NodesP_min_
"Lower" node information obtained by combinaison of parent&#39;s messages.
NodeProperty< bool > update_p_
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s parents...
ArcProperty< GUM_SCALAR > ArcsP_max_
"Upper" information coming from one&#39;s parent.
NodeProperty< GUM_SCALAR > NodesL_max_
"Upper" node information obtained by combinaison of children messages.
bool InferenceUpToDate_
TRUE if inference has already been performed, FALSE otherwise.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
NodeSet next_active_nodes_set
The next node-set, i.e.
virtual void eraseAllEvidence()
Erase all inference related data to perform another one.
ArcProperty< GUM_SCALAR > ArcsL_min_
"Lower" information coming from one&#39;s children.

◆ expectationMax() [1/2]

template<typename 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  try {
475  return expectationMax_[id];
476  } catch (NotFound& err) { throw(err); }
477  }
expe expectationMax_
Upper expectations, if some variables modalities were inserted.

◆ expectationMax() [2/2]

template<typename GUM_SCALAR >
const GUM_SCALAR & gum::credal::InferenceEngine< GUM_SCALAR >::expectationMax ( const std::string &  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 459 of file inferenceEngine_tpl.h.

459  {
460  try {
461  return expectationMax_[credalNet_->current_bn().idFromName(varName)];
462  } catch (NotFound& err) { throw(err); }
463  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
expe expectationMax_
Upper expectations, if some variables modalities were inserted.

◆ expectationMin() [1/2]

template<typename 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 466 of file inferenceEngine_tpl.h.

466  {
467  try {
468  return expectationMin_[id];
469  } catch (NotFound& err) { throw(err); }
470  }
expe expectationMin_
Lower expectations, if some variables modalities were inserted.

◆ expectationMin() [2/2]

template<typename GUM_SCALAR >
const GUM_SCALAR & gum::credal::InferenceEngine< GUM_SCALAR >::expectationMin ( const std::string &  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 451 of file inferenceEngine_tpl.h.

451  {
452  try {
453  return expectationMin_[credalNet_->current_bn().idFromName(varName)];
454  } catch (NotFound& err) { throw(err); }
455  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
expe expectationMin_
Lower expectations, if some variables modalities were inserted.

◆ getApproximationSchemeMsg()

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

Get approximation scheme state.

Returns
A constant string about approximation scheme state.

Definition at line 500 of file inferenceEngine.h.

500 { return this->messageApproximationScheme(); }
std::string messageApproximationScheme() const
Returns the approximation scheme message.

◆ getT0Cluster()

template<typename 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 976 of file inferenceEngine_tpl.h.

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

◆ getT1Cluster()

template<typename 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 982 of file inferenceEngine_tpl.h.

982  {
983  return t1_;
984  }
cluster t1_
Clusters of nodes used with dynamic networks.

◆ getVarMod2BNsMap()

template<typename 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 138 of file inferenceEngine_tpl.h.

138  {
139  return &dbnOpt_;
140  }
VarMod2BNsMap< GUM_SCALAR > dbnOpt_
Object used to efficiently store optimal bayes net during inference, for some algorithms.

◆ history()

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

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 157 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

157  {
159  GUM_ERROR(OperationNotAllowed, "state of the approximation scheme is udefined")
160  }
161 
162  if (verbosity() == false) { GUM_ERROR(OperationNotAllowed, "No history when verbosity=false") }
163 
164  return history_;
165  }
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
std::vector< double > history_
The scheme history, used only if verbosity == true.
bool verbosity() const
Returns true if verbosity is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ inferenceType() [1/2]

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

Set the inference type.

Parameters
inftThe choosen InferenceType.

Definition at line 1517 of file CNLoopyPropagation_tpl.h.

1517  {
1518  _inferenceType_ = inft;
1519  }
InferenceType _inferenceType_
The choosen inference type.

◆ inferenceType() [2/2]

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

Get the inference type.

Returns
The inference type.

Definition at line 1523 of file CNLoopyPropagation_tpl.h.

1523  {
1524  return _inferenceType_;
1525  }
InferenceType _inferenceType_
The choosen inference type.

◆ initApproximationScheme()

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

Initialise the scheme.

Definition at line 168 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

168  {
170  current_step_ = 0;
172  history_.clear();
173  timer_.reset();
174  }
ApproximationSchemeSTATE current_state_
The current state.
void reset()
Reset the timer.
Definition: timer_inl.h:31
double current_rate_
Current rate.
double current_epsilon_
Current epsilon.
std::vector< double > history_
The scheme history, used only if verbosity == true.
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ initExpectations_()

template<typename 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 678 of file inferenceEngine_tpl.h.

678  {
681 
682  if (modal_.empty()) return;
683 
684  for (auto node: credalNet_->current_bn().nodes()) {
685  std::string var_name, time_step;
686 
687  var_name = credalNet_->current_bn().variable(node).name();
688  auto delim = var_name.find_first_of("_");
689  var_name = var_name.substr(0, delim);
690 
691  if (!modal_.exists(var_name)) continue;
692 
693  expectationMin_.insert(node, modal_[var_name].back());
694  expectationMax_.insert(node, modal_[var_name].front());
695  }
696  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
dynExpe modal_
Variables modalities used to compute expectations.
expe expectationMax_
Upper expectations, if some variables modalities were inserted.
expe expectationMin_
Lower expectations, if some variables modalities were inserted.
void clear()
Removes all the elements in the hash table.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ initialize_()

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

Topological forward propagation to initialize old marginals & messages.

Definition at line 594 of file CNLoopyPropagation_tpl.h.

594  {
595  const DAG& graphe = _bnet_->dag();
596 
597  // use const iterators with cbegin when available
598  for (auto node: _bnet_->topologicalOrder()) {
599  update_p_.set(node, false);
600  update_l_.set(node, false);
601  NodeSet* parents_ = new NodeSet();
602  msg_l_sent_.set(node, parents_);
603 
604  // accelerer init pour evidences
605  if (_infE_::evidence_.exists(node)) {
606  if (_infE_::evidence_[node][1] != 0. && _infE_::evidence_[node][1] != 1.) {
607  GUM_ERROR(OperationNotAllowed, "CNLoopyPropagation can only handle HARD evidences")
608  }
609 
610  active_nodes_set.insert(node);
611  update_l_.set(node, true);
612  update_p_.set(node, true);
613 
614  if (_infE_::evidence_[node][1] == (GUM_SCALAR)1.) {
615  NodesL_min_.set(node, INF_);
616  NodesP_min_.set(node, (GUM_SCALAR)1.);
617  } else if (_infE_::evidence_[node][1] == (GUM_SCALAR)0.) {
618  NodesL_min_.set(node, (GUM_SCALAR)0.);
619  NodesP_min_.set(node, (GUM_SCALAR)0.);
620  }
621 
622  std::vector< GUM_SCALAR > marg(2);
623  marg[1] = NodesP_min_[node];
624  marg[0] = 1 - marg[1];
625 
626  _infE_::oldMarginalMin_.set(node, marg);
627  _infE_::oldMarginalMax_.set(node, marg);
628 
629  continue;
630  }
631 
632  NodeSet par_ = graphe.parents(node);
633  NodeSet enf_ = graphe.children(node);
634 
635  if (par_.size() == 0) {
636  active_nodes_set.insert(node);
637  update_p_.set(node, true);
638  update_l_.set(node, true);
639  }
640 
641  if (enf_.size() == 0) {
642  active_nodes_set.insert(node);
643  update_p_.set(node, true);
644  update_l_.set(node, true);
645  }
646 
651  const auto parents = &_bnet_->cpt(node).variablesSequence();
652 
653  std::vector< std::vector< std::vector< GUM_SCALAR > > > msgs_p;
654  std::vector< std::vector< GUM_SCALAR > > msg_p;
655  std::vector< GUM_SCALAR > distri(2);
656 
657  // +1 from start to avoid counting_ itself
658  // use const iterators when available with cbegin
659  for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd; ++jt) {
660  // compute probability distribution to avoid doing it multiple times
661  // (at
662  // each combination of messages)
663  distri[1] = NodesP_min_[_bnet_->nodeId(**jt)];
664  distri[0] = (GUM_SCALAR)1. - distri[1];
665  msg_p.push_back(distri);
666 
667  if (NodesP_max_.exists(_bnet_->nodeId(**jt))) {
668  distri[1] = NodesP_max_[_bnet_->nodeId(**jt)];
669  distri[0] = (GUM_SCALAR)1. - distri[1];
670  msg_p.push_back(distri);
671  }
672 
673  msgs_p.push_back(msg_p);
674  msg_p.clear();
675  }
676 
677  GUM_SCALAR msg_p_min = 1.;
678  GUM_SCALAR msg_p_max = 0.;
679 
680  if (_cn_->currentNodeType(node) != CredalNet< GUM_SCALAR >::NodeType::Indic) {
681  enum_combi_(msgs_p, node, msg_p_min, msg_p_max);
682  }
683 
684  if (msg_p_min <= (GUM_SCALAR)0.) { msg_p_min = (GUM_SCALAR)0.; }
685 
686  if (msg_p_max <= (GUM_SCALAR)0.) { msg_p_max = (GUM_SCALAR)0.; }
687 
688  NodesP_min_.set(node, msg_p_min);
689  std::vector< GUM_SCALAR > marg(2);
690  marg[1] = msg_p_min;
691  marg[0] = 1 - msg_p_min;
692 
693  _infE_::oldMarginalMin_.set(node, marg);
694 
695  if (msg_p_min != msg_p_max) {
696  marg[1] = msg_p_max;
697  marg[0] = 1 - msg_p_max;
698  NodesP_max_.insert(node, msg_p_max);
699  }
700 
701  _infE_::oldMarginalMax_.set(node, marg);
702 
703  NodesL_min_.set(node, (GUM_SCALAR)1.);
704  }
705 
706  for (auto arc: _bnet_->arcs()) {
707  ArcsP_min_.set(arc, NodesP_min_[arc.tail()]);
708 
709  if (NodesP_max_.exists(arc.tail())) { ArcsP_max_.set(arc, NodesP_max_[arc.tail()]); }
710 
711  ArcsL_min_.set(arc, NodesL_min_[arc.tail()]);
712  }
713  }
#define INF_
NodeProperty< NodeSet *> msg_l_sent_
Used to keep track of one&#39;s messages sent to it&#39;s parents.
margi oldMarginalMin_
Old lower marginals used to compute epsilon.
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
NodeProperty< bool > update_l_
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s children...
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
ArcProperty< GUM_SCALAR > ArcsP_min_
"Lower" information coming from one&#39;s parent.
NodeSet active_nodes_set
The current node-set to iterate through at this current step.
NodeProperty< GUM_SCALAR > NodesL_min_
"Lower" node information obtained by combinaison of children messages.
margi oldMarginalMax_
Old upper marginals used to compute epsilon.
NodeProperty< GUM_SCALAR > NodesP_max_
"Upper" node information obtained by combinaison of parent&#39;s messages.
NodeProperty< GUM_SCALAR > NodesP_min_
"Lower" node information obtained by combinaison of parent&#39;s messages.
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_.
NodeProperty< bool > update_p_
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s parents...
ArcProperty< GUM_SCALAR > ArcsP_max_
"Upper" information coming from one&#39;s parent.
margi evidence_
Holds observed variables states.
void set(const Key &key, const Val &default_value)
Add a new property or modify it if it already existed.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
ArcProperty< GUM_SCALAR > ArcsL_min_
"Lower" information coming from one&#39;s children.

◆ initMarginals_()

template<typename 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 646 of file inferenceEngine_tpl.h.

646  {
651 
652  for (auto node: credalNet_->current_bn().nodes()) {
653  auto dSize = credalNet_->current_bn().variable(node).domainSize();
654  marginalMin_.insert(node, std::vector< GUM_SCALAR >(dSize, 1));
655  oldMarginalMin_.insert(node, std::vector< GUM_SCALAR >(dSize, 1));
656 
657  marginalMax_.insert(node, std::vector< GUM_SCALAR >(dSize, 0));
658  oldMarginalMax_.insert(node, std::vector< GUM_SCALAR >(dSize, 0));
659  }
660  }
margi oldMarginalMin_
Old lower marginals used to compute epsilon.
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
margi oldMarginalMax_
Old upper marginals used to compute epsilon.
void clear()
Removes all the elements in the hash table.
margi marginalMax_
Upper marginals.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
margi marginalMin_
Lower marginals.

◆ initMarginalSets_()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::initMarginalSets_ ( )
protectedinherited

Initialize credal set vertices with empty sets.

Definition at line 663 of file inferenceEngine_tpl.h.

663  {
665 
666  if (!storeVertices_) return;
667 
668  for (auto node: credalNet_->current_bn().nodes())
669  marginalSets_.insert(node, std::vector< std::vector< GUM_SCALAR > >());
670  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
bool storeVertices_
True if credal sets vertices are stored, False otherwise.
credalSet marginalSets_
Credal sets vertices, if enabled.
void clear()
Removes all the elements in the hash table.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ insertEvidence() [1/2]

template<typename 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 226 of file inferenceEngine_tpl.h.

227  {
228  if (!evidence_.empty()) evidence_.clear();
229 
230  for (auto it = eviMap.cbegin(), theEnd = eviMap.cend(); it != theEnd; ++it) {
231  NodeId id;
232 
233  try {
234  id = credalNet_->current_bn().idFromName(it->first);
235  } catch (NotFound& err) {
236  GUM_SHOWERROR(err);
237  continue;
238  }
239 
240  evidence_.insert(id, it->second);
241  }
242  }
#define GUM_SHOWERROR(e)
Definition: exceptions.h:57
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
margi evidence_
Holds observed variables states.
void clear()
Removes all the elements in the hash table.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
bool empty() const noexcept
Indicates whether the hash table is empty.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ insertEvidence() [2/2]

template<typename 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 248 of file inferenceEngine_tpl.h.

249  {
250  if (!evidence_.empty()) evidence_.clear();
251 
252  // use cbegin() to get const_iterator when available in aGrUM hashtables
253  for (const auto& elt: evidence) {
254  try {
255  credalNet_->current_bn().variable(elt.first);
256  } catch (NotFound& err) {
257  GUM_SHOWERROR(err);
258  continue;
259  }
260 
261  evidence_.insert(elt.first, elt.second);
262  }
263  }
#define GUM_SHOWERROR(e)
Definition: exceptions.h:57
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
margi evidence_
Holds observed variables states.
void clear()
Removes all the elements in the hash table.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
bool empty() const noexcept
Indicates whether the hash table is empty.

◆ insertEvidenceFile()

template<typename GUM_SCALAR >
virtual void gum::credal::CNLoopyPropagation< GUM_SCALAR >::insertEvidenceFile ( const std::string &  path)
inlinevirtual

Insert evidence from file.

Parameters
pathThe path to the evidence file.

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

Definition at line 379 of file CNLoopyPropagation.h.

379  {
381  };
virtual void insertEvidenceFile(const std::string &path)
Insert evidence from file.

◆ insertModals()

template<typename 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 190 of file inferenceEngine_tpl.h.

191  {
192  if (!modal_.empty()) modal_.clear();
193 
194  for (auto it = modals.cbegin(), theEnd = modals.cend(); it != theEnd; ++it) {
195  NodeId id;
196 
197  try {
198  id = credalNet_->current_bn().idFromName(it->first);
199  } catch (NotFound& err) {
200  GUM_SHOWERROR(err);
201  continue;
202  }
203 
204  // check that modals are net compatible
205  auto dSize = credalNet_->current_bn().variable(id).domainSize();
206 
207  if (dSize != it->second.size()) continue;
208 
209  // GUM_ERROR(OperationNotAllowed, "void InferenceEngine< GUM_SCALAR
210  // >::insertModals( const std::map< std::string, std::vector< GUM_SCALAR
211  // > >
212  // &modals) : modalities does not respect variable cardinality : " <<
213  // credalNet_->current_bn().variable( id ).name() << " : " << dSize << "
214  // != "
215  // << it->second.size());
216 
217  modal_.insert(it->first, it->second); //[ it->first ] = it->second;
218  }
219 
220  //_modal = modals;
221 
223  }
void initExpectations_()
Initialize lower and upper expectations before inference, with the lower expectation being initialize...
#define GUM_SHOWERROR(e)
Definition: exceptions.h:57
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
dynExpe modal_
Variables modalities used to compute expectations.
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ insertModalsFile()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::insertModalsFile ( const std::string &  path)
inherited

Insert variables modalities from file to compute expectations.

Parameters
pathThe path to the modalities file.

Definition at line 143 of file inferenceEngine_tpl.h.

143  {
144  std::ifstream mod_stream(path.c_str(), std::ios::in);
145 
146  if (!mod_stream.good()) {
147  GUM_ERROR(OperationNotAllowed,
148  "void InferenceEngine< GUM_SCALAR "
149  ">::insertModals(const std::string & path) : "
150  "could not open input file : "
151  << path);
152  }
153 
154  if (!modal_.empty()) modal_.clear();
155 
156  std::string line, tmp;
157  char * cstr, *p;
158 
159  while (mod_stream.good()) {
160  getline(mod_stream, line);
161 
162  if (line.size() == 0) continue;
163 
164  cstr = new char[line.size() + 1];
165  strcpy(cstr, line.c_str());
166 
167  p = strtok(cstr, " ");
168  tmp = p;
169 
170  std::vector< GUM_SCALAR > values;
171  p = strtok(nullptr, " ");
172 
173  while (p != nullptr) {
174  values.push_back(GUM_SCALAR(atof(p)));
175  p = strtok(nullptr, " ");
176  } // end of : line
177 
178  modal_.insert(tmp, values); //[tmp] = values;
179 
180  delete[] p;
181  delete[] cstr;
182  } // end of : file
183 
184  mod_stream.close();
185 
187  }
void initExpectations_()
Initialize lower and upper expectations before inference, with the lower expectation being initialize...
dynExpe modal_
Variables modalities used to compute expectations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ insertQuery()

template<typename 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 327 of file inferenceEngine_tpl.h.

328  {
329  if (!query_.empty()) query_.clear();
330 
331  for (const auto& elt: query) {
332  try {
333  credalNet_->current_bn().variable(elt.first);
334  } catch (NotFound& err) {
335  GUM_SHOWERROR(err);
336  continue;
337  }
338 
339  query_.insert(elt.first, elt.second);
340  }
341  }
#define GUM_SHOWERROR(e)
Definition: exceptions.h:57
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
query query_
Holds the query nodes states.
void clear()
Removes all the elements in the hash table.
NodeProperty< std::vector< bool > > query
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
bool empty() const noexcept
Indicates whether the hash table is empty.

◆ insertQueryFile()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::insertQueryFile ( const std::string &  path)
inherited

Insert query variables states from file.

Parameters
pathThe path to the query file.

Definition at line 344 of file inferenceEngine_tpl.h.

344  {
345  std::ifstream evi_stream(path.c_str(), std::ios::in);
346 
347  if (!evi_stream.good()) {
348  GUM_ERROR(IOError,
349  "void InferenceEngine< GUM_SCALAR >::insertQuery(const "
350  "std::string & path) : could not open input file : "
351  << path);
352  }
353 
354  if (!query_.empty()) query_.clear();
355 
356  std::string line, tmp;
357  char * cstr, *p;
358 
359  while (evi_stream.good() && std::strcmp(line.c_str(), "[QUERY]") != 0) {
360  getline(evi_stream, line);
361  }
362 
363  while (evi_stream.good()) {
364  getline(evi_stream, line);
365 
366  if (std::strcmp(line.c_str(), "[EVIDENCE]") == 0) break;
367 
368  if (line.size() == 0) continue;
369 
370  cstr = new char[line.size() + 1];
371  strcpy(cstr, line.c_str());
372 
373  p = strtok(cstr, " ");
374  tmp = p;
375 
376  // if user input is wrong
377  NodeId node = -1;
378 
379  try {
380  node = credalNet_->current_bn().idFromName(tmp);
381  } catch (NotFound& err) {
382  GUM_SHOWERROR(err);
383  continue;
384  }
385 
386  auto dSize = credalNet_->current_bn().variable(node).domainSize();
387 
388  p = strtok(nullptr, " ");
389 
390  if (p == nullptr) {
391  query_.insert(node, std::vector< bool >(dSize, true));
392  } else {
393  std::vector< bool > values(dSize, false);
394 
395  while (p != nullptr) {
396  if ((Size)atoi(p) >= dSize)
397  GUM_ERROR(OutOfBounds,
398  "void InferenceEngine< GUM_SCALAR "
399  ">::insertQuery(const std::string & path) : "
400  "query modality is higher or equal to "
401  "cardinality");
402 
403  values[atoi(p)] = true;
404  p = strtok(nullptr, " ");
405  } // end of : line
406 
407  query_.insert(node, values);
408  }
409 
410  delete[] p;
411  delete[] cstr;
412  } // end of : file
413 
414  evi_stream.close();
415  }
#define GUM_SHOWERROR(e)
Definition: exceptions.h:57
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
query query_
Holds the query nodes states.
void clear()
Removes all the elements in the hash table.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
bool empty() const noexcept
Indicates whether the hash table is empty.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ isEnabledEpsilon()

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

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 60 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

60 { return enabled_eps_; }
bool enabled_eps_
If true, the threshold convergence is enabled.
+ Here is the call graph for this function:

◆ isEnabledMaxIter()

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

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 101 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

101 { return enabled_max_iter_; }
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
+ Here is the call graph for this function:

◆ isEnabledMaxTime()

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

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 125 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

125 { return enabled_max_time_; }
bool enabled_max_time_
If true, the timeout is enabled.
+ Here is the call graph for this function:

◆ isEnabledMinEpsilonRate()

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

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 81 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

81 { return enabled_min_rate_eps_; }
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
+ Here is the call graph for this function:

◆ makeInference()

template<typename GUM_SCALAR >
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInference ( )
virtual

Starts the inference.

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

Definition at line 535 of file CNLoopyPropagation_tpl.h.

535  {
536  if (InferenceUpToDate_) { return; }
537 
538  initialize_();
539 
541 
542  switch (_inferenceType_) {
545  break;
546 
549  break;
550 
553  break;
554  }
555 
556  //_updateMarginals();
557  updateIndicatrices_(); // will call updateMarginals_()
558 
560 
561  InferenceUpToDate_ = true;
562  }
void makeInferenceByOrderedArcs_()
Starts the inference with this inference type.
InferenceType _inferenceType_
The choosen inference type.
void makeInferenceNodeToNeighbours_()
Starts the inference with this inference type.
void initApproximationScheme()
Initialise the scheme.
Chooses an arc ordering and sends messages accordingly at all steps.
bool InferenceUpToDate_
TRUE if inference has already been performed, FALSE otherwise.
Uses a node-set so we don&#39;t iterate on nodes that can&#39;t send a new message.
void makeInferenceByRandomOrder_()
Starts the inference with this inference type.
void initialize_()
Topological forward propagation to initialize old marginals & messages.
void updateIndicatrices_()
Only update indicatrices variables at the end of computations ( calls msgP_ ).
Chooses a random arc ordering and sends messages accordingly.
void computeExpectations_()
Since the network is binary, expectations can be computed from the final marginals which give us the ...

◆ makeInferenceByOrderedArcs_()

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

Starts the inference with this inference type.

Definition at line 802 of file CNLoopyPropagation_tpl.h.

802  {
803  Size nbrArcs = _bnet_->dag().sizeArcs();
804 
805  std::vector< cArcP > seq;
806  seq.reserve(nbrArcs);
807 
808  for (const auto& arc: _bnet_->arcs()) {
809  seq.push_back(&arc);
810  }
811 
812  GUM_SCALAR eps;
813  // validate TestSuite
815 
816  do {
817  for (const auto it: seq) {
818  if (_cn_->currentNodeType(it->tail()) == CredalNet< GUM_SCALAR >::NodeType::Indic
819  || _cn_->currentNodeType(it->head()) == CredalNet< GUM_SCALAR >::NodeType::Indic) {
820  continue;
821  }
822 
823  msgP_(it->tail(), it->head());
824  msgL_(it->head(), it->tail());
825  }
826 
827  eps = calculateEpsilon_();
828 
830 
832  }
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
GUM_SCALAR calculateEpsilon_()
Compute epsilon.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
void msgP_(const NodeId X, const NodeId demanding_child)
Sends a message to one&#39;s child, i.e.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
void msgL_(const NodeId X, const NodeId demanding_parent)
Sends a message to one&#39;s parent, i.e.
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.

◆ makeInferenceByRandomOrder_()

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

Starts the inference with this inference type.

Definition at line 758 of file CNLoopyPropagation_tpl.h.

758  {
759  Size nbrArcs = _bnet_->dag().sizeArcs();
760 
761  std::vector< cArcP > seq;
762  seq.reserve(nbrArcs);
763 
764  for (const auto& arc: _bnet_->arcs()) {
765  seq.push_back(&arc);
766  }
767 
768  GUM_SCALAR eps;
769  // validate TestSuite
771 
772  do {
773  for (Size j = 0, theEnd = nbrArcs / 2; j < theEnd; j++) {
774  auto w1 = rand() % nbrArcs, w2 = rand() % nbrArcs;
775 
776  if (w1 == w2) { continue; }
777 
778  std::swap(seq[w1], seq[w2]);
779  }
780 
781  for (const auto it: seq) {
782  if (_cn_->currentNodeType(it->tail()) == CredalNet< GUM_SCALAR >::NodeType::Indic
783  || _cn_->currentNodeType(it->head()) == CredalNet< GUM_SCALAR >::NodeType::Indic) {
784  continue;
785  }
786 
787  msgP_(it->tail(), it->head());
788  msgL_(it->head(), it->tail());
789  }
790 
791  eps = calculateEpsilon_();
792 
794 
796  }
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
GUM_SCALAR calculateEpsilon_()
Compute epsilon.
void swap(HashTable< LpCol, double > *&a, HashTable< LpCol, double > *&b)
Swap the addresses of two pointers to hashTables.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
void msgP_(const NodeId X, const NodeId demanding_child)
Sends a message to one&#39;s child, i.e.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
void msgL_(const NodeId X, const NodeId demanding_parent)
Sends a message to one&#39;s parent, i.e.
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.

◆ makeInferenceNodeToNeighbours_()

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

Starts the inference with this inference type.

Definition at line 716 of file CNLoopyPropagation_tpl.h.

716  {
717  const DAG& graphe = _bnet_->dag();
718 
719  GUM_SCALAR eps;
720  // to validate TestSuite
722 
723  do {
724  for (auto node: active_nodes_set) {
725  for (auto chil: graphe.children(node)) {
726  if (_cn_->currentNodeType(chil) == CredalNet< GUM_SCALAR >::NodeType::Indic) {
727  continue;
728  }
729 
730  msgP_(node, chil);
731  }
732 
733  for (auto par: graphe.parents(node)) {
734  if (_cn_->currentNodeType(node) == CredalNet< GUM_SCALAR >::NodeType::Indic) {
735  continue;
736  }
737 
738  msgL_(node, par);
739  }
740  }
741 
742  eps = calculateEpsilon_();
743 
745 
746  active_nodes_set.clear();
747  active_nodes_set = next_active_nodes_set;
749 
750  } while (_infE_::continueApproximationScheme(eps) && active_nodes_set.size() > 0);
751 
752  _infE_::stopApproximationScheme(); // just to be sure of the
753  // approximationScheme has been notified of
754  // the end of looop
755  }
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
GUM_SCALAR calculateEpsilon_()
Compute epsilon.
NodeSet active_nodes_set
The current node-set to iterate through at this current step.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
void stopApproximationScheme()
Stop the approximation scheme.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
void msgP_(const NodeId X, const NodeId demanding_child)
Sends a message to one&#39;s child, i.e.
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
void msgL_(const NodeId X, const NodeId demanding_parent)
Sends a message to one&#39;s parent, i.e.
NodeSet next_active_nodes_set
The next node-set, i.e.
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.

◆ marginalMax() [1/2]

template<typename GUM_SCALAR >
gum::Potential< 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 440 of file inferenceEngine_tpl.h.

440  {
441  try {
442  Potential< GUM_SCALAR > res;
443  res.add(credalNet_->current_bn().variable(id));
444  res.fillWith(marginalMax_[id]);
445  return res;
446  } catch (NotFound& err) { throw(err); }
447  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
margi marginalMax_
Upper marginals.

◆ marginalMax() [2/2]

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax ( const std::string &  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 425 of file inferenceEngine_tpl.h.

425  {
426  return marginalMax(credalNet_->current_bn().idFromName(varName));
427  }
Potential< GUM_SCALAR > marginalMax(const NodeId id) const
Get the upper marginals of a given node id.
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.

◆ marginalMin() [1/2]

template<typename GUM_SCALAR >
gum::Potential< 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 430 of file inferenceEngine_tpl.h.

430  {
431  try {
432  Potential< GUM_SCALAR > res;
433  res.add(credalNet_->current_bn().variable(id));
434  res.fillWith(marginalMin_[id]);
435  return res;
436  } catch (NotFound& err) { throw(err); }
437  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
margi marginalMin_
Lower marginals.

◆ marginalMin() [2/2]

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin ( const std::string &  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 419 of file inferenceEngine_tpl.h.

419  {
420  return marginalMin(credalNet_->current_bn().idFromName(varName));
421  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
Potential< GUM_SCALAR > marginalMin(const NodeId id) const
Get the lower marginals of a given node id.

◆ maxIter()

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

Returns the criterion on number of iterations.

Returns
Returns the criterion on number of iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 91 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

91 { return max_iter_; }
Size max_iter_
The maximum iterations.
+ Here is the call graph for this function:

◆ maxTime()

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

Returns the timeout (in seconds).

Returns
Returns the timeout (in seconds).

Implements gum::IApproximationSchemeConfiguration.

Definition at line 112 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

112 { return max_time_; }
double max_time_
The timeout.
+ Here is the call graph for this function:

◆ messageApproximationScheme()

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

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 38 of file IApproximationSchemeConfiguration_inl.h.

References gum::Set< Key, Alloc >::emplace().

38  {
39  std::stringstream s;
40 
41  switch (stateApproximationScheme()) {
43  s << "in progress";
44  break;
45 
47  s << "stopped with epsilon=" << epsilon();
48  break;
49 
51  s << "stopped with rate=" << minEpsilonRate();
52  break;
53 
55  s << "stopped with max iteration=" << maxIter();
56  break;
57 
59  s << "stopped with timeout=" << maxTime();
60  break;
61 
63  s << "stopped on request";
64  break;
65 
67  s << "undefined state";
68  break;
69  };
70 
71  return s.str();
72  }
virtual double epsilon() const =0
Returns the value of epsilon.
virtual ApproximationSchemeSTATE stateApproximationScheme() const =0
Returns the approximation scheme state.
virtual double maxTime() const =0
Returns the timeout (in seconds).
virtual Size maxIter() const =0
Returns the criterion on number of iterations.
virtual double minEpsilonRate() const =0
Returns the value of the minimal epsilon rate.
+ Here is the call graph for this function:

◆ minEpsilonRate()

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

Returns the value of the minimal epsilon rate.

Returns
Returns the value of the minimal epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 71 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

71 { return min_rate_eps_; }
double min_rate_eps_
Threshold for the epsilon rate.
+ Here is the call graph for this function:

◆ msgL_()

template<typename 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 835 of file CNLoopyPropagation_tpl.h.

835  {
836  NodeSet const& children = _bnet_->children(Y);
837  NodeSet const& parents_ = _bnet_->parents(Y);
838 
839  const auto parents = &_bnet_->cpt(Y).variablesSequence();
840 
841  if (((children.size() + parents->size() - 1) == 1) && (!_infE_::evidence_.exists(Y))) {
842  return;
843  }
844 
845  bool update_l = update_l_[Y];
846  bool update_p = update_p_[Y];
847 
848  if (!update_p && !update_l) { return; }
849 
850  msg_l_sent_[Y]->insert(X);
851 
852  // for future refresh LM/PI
853  if (msg_l_sent_[Y]->size() == parents_.size()) {
854  msg_l_sent_[Y]->clear();
855  update_l_[Y] = false;
856  }
857 
858  // refresh LM_part
859  if (update_l) {
860  if (!children.empty() && !_infE_::evidence_.exists(Y)) {
861  GUM_SCALAR lmin = 1.;
862  GUM_SCALAR lmax = 1.;
863 
864  for (auto chil: children) {
865  lmin *= ArcsL_min_[Arc(Y, chil)];
866 
867  if (ArcsL_max_.exists(Arc(Y, chil))) {
868  lmax *= ArcsL_max_[Arc(Y, chil)];
869  } else {
870  lmax *= ArcsL_min_[Arc(Y, chil)];
871  }
872  }
873 
874  lmin = lmax;
875 
876  if (lmax != lmax && lmin == lmin) { lmax = lmin; }
877 
878  if (lmax != lmax && lmin != lmin) {
879  std::cout << "no likelihood defined [lmin, lmax] (incompatibles "
880  "evidence ?)"
881  << std::endl;
882  }
883 
884  if (lmin < 0.) { lmin = 0.; }
885 
886  if (lmax < 0.) { lmax = 0.; }
887 
888  // no need to update nodeL if evidence since nodeL will never be used
889 
890  NodesL_min_[Y] = lmin;
891 
892  if (lmin != lmax) {
893  NodesL_max_.set(Y, lmax);
894  } else if (NodesL_max_.exists(Y)) {
895  NodesL_max_.erase(Y);
896  }
897 
898  } // end of : node has children & no evidence
899 
900  } // end of : if update_l
901 
902  GUM_SCALAR lmin = NodesL_min_[Y];
903  GUM_SCALAR lmax;
904 
905  if (NodesL_max_.exists(Y)) {
906  lmax = NodesL_max_[Y];
907  } else {
908  lmax = lmin;
909  }
910 
915  if (lmin == lmax && lmin == 1.) {
916  ArcsL_min_[Arc(X, Y)] = lmin;
917 
918  if (ArcsL_max_.exists(Arc(X, Y))) { ArcsL_max_.erase(Arc(X, Y)); }
919 
920  return;
921  }
922 
923  // garder pour chaque noeud un table des parents maj, une fois tous maj,
924  // stop
925  // jusque notification msg L ou P
926 
927  if (update_p || update_l) {
928  std::vector< std::vector< std::vector< GUM_SCALAR > > > msgs_p;
929  std::vector< std::vector< GUM_SCALAR > > msg_p;
930  std::vector< GUM_SCALAR > distri(2);
931 
932  Idx pos;
933 
934  // +1 from start to avoid counting_ itself
935  // use const iterators with cbegin when available
936  for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd; ++jt) {
937  if (_bnet_->nodeId(**jt) == X) {
938  // retirer la variable courante de la taille
939  pos = parents->pos(*jt) - 1;
940  continue;
941  }
942 
943  // compute probability distribution to avoid doing it multiple times
944  // (at each combination of messages)
945  distri[1] = ArcsP_min_[Arc(_bnet_->nodeId(**jt), Y)];
946  distri[0] = GUM_SCALAR(1.) - distri[1];
947  msg_p.push_back(distri);
948 
949  if (ArcsP_max_.exists(Arc(_bnet_->nodeId(**jt), Y))) {
950  distri[1] = ArcsP_max_[Arc(_bnet_->nodeId(**jt), Y)];
951  distri[0] = GUM_SCALAR(1.) - distri[1];
952  msg_p.push_back(distri);
953  }
954 
955  msgs_p.push_back(msg_p);
956  msg_p.clear();
957  }
958 
959  GUM_SCALAR min = -2.;
960  GUM_SCALAR max = -2.;
961 
962  std::vector< GUM_SCALAR > lx;
963  lx.push_back(lmin);
964 
965  if (lmin != lmax) { lx.push_back(lmax); }
966 
967  enum_combi_(msgs_p, Y, min, max, lx, pos);
968 
969  if (min == -2. || max == -2.) {
970  if (min != -2.) {
971  max = min;
972  } else if (max != -2.) {
973  min = max;
974  } else {
975  std::cout << std::endl;
976  std::cout << "!!!! pas de message L calculable !!!!" << std::endl;
977  return;
978  }
979  }
980 
981  if (min < 0.) { min = 0.; }
982 
983  if (max < 0.) { max = 0.; }
984 
985  bool update = false;
986 
987  if (min != ArcsL_min_[Arc(X, Y)]) {
988  ArcsL_min_[Arc(X, Y)] = min;
989  update = true;
990  }
991 
992  if (ArcsL_max_.exists(Arc(X, Y))) {
993  if (max != ArcsL_max_[Arc(X, Y)]) {
994  if (max != min) {
995  ArcsL_max_[Arc(X, Y)] = max;
996  } else { // if ( max == min )
997  ArcsL_max_.erase(Arc(X, Y));
998  }
999 
1000  update = true;
1001  }
1002  } else {
1003  if (max != min) {
1004  ArcsL_max_.insert(Arc(X, Y), max);
1005  update = true;
1006  }
1007  }
1008 
1009  if (update) {
1010  update_l_.set(X, true);
1012  }
1013 
1014  } // end of update_p || update_l
1015  }
NodeProperty< NodeSet *> msg_l_sent_
Used to keep track of one&#39;s messages sent to it&#39;s parents.
NodeProperty< bool > update_l_
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s children...
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
ArcProperty< GUM_SCALAR > ArcsP_min_
"Lower" information coming from one&#39;s parent.
ArcProperty< GUM_SCALAR > ArcsL_max_
"Upper" information coming from one&#39;s children.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
NodeProperty< GUM_SCALAR > NodesL_min_
"Lower" node information obtained by combinaison of children messages.
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_.
NodeProperty< bool > update_p_
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s parents...
ArcProperty< GUM_SCALAR > ArcsP_max_
"Upper" information coming from one&#39;s parent.
margi evidence_
Holds observed variables states.
NodeProperty< GUM_SCALAR > NodesL_max_
"Upper" node information obtained by combinaison of children messages.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
NodeSet next_active_nodes_set
The next node-set, i.e.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
ArcProperty< GUM_SCALAR > ArcsL_min_
"Lower" information coming from one&#39;s children.

◆ msgP_()

template<typename 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 1018 of file CNLoopyPropagation_tpl.h.

1018  {
1019  NodeSet const& children = _bnet_->children(X);
1020 
1021  const auto parents = &_bnet_->cpt(X).variablesSequence();
1022 
1023  if (((children.size() + parents->size() - 1) == 1) && (!_infE_::evidence_.exists(X))) {
1024  return;
1025  }
1026 
1027  // LM_part ---- from all children but one --- the lonely one will get the
1028  // message
1029 
1030  if (_infE_::evidence_.exists(X)) {
1031  ArcsP_min_[Arc(X, demanding_child)] = _infE_::evidence_[X][1];
1032 
1033  if (ArcsP_max_.exists(Arc(X, demanding_child))) {
1034  ArcsP_max_.erase(Arc(X, demanding_child));
1035  }
1036 
1037  return;
1038  }
1039 
1040  bool update_l = update_l_[X];
1041  bool update_p = update_p_[X];
1042 
1043  if (!update_p && !update_l) { return; }
1044 
1045  GUM_SCALAR lmin = 1.;
1046  GUM_SCALAR lmax = 1.;
1047 
1048  // use cbegin if available
1049  for (auto chil: children) {
1050  if (chil == demanding_child) { continue; }
1051 
1052  lmin *= ArcsL_min_[Arc(X, chil)];
1053 
1054  if (ArcsL_max_.exists(Arc(X, chil))) {
1055  lmax *= ArcsL_max_[Arc(X, chil)];
1056  } else {
1057  lmax *= ArcsL_min_[Arc(X, chil)];
1058  }
1059  }
1060 
1061  if (lmin != lmin && lmax == lmax) { lmin = lmax; }
1062 
1063  if (lmax != lmax && lmin == lmin) { lmax = lmin; }
1064 
1065  if (lmax != lmax && lmin != lmin) {
1066  std::cout << "pas de vraisemblance definie [lmin, lmax] (observations "
1067  "incompatibles ?)"
1068  << std::endl;
1069  return;
1070  }
1071 
1072  if (lmin < 0.) { lmin = 0.; }
1073 
1074  if (lmax < 0.) { lmax = 0.; }
1075 
1076  // refresh PI_part
1077  GUM_SCALAR min = INF_;
1078  GUM_SCALAR max = 0.;
1079 
1080  if (update_p) {
1081  std::vector< std::vector< std::vector< GUM_SCALAR > > > msgs_p;
1082  std::vector< std::vector< GUM_SCALAR > > msg_p;
1083  std::vector< GUM_SCALAR > distri(2);
1084 
1085  // +1 from start to avoid counting_ itself
1086  // use const_iterators if available
1087  for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd; ++jt) {
1088  // compute probability distribution to avoid doing it multiple times
1089  // (at
1090  // each combination of messages)
1091  distri[1] = ArcsP_min_[Arc(_bnet_->nodeId(**jt), X)];
1092  distri[0] = GUM_SCALAR(1.) - distri[1];
1093  msg_p.push_back(distri);
1094 
1095  if (ArcsP_max_.exists(Arc(_bnet_->nodeId(**jt), X))) {
1096  distri[1] = ArcsP_max_[Arc(_bnet_->nodeId(**jt), X)];
1097  distri[0] = GUM_SCALAR(1.) - distri[1];
1098  msg_p.push_back(distri);
1099  }
1100 
1101  msgs_p.push_back(msg_p);
1102  msg_p.clear();
1103  }
1104 
1105  enum_combi_(msgs_p, X, min, max);
1106 
1107  if (min < 0.) { min = 0.; }
1108 
1109  if (max < 0.) { max = 0.; }
1110 
1111  if (min == INF_ || max == INF_) {
1112  std::cout << " ERREUR msg P min = max = INF " << std::endl;
1113  std::cout.flush();
1114  return;
1115  }
1116 
1117  NodesP_min_[X] = min;
1118 
1119  if (min != max) {
1120  NodesP_max_.set(X, max);
1121  } else if (NodesP_max_.exists(X)) {
1122  NodesP_max_.erase(X);
1123  }
1124 
1125  update_p_.set(X, false);
1126 
1127  } // end of update_p
1128  else {
1129  min = NodesP_min_[X];
1130 
1131  if (NodesP_max_.exists(X)) {
1132  max = NodesP_max_[X];
1133  } else {
1134  max = min;
1135  }
1136  }
1137 
1138  if (update_p || update_l) {
1139  GUM_SCALAR msg_p_min;
1140  GUM_SCALAR msg_p_max;
1141 
1142  // cas limites sur min
1143  if (min == INF_ && lmin == 0.) {
1144  std::cout << "MESSAGE P ERR (negatif) : pi = inf, l = 0" << std::endl;
1145  }
1146 
1147  if (lmin == INF_) { // cas infini
1148  msg_p_min = GUM_SCALAR(1.);
1149  } else if (min == 0. || lmin == 0.) {
1150  msg_p_min = 0;
1151  } else {
1152  msg_p_min = GUM_SCALAR(1. / (1. + ((1. / min - 1.) * 1. / lmin)));
1153  }
1154 
1155  // cas limites sur max
1156  if (max == INF_ && lmax == 0.) {
1157  std::cout << "MESSAGE P ERR (negatif) : pi = inf, l = 0" << std::endl;
1158  }
1159 
1160  if (lmax == INF_) { // cas infini
1161  msg_p_max = GUM_SCALAR(1.);
1162  } else if (max == 0. || lmax == 0.) {
1163  msg_p_max = 0;
1164  } else {
1165  msg_p_max = GUM_SCALAR(1. / (1. + ((1. / max - 1.) * 1. / lmax)));
1166  }
1167 
1168  if (msg_p_min != msg_p_min && msg_p_max == msg_p_max) {
1169  msg_p_min = msg_p_max;
1170  std::cout << std::endl;
1171  std::cout << "msg_p_min is NaN" << std::endl;
1172  }
1173 
1174  if (msg_p_max != msg_p_max && msg_p_min == msg_p_min) {
1175  msg_p_max = msg_p_min;
1176  std::cout << std::endl;
1177  std::cout << "msg_p_max is NaN" << std::endl;
1178  }
1179 
1180  if (msg_p_max != msg_p_max && msg_p_min != msg_p_min) {
1181  std::cout << std::endl;
1182  std::cout << "pas de message P calculable (verifier observations)" << std::endl;
1183  return;
1184  }
1185 
1186  if (msg_p_min < 0.) { msg_p_min = 0.; }
1187 
1188  if (msg_p_max < 0.) { msg_p_max = 0.; }
1189 
1190  bool update = false;
1191 
1192  if (msg_p_min != ArcsP_min_[Arc(X, demanding_child)]) {
1193  ArcsP_min_[Arc(X, demanding_child)] = msg_p_min;
1194  update = true;
1195  }
1196 
1197  if (ArcsP_max_.exists(Arc(X, demanding_child))) {
1198  if (msg_p_max != ArcsP_max_[Arc(X, demanding_child)]) {
1199  if (msg_p_max != msg_p_min) {
1200  ArcsP_max_[Arc(X, demanding_child)] = msg_p_max;
1201  } else { // if ( msg_p_max == msg_p_min )
1202  ArcsP_max_.erase(Arc(X, demanding_child));
1203  }
1204 
1205  update = true;
1206  }
1207  } else {
1208  if (msg_p_max != msg_p_min) {
1209  ArcsP_max_.insert(Arc(X, demanding_child), msg_p_max);
1210  update = true;
1211  }
1212  }
1213 
1214  if (update) {
1215  update_p_.set(demanding_child, true);
1216  next_active_nodes_set.insert(demanding_child);
1217  }
1218 
1219  } // end of : update_l || update_p
1220  }
#define INF_
NodeProperty< bool > update_l_
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s children...
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
ArcProperty< GUM_SCALAR > ArcsP_min_
"Lower" information coming from one&#39;s parent.
ArcProperty< GUM_SCALAR > ArcsL_max_
"Upper" information coming from one&#39;s children.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
NodeProperty< GUM_SCALAR > NodesP_max_
"Upper" node information obtained by combinaison of parent&#39;s messages.
NodeProperty< GUM_SCALAR > NodesP_min_
"Lower" node information obtained by combinaison of parent&#39;s messages.
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_.
NodeProperty< bool > update_p_
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s parents...
ArcProperty< GUM_SCALAR > ArcsP_max_
"Upper" information coming from one&#39;s parent.
margi evidence_
Holds observed variables states.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
NodeSet next_active_nodes_set
The next node-set, i.e.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
ArcProperty< GUM_SCALAR > ArcsL_min_
"Lower" information coming from one&#39;s children.

◆ nbrIterations()

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

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 148 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

148  {
150  GUM_ERROR(OperationNotAllowed, "state of the approximation scheme is undefined")
151  }
152 
153  return current_step_;
154  }
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
Size current_step_
The current step.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ periodSize()

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

Returns the period size.

Returns
Returns the period size.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 134 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

134 { return period_size_; }
Size period_size_
Checking criteria frequency.
+ Here is the call graph for this function:

◆ refreshLMsPIs_()

template<typename 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 1223 of file CNLoopyPropagation_tpl.h.

1223  {
1224  for (auto node: _bnet_->nodes()) {
1225  if ((!refreshIndic)
1226  && _cn_->currentNodeType(node) == CredalNet< GUM_SCALAR >::NodeType::Indic) {
1227  continue;
1228  }
1229 
1230  NodeSet const& children = _bnet_->children(node);
1231 
1232  auto parents = &_bnet_->cpt(node).variablesSequence();
1233 
1234  if (update_l_[node]) {
1235  GUM_SCALAR lmin = 1.;
1236  GUM_SCALAR lmax = 1.;
1237 
1238  if (!children.empty() && !_infE_::evidence_.exists(node)) {
1239  for (auto chil: children) {
1240  lmin *= ArcsL_min_[Arc(node, chil)];
1241 
1242  if (ArcsL_max_.exists(Arc(node, chil))) {
1243  lmax *= ArcsL_max_[Arc(node, chil)];
1244  } else {
1245  lmax *= ArcsL_min_[Arc(node, chil)];
1246  }
1247  }
1248 
1249  if (lmin != lmin && lmax == lmax) { lmin = lmax; }
1250 
1251  lmax = lmin;
1252 
1253  if (lmax != lmax && lmin != lmin) {
1254  std::cout << "pas de vraisemblance definie [lmin, lmax] (observations "
1255  "incompatibles ?)"
1256  << std::endl;
1257  return;
1258  }
1259 
1260  if (lmin < 0.) { lmin = 0.; }
1261 
1262  if (lmax < 0.) { lmax = 0.; }
1263 
1264  NodesL_min_[node] = lmin;
1265 
1266  if (lmin != lmax) {
1267  NodesL_max_.set(node, lmax);
1268  } else if (NodesL_max_.exists(node)) {
1269  NodesL_max_.erase(node);
1270  }
1271  }
1272 
1273  } // end of : update_l
1274 
1275  if (update_p_[node]) {
1276  if ((parents->size() - 1) > 0 && !_infE_::evidence_.exists(node)) {
1277  std::vector< std::vector< std::vector< GUM_SCALAR > > > msgs_p;
1278  std::vector< std::vector< GUM_SCALAR > > msg_p;
1279  std::vector< GUM_SCALAR > distri(2);
1280 
1281  // +1 from start to avoid counting_ itself
1282  // cbegin
1283  for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd; ++jt) {
1284  // compute probability distribution to avoid doing it multiple
1285  // times
1286  // (at each combination of messages)
1287  distri[1] = ArcsP_min_[Arc(_bnet_->nodeId(**jt), node)];
1288  distri[0] = GUM_SCALAR(1.) - distri[1];
1289  msg_p.push_back(distri);
1290 
1291  if (ArcsP_max_.exists(Arc(_bnet_->nodeId(**jt), node))) {
1292  distri[1] = ArcsP_max_[Arc(_bnet_->nodeId(**jt), node)];
1293  distri[0] = GUM_SCALAR(1.) - distri[1];
1294  msg_p.push_back(distri);
1295  }
1296 
1297  msgs_p.push_back(msg_p);
1298  msg_p.clear();
1299  }
1300 
1301  GUM_SCALAR min = INF_;
1302  GUM_SCALAR max = 0.;
1303 
1304  enum_combi_(msgs_p, node, min, max);
1305 
1306  if (min < 0.) { min = 0.; }
1307 
1308  if (max < 0.) { max = 0.; }
1309 
1310  NodesP_min_[node] = min;
1311 
1312  if (min != max) {
1313  NodesP_max_.set(node, max);
1314  } else if (NodesP_max_.exists(node)) {
1315  NodesP_max_.erase(node);
1316  }
1317 
1318  update_p_[node] = false;
1319  }
1320  } // end of update_p
1321 
1322  } // end of : for each node
1323  }
#define INF_
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
NodeProperty< bool > update_l_
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s children...
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
ArcProperty< GUM_SCALAR > ArcsP_min_
"Lower" information coming from one&#39;s parent.
ArcProperty< GUM_SCALAR > ArcsL_max_
"Upper" information coming from one&#39;s children.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
NodeProperty< GUM_SCALAR > NodesL_min_
"Lower" node information obtained by combinaison of children messages.
NodeProperty< GUM_SCALAR > NodesP_max_
"Upper" node information obtained by combinaison of parent&#39;s messages.
NodeProperty< GUM_SCALAR > NodesP_min_
"Lower" node information obtained by combinaison of parent&#39;s messages.
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_.
NodeProperty< bool > update_p_
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s parents...
ArcProperty< GUM_SCALAR > ArcsP_max_
"Upper" information coming from one&#39;s parent.
margi evidence_
Holds observed variables states.
NodeProperty< GUM_SCALAR > NodesL_max_
"Upper" node information obtained by combinaison of children messages.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
ArcProperty< GUM_SCALAR > ArcsL_min_
"Lower" information coming from one&#39;s children.

◆ remainingBurnIn()

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

Returns the remaining burn in.

Returns
Returns the remaining burn in.

Definition at line 191 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

191  {
192  if (burn_in_ > current_step_) {
193  return burn_in_ - current_step_;
194  } else {
195  return 0;
196  }
197  }
Size burn_in_
Number of iterations before checking stopping criteria.
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ repetitiveInd()

template<typename 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 118 of file inferenceEngine_tpl.h.

118  {
119  return repetitiveInd_;
120  }
bool repetitiveInd_
True if using repetitive independence ( dynamic network only ), False otherwise.

◆ repetitiveInit_()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::repetitiveInit_ ( )
protectedinherited

Initialize t0_ and t1_ clusters.

Definition at line 767 of file inferenceEngine_tpl.h.

767  {
768  timeSteps_ = 0;
769  t0_.clear();
770  t1_.clear();
771 
772  // t = 0 vars belongs to t0_ as keys
773  for (auto node: credalNet_->current_bn().dag().nodes()) {
774  std::string var_name = credalNet_->current_bn().variable(node).name();
775  auto delim = var_name.find_first_of("_");
776 
777  if (delim > var_name.size()) {
778  GUM_ERROR(InvalidArgument,
779  "void InferenceEngine< GUM_SCALAR "
780  ">::repetitiveInit_() : the network does not "
781  "appear to be dynamic");
782  }
783 
784  std::string time_step = var_name.substr(delim + 1, 1);
785 
786  if (time_step.compare("0") == 0) t0_.insert(node, std::vector< NodeId >());
787  }
788 
789  // t = 1 vars belongs to either t0_ as member value or t1_ as keys
790  for (const auto& node: credalNet_->current_bn().dag().nodes()) {
791  std::string var_name = credalNet_->current_bn().variable(node).name();
792  auto delim = var_name.find_first_of("_");
793  std::string time_step = var_name.substr(delim + 1, var_name.size());
794  var_name = var_name.substr(0, delim);
795  delim = time_step.find_first_of("_");
796  time_step = time_step.substr(0, delim);
797 
798  if (time_step.compare("1") == 0) {
799  bool found = false;
800 
801  for (const auto& elt: t0_) {
802  std::string var_0_name = credalNet_->current_bn().variable(elt.first).name();
803  delim = var_0_name.find_first_of("_");
804  var_0_name = var_0_name.substr(0, delim);
805 
806  if (var_name.compare(var_0_name) == 0) {
807  const Potential< GUM_SCALAR >* potential(&credalNet_->current_bn().cpt(node));
808  const Potential< GUM_SCALAR >* potential2(&credalNet_->current_bn().cpt(elt.first));
809 
810  if (potential->domainSize() == potential2->domainSize())
811  t0_[elt.first].push_back(node);
812  else
813  t1_.insert(node, std::vector< NodeId >());
814 
815  found = true;
816  break;
817  }
818  }
819 
820  if (!found) { t1_.insert(node, std::vector< NodeId >()); }
821  }
822  }
823 
824  // t > 1 vars belongs to either t0_ or t1_ as member value
825  // remember timeSteps_
826  for (auto node: credalNet_->current_bn().dag().nodes()) {
827  std::string var_name = credalNet_->current_bn().variable(node).name();
828  auto delim = var_name.find_first_of("_");
829  std::string time_step = var_name.substr(delim + 1, var_name.size());
830  var_name = var_name.substr(0, delim);
831  delim = time_step.find_first_of("_");
832  time_step = time_step.substr(0, delim);
833 
834  if (time_step.compare("0") != 0 && time_step.compare("1") != 0) {
835  // keep max time_step
836  if (atoi(time_step.c_str()) > timeSteps_) timeSteps_ = atoi(time_step.c_str());
837 
838  std::string var_0_name;
839  bool found = false;
840 
841  for (const auto& elt: t0_) {
842  std::string var_0_name = credalNet_->current_bn().variable(elt.first).name();
843  delim = var_0_name.find_first_of("_");
844  var_0_name = var_0_name.substr(0, delim);
845 
846  if (var_name.compare(var_0_name) == 0) {
847  const Potential< GUM_SCALAR >* potential(&credalNet_->current_bn().cpt(node));
848  const Potential< GUM_SCALAR >* potential2(&credalNet_->current_bn().cpt(elt.first));
849 
850  if (potential->domainSize() == potential2->domainSize()) {
851  t0_[elt.first].push_back(node);
852  found = true;
853  break;
854  }
855  }
856  }
857 
858  if (!found) {
859  for (const auto& elt: t1_) {
860  std::string var_0_name = credalNet_->current_bn().variable(elt.first).name();
861  auto delim = var_0_name.find_first_of("_");
862  var_0_name = var_0_name.substr(0, delim);
863 
864  if (var_name.compare(var_0_name) == 0) {
865  const Potential< GUM_SCALAR >* potential(&credalNet_->current_bn().cpt(node));
866  const Potential< GUM_SCALAR >* potential2(&credalNet_->current_bn().cpt(elt.first));
867 
868  if (potential->domainSize() == potential2->domainSize()) {
869  t1_[elt.first].push_back(node);
870  break;
871  }
872  }
873  }
874  }
875  }
876  }
877  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
cluster t1_
Clusters of nodes used with dynamic networks.
cluster t0_
Clusters of nodes used with dynamic networks.
void clear()
Removes all the elements in the hash table.
int timeSteps_
The number of time steps of this network (only usefull for dynamic networks).
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ saveExpectations()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::saveExpectations ( const std::string &  path) const
inherited

Saves expectations to file.

Parameters
pathThe path to the file to be used.

Definition at line 542 of file inferenceEngine_tpl.h.

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

◆ saveInference()

template<typename GUM_SCALAR >
void gum::credal::CNLoopyPropagation< GUM_SCALAR >::saveInference ( const std::string &  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 28 of file CNLoopyPropagation_tpl.h.

28  {
29  std::string path_name = path.substr(0, path.size() - 4);
30  path_name = path_name + ".res";
31 
32  std::ofstream res(path_name.c_str(), std::ios::out | std::ios::trunc);
33 
34  if (!res.good()) {
35  GUM_ERROR(NotFound,
36  "CNLoopyPropagation<GUM_SCALAR>::saveInference(std::"
37  "string & path) : could not open file : "
38  + path_name);
39  }
40 
41  std::string ext = path.substr(path.size() - 3, path.size());
42 
43  if (std::strcmp(ext.c_str(), "evi") == 0) {
44  std::ifstream evi(path.c_str(), std::ios::in);
45  std::string ligne;
46 
47  if (!evi.good()) {
48  GUM_ERROR(NotFound,
49  "CNLoopyPropagation<GUM_SCALAR>::saveInference(std::"
50  "string & path) : could not open file : "
51  + ext);
52  }
53 
54  while (evi.good()) {
55  getline(evi, ligne);
56  res << ligne << "\n";
57  }
58 
59  evi.close();
60  }
61 
62  res << "[RESULTATS]"
63  << "\n";
64 
65  for (auto node: _bnet_->nodes()) {
66  // calcul distri posteriori
67  GUM_SCALAR msg_p_min = 1.0;
68  GUM_SCALAR msg_p_max = 0.0;
69 
70  // cas evidence, calcul immediat
71  if (_infE_::evidence_.exists(node)) {
72  if (_infE_::evidence_[node][1] == 0.) {
73  msg_p_min = 0.;
74  } else if (_infE_::evidence_[node][1] == 1.) {
75  msg_p_min = 1.;
76  }
77 
78  msg_p_max = msg_p_min;
79  }
80  // sinon depuis node P et node L
81  else {
82  GUM_SCALAR min = NodesP_min_[node];
83  GUM_SCALAR max;
84 
85  if (NodesP_max_.exists(node)) {
86  max = NodesP_max_[node];
87  } else {
88  max = min;
89  }
90 
91  GUM_SCALAR lmin = NodesL_min_[node];
92  GUM_SCALAR lmax;
93 
94  if (NodesL_max_.exists(node)) {
95  lmax = NodesL_max_[node];
96  } else {
97  lmax = lmin;
98  }
99 
100  // cas limites sur min
101  if (min == INF_ && lmin == 0.) {
102  std::cout << "proba ERR (negatif) : pi = inf, l = 0" << std::endl;
103  }
104 
105  if (lmin == INF_) { // cas infini
106  msg_p_min = GUM_SCALAR(1.);
107  } else if (min == 0. || lmin == 0.) {
108  msg_p_min = GUM_SCALAR(0.);
109  } else {
110  msg_p_min = GUM_SCALAR(1. / (1. + ((1. / min - 1.) * 1. / lmin)));
111  }
112 
113  // cas limites sur max
114  if (max == INF_ && lmax == 0.) {
115  std::cout << "proba ERR (negatif) : pi = inf, l = 0" << std::endl;
116  }
117 
118  if (lmax == INF_) { // cas infini
119  msg_p_max = GUM_SCALAR(1.);
120  } else if (max == 0. || lmax == 0.) {
121  msg_p_max = GUM_SCALAR(0.);
122  } else {
123  msg_p_max = GUM_SCALAR(1. / (1. + ((1. / max - 1.) * 1. / lmax)));
124  }
125  }
126 
127  if (msg_p_min != msg_p_min && msg_p_max == msg_p_max) { msg_p_min = msg_p_max; }
128 
129  if (msg_p_max != msg_p_max && msg_p_min == msg_p_min) { msg_p_max = msg_p_min; }
130 
131  if (msg_p_max != msg_p_max && msg_p_min != msg_p_min) {
132  std::cout << std::endl;
133  std::cout << "pas de proba calculable (verifier observations)" << std::endl;
134  }
135 
136  res << "P(" << _bnet_->variable(node).name() << " | e) = ";
137 
138  if (_infE_::evidence_.exists(node)) {
139  res << "(observe)" << std::endl;
140  } else {
141  res << std::endl;
142  }
143 
144  res << "\t\t" << _bnet_->variable(node).label(0) << " [ " << (GUM_SCALAR)1. - msg_p_max;
145 
146  if (msg_p_min != msg_p_max) {
147  res << ", " << (GUM_SCALAR)1. - msg_p_min << " ] | ";
148  } else {
149  res << " ] | ";
150  }
151 
152  res << _bnet_->variable(node).label(1) << " [ " << msg_p_min;
153 
154  if (msg_p_min != msg_p_max) {
155  res << ", " << msg_p_max << " ]" << std::endl;
156  } else {
157  res << " ]" << std::endl;
158  }
159  } // end of : for each node
160 
161  res.close();
162  }
#define INF_
NodeProperty< GUM_SCALAR > NodesL_min_
"Lower" node information obtained by combinaison of children messages.
NodeProperty< GUM_SCALAR > NodesP_max_
"Upper" node information obtained by combinaison of parent&#39;s messages.
NodeProperty< GUM_SCALAR > NodesP_min_
"Lower" node information obtained by combinaison of parent&#39;s messages.
margi evidence_
Holds observed variables states.
NodeProperty< GUM_SCALAR > NodesL_max_
"Upper" node information obtained by combinaison of children messages.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ saveMarginals()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::saveMarginals ( const std::string &  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  {
519  std::ofstream m_stream(path.c_str(), std::ios::out | std::ios::trunc);
520 
521  if (!m_stream.good()) {
522  GUM_ERROR(IOError,
523  "void InferenceEngine< GUM_SCALAR >::saveMarginals(const "
524  "std::string & path) const : could not open output file "
525  ": "
526  << path);
527  }
528 
529  for (const auto& elt: marginalMin_) {
530  Size esize = Size(elt.second.size());
531 
532  for (Size mod = 0; mod < esize; mod++) {
533  m_stream << credalNet_->current_bn().variable(elt.first).name() << " " << mod << " "
534  << (elt.second)[mod] << " " << marginalMax_[elt.first][mod] << std::endl;
535  }
536  }
537 
538  m_stream.close();
539  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
margi marginalMax_
Upper marginals.
margi marginalMin_
Lower marginals.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ saveVertices()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::saveVertices ( const std::string &  path) const
inherited

Saves vertices to file.

Parameters
pathThe path to the file to be used.

Definition at line 612 of file inferenceEngine_tpl.h.

612  {
613  std::ofstream m_stream(path.c_str(), std::ios::out | std::ios::trunc);
614 
615  if (!m_stream.good()) {
616  GUM_ERROR(IOError,
617  "void InferenceEngine< GUM_SCALAR >::saveVertices(const "
618  "std::string & path) : could not open outpul file : "
619  << path);
620  }
621 
622  for (const auto& elt: marginalSets_) {
623  m_stream << credalNet_->current_bn().variable(elt.first).name() << std::endl;
624 
625  for (const auto& elt2: elt.second) {
626  m_stream << "[";
627  bool first = true;
628 
629  for (const auto& elt3: elt2) {
630  if (!first) {
631  m_stream << ",";
632  first = false;
633  }
634 
635  m_stream << elt3;
636  }
637 
638  m_stream << "]\n";
639  }
640  }
641 
642  m_stream.close();
643  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
credalSet marginalSets_
Credal sets vertices, if enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ setEpsilon()

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

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
OutOfLowerBoundRaised if eps < 0.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 42 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

42  {
43  if (eps < 0.) { GUM_ERROR(OutOfLowerBound, "eps should be >=0") }
44 
45  eps_ = eps;
46  enabled_eps_ = true;
47  }
double eps_
Threshold for convergence.
bool enabled_eps_
If true, the threshold convergence is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ setMaxIter()

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

Stopping criterion on number of iterations.

If the criterion was disabled it will be enabled.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 84 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

84  {
85  if (max < 1) { GUM_ERROR(OutOfLowerBound, "max should be >=1") }
86  max_iter_ = max;
87  enabled_max_iter_ = true;
88  }
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
Size max_iter_
The maximum iterations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ setMaxTime()

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

Stopping criterion on timeout.

If the criterion was disabled it will be enabled.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 105 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

105  {
106  if (timeout <= 0.) { GUM_ERROR(OutOfLowerBound, "timeout should be >0.") }
107  max_time_ = timeout;
108  enabled_max_time_ = true;
109  }
double max_time_
The timeout.
bool enabled_max_time_
If true, the timeout is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ setMinEpsilonRate()

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

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
OutOfLowerBoundif rate<0

Implements gum::IApproximationSchemeConfiguration.

Definition at line 63 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

63  {
64  if (rate < 0) { GUM_ERROR(OutOfLowerBound, "rate should be >=0") }
65 
66  min_rate_eps_ = rate;
67  enabled_min_rate_eps_ = true;
68  }
double min_rate_eps_
Threshold for the epsilon rate.
bool enabled_min_rate_eps_
If true, the minimal threshold for epsilon rate is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ setPeriodSize()

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

How many samples between two stopping is enable.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 128 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

128  {
129  if (p < 1) { GUM_ERROR(OutOfLowerBound, "p should be >=1") }
130 
131  period_size_ = p;
132  }
Size period_size_
Checking criteria frequency.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ setRepetitiveInd()

template<typename 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 usefull with dynamic networks.

Definition at line 109 of file inferenceEngine_tpl.h.

109  {
110  bool oldValue = repetitiveInd_;
111  repetitiveInd_ = repetitive;
112 
113  // do not compute clusters more than once
114  if (repetitiveInd_ && !oldValue) repetitiveInit_();
115  }
bool repetitiveInd_
True if using repetitive independence ( dynamic network only ), False otherwise.
void repetitiveInit_()
Initialize t0_ and t1_ clusters.

◆ setVerbosity()

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

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

Parameters
vIf true, then verbosity is turned on.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 137 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

137 { verbosity_ = v; }
bool verbosity_
If true, verbosity is enabled.
+ Here is the call graph for this function:

◆ startOfPeriod()

INLINE bool gum::ApproximationScheme::startOfPeriod ( )
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 178 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

178  {
179  if (current_step_ < burn_in_) { return false; }
180 
181  if (period_size_ == 1) { return true; }
182 
183  return ((current_step_ - burn_in_) % period_size_ == 0);
184  }
Size burn_in_
Number of iterations before checking stopping criteria.
Size period_size_
Checking criteria frequency.
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ stateApproximationScheme()

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

Returns the approximation scheme state.

Returns
Returns the approximation scheme state.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 143 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

143  {
144  return current_state_;
145  }
ApproximationSchemeSTATE current_state_
The current state.
+ Here is the call graph for this function:

◆ stopApproximationScheme()

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

Stop the approximation scheme.

Definition at line 200 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

+ Here is the call graph for this function:

◆ storeBNOpt() [1/2]

template<typename 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 97 of file inferenceEngine_tpl.h.

97  {
98  storeBNOpt_ = value;
99  }
bool storeBNOpt_
Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling.

◆ storeBNOpt() [2/2]

template<typename 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 133 of file inferenceEngine_tpl.h.

133  {
134  return storeBNOpt_;
135  }
bool storeBNOpt_
Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling.

◆ storeVertices() [1/2]

template<typename 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 102 of file inferenceEngine_tpl.h.

102  {
103  storeVertices_ = value;
104 
105  if (value) initMarginalSets_();
106  }
bool storeVertices_
True if credal sets vertices are stored, False otherwise.
void initMarginalSets_()
Initialize credal set vertices with empty sets.

◆ storeVertices() [2/2]

template<typename 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 128 of file inferenceEngine_tpl.h.

128  {
129  return storeVertices_;
130  }
bool storeVertices_
True if credal sets vertices are stored, False otherwise.

◆ toString()

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

Print all nodes marginals to standart output.

Definition at line 586 of file inferenceEngine_tpl.h.

586  {
587  std::stringstream output;
588  output << std::endl;
589 
590  // use cbegin() when available
591  for (const auto& elt: marginalMin_) {
592  Size esize = Size(elt.second.size());
593 
594  for (Size mod = 0; mod < esize; mod++) {
595  output << "P(" << credalNet_->current_bn().variable(elt.first).name() << "=" << mod
596  << "|e) = [ ";
597  output << marginalMin_[elt.first][mod] << ", " << marginalMax_[elt.first][mod] << " ]";
598 
599  if (!query_.empty())
600  if (query_.exists(elt.first) && query_[elt.first][mod]) output << " QUERY";
601 
602  output << std::endl;
603  }
604 
605  output << std::endl;
606  }
607 
608  return output.str();
609  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
query query_
Holds the query nodes states.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
margi marginalMax_
Upper marginals.
margi marginalMin_
Lower marginals.
bool empty() const noexcept
Indicates whether the hash table is empty.

◆ updateApproximationScheme()

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

Update the scheme w.r.t the new error and increment steps.

Parameters
incrThe new increment steps.

Definition at line 187 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

187  {
188  current_step_ += incr;
189  }
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ updateCredalSets_()

template<typename 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 (potential) vertex of the node credal set
elimRedundremove redundant vertex (inside a facet)

Definition at line 902 of file inferenceEngine_tpl.h.

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

◆ updateExpectations_()

template<typename 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 (potential) vertex of the node credal set

Definition at line 881 of file inferenceEngine_tpl.h.

882  {
883  std::string var_name = credalNet_->current_bn().variable(id).name();
884  auto delim = var_name.find_first_of("_");
885 
886  var_name = var_name.substr(0, delim);
887 
888  if (modal_.exists(var_name) /*modal_.find(var_name) != modal_.end()*/) {
889  GUM_SCALAR exp = 0;
890  auto vsize = vertex.size();
891 
892  for (Size mod = 0; mod < vsize; mod++)
893  exp += vertex[mod] * modal_[var_name][mod];
894 
895  if (exp > expectationMax_[id]) expectationMax_[id] = exp;
896 
897  if (exp < expectationMin_[id]) expectationMin_[id] = exp;
898  }
899  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
dynExpe modal_
Variables modalities used to compute expectations.
expe expectationMax_
Upper expectations, if some variables modalities were inserted.
expe expectationMin_
Lower expectations, if some variables modalities were inserted.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

◆ updateIndicatrices_()

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

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

Definition at line 1427 of file CNLoopyPropagation_tpl.h.

1427  {
1428  for (auto node: _bnet_->nodes()) {
1429  if (_cn_->currentNodeType(node) != CredalNet< GUM_SCALAR >::NodeType::Indic) { continue; }
1430 
1431  for (auto pare: _bnet_->parents(node)) {
1432  msgP_(pare, node);
1433  }
1434  }
1435 
1436  refreshLMsPIs_(true);
1437  updateMarginals_();
1438  }
void refreshLMsPIs_(bool refreshIndic=false)
Get the last messages from one&#39;s parents and children.
const CredalNet< GUM_SCALAR > * _cn_
A pointer to the CredalNet to be used.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
void msgP_(const NodeId X, const NodeId demanding_child)
Sends a message to one&#39;s child, i.e.
void updateMarginals_()
Compute marginals from up-to-date messages.

◆ updateMarginals_()

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

Compute marginals from up-to-date messages.

Definition at line 1326 of file CNLoopyPropagation_tpl.h.

1326  {
1327  for (auto node: _bnet_->nodes()) {
1328  GUM_SCALAR msg_p_min = 1.;
1329  GUM_SCALAR msg_p_max = 0.;
1330 
1331  if (_infE_::evidence_.exists(node)) {
1332  if (_infE_::evidence_[node][1] == 0.) {
1333  msg_p_min = (GUM_SCALAR)0.;
1334  } else if (_infE_::evidence_[node][1] == 1.) {
1335  msg_p_min = 1.;
1336  }
1337 
1338  msg_p_max = msg_p_min;
1339  } else {
1340  GUM_SCALAR min = NodesP_min_[node];
1341  GUM_SCALAR max;
1342 
1343  if (NodesP_max_.exists(node)) {
1344  max = NodesP_max_[node];
1345  } else {
1346  max = min;
1347  }
1348 
1349  GUM_SCALAR lmin = NodesL_min_[node];
1350  GUM_SCALAR lmax;
1351  if (NodesL_max_.exists(node)) {
1352  lmax = NodesL_max_[node];
1353  } else {
1354  lmax = lmin;
1355  }
1356 
1357  if (min == INF_ || max == INF_) {
1358  std::cout << " min ou max === INF_ !!!!!!!!!!!!!!!!!!!!!!!!!! " << std::endl;
1359  return;
1360  }
1361 
1362  if (min == INF_ && lmin == 0.) {
1363  std::cout << "proba ERR (negatif) : pi = inf, l = 0" << std::endl;
1364  return;
1365  }
1366 
1367  if (lmin == INF_) {
1368  msg_p_min = GUM_SCALAR(1.);
1369  } else if (min == 0. || lmin == 0.) {
1370  msg_p_min = GUM_SCALAR(0.);
1371  } else {
1372  msg_p_min = GUM_SCALAR(1. / (1. + ((1. / min - 1.) * 1. / lmin)));
1373  }
1374 
1375  if (max == INF_ && lmax == 0.) {
1376  std::cout << "proba ERR (negatif) : pi = inf, l = 0" << std::endl;
1377  return;
1378  }
1379 
1380  if (lmax == INF_) {
1381  msg_p_max = GUM_SCALAR(1.);
1382  } else if (max == 0. || lmax == 0.) {
1383  msg_p_max = GUM_SCALAR(0.);
1384  } else {
1385  msg_p_max = GUM_SCALAR(1. / (1. + ((1. / max - 1.) * 1. / lmax)));
1386  }
1387  }
1388 
1389  if (msg_p_min != msg_p_min && msg_p_max == msg_p_max) {
1390  msg_p_min = msg_p_max;
1391  std::cout << std::endl;
1392  std::cout << "msg_p_min is NaN" << std::endl;
1393  }
1394 
1395  if (msg_p_max != msg_p_max && msg_p_min == msg_p_min) {
1396  msg_p_max = msg_p_min;
1397  std::cout << std::endl;
1398  std::cout << "msg_p_max is NaN" << std::endl;
1399  }
1400 
1401  if (msg_p_max != msg_p_max && msg_p_min != msg_p_min) {
1402  std::cout << std::endl;
1403  std::cout << "Please check the observations (no proba can be computed)" << std::endl;
1404  return;
1405  }
1406 
1407  if (msg_p_min < 0.) { msg_p_min = 0.; }
1408 
1409  if (msg_p_max < 0.) { msg_p_max = 0.; }
1410 
1411  _infE_::marginalMin_[node][0] = 1 - msg_p_max;
1412  _infE_::marginalMax_[node][0] = 1 - msg_p_min;
1413  _infE_::marginalMin_[node][1] = msg_p_min;
1414  _infE_::marginalMax_[node][1] = msg_p_max;
1415  }
1416  }
#define INF_
NodeProperty< GUM_SCALAR > NodesL_min_
"Lower" node information obtained by combinaison of children messages.
NodeProperty< GUM_SCALAR > NodesP_max_
"Upper" node information obtained by combinaison of parent&#39;s messages.
NodeProperty< GUM_SCALAR > NodesP_min_
"Lower" node information obtained by combinaison of parent&#39;s messages.
margi evidence_
Holds observed variables states.
NodeProperty< GUM_SCALAR > NodesL_max_
"Upper" node information obtained by combinaison of children messages.
const IBayesNet< GUM_SCALAR > * _bnet_
A pointer to it&#39;s IBayesNet used as a DAG.
margi marginalMax_
Upper marginals.
margi marginalMin_
Lower marginals.

◆ verbosity()

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

Returns true if verbosity is enabled.

Returns
Returns true if verbosity is enabled.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 139 of file approximationScheme_inl.h.

References gum::Set< Key, Alloc >::emplace().

139 { return verbosity_; }
bool verbosity_
If true, verbosity is enabled.
+ Here is the call graph for this function:

◆ vertices()

template<typename 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  }
credalSet marginalSets_
Credal sets vertices, if enabled.

Member Data Documentation

◆ _bnet_

template<typename GUM_SCALAR >
const IBayesNet< GUM_SCALAR >* gum::credal::CNLoopyPropagation< GUM_SCALAR >::_bnet_
private

A pointer to it's IBayesNet used as a DAG.

Definition at line 374 of file CNLoopyPropagation.h.

◆ _cn_

template<typename GUM_SCALAR >
const CredalNet< GUM_SCALAR >* gum::credal::CNLoopyPropagation< GUM_SCALAR >::_cn_
private

A pointer to the CredalNet to be used.

Definition at line 371 of file CNLoopyPropagation.h.

◆ _inferenceType_

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

The choosen inference type.

nodeToNeighbours by Default.

Definition at line 368 of file CNLoopyPropagation.h.

◆ active_nodes_set

template<typename 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 326 of file CNLoopyPropagation.h.

◆ ArcsL_max_

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

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

Definition at line 348 of file CNLoopyPropagation.h.

◆ ArcsL_min_

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

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

Definition at line 336 of file CNLoopyPropagation.h.

◆ ArcsP_max_

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

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

Definition at line 350 of file CNLoopyPropagation.h.

◆ ArcsP_min_

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

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

Definition at line 338 of file CNLoopyPropagation.h.

◆ burn_in_

Size gum::ApproximationScheme::burn_in_
protectedinherited

Number of iterations before checking stopping criteria.

Definition at line 413 of file approximationScheme.h.

◆ credalNet_

template<typename GUM_SCALAR >
const CredalNet< GUM_SCALAR >* gum::credal::InferenceEngine< GUM_SCALAR >::credalNet_
protectedinherited

A pointer to the Credal Net used.

Definition at line 68 of file inferenceEngine.h.

◆ current_epsilon_

double gum::ApproximationScheme::current_epsilon_
protectedinherited

Current epsilon.

Definition at line 368 of file approximationScheme.h.

◆ current_rate_

double gum::ApproximationScheme::current_rate_
protectedinherited

Current rate.

Definition at line 374 of file approximationScheme.h.

◆ current_state_

ApproximationSchemeSTATE gum::ApproximationScheme::current_state_
protectedinherited

The current state.

Definition at line 383 of file approximationScheme.h.

◆ current_step_

Size gum::ApproximationScheme::current_step_
protectedinherited

The current step.

Definition at line 377 of file approximationScheme.h.

◆ dbnOpt_

template<typename 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 141 of file inferenceEngine.h.

◆ dynamicExpMax_

template<typename 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 95 of file inferenceEngine.h.

◆ dynamicExpMin_

template<typename 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 92 of file inferenceEngine.h.

◆ enabled_eps_

bool gum::ApproximationScheme::enabled_eps_
protectedinherited

If true, the threshold convergence is enabled.

Definition at line 392 of file approximationScheme.h.

◆ enabled_max_iter_

bool gum::ApproximationScheme::enabled_max_iter_
protectedinherited

If true, the maximum iterations stopping criterion is enabled.

Definition at line 410 of file approximationScheme.h.

◆ enabled_max_time_

bool gum::ApproximationScheme::enabled_max_time_
protectedinherited

If true, the timeout is enabled.

Definition at line 404 of file approximationScheme.h.

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

◆ eps_

double gum::ApproximationScheme::eps_
protectedinherited

Threshold for convergence.

Definition at line 389 of file approximationScheme.h.

◆ evidence_

template<typename GUM_SCALAR >
margi gum::credal::InferenceEngine< GUM_SCALAR >::evidence_
protectedinherited

Holds observed variables states.

Definition at line 101 of file inferenceEngine.h.

◆ expectationMax_

template<typename GUM_SCALAR >
expe gum::credal::InferenceEngine< GUM_SCALAR >::expectationMax_
protectedinherited

Upper expectations, if some variables modalities were inserted.

Definition at line 88 of file inferenceEngine.h.

◆ expectationMin_

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

Lower expectations, if some variables modalities were inserted.

Definition at line 85 of file inferenceEngine.h.

◆ history_

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

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

Definition at line 386 of file approximationScheme.h.

◆ InferenceUpToDate_

template<typename GUM_SCALAR >
bool gum::credal::CNLoopyPropagation< GUM_SCALAR >::InferenceUpToDate_
protected

TRUE if inference has already been performed, FALSE otherwise.

Definition at line 361 of file CNLoopyPropagation.h.

◆ last_epsilon_

double gum::ApproximationScheme::last_epsilon_
protectedinherited

Last epsilon value.

Definition at line 371 of file approximationScheme.h.

◆ marginalMax_

template<typename GUM_SCALAR >
margi gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax_
protectedinherited

Upper marginals.

Definition at line 78 of file inferenceEngine.h.

◆ marginalMin_

template<typename GUM_SCALAR >
margi gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin_
protectedinherited

Lower marginals.

Definition at line 76 of file inferenceEngine.h.

◆ marginalSets_

template<typename GUM_SCALAR >
credalSet gum::credal::InferenceEngine< GUM_SCALAR >::marginalSets_
protectedinherited

Credal sets vertices, if enabled.

Definition at line 81 of file inferenceEngine.h.

◆ max_iter_

Size gum::ApproximationScheme::max_iter_
protectedinherited

The maximum iterations.

Definition at line 407 of file approximationScheme.h.

◆ max_time_

double gum::ApproximationScheme::max_time_
protectedinherited

The timeout.

Definition at line 401 of file approximationScheme.h.

◆ min_rate_eps_

double gum::ApproximationScheme::min_rate_eps_
protectedinherited

Threshold for the epsilon rate.

Definition at line 395 of file approximationScheme.h.

◆ modal_

template<typename GUM_SCALAR >
dynExpe gum::credal::InferenceEngine< GUM_SCALAR >::modal_
protectedinherited

Variables modalities used to compute expectations.

Definition at line 98 of file inferenceEngine.h.

◆ msg_l_sent_

template<typename 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 333 of file CNLoopyPropagation.h.

◆ next_active_nodes_set

template<typename 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 330 of file CNLoopyPropagation.h.

◆ NodesL_max_

template<typename 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 353 of file CNLoopyPropagation.h.

◆ NodesL_min_

template<typename 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 341 of file CNLoopyPropagation.h.

◆ NodesP_max_

template<typename 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 357 of file CNLoopyPropagation.h.

◆ NodesP_min_

template<typename 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 345 of file CNLoopyPropagation.h.

◆ oldMarginalMax_

template<typename GUM_SCALAR >
margi gum::credal::InferenceEngine< GUM_SCALAR >::oldMarginalMax_
protectedinherited

Old upper marginals used to compute epsilon.

Definition at line 73 of file inferenceEngine.h.

◆ oldMarginalMin_

template<typename GUM_SCALAR >
margi gum::credal::InferenceEngine< GUM_SCALAR >::oldMarginalMin_
protectedinherited

Old lower marginals used to compute epsilon.

Definition at line 71 of file inferenceEngine.h.

◆ onProgress

Signaler3< Size, double, double > gum::IApproximationSchemeConfiguration::onProgress
inherited

Progression, error and time.

Definition at line 58 of file IApproximationSchemeConfiguration.h.

◆ onStop

Signaler1< std::string > gum::IApproximationSchemeConfiguration::onStop
inherited

Criteria messageApproximationScheme.

Definition at line 61 of file IApproximationSchemeConfiguration.h.

◆ period_size_

Size gum::ApproximationScheme::period_size_
protectedinherited

Checking criteria frequency.

Definition at line 416 of file approximationScheme.h.

◆ query_

template<typename GUM_SCALAR >
query gum::credal::InferenceEngine< GUM_SCALAR >::query_
protectedinherited

Holds the query nodes states.

Definition at line 103 of file inferenceEngine.h.

◆ repetitiveInd_

template<typename GUM_SCALAR >
bool gum::credal::InferenceEngine< GUM_SCALAR >::repetitiveInd_
protectedinherited

True if using repetitive independence ( dynamic network only ), False otherwise.

False by default.

Definition at line 127 of file inferenceEngine.h.

◆ storeBNOpt_

template<typename GUM_SCALAR >
bool gum::credal::InferenceEngine< GUM_SCALAR >::storeBNOpt_
protectedinherited

Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling.

The algorithms stops if no changes occured within 1000 iterations by default. int iterStop_; True is optimal bayes net are stored, for each variable and each modality, False otherwise. Not all algorithms offers this option. False by default.

Definition at line 137 of file inferenceEngine.h.

◆ storeVertices_

template<typename GUM_SCALAR >
bool gum::credal::InferenceEngine< GUM_SCALAR >::storeVertices_
protectedinherited

True if credal sets vertices are stored, False otherwise.

False by default.

Definition at line 123 of file inferenceEngine.h.

◆ t0_

template<typename 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 111 of file inferenceEngine.h.

◆ t1_

template<typename 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 118 of file inferenceEngine.h.

◆ timer_

Timer gum::ApproximationScheme::timer_
protectedinherited

The timer.

Definition at line 380 of file approximationScheme.h.

◆ timeSteps_

template<typename GUM_SCALAR >
int gum::credal::InferenceEngine< GUM_SCALAR >::timeSteps_
protectedinherited

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

Deprecated:

Definition at line 148 of file inferenceEngine.h.

◆ update_l_

template<typename 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 323 of file CNLoopyPropagation.h.

◆ update_p_

template<typename 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 319 of file CNLoopyPropagation.h.

◆ verbosity_

bool gum::ApproximationScheme::verbosity_
protectedinherited

If true, verbosity is enabled.

Definition at line 419 of file approximationScheme.h.


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