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

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

#include <CNLoopyPropagation.h>

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

◆ cArcP

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

Definition at line 60 of file CNLoopyPropagation.h.

◆ 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 368 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 1515 of file CNLoopyPropagation_tpl.h.

1516  :
1518  if (!cnet.isSeparatelySpecified()) {
1519  GUM_ERROR(OperationNotAllowed,
1520  "CNLoopyPropagation is only available "
1521  "with separately specified nets");
1522  }
1523 
1524  // test for binary cn
1525  for (auto node: cnet.current_bn().nodes())
1526  if (cnet.current_bn().variable(node).domainSize() != 2) {
1527  GUM_ERROR(OperationNotAllowed,
1528  "CNLoopyPropagation is only available "
1529  "with binary credal networks");
1530  }
1531 
1532  // test if compute CPTMinMax has been called
1533  if (!cnet.hasComputedBinaryCPTMinMax()) {
1534  GUM_ERROR(OperationNotAllowed,
1535  "CNLoopyPropagation only works when "
1536  "\"computeBinaryCPTMinMax()\" has been called for "
1537  "this credal net");
1538  }
1539 
1540  cn__ = &cnet;
1541  bnet__ = &cnet.current_bn();
1542 
1544  InferenceUpToDate_ = false;
1545 
1546  GUM_CONSTRUCTOR(CNLoopyPropagation);
1547  }
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.
const IBayesNet< GUM_SCALAR > * bnet__
A pointer to it&#39;s IBayesNet used as a DAG.
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.
InferenceType inferenceType__
The choosen inference type.
const CredalNet< GUM_SCALAR > * cn__
A pointer to the CredalNet to be used.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ ~CNLoopyPropagation()

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

Destructor.

Definition at line 1550 of file CNLoopyPropagation_tpl.h.

1550  {
1551  InferenceUpToDate_ = false;
1552 
1553  if (msg_l_sent_.size() > 0) {
1554  for (auto node: bnet__->nodes()) {
1555  delete msg_l_sent_[node];
1556  }
1557  }
1558 
1559  //_msg_l_sent.clear();
1560  //_update_l.clear();
1561  //_update_p.clear();
1562 
1563  GUM_DESTRUCTOR(CNLoopyPropagation);
1564  }
NodeProperty< NodeSet *> msg_l_sent_
Used to keep track of one&#39;s messages sent to it&#39;s parents.
const IBayesNet< GUM_SCALAR > * bnet__
A pointer to it&#39;s IBayesNet used as a DAG.
CNLoopyPropagation(const CredalNet< GUM_SCALAR > &cnet)
Constructor.
bool InferenceUpToDate_
TRUE if inference has already been performed, FALSE otherwise.

Member Function Documentation

◆ calculateEpsilon_()

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

Compute epsilon.

Returns
Epsilon.

Definition at line 1463 of file CNLoopyPropagation_tpl.h.

1463  {
1464  refreshLMsPIs_();
1465  updateMarginals_();
1466 
1467  return infE__::computeEpsilon_();
1468  }
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 180 of file CNLoopyPropagation_tpl.h.

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

276  {
277  GUM_SCALAR num_min = 0.;
278  GUM_SCALAR num_max = 0.;
279  GUM_SCALAR den_min = 0.;
280  GUM_SCALAR den_max = 0.;
281 
282  auto taille = combi_msg_p.size();
283 
284  std::vector< typename std::vector< GUM_SCALAR >::iterator > it(taille);
285 
286  for (decltype(taille) i = 0; i < taille; i++) {
287  it[i] = combi_msg_p[i].begin();
288  }
289 
290  Size pp = pos;
291 
292  Size combi_den = 0;
293  Size combi_num = pp;
294 
295  // marginalisation
296  while (it[taille - 1] != combi_msg_p[taille - 1].end()) {
297  GUM_SCALAR prod = 1.;
298 
299  for (decltype(taille) k = 0; k < taille; k++) {
300  prod *= *it[k];
301  }
302 
303  den_min += (cn__->get_binaryCPT_min()[id][combi_den] * prod);
304  den_max += (cn__->get_binaryCPT_max()[id][combi_den] * prod);
305 
306  num_min += (cn__->get_binaryCPT_min()[id][combi_num] * prod);
307  num_max += (cn__->get_binaryCPT_max()[id][combi_num] * prod);
308 
309  combi_den++;
310  combi_num++;
311 
312  if (pp != 0) {
313  if (combi_den % pp == 0) {
314  combi_den += pp;
315  combi_num += pp;
316  }
317  }
318 
319  // incrementation
320  ++it[0];
321 
322  for (decltype(taille) i = 0;
323  (i < taille - 1) && (it[i] == combi_msg_p[i].end());
324  ++i) {
325  it[i] = combi_msg_p[i].begin();
326  ++it[i + 1];
327  }
328  } // end of : marginalisation
329 
330  compute_ext_(msg_l_min, msg_l_max, lx, num_min, num_max, den_min, den_max);
331  }
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
const CredalNet< GUM_SCALAR > * cn__
A pointer to the CredalNet to be used.

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

342  {
343  GUM_SCALAR min = 0.;
344  GUM_SCALAR max = 0.;
345 
346  auto taille = combi_msg_p.size();
347 
348  std::vector< typename std::vector< GUM_SCALAR >::iterator > it(taille);
349 
350  for (decltype(taille) i = 0; i < taille; i++) {
351  it[i] = combi_msg_p[i].begin();
352  }
353 
354  int combi = 0;
355  auto theEnd = combi_msg_p[taille - 1].end();
356 
357  while (it[taille - 1] != theEnd) {
358  GUM_SCALAR prod = 1.;
359 
360  for (decltype(taille) k = 0; k < taille; k++) {
361  prod *= *it[k];
362  }
363 
364  min += (cn__->get_binaryCPT_min()[id][combi] * prod);
365  max += (cn__->get_binaryCPT_max()[id][combi] * prod);
366 
367  combi++;
368 
369  // incrementation
370  ++it[0];
371 
372  for (decltype(taille) i = 0;
373  (i < taille - 1) && (it[i] == combi_msg_p[i].end());
374  ++i) {
375  it[i] = combi_msg_p[i].begin();
376  ++it[i + 1];
377  }
378  }
379 
380  if (min < msg_p_min) { msg_p_min = min; }
381 
382  if (max > msg_p_max) { msg_p_max = max; }
383  }
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 1019 of file inferenceEngine_tpl.h.

1019  {
1020  GUM_SCALAR eps = 0;
1021 #pragma omp parallel
1022  {
1023  GUM_SCALAR tEps = 0;
1024  GUM_SCALAR delta;
1025 
1027  int nsize = int(marginalMin_.size());
1028 
1029 #pragma omp for
1030 
1031  for (int i = 0; i < nsize; i++) {
1032  auto dSize = marginalMin_[i].size();
1033 
1034  for (Size j = 0; j < dSize; j++) {
1035  // on min
1036  delta = marginalMin_[i][j] - oldMarginalMin_[i][j];
1037  delta = (delta < 0) ? (-delta) : delta;
1038  tEps = (tEps < delta) ? delta : tEps;
1039 
1040  // on max
1041  delta = marginalMax_[i][j] - oldMarginalMax_[i][j];
1042  delta = (delta < 0) ? (-delta) : delta;
1043  tEps = (tEps < delta) ? delta : tEps;
1044 
1045  oldMarginalMin_[i][j] = marginalMin_[i][j];
1046  oldMarginalMax_[i][j] = marginalMax_[i][j];
1047  }
1048  } // end of : all variables
1049 
1050 #pragma omp critical(epsilon_max)
1051  {
1052 #pragma omp flush(eps)
1053  eps = (eps < tEps) ? tEps : eps;
1054  }
1055  }
1056 
1057  return eps;
1058  }
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 1488 of file CNLoopyPropagation_tpl.h.

1488  {
1489  if (infE__::modal_.empty()) { return; }
1490 
1491  std::vector< std::vector< GUM_SCALAR > > vertices(
1492  2,
1493  std::vector< GUM_SCALAR >(2));
1494 
1495  for (auto node: bnet__->nodes()) {
1496  vertices[0][0] = infE__::marginalMin_[node][0];
1497  vertices[0][1] = infE__::marginalMax_[node][1];
1498 
1499  vertices[1][0] = infE__::marginalMax_[node][0];
1500  vertices[1][1] = infE__::marginalMin_[node][1];
1501 
1502  for (auto vertex = 0, vend = 2; vertex != vend; vertex++) {
1503  infE__::updateExpectations_(node, vertices[vertex]);
1504  // test credal sets vertices elim
1505  // remove with L2U since variables are binary
1506  // but does the user know that ?
1508  node,
1509  vertices[vertex]); // no redundancy elimination with 2 vertices
1510  }
1511  }
1512  }
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 226 of file approximationScheme_inl.h.

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

226  {
227  // For coherence, we fix the time used in the method
228 
229  double timer_step = timer_.step();
230 
231  if (enabled_max_time_) {
232  if (timer_step > max_time_) {
234  return false;
235  }
236  }
237 
238  if (!startOfPeriod()) { return true; }
239 
241  GUM_ERROR(OperationNotAllowed,
242  "state of the approximation scheme is not correct : "
244  }
245 
246  if (verbosity()) { history_.push_back(error); }
247 
248  if (enabled_max_iter_) {
249  if (current_step_ > max_iter_) {
251  return false;
252  }
253  }
254 
256  current_epsilon_ = error; // eps rate isEnabled needs it so affectation was
257  // moved from eps isEnabled below
258 
259  if (enabled_eps_) {
260  if (current_epsilon_ <= eps_) {
262  return false;
263  }
264  }
265 
266  if (last_epsilon_ >= 0.) {
267  if (current_epsilon_ > .0) {
268  // ! current_epsilon_ can be 0. AND epsilon
269  // isEnabled can be disabled !
272  }
273  // limit with current eps ---> 0 is | 1 - ( last_eps / 0 ) | --->
274  // infinity the else means a return false if we isEnabled the rate below,
275  // as we would have returned false if epsilon isEnabled was enabled
276  else {
278  }
279 
280  if (enabled_min_rate_eps_) {
281  if (current_rate_ <= min_rate_eps_) {
283  return false;
284  }
285  }
286  }
287 
289  if (onProgress.hasListener()) {
291  }
292 
293  return true;
294  } else {
295  return false;
296  }
297  }
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:54
+ 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 59 of file inferenceEngine_tpl.h.

59  {
60  return *credalNet_;
61  }
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 127 of file approximationScheme_inl.h.

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

127 { 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 104 of file approximationScheme_inl.h.

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

104 { 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 130 of file approximationScheme_inl.h.

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

130 { 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 78 of file approximationScheme_inl.h.

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

78  {
79  enabled_min_rate_eps_ = false;
80  }
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 718 of file inferenceEngine_tpl.h.

718  {
720  }
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 723 of file inferenceEngine_tpl.h.

723  {
724  // no modals, no expectations computed during inference
725  if (expectationMin_.empty() || modal_.empty()) return;
726 
727  // already called by the algorithm or the user
728  if (dynamicExpMax_.size() > 0 && dynamicExpMin_.size() > 0) return;
729 
730  // typedef typename std::map< int, GUM_SCALAR > innerMap;
731  using innerMap = typename gum::HashTable< int, GUM_SCALAR >;
732 
733  // typedef typename std::map< std::string, innerMap > outerMap;
734  using outerMap = typename gum::HashTable< std::string, innerMap >;
735 
736  // typedef typename std::map< std::string, std::vector< GUM_SCALAR > >
737  // mod;
738 
739  // si non dynamique, sauver directement expectationMin_ et Max (revient au
740  // meme
741  // mais plus rapide)
742  outerMap expectationsMin, expectationsMax;
743 
744  for (const auto& elt: expectationMin_) {
745  std::string var_name, time_step;
746 
747  var_name = credalNet_->current_bn().variable(elt.first).name();
748  auto delim = var_name.find_first_of("_");
749  time_step = var_name.substr(delim + 1, var_name.size());
750  var_name = var_name.substr(0, delim);
751 
752  // to be sure (don't store not monitored variables' expectations)
753  // although it
754  // should be taken care of before this point
755  if (!modal_.exists(var_name)) continue;
756 
757  expectationsMin.getWithDefault(var_name, innerMap())
758  .getWithDefault(atoi(time_step.c_str()), 0)
759  = elt.second; // we iterate with min iterators
760  expectationsMax.getWithDefault(var_name, innerMap())
761  .getWithDefault(atoi(time_step.c_str()), 0)
762  = expectationMax_[elt.first];
763  }
764 
765  for (const auto& elt: expectationsMin) {
766  typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
767 
768  for (const auto& elt2: elt.second)
769  dynExp[elt2.first] = elt2.second;
770 
771  dynamicExpMin_.insert(elt.first, dynExp);
772  }
773 
774  for (const auto& elt: expectationsMax) {
775  typename std::vector< GUM_SCALAR > dynExp(elt.second.size());
776 
777  for (const auto& elt2: elt.second) {
778  dynExp[elt2.first] = elt2.second;
779  }
780 
781  dynamicExpMax_.insert(elt.first, dynExp);
782  }
783  }
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:679
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 506 of file inferenceEngine_tpl.h.

507  {
508  std::string errTxt = "const std::vector< GUM_SCALAR > & InferenceEngine< "
509  "GUM_SCALAR >::dynamicExpMax ( const std::string & "
510  "varName ) const : ";
511 
512  if (dynamicExpMax_.empty())
513  GUM_ERROR(OperationNotAllowed,
514  errTxt + "_dynamicExpectations() needs to be called before");
515 
516  if (!dynamicExpMax_.exists(
517  varName) /*dynamicExpMin_.find(varName) == dynamicExpMin_.end()*/)
518  GUM_ERROR(NotFound, errTxt + "variable name not found : " << varName);
519 
520  return dynamicExpMax_[varName];
521  }
dynExpe dynamicExpMax_
Upper dynamic expectations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

489  {
490  std::string errTxt = "const std::vector< GUM_SCALAR > & InferenceEngine< "
491  "GUM_SCALAR >::dynamicExpMin ( const std::string & "
492  "varName ) const : ";
493 
494  if (dynamicExpMin_.empty())
495  GUM_ERROR(OperationNotAllowed,
496  errTxt + "_dynamicExpectations() needs to be called before");
497 
498  if (!dynamicExpMin_.exists(
499  varName) /*dynamicExpMin_.find(varName) == dynamicExpMin_.end()*/)
500  GUM_ERROR(NotFound, errTxt + "variable name not found : " << varName);
501 
502  return dynamicExpMin_[varName];
503  }
dynExpe dynamicExpMin_
Lower dynamic expectations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

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

107 { 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 133 of file approximationScheme_inl.h.

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

133 { 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 83 of file approximationScheme_inl.h.

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

83  {
84  enabled_min_rate_eps_ = true;
85  }
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 465 of file CNLoopyPropagation_tpl.h.

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

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

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

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

581  {
583 
584  ArcsL_min_.clear();
585  ArcsL_max_.clear();
586  ArcsP_min_.clear();
587  ArcsP_max_.clear();
588  NodesL_min_.clear();
589  NodesL_max_.clear();
590  NodesP_min_.clear();
591  NodesP_max_.clear();
592 
593  InferenceUpToDate_ = false;
594 
595  if (msg_l_sent_.size() > 0) {
596  for (auto node: bnet__->nodes()) {
597  delete msg_l_sent_[node];
598  }
599  }
600 
601  msg_l_sent_.clear();
602  update_l_.clear();
603  update_p_.clear();
604 
607  }
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.
const IBayesNet< GUM_SCALAR > * bnet__
A pointer to it&#39;s IBayesNet used as a DAG.
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.
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:374
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 481 of file inferenceEngine_tpl.h.

481  {
482  try {
483  return expectationMax_[id];
484  } catch (NotFound& err) { throw(err); }
485  }
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 464 of file inferenceEngine_tpl.h.

465  {
466  try {
467  return expectationMax_[credalNet_->current_bn().idFromName(varName)];
468  } catch (NotFound& err) { throw(err); }
469  }
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 473 of file inferenceEngine_tpl.h.

473  {
474  try {
475  return expectationMin_[id];
476  } catch (NotFound& err) { throw(err); }
477  }
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 456 of file inferenceEngine_tpl.h.

457  {
458  try {
459  return expectationMin_[credalNet_->current_bn().idFromName(varName)];
460  } catch (NotFound& err) { throw(err); }
461  }
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 508 of file inferenceEngine.h.

508  {
509  return this->messageApproximationScheme();
510  }
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 1008 of file inferenceEngine_tpl.h.

1008  {
1009  return t0_;
1010  }
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 1014 of file inferenceEngine_tpl.h.

1014  {
1015  return t1_;
1016  }
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 141 of file inferenceEngine_tpl.h.

141  {
142  return &dbnOpt_;
143  }
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 172 of file approximationScheme_inl.h.

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

172  {
174  GUM_ERROR(OperationNotAllowed,
175  "state of the approximation scheme is udefined");
176  }
177 
178  if (verbosity() == false) {
179  GUM_ERROR(OperationNotAllowed, "No history when verbosity=false");
180  }
181 
182  return history_;
183  }
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:54
+ 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 1567 of file CNLoopyPropagation_tpl.h.

1567  {
1568  inferenceType__ = inft;
1569  }
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 1573 of file CNLoopyPropagation_tpl.h.

1573  {
1574  return inferenceType__;
1575  }
InferenceType inferenceType__
The choosen inference type.

◆ initApproximationScheme()

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

Initialise the scheme.

Definition at line 186 of file approximationScheme_inl.h.

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

186  {
188  current_step_ = 0;
190  history_.clear();
191  timer_.reset();
192  }
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 697 of file inferenceEngine_tpl.h.

697  {
700 
701  if (modal_.empty()) return;
702 
703  for (auto node: credalNet_->current_bn().nodes()) {
704  std::string var_name, time_step;
705 
706  var_name = credalNet_->current_bn().variable(node).name();
707  auto delim = var_name.find_first_of("_");
708  var_name = var_name.substr(0, delim);
709 
710  if (!modal_.exists(var_name)) continue;
711 
712  expectationMin_.insert(node, modal_[var_name].back());
713  expectationMax_.insert(node, modal_[var_name].front());
714  }
715  }
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 610 of file CNLoopyPropagation_tpl.h.

610  {
611  const DAG& graphe = bnet__->dag();
612 
613  // use const iterators with cbegin when available
614  for (auto node: bnet__->topologicalOrder()) {
615  update_p_.set(node, false);
616  update_l_.set(node, false);
617  NodeSet* parents_ = new NodeSet();
618  msg_l_sent_.set(node, parents_);
619 
620  // accelerer init pour evidences
621  if (infE__::evidence_.exists(node)) {
622  if (infE__::evidence_[node][1] != 0.
623  && infE__::evidence_[node][1] != 1.) {
624  GUM_ERROR(OperationNotAllowed,
625  "CNLoopyPropagation can only handle HARD evidences");
626  }
627 
628  active_nodes_set.insert(node);
629  update_l_.set(node, true);
630  update_p_.set(node, true);
631 
632  if (infE__::evidence_[node][1] == (GUM_SCALAR)1.) {
633  NodesL_min_.set(node, INF_);
634  NodesP_min_.set(node, (GUM_SCALAR)1.);
635  } else if (infE__::evidence_[node][1] == (GUM_SCALAR)0.) {
636  NodesL_min_.set(node, (GUM_SCALAR)0.);
637  NodesP_min_.set(node, (GUM_SCALAR)0.);
638  }
639 
640  std::vector< GUM_SCALAR > marg(2);
641  marg[1] = NodesP_min_[node];
642  marg[0] = 1 - marg[1];
643 
644  infE__::oldMarginalMin_.set(node, marg);
645  infE__::oldMarginalMax_.set(node, marg);
646 
647  continue;
648  }
649 
650  NodeSet par_ = graphe.parents(node);
651  NodeSet enf_ = graphe.children(node);
652 
653  if (par_.size() == 0) {
654  active_nodes_set.insert(node);
655  update_p_.set(node, true);
656  update_l_.set(node, true);
657  }
658 
659  if (enf_.size() == 0) {
660  active_nodes_set.insert(node);
661  update_p_.set(node, true);
662  update_l_.set(node, true);
663  }
664 
669  const auto parents = &bnet__->cpt(node).variablesSequence();
670 
671  std::vector< std::vector< std::vector< GUM_SCALAR > > > msgs_p;
672  std::vector< std::vector< GUM_SCALAR > > msg_p;
673  std::vector< GUM_SCALAR > distri(2);
674 
675  // +1 from start to avoid counting_ itself
676  // use const iterators when available with cbegin
677  for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd;
678  ++jt) {
679  // compute probability distribution to avoid doing it multiple times
680  // (at
681  // each combination of messages)
682  distri[1] = NodesP_min_[bnet__->nodeId(**jt)];
683  distri[0] = (GUM_SCALAR)1. - distri[1];
684  msg_p.push_back(distri);
685 
686  if (NodesP_max_.exists(bnet__->nodeId(**jt))) {
687  distri[1] = NodesP_max_[bnet__->nodeId(**jt)];
688  distri[0] = (GUM_SCALAR)1. - distri[1];
689  msg_p.push_back(distri);
690  }
691 
692  msgs_p.push_back(msg_p);
693  msg_p.clear();
694  }
695 
696  GUM_SCALAR msg_p_min = 1.;
697  GUM_SCALAR msg_p_max = 0.;
698 
699  if (cn__->currentNodeType(node)
701  enum_combi_(msgs_p, node, msg_p_min, msg_p_max);
702  }
703 
704  if (msg_p_min <= (GUM_SCALAR)0.) { msg_p_min = (GUM_SCALAR)0.; }
705 
706  if (msg_p_max <= (GUM_SCALAR)0.) { msg_p_max = (GUM_SCALAR)0.; }
707 
708  NodesP_min_.set(node, msg_p_min);
709  std::vector< GUM_SCALAR > marg(2);
710  marg[1] = msg_p_min;
711  marg[0] = 1 - msg_p_min;
712 
713  infE__::oldMarginalMin_.set(node, marg);
714 
715  if (msg_p_min != msg_p_max) {
716  marg[1] = msg_p_max;
717  marg[0] = 1 - msg_p_max;
718  NodesP_max_.insert(node, msg_p_max);
719  }
720 
721  infE__::oldMarginalMax_.set(node, marg);
722 
723  NodesL_min_.set(node, (GUM_SCALAR)1.);
724  }
725 
726  for (auto arc: bnet__->arcs()) {
727  ArcsP_min_.set(arc, NodesP_min_[arc.tail()]);
728 
729  if (NodesP_max_.exists(arc.tail())) {
730  ArcsP_max_.set(arc, NodesP_max_[arc.tail()]);
731  }
732 
733  ArcsL_min_.set(arc, NodesL_min_[arc.tail()]);
734  }
735  }
#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.
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.
const IBayesNet< GUM_SCALAR > * bnet__
A pointer to it&#39;s IBayesNet used as a DAG.
void set(const Key &key, const Val &default_value)
Add a new property or modify it if it already existed.
const CredalNet< GUM_SCALAR > * cn__
A pointer to the CredalNet to be used.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
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 665 of file inferenceEngine_tpl.h.

665  {
670 
671  for (auto node: credalNet_->current_bn().nodes()) {
672  auto dSize = credalNet_->current_bn().variable(node).domainSize();
673  marginalMin_.insert(node, std::vector< GUM_SCALAR >(dSize, 1));
674  oldMarginalMin_.insert(node, std::vector< GUM_SCALAR >(dSize, 1));
675 
676  marginalMax_.insert(node, std::vector< GUM_SCALAR >(dSize, 0));
677  oldMarginalMax_.insert(node, std::vector< GUM_SCALAR >(dSize, 0));
678  }
679  }
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 682 of file inferenceEngine_tpl.h.

682  {
684 
685  if (!storeVertices_) return;
686 
687  for (auto node: credalNet_->current_bn().nodes())
688  marginalSets_.insert(node, std::vector< std::vector< GUM_SCALAR > >());
689  }
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 229 of file inferenceEngine_tpl.h.

230  {
231  if (!evidence_.empty()) evidence_.clear();
232 
233  for (auto it = eviMap.cbegin(), theEnd = eviMap.cend(); it != theEnd; ++it) {
234  NodeId id;
235 
236  try {
237  id = credalNet_->current_bn().idFromName(it->first);
238  } catch (NotFound& err) {
239  GUM_SHOWERROR(err);
240  continue;
241  }
242 
243  evidence_.insert(id, it->second);
244  }
245  }
#define GUM_SHOWERROR(e)
Definition: exceptions.h:60
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 251 of file inferenceEngine_tpl.h.

252  {
253  if (!evidence_.empty()) evidence_.clear();
254 
255  // use cbegin() to get const_iterator when available in aGrUM hashtables
256  for (const auto& elt: evidence) {
257  try {
258  credalNet_->current_bn().variable(elt.first);
259  } catch (NotFound& err) {
260  GUM_SHOWERROR(err);
261  continue;
262  }
263 
264  evidence_.insert(elt.first, elt.second);
265  }
266  }
#define GUM_SHOWERROR(e)
Definition: exceptions.h:60
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 382 of file CNLoopyPropagation.h.

382  {
384  };
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 193 of file inferenceEngine_tpl.h.

194  {
195  if (!modal_.empty()) modal_.clear();
196 
197  for (auto it = modals.cbegin(), theEnd = modals.cend(); it != theEnd; ++it) {
198  NodeId id;
199 
200  try {
201  id = credalNet_->current_bn().idFromName(it->first);
202  } catch (NotFound& err) {
203  GUM_SHOWERROR(err);
204  continue;
205  }
206 
207  // check that modals are net compatible
208  auto dSize = credalNet_->current_bn().variable(id).domainSize();
209 
210  if (dSize != it->second.size()) continue;
211 
212  // GUM_ERROR(OperationNotAllowed, "void InferenceEngine< GUM_SCALAR
213  // >::insertModals( const std::map< std::string, std::vector< GUM_SCALAR
214  // > >
215  // &modals) : modalities does not respect variable cardinality : " <<
216  // credalNet_->current_bn().variable( id ).name() << " : " << dSize << "
217  // != "
218  // << it->second.size());
219 
220  modal_.insert(it->first, it->second); //[ it->first ] = it->second;
221  }
222 
223  //_modal = modals;
224 
226  }
void initExpectations_()
Initialize lower and upper expectations before inference, with the lower expectation being initialize...
#define GUM_SHOWERROR(e)
Definition: exceptions.h:60
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 146 of file inferenceEngine_tpl.h.

146  {
147  std::ifstream mod_stream(path.c_str(), std::ios::in);
148 
149  if (!mod_stream.good()) {
150  GUM_ERROR(OperationNotAllowed,
151  "void InferenceEngine< GUM_SCALAR "
152  ">::insertModals(const std::string & path) : "
153  "could not open input file : "
154  << path);
155  }
156 
157  if (!modal_.empty()) modal_.clear();
158 
159  std::string line, tmp;
160  char * cstr, *p;
161 
162  while (mod_stream.good()) {
163  getline(mod_stream, line);
164 
165  if (line.size() == 0) continue;
166 
167  cstr = new char[line.size() + 1];
168  strcpy(cstr, line.c_str());
169 
170  p = strtok(cstr, " ");
171  tmp = p;
172 
173  std::vector< GUM_SCALAR > values;
174  p = strtok(nullptr, " ");
175 
176  while (p != nullptr) {
177  values.push_back(GUM_SCALAR(atof(p)));
178  p = strtok(nullptr, " ");
179  } // end of : line
180 
181  modal_.insert(tmp, values); //[tmp] = values;
182 
183  delete[] p;
184  delete[] cstr;
185  } // end of : file
186 
187  mod_stream.close();
188 
190  }
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:54

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

332  {
333  if (!query_.empty()) query_.clear();
334 
335  for (const auto& elt: query) {
336  try {
337  credalNet_->current_bn().variable(elt.first);
338  } catch (NotFound& err) {
339  GUM_SHOWERROR(err);
340  continue;
341  }
342 
343  query_.insert(elt.first, elt.second);
344  }
345  }
#define GUM_SHOWERROR(e)
Definition: exceptions.h:60
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 348 of file inferenceEngine_tpl.h.

348  {
349  std::ifstream evi_stream(path.c_str(), std::ios::in);
350 
351  if (!evi_stream.good()) {
352  GUM_ERROR(IOError,
353  "void InferenceEngine< GUM_SCALAR >::insertQuery(const "
354  "std::string & path) : could not open input file : "
355  << path);
356  }
357 
358  if (!query_.empty()) query_.clear();
359 
360  std::string line, tmp;
361  char * cstr, *p;
362 
363  while (evi_stream.good() && std::strcmp(line.c_str(), "[QUERY]") != 0) {
364  getline(evi_stream, line);
365  }
366 
367  while (evi_stream.good()) {
368  getline(evi_stream, line);
369 
370  if (std::strcmp(line.c_str(), "[EVIDENCE]") == 0) break;
371 
372  if (line.size() == 0) continue;
373 
374  cstr = new char[line.size() + 1];
375  strcpy(cstr, line.c_str());
376 
377  p = strtok(cstr, " ");
378  tmp = p;
379 
380  // if user input is wrong
381  NodeId node = -1;
382 
383  try {
384  node = credalNet_->current_bn().idFromName(tmp);
385  } catch (NotFound& err) {
386  GUM_SHOWERROR(err);
387  continue;
388  }
389 
390  auto dSize = credalNet_->current_bn().variable(node).domainSize();
391 
392  p = strtok(nullptr, " ");
393 
394  if (p == nullptr) {
395  query_.insert(node, std::vector< bool >(dSize, true));
396  } else {
397  std::vector< bool > values(dSize, false);
398 
399  while (p != nullptr) {
400  if ((Size)atoi(p) >= dSize)
401  GUM_ERROR(OutOfBounds,
402  "void InferenceEngine< GUM_SCALAR "
403  ">::insertQuery(const std::string & path) : "
404  "query modality is higher or equal to "
405  "cardinality");
406 
407  values[atoi(p)] = true;
408  p = strtok(nullptr, " ");
409  } // end of : line
410 
411  query_.insert(node, values);
412  }
413 
414  delete[] p;
415  delete[] cstr;
416  } // end of : file
417 
418  evi_stream.close();
419  }
#define GUM_SHOWERROR(e)
Definition: exceptions.h:60
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:54

◆ 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  {
61  return enabled_eps_;
62  }
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 111 of file approximationScheme_inl.h.

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

111  {
112  return enabled_max_iter_;
113  }
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 137 of file approximationScheme_inl.h.

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

137  {
138  return enabled_max_time_;
139  }
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 89 of file approximationScheme_inl.h.

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

89  {
90  return enabled_min_rate_eps_;
91  }
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 551 of file CNLoopyPropagation_tpl.h.

551  {
552  if (InferenceUpToDate_) { return; }
553 
554  initialize_();
555 
557 
558  switch (inferenceType__) {
561  break;
562 
565  break;
566 
569  break;
570  }
571 
572  //_updateMarginals();
573  updateIndicatrices_(); // will call updateMarginals_()
574 
576 
577  InferenceUpToDate_ = true;
578  }
void makeInferenceByOrderedArcs_()
Starts the inference with this 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_ ).
InferenceType inferenceType__
The choosen inference type.
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 829 of file CNLoopyPropagation_tpl.h.

829  {
830  Size nbrArcs = bnet__->dag().sizeArcs();
831 
832  std::vector< cArcP > seq;
833  seq.reserve(nbrArcs);
834 
835  for (const auto& arc: bnet__->arcs()) {
836  seq.push_back(&arc);
837  }
838 
839  GUM_SCALAR eps;
840  // validate TestSuite
842 
843  do {
844  for (const auto it: seq) {
845  if (cn__->currentNodeType(it->tail())
847  || cn__->currentNodeType(it->head())
849  continue;
850  }
851 
852  msgP_(it->tail(), it->head());
853  msgL_(it->head(), it->tail());
854  }
855 
856  eps = calculateEpsilon_();
857 
859 
861  }
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.
const CredalNet< GUM_SCALAR > * cn__
A pointer to the CredalNet to be used.
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 783 of file CNLoopyPropagation_tpl.h.

783  {
784  Size nbrArcs = bnet__->dag().sizeArcs();
785 
786  std::vector< cArcP > seq;
787  seq.reserve(nbrArcs);
788 
789  for (const auto& arc: bnet__->arcs()) {
790  seq.push_back(&arc);
791  }
792 
793  GUM_SCALAR eps;
794  // validate TestSuite
796 
797  do {
798  for (Size j = 0, theEnd = nbrArcs / 2; j < theEnd; j++) {
799  auto w1 = rand() % nbrArcs, w2 = rand() % nbrArcs;
800 
801  if (w1 == w2) { continue; }
802 
803  std::swap(seq[w1], seq[w2]);
804  }
805 
806  for (const auto it: seq) {
807  if (cn__->currentNodeType(it->tail())
809  || cn__->currentNodeType(it->head())
811  continue;
812  }
813 
814  msgP_(it->tail(), it->head());
815  msgL_(it->head(), it->tail());
816  }
817 
818  eps = calculateEpsilon_();
819 
821 
823  }
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.
const CredalNet< GUM_SCALAR > * cn__
A pointer to the CredalNet to be used.
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 738 of file CNLoopyPropagation_tpl.h.

738  {
739  const DAG& graphe = bnet__->dag();
740 
741  GUM_SCALAR eps;
742  // to validate TestSuite
744 
745  do {
746  for (auto node: active_nodes_set) {
747  for (auto chil: graphe.children(node)) {
748  if (cn__->currentNodeType(chil)
750  continue;
751  }
752 
753  msgP_(node, chil);
754  }
755 
756  for (auto par: graphe.parents(node)) {
757  if (cn__->currentNodeType(node)
759  continue;
760  }
761 
762  msgL_(node, par);
763  }
764  }
765 
766  eps = calculateEpsilon_();
767 
769 
770  active_nodes_set.clear();
771  active_nodes_set = next_active_nodes_set;
773 
775  && active_nodes_set.size() > 0);
776 
777  infE__::stopApproximationScheme(); // just to be sure of the
778  // approximationScheme has been notified of
779  // the end of looop
780  }
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.
const IBayesNet< GUM_SCALAR > * bnet__
A pointer to it&#39;s IBayesNet used as a DAG.
void stopApproximationScheme()
Stop the approximation scheme.
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:374
void msgL_(const NodeId X, const NodeId demanding_parent)
Sends a message to one&#39;s parent, i.e.
const CredalNet< GUM_SCALAR > * cn__
A pointer to the CredalNet to be used.
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 446 of file inferenceEngine_tpl.h.

446  {
447  try {
448  Potential< GUM_SCALAR > res;
449  res.add(credalNet_->current_bn().variable(id));
450  res.fillWith(marginalMax_[id]);
451  return res;
452  } catch (NotFound& err) { throw(err); }
453  }
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 428 of file inferenceEngine_tpl.h.

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

435  {
436  try {
437  Potential< GUM_SCALAR > res;
438  res.add(credalNet_->current_bn().variable(id));
439  res.fillWith(marginalMin_[id]);
440  return res;
441  } catch (NotFound& err) { throw(err); }
442  }
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 422 of file inferenceEngine_tpl.h.

423  {
424  return marginalMin(credalNet_->current_bn().idFromName(varName));
425  }
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 101 of file approximationScheme_inl.h.

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

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

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

124 { 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 39 of file IApproximationSchemeConfiguration_inl.h.

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

39  {
40  std::stringstream s;
41 
42  switch (stateApproximationScheme()) {
44  s << "in progress";
45  break;
46 
48  s << "stopped with epsilon=" << epsilon();
49  break;
50 
52  s << "stopped with rate=" << minEpsilonRate();
53  break;
54 
56  s << "stopped with max iteration=" << maxIter();
57  break;
58 
60  s << "stopped with timeout=" << maxTime();
61  break;
62 
64  s << "stopped on request";
65  break;
66 
68  s << "undefined state";
69  break;
70  };
71 
72  return s.str();
73  }
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 73 of file approximationScheme_inl.h.

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

73  {
74  return min_rate_eps_;
75  }
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 864 of file CNLoopyPropagation_tpl.h.

864  {
865  NodeSet const& children = bnet__->children(Y);
866  NodeSet const& parents_ = bnet__->parents(Y);
867 
868  const auto parents = &bnet__->cpt(Y).variablesSequence();
869 
870  if (((children.size() + parents->size() - 1) == 1)
871  && (!infE__::evidence_.exists(Y))) {
872  return;
873  }
874 
875  bool update_l = update_l_[Y];
876  bool update_p = update_p_[Y];
877 
878  if (!update_p && !update_l) { return; }
879 
880  msg_l_sent_[Y]->insert(X);
881 
882  // for future refresh LM/PI
883  if (msg_l_sent_[Y]->size() == parents_.size()) {
884  msg_l_sent_[Y]->clear();
885  update_l_[Y] = false;
886  }
887 
888  // refresh LM_part
889  if (update_l) {
890  if (!children.empty() && !infE__::evidence_.exists(Y)) {
891  GUM_SCALAR lmin = 1.;
892  GUM_SCALAR lmax = 1.;
893 
894  for (auto chil: children) {
895  lmin *= ArcsL_min_[Arc(Y, chil)];
896 
897  if (ArcsL_max_.exists(Arc(Y, chil))) {
898  lmax *= ArcsL_max_[Arc(Y, chil)];
899  } else {
900  lmax *= ArcsL_min_[Arc(Y, chil)];
901  }
902  }
903 
904  lmin = lmax;
905 
906  if (lmax != lmax && lmin == lmin) { lmax = lmin; }
907 
908  if (lmax != lmax && lmin != lmin) {
909  std::cout << "no likelihood defined [lmin, lmax] (incompatibles "
910  "evidence ?)"
911  << std::endl;
912  }
913 
914  if (lmin < 0.) { lmin = 0.; }
915 
916  if (lmax < 0.) { lmax = 0.; }
917 
918  // no need to update nodeL if evidence since nodeL will never be used
919 
920  NodesL_min_[Y] = lmin;
921 
922  if (lmin != lmax) {
923  NodesL_max_.set(Y, lmax);
924  } else if (NodesL_max_.exists(Y)) {
925  NodesL_max_.erase(Y);
926  }
927 
928  } // end of : node has children & no evidence
929 
930  } // end of : if update_l
931 
932  GUM_SCALAR lmin = NodesL_min_[Y];
933  GUM_SCALAR lmax;
934 
935  if (NodesL_max_.exists(Y)) {
936  lmax = NodesL_max_[Y];
937  } else {
938  lmax = lmin;
939  }
940 
945  if (lmin == lmax && lmin == 1.) {
946  ArcsL_min_[Arc(X, Y)] = lmin;
947 
948  if (ArcsL_max_.exists(Arc(X, Y))) { ArcsL_max_.erase(Arc(X, Y)); }
949 
950  return;
951  }
952 
953  // garder pour chaque noeud un table des parents maj, une fois tous maj,
954  // stop
955  // jusque notification msg L ou P
956 
957  if (update_p || update_l) {
958  std::vector< std::vector< std::vector< GUM_SCALAR > > > msgs_p;
959  std::vector< std::vector< GUM_SCALAR > > msg_p;
960  std::vector< GUM_SCALAR > distri(2);
961 
962  Idx pos;
963 
964  // +1 from start to avoid counting_ itself
965  // use const iterators with cbegin when available
966  for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd;
967  ++jt) {
968  if (bnet__->nodeId(**jt) == X) {
969  // retirer la variable courante de la taille
970  pos = parents->pos(*jt) - 1;
971  continue;
972  }
973 
974  // compute probability distribution to avoid doing it multiple times
975  // (at each combination of messages)
976  distri[1] = ArcsP_min_[Arc(bnet__->nodeId(**jt), Y)];
977  distri[0] = GUM_SCALAR(1.) - distri[1];
978  msg_p.push_back(distri);
979 
980  if (ArcsP_max_.exists(Arc(bnet__->nodeId(**jt), Y))) {
981  distri[1] = ArcsP_max_[Arc(bnet__->nodeId(**jt), Y)];
982  distri[0] = GUM_SCALAR(1.) - distri[1];
983  msg_p.push_back(distri);
984  }
985 
986  msgs_p.push_back(msg_p);
987  msg_p.clear();
988  }
989 
990  GUM_SCALAR min = -2.;
991  GUM_SCALAR max = -2.;
992 
993  std::vector< GUM_SCALAR > lx;
994  lx.push_back(lmin);
995 
996  if (lmin != lmax) { lx.push_back(lmax); }
997 
998  enum_combi_(msgs_p, Y, min, max, lx, pos);
999 
1000  if (min == -2. || max == -2.) {
1001  if (min != -2.) {
1002  max = min;
1003  } else if (max != -2.) {
1004  min = max;
1005  } else {
1006  std::cout << std::endl;
1007  std::cout << "!!!! pas de message L calculable !!!!" << std::endl;
1008  return;
1009  }
1010  }
1011 
1012  if (min < 0.) { min = 0.; }
1013 
1014  if (max < 0.) { max = 0.; }
1015 
1016  bool update = false;
1017 
1018  if (min != ArcsL_min_[Arc(X, Y)]) {
1019  ArcsL_min_[Arc(X, Y)] = min;
1020  update = true;
1021  }
1022 
1023  if (ArcsL_max_.exists(Arc(X, Y))) {
1024  if (max != ArcsL_max_[Arc(X, Y)]) {
1025  if (max != min) {
1026  ArcsL_max_[Arc(X, Y)] = max;
1027  } else { // if ( max == min )
1028  ArcsL_max_.erase(Arc(X, Y));
1029  }
1030 
1031  update = true;
1032  }
1033  } else {
1034  if (max != min) {
1035  ArcsL_max_.insert(Arc(X, Y), max);
1036  update = true;
1037  }
1038  }
1039 
1040  if (update) {
1041  update_l_.set(X, true);
1043  }
1044 
1045  } // end of update_p || update_l
1046  }
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.
const IBayesNet< GUM_SCALAR > * bnet__
A pointer to it&#39;s IBayesNet used as a DAG.
NodeProperty< GUM_SCALAR > NodesL_max_
"Upper" node information obtained by combinaison of children messages.
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:632
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 1049 of file CNLoopyPropagation_tpl.h.

1050  {
1051  NodeSet const& children = bnet__->children(X);
1052 
1053  const auto parents = &bnet__->cpt(X).variablesSequence();
1054 
1055  if (((children.size() + parents->size() - 1) == 1)
1056  && (!infE__::evidence_.exists(X))) {
1057  return;
1058  }
1059 
1060  // LM_part ---- from all children but one --- the lonely one will get the
1061  // message
1062 
1063  if (infE__::evidence_.exists(X)) {
1064  ArcsP_min_[Arc(X, demanding_child)] = infE__::evidence_[X][1];
1065 
1066  if (ArcsP_max_.exists(Arc(X, demanding_child))) {
1067  ArcsP_max_.erase(Arc(X, demanding_child));
1068  }
1069 
1070  return;
1071  }
1072 
1073  bool update_l = update_l_[X];
1074  bool update_p = update_p_[X];
1075 
1076  if (!update_p && !update_l) { return; }
1077 
1078  GUM_SCALAR lmin = 1.;
1079  GUM_SCALAR lmax = 1.;
1080 
1081  // use cbegin if available
1082  for (auto chil: children) {
1083  if (chil == demanding_child) { continue; }
1084 
1085  lmin *= ArcsL_min_[Arc(X, chil)];
1086 
1087  if (ArcsL_max_.exists(Arc(X, chil))) {
1088  lmax *= ArcsL_max_[Arc(X, chil)];
1089  } else {
1090  lmax *= ArcsL_min_[Arc(X, chil)];
1091  }
1092  }
1093 
1094  if (lmin != lmin && lmax == lmax) { lmin = lmax; }
1095 
1096  if (lmax != lmax && lmin == lmin) { lmax = lmin; }
1097 
1098  if (lmax != lmax && lmin != lmin) {
1099  std::cout << "pas de vraisemblance definie [lmin, lmax] (observations "
1100  "incompatibles ?)"
1101  << std::endl;
1102  return;
1103  }
1104 
1105  if (lmin < 0.) { lmin = 0.; }
1106 
1107  if (lmax < 0.) { lmax = 0.; }
1108 
1109  // refresh PI_part
1110  GUM_SCALAR min = INF_;
1111  GUM_SCALAR max = 0.;
1112 
1113  if (update_p) {
1114  std::vector< std::vector< std::vector< GUM_SCALAR > > > msgs_p;
1115  std::vector< std::vector< GUM_SCALAR > > msg_p;
1116  std::vector< GUM_SCALAR > distri(2);
1117 
1118  // +1 from start to avoid counting_ itself
1119  // use const_iterators if available
1120  for (auto jt = ++parents->begin(), theEnd = parents->end(); jt != theEnd;
1121  ++jt) {
1122  // compute probability distribution to avoid doing it multiple times
1123  // (at
1124  // each combination of messages)
1125  distri[1] = ArcsP_min_[Arc(bnet__->nodeId(**jt), X)];
1126  distri[0] = GUM_SCALAR(1.) - distri[1];
1127  msg_p.push_back(distri);
1128 
1129  if (ArcsP_max_.exists(Arc(bnet__->nodeId(**jt), X))) {
1130  distri[1] = ArcsP_max_[Arc(bnet__->nodeId(**jt), X)];
1131  distri[0] = GUM_SCALAR(1.) - distri[1];
1132  msg_p.push_back(distri);
1133  }
1134 
1135  msgs_p.push_back(msg_p);
1136  msg_p.clear();
1137  }
1138 
1139  enum_combi_(msgs_p, X, min, max);
1140 
1141  if (min < 0.) { min = 0.; }
1142 
1143  if (max < 0.) { max = 0.; }
1144 
1145  if (min == INF_ || max == INF_) {
1146  std::cout << " ERREUR msg P min = max = INF " << std::endl;
1147  std::cout.flush();
1148  return;
1149  }
1150 
1151  NodesP_min_[X] = min;
1152 
1153  if (min != max) {
1154  NodesP_max_.set(X, max);
1155  } else if (NodesP_max_.exists(X)) {
1156  NodesP_max_.erase(X);
1157  }
1158 
1159  update_p_.set(X, false);
1160 
1161  } // end of update_p
1162  else {
1163  min = NodesP_min_[X];
1164 
1165  if (NodesP_max_.exists(X)) {
1166  max = NodesP_max_[X];
1167  } else {
1168  max = min;
1169  }
1170  }
1171 
1172  if (update_p || update_l) {
1173  GUM_SCALAR msg_p_min;
1174  GUM_SCALAR msg_p_max;
1175 
1176  // cas limites sur min
1177  if (min == INF_ && lmin == 0.) {
1178  std::cout << "MESSAGE P ERR (negatif) : pi = inf, l = 0" << std::endl;
1179  }
1180 
1181  if (lmin == INF_) { // cas infini
1182  msg_p_min = GUM_SCALAR(1.);
1183  } else if (min == 0. || lmin == 0.) {
1184  msg_p_min = 0;
1185  } else {
1186  msg_p_min = GUM_SCALAR(1. / (1. + ((1. / min - 1.) * 1. / lmin)));
1187  }
1188 
1189  // cas limites sur max
1190  if (max == INF_ && lmax == 0.) {
1191  std::cout << "MESSAGE P ERR (negatif) : pi = inf, l = 0" << std::endl;
1192  }
1193 
1194  if (lmax == INF_) { // cas infini
1195  msg_p_max = GUM_SCALAR(1.);
1196  } else if (max == 0. || lmax == 0.) {
1197  msg_p_max = 0;
1198  } else {
1199  msg_p_max = GUM_SCALAR(1. / (1. + ((1. / max - 1.) * 1. / lmax)));
1200  }
1201 
1202  if (msg_p_min != msg_p_min && msg_p_max == msg_p_max) {
1203  msg_p_min = msg_p_max;
1204  std::cout << std::endl;
1205  std::cout << "msg_p_min is NaN" << std::endl;
1206  }
1207 
1208  if (msg_p_max != msg_p_max && msg_p_min == msg_p_min) {
1209  msg_p_max = msg_p_min;
1210  std::cout << std::endl;
1211  std::cout << "msg_p_max is NaN" << std::endl;
1212  }
1213 
1214  if (msg_p_max != msg_p_max && msg_p_min != msg_p_min) {
1215  std::cout << std::endl;
1216  std::cout << "pas de message P calculable (verifier observations)"
1217  << std::endl;
1218  return;
1219  }
1220 
1221  if (msg_p_min < 0.) { msg_p_min = 0.; }
1222 
1223  if (msg_p_max < 0.) { msg_p_max = 0.; }
1224 
1225  bool update = false;
1226 
1227  if (msg_p_min != ArcsP_min_[Arc(X, demanding_child)]) {
1228  ArcsP_min_[Arc(X, demanding_child)] = msg_p_min;
1229  update = true;
1230  }
1231 
1232  if (ArcsP_max_.exists(Arc(X, demanding_child))) {
1233  if (msg_p_max != ArcsP_max_[Arc(X, demanding_child)]) {
1234  if (msg_p_max != msg_p_min) {
1235  ArcsP_max_[Arc(X, demanding_child)] = msg_p_max;
1236  } else { // if ( msg_p_max == msg_p_min )
1237  ArcsP_max_.erase(Arc(X, demanding_child));
1238  }
1239 
1240  update = true;
1241  }
1242  } else {
1243  if (msg_p_max != msg_p_min) {
1244  ArcsP_max_.insert(Arc(X, demanding_child), msg_p_max);
1245  update = true;
1246  }
1247  }
1248 
1249  if (update) {
1250  update_p_.set(demanding_child, true);
1251  next_active_nodes_set.insert(demanding_child);
1252  }
1253 
1254  } // end of : update_l || update_p
1255  }
#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:632
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 162 of file approximationScheme_inl.h.

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

162  {
164  GUM_ERROR(OperationNotAllowed,
165  "state of the approximation scheme is undefined");
166  }
167 
168  return current_step_;
169  }
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
Size current_step_
The current step.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ 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 148 of file approximationScheme_inl.h.

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

148 { 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 1258 of file CNLoopyPropagation_tpl.h.

1258  {
1259  for (auto node: bnet__->nodes()) {
1260  if ((!refreshIndic)
1261  && cn__->currentNodeType(node)
1263  continue;
1264  }
1265 
1266  NodeSet const& children = bnet__->children(node);
1267 
1268  auto parents = &bnet__->cpt(node).variablesSequence();
1269 
1270  if (update_l_[node]) {
1271  GUM_SCALAR lmin = 1.;
1272  GUM_SCALAR lmax = 1.;
1273 
1274  if (!children.empty() && !infE__::evidence_.exists(node)) {
1275  for (auto chil: children) {
1276  lmin *= ArcsL_min_[Arc(node, chil)];
1277 
1278  if (ArcsL_max_.exists(Arc(node, chil))) {
1279  lmax *= ArcsL_max_[Arc(node, chil)];
1280  } else {
1281  lmax *= ArcsL_min_[Arc(node, chil)];
1282  }
1283  }
1284 
1285  if (lmin != lmin && lmax == lmax) { lmin = lmax; }
1286 
1287  lmax = lmin;
1288 
1289  if (lmax != lmax && lmin != lmin) {
1290  std::cout
1291  << "pas de vraisemblance definie [lmin, lmax] (observations "
1292  "incompatibles ?)"
1293  << std::endl;
1294  return;
1295  }
1296 
1297  if (lmin < 0.) { lmin = 0.; }
1298 
1299  if (lmax < 0.) { lmax = 0.; }
1300 
1301  NodesL_min_[node] = lmin;
1302 
1303  if (lmin != lmax) {
1304  NodesL_max_.set(node, lmax);
1305  } else if (NodesL_max_.exists(node)) {
1306  NodesL_max_.erase(node);
1307  }
1308  }
1309 
1310  } // end of : update_l
1311 
1312  if (update_p_[node]) {
1313  if ((parents->size() - 1) > 0 && !infE__::evidence_.exists(node)) {
1314  std::vector< std::vector< std::vector< GUM_SCALAR > > > msgs_p;
1315  std::vector< std::vector< GUM_SCALAR > > msg_p;
1316  std::vector< GUM_SCALAR > distri(2);
1317 
1318  // +1 from start to avoid counting_ itself
1319  // cbegin
1320  for (auto jt = ++parents->begin(), theEnd = parents->end();
1321  jt != theEnd;
1322  ++jt) {
1323  // compute probability distribution to avoid doing it multiple
1324  // times
1325  // (at each combination of messages)
1326  distri[1] = ArcsP_min_[Arc(bnet__->nodeId(**jt), node)];
1327  distri[0] = GUM_SCALAR(1.) - distri[1];
1328  msg_p.push_back(distri);
1329 
1330  if (ArcsP_max_.exists(Arc(bnet__->nodeId(**jt), node))) {
1331  distri[1] = ArcsP_max_[Arc(bnet__->nodeId(**jt), node)];
1332  distri[0] = GUM_SCALAR(1.) - distri[1];
1333  msg_p.push_back(distri);
1334  }
1335 
1336  msgs_p.push_back(msg_p);
1337  msg_p.clear();
1338  }
1339 
1340  GUM_SCALAR min = INF_;
1341  GUM_SCALAR max = 0.;
1342 
1343  enum_combi_(msgs_p, node, min, max);
1344 
1345  if (min < 0.) { min = 0.; }
1346 
1347  if (max < 0.) { max = 0.; }
1348 
1349  NodesP_min_[node] = min;
1350 
1351  if (min != max) {
1352  NodesP_max_.set(node, max);
1353  } else if (NodesP_max_.exists(node)) {
1354  NodesP_max_.erase(node);
1355  }
1356 
1357  update_p_[node] = false;
1358  }
1359  } // end of update_p
1360 
1361  } // end of : for each node
1362  }
#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 > 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.
const IBayesNet< GUM_SCALAR > * bnet__
A pointer to it&#39;s IBayesNet used as a DAG.
NodeProperty< GUM_SCALAR > NodesL_max_
"Upper" node information obtained by combinaison of children messages.
const CredalNet< GUM_SCALAR > * cn__
A pointer to the CredalNet to be used.
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 209 of file approximationScheme_inl.h.

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

209  {
210  if (burn_in_ > current_step_) {
211  return burn_in_ - current_step_;
212  } else {
213  return 0;
214  }
215  }
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 120 of file inferenceEngine_tpl.h.

120  {
121  return repetitiveInd_;
122  }
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 786 of file inferenceEngine_tpl.h.

786  {
787  timeSteps_ = 0;
788  t0_.clear();
789  t1_.clear();
790 
791  // t = 0 vars belongs to t0_ as keys
792  for (auto node: credalNet_->current_bn().dag().nodes()) {
793  std::string var_name = credalNet_->current_bn().variable(node).name();
794  auto delim = var_name.find_first_of("_");
795 
796  if (delim > var_name.size()) {
797  GUM_ERROR(InvalidArgument,
798  "void InferenceEngine< GUM_SCALAR "
799  ">::repetitiveInit_() : the network does not "
800  "appear to be dynamic");
801  }
802 
803  std::string time_step = var_name.substr(delim + 1, 1);
804 
805  if (time_step.compare("0") == 0) t0_.insert(node, std::vector< NodeId >());
806  }
807 
808  // t = 1 vars belongs to either t0_ as member value or t1_ as keys
809  for (const auto& node: credalNet_->current_bn().dag().nodes()) {
810  std::string var_name = credalNet_->current_bn().variable(node).name();
811  auto delim = var_name.find_first_of("_");
812  std::string time_step = var_name.substr(delim + 1, var_name.size());
813  var_name = var_name.substr(0, delim);
814  delim = time_step.find_first_of("_");
815  time_step = time_step.substr(0, delim);
816 
817  if (time_step.compare("1") == 0) {
818  bool found = false;
819 
820  for (const auto& elt: t0_) {
821  std::string var_0_name
822  = credalNet_->current_bn().variable(elt.first).name();
823  delim = var_0_name.find_first_of("_");
824  var_0_name = var_0_name.substr(0, delim);
825 
826  if (var_name.compare(var_0_name) == 0) {
827  const Potential< GUM_SCALAR >* potential(
828  &credalNet_->current_bn().cpt(node));
829  const Potential< GUM_SCALAR >* potential2(
830  &credalNet_->current_bn().cpt(elt.first));
831 
832  if (potential->domainSize() == potential2->domainSize())
833  t0_[elt.first].push_back(node);
834  else
835  t1_.insert(node, std::vector< NodeId >());
836 
837  found = true;
838  break;
839  }
840  }
841 
842  if (!found) { t1_.insert(node, std::vector< NodeId >()); }
843  }
844  }
845 
846  // t > 1 vars belongs to either t0_ or t1_ as member value
847  // remember timeSteps_
848  for (auto node: credalNet_->current_bn().dag().nodes()) {
849  std::string var_name = credalNet_->current_bn().variable(node).name();
850  auto delim = var_name.find_first_of("_");
851  std::string time_step = var_name.substr(delim + 1, var_name.size());
852  var_name = var_name.substr(0, delim);
853  delim = time_step.find_first_of("_");
854  time_step = time_step.substr(0, delim);
855 
856  if (time_step.compare("0") != 0 && time_step.compare("1") != 0) {
857  // keep max time_step
858  if (atoi(time_step.c_str()) > timeSteps_)
859  timeSteps_ = atoi(time_step.c_str());
860 
861  std::string var_0_name;
862  bool found = false;
863 
864  for (const auto& elt: t0_) {
865  std::string var_0_name
866  = credalNet_->current_bn().variable(elt.first).name();
867  delim = var_0_name.find_first_of("_");
868  var_0_name = var_0_name.substr(0, delim);
869 
870  if (var_name.compare(var_0_name) == 0) {
871  const Potential< GUM_SCALAR >* potential(
872  &credalNet_->current_bn().cpt(node));
873  const Potential< GUM_SCALAR >* potential2(
874  &credalNet_->current_bn().cpt(elt.first));
875 
876  if (potential->domainSize() == potential2->domainSize()) {
877  t0_[elt.first].push_back(node);
878  found = true;
879  break;
880  }
881  }
882  }
883 
884  if (!found) {
885  for (const auto& elt: t1_) {
886  std::string var_0_name
887  = credalNet_->current_bn().variable(elt.first).name();
888  auto delim = var_0_name.find_first_of("_");
889  var_0_name = var_0_name.substr(0, delim);
890 
891  if (var_name.compare(var_0_name) == 0) {
892  const Potential< GUM_SCALAR >* potential(
893  &credalNet_->current_bn().cpt(node));
894  const Potential< GUM_SCALAR >* potential2(
895  &credalNet_->current_bn().cpt(elt.first));
896 
897  if (potential->domainSize() == potential2->domainSize()) {
898  t1_[elt.first].push_back(node);
899  break;
900  }
901  }
902  }
903  }
904  }
905  }
906  }
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:54

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

557  {
558  if (dynamicExpMin_.empty()) //_modal.empty())
559  return;
560 
561  // else not here, to keep the const (natural with a saving process)
562  // else if(dynamicExpMin_.empty() || dynamicExpMax_.empty())
563  //_dynamicExpectations(); // works with or without a dynamic network
564 
565  std::ofstream m_stream(path.c_str(), std::ios::out | std::ios::trunc);
566 
567  if (!m_stream.good()) {
568  GUM_ERROR(IOError,
569  "void InferenceEngine< GUM_SCALAR "
570  ">::saveExpectations(const std::string & path) : could "
571  "not open output file : "
572  << path);
573  }
574 
575  for (const auto& elt: dynamicExpMin_) {
576  m_stream << elt.first; // it->first;
577 
578  // iterates over a vector
579  for (const auto& elt2: elt.second) {
580  m_stream << " " << elt2;
581  }
582 
583  m_stream << std::endl;
584  }
585 
586  for (const auto& elt: dynamicExpMax_) {
587  m_stream << elt.first;
588 
589  // iterates over a vector
590  for (const auto& elt2: elt.second) {
591  m_stream << " " << elt2;
592  }
593 
594  m_stream << std::endl;
595  }
596 
597  m_stream.close();
598  }
dynExpe dynamicExpMin_
Lower dynamic expectations.
dynExpe dynamicExpMax_
Upper dynamic expectations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ 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) {
128  msg_p_min = msg_p_max;
129  }
130 
131  if (msg_p_max != msg_p_max && msg_p_min == msg_p_min) {
132  msg_p_max = msg_p_min;
133  }
134 
135  if (msg_p_max != msg_p_max && msg_p_min != msg_p_min) {
136  std::cout << std::endl;
137  std::cout << "pas de proba calculable (verifier observations)"
138  << std::endl;
139  }
140 
141  res << "P(" << bnet__->variable(node).name() << " | e) = ";
142 
143  if (infE__::evidence_.exists(node)) {
144  res << "(observe)" << std::endl;
145  } else {
146  res << std::endl;
147  }
148 
149  res << "\t\t" << bnet__->variable(node).label(0) << " [ "
150  << (GUM_SCALAR)1. - msg_p_max;
151 
152  if (msg_p_min != msg_p_max) {
153  res << ", " << (GUM_SCALAR)1. - msg_p_min << " ] | ";
154  } else {
155  res << " ] | ";
156  }
157 
158  res << bnet__->variable(node).label(1) << " [ " << msg_p_min;
159 
160  if (msg_p_min != msg_p_max) {
161  res << ", " << msg_p_max << " ]" << std::endl;
162  } else {
163  res << " ]" << std::endl;
164  }
165  } // end of : for each node
166 
167  res.close();
168  }
#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.
const IBayesNet< GUM_SCALAR > * bnet__
A pointer to it&#39;s IBayesNet used as a DAG.
NodeProperty< GUM_SCALAR > NodesL_max_
"Upper" node information obtained by combinaison of children messages.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

531  {
532  std::ofstream m_stream(path.c_str(), std::ios::out | std::ios::trunc);
533 
534  if (!m_stream.good()) {
535  GUM_ERROR(IOError,
536  "void InferenceEngine< GUM_SCALAR >::saveMarginals(const "
537  "std::string & path) const : could not open output file "
538  ": "
539  << path);
540  }
541 
542  for (const auto& elt: marginalMin_) {
543  Size esize = Size(elt.second.size());
544 
545  for (Size mod = 0; mod < esize; mod++) {
546  m_stream << credalNet_->current_bn().variable(elt.first).name() << " "
547  << mod << " " << (elt.second)[mod] << " "
548  << marginalMax_[elt.first][mod] << std::endl;
549  }
550  }
551 
552  m_stream.close();
553  }
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:54

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

630  {
631  std::ofstream m_stream(path.c_str(), std::ios::out | std::ios::trunc);
632 
633  if (!m_stream.good()) {
634  GUM_ERROR(IOError,
635  "void InferenceEngine< GUM_SCALAR >::saveVertices(const "
636  "std::string & path) : could not open outpul file : "
637  << path);
638  }
639 
640  for (const auto& elt: marginalSets_) {
641  m_stream << credalNet_->current_bn().variable(elt.first).name()
642  << std::endl;
643 
644  for (const auto& elt2: elt.second) {
645  m_stream << "[";
646  bool first = true;
647 
648  for (const auto& elt3: elt2) {
649  if (!first) {
650  m_stream << ",";
651  first = false;
652  }
653 
654  m_stream << elt3;
655  }
656 
657  m_stream << "]\n";
658  }
659  }
660 
661  m_stream.close();
662  }
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:54

◆ 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:54
+ 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 94 of file approximationScheme_inl.h.

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

94  {
95  if (max < 1) { GUM_ERROR(OutOfLowerBound, "max should be >=1"); }
96  max_iter_ = max;
97  enabled_max_iter_ = true;
98  }
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:54
+ 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 117 of file approximationScheme_inl.h.

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

117  {
118  if (timeout <= 0.) { GUM_ERROR(OutOfLowerBound, "timeout should be >0."); }
119  max_time_ = timeout;
120  enabled_max_time_ = true;
121  }
double max_time_
The timeout.
bool enabled_max_time_
If true, the timeout is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ 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 65 of file approximationScheme_inl.h.

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

65  {
66  if (rate < 0) { GUM_ERROR(OutOfLowerBound, "rate should be >=0"); }
67 
68  min_rate_eps_ = rate;
69  enabled_min_rate_eps_ = true;
70  }
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:54
+ 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 142 of file approximationScheme_inl.h.

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

142  {
143  if (p < 1) { GUM_ERROR(OutOfLowerBound, "p should be >=1"); }
144 
145  period_size_ = p;
146  }
Size period_size_
Checking criteria frequency.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ 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 111 of file inferenceEngine_tpl.h.

111  {
112  bool oldValue = repetitiveInd_;
113  repetitiveInd_ = repetitive;
114 
115  // do not compute clusters more than once
116  if (repetitiveInd_ && !oldValue) repetitiveInit_();
117  }
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 151 of file approximationScheme_inl.h.

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

151 { 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 196 of file approximationScheme_inl.h.

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

196  {
197  if (current_step_ < burn_in_) { return false; }
198 
199  if (period_size_ == 1) { return true; }
200 
201  return ((current_step_ - burn_in_) % period_size_ == 0);
202  }
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 157 of file approximationScheme_inl.h.

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

157  {
158  return current_state_;
159  }
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 218 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 99 of file inferenceEngine_tpl.h.

99  {
100  storeBNOpt_ = value;
101  }
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 135 of file inferenceEngine_tpl.h.

135  {
136  return storeBNOpt_;
137  }
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 104 of file inferenceEngine_tpl.h.

104  {
105  storeVertices_ = value;
106 
107  if (value) initMarginalSets_();
108  }
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 130 of file inferenceEngine_tpl.h.

130  {
131  return storeVertices_;
132  }
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 601 of file inferenceEngine_tpl.h.

601  {
602  std::stringstream output;
603  output << std::endl;
604 
605  // use cbegin() when available
606  for (const auto& elt: marginalMin_) {
607  Size esize = Size(elt.second.size());
608 
609  for (Size mod = 0; mod < esize; mod++) {
610  output << "P(" << credalNet_->current_bn().variable(elt.first).name()
611  << "=" << mod << "|e) = [ ";
612  output << marginalMin_[elt.first][mod] << ", "
613  << marginalMax_[elt.first][mod] << " ]";
614 
615  if (!query_.empty())
616  if (query_.exists(elt.first) && query_[elt.first][mod])
617  output << " QUERY";
618 
619  output << std::endl;
620  }
621 
622  output << std::endl;
623  }
624 
625  return output.str();
626  }
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 205 of file approximationScheme_inl.h.

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

205  {
206  current_step_ += incr;
207  }
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 931 of file inferenceEngine_tpl.h.

934  {
935  auto& nodeCredalSet = marginalSets_[id];
936  auto dsize = vertex.size();
937 
938  bool eq = true;
939 
940  for (auto it = nodeCredalSet.cbegin(), itEnd = nodeCredalSet.cend();
941  it != itEnd;
942  ++it) {
943  eq = true;
944 
945  for (Size i = 0; i < dsize; i++) {
946  if (std::fabs(vertex[i] - (*it)[i]) > 1e-6) {
947  eq = false;
948  break;
949  }
950  }
951 
952  if (eq) break;
953  }
954 
955  if (!eq || nodeCredalSet.size() == 0) {
956  nodeCredalSet.push_back(vertex);
957  return;
958  } else
959  return;
960 
961  // because of next lambda return condition
962  if (nodeCredalSet.size() == 1) return;
963 
964  // check that the point and all previously added ones are not inside the
965  // actual
966  // polytope
967  auto itEnd = std::remove_if(
968  nodeCredalSet.begin(),
969  nodeCredalSet.end(),
970  [&](const std::vector< GUM_SCALAR >& v) -> bool {
971  for (auto jt = v.cbegin(),
972  jtEnd = v.cend(),
973  minIt = marginalMin_[id].cbegin(),
974  minItEnd = marginalMin_[id].cend(),
975  maxIt = marginalMax_[id].cbegin(),
976  maxItEnd = marginalMax_[id].cend();
977  jt != jtEnd && minIt != minItEnd && maxIt != maxItEnd;
978  ++jt, ++minIt, ++maxIt) {
979  if ((std::fabs(*jt - *minIt) < 1e-6 || std::fabs(*jt - *maxIt) < 1e-6)
980  && std::fabs(*minIt - *maxIt) > 1e-6)
981  return false;
982  }
983  return true;
984  });
985 
986  nodeCredalSet.erase(itEnd, nodeCredalSet.end());
987 
988  // we need at least 2 points to make a convex combination
989  if (!elimRedund || nodeCredalSet.size() <= 2) return;
990 
991  // there may be points not inside the polytope but on one of it's facet,
992  // meaning it's still a convex combination of vertices of this facet. Here
993  // we
994  // need lrs.
995  LRSWrapper< GUM_SCALAR > lrsWrapper;
996  lrsWrapper.setUpV((unsigned int)dsize, (unsigned int)(nodeCredalSet.size()));
997 
998  for (const auto& vtx: nodeCredalSet)
999  lrsWrapper.fillV(vtx);
1000 
1001  lrsWrapper.elimRedundVrep();
1002 
1003  marginalSets_[id] = lrsWrapper.getOutput();
1004  }
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 909 of file inferenceEngine_tpl.h.

911  {
912  std::string var_name = credalNet_->current_bn().variable(id).name();
913  auto delim = var_name.find_first_of("_");
914 
915  var_name = var_name.substr(0, delim);
916 
917  if (modal_.exists(var_name) /*modal_.find(var_name) != modal_.end()*/) {
918  GUM_SCALAR exp = 0;
919  auto vsize = vertex.size();
920 
921  for (Size mod = 0; mod < vsize; mod++)
922  exp += vertex[mod] * modal_[var_name][mod];
923 
924  if (exp > expectationMax_[id]) expectationMax_[id] = exp;
925 
926  if (exp < expectationMin_[id]) expectationMin_[id] = exp;
927  }
928  }
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 1471 of file CNLoopyPropagation_tpl.h.

1471  {
1472  for (auto node: bnet__->nodes()) {
1473  if (cn__->currentNodeType(node)
1475  continue;
1476  }
1477 
1478  for (auto pare: bnet__->parents(node)) {
1479  msgP_(pare, node);
1480  }
1481  }
1482 
1483  refreshLMsPIs_(true);
1484  updateMarginals_();
1485  }
void refreshLMsPIs_(bool refreshIndic=false)
Get the last messages from one&#39;s parents and children.
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.
const CredalNet< GUM_SCALAR > * cn__
A pointer to the CredalNet to be used.

◆ updateMarginals_()

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

Compute marginals from up-to-date messages.

Definition at line 1365 of file CNLoopyPropagation_tpl.h.

1365  {
1366  for (auto node: bnet__->nodes()) {
1367  GUM_SCALAR msg_p_min = 1.;
1368  GUM_SCALAR msg_p_max = 0.;
1369 
1370  if (infE__::evidence_.exists(node)) {
1371  if (infE__::evidence_[node][1] == 0.) {
1372  msg_p_min = (GUM_SCALAR)0.;
1373  } else if (infE__::evidence_[node][1] == 1.) {
1374  msg_p_min = 1.;
1375  }
1376 
1377  msg_p_max = msg_p_min;
1378  } else {
1379  GUM_SCALAR min = NodesP_min_[node];
1380  GUM_SCALAR max;
1381 
1382  if (NodesP_max_.exists(node)) {
1383  max = NodesP_max_[node];
1384  } else {
1385  max = min;
1386  }
1387 
1388  GUM_SCALAR lmin = NodesL_min_[node];
1389  GUM_SCALAR lmax;
1390  GUM_TRACE_VAR(NodesL_max_.exists(node))
1391  if (NodesL_max_.exists(node)) {
1392  lmax = NodesL_max_[node];
1393  } else {
1394  lmax = lmin;
1395  }
1396 
1397  if (min == INF_ || max == INF_) {
1398  std::cout << " min ou max === INF_ !!!!!!!!!!!!!!!!!!!!!!!!!! "
1399  << std::endl;
1400  return;
1401  }
1402 
1403  if (min == INF_ && lmin == 0.) {
1404  std::cout << "proba ERR (negatif) : pi = inf, l = 0" << std::endl;
1405  return;
1406  }
1407 
1408  if (lmin == INF_) {
1409  msg_p_min = GUM_SCALAR(1.);
1410  } else if (min == 0. || lmin == 0.) {
1411  msg_p_min = GUM_SCALAR(0.);
1412  } else {
1413  msg_p_min = GUM_SCALAR(1. / (1. + ((1. / min - 1.) * 1. / lmin)));
1414  }
1415 
1416  if (max == INF_ && lmax == 0.) {
1417  std::cout << "proba ERR (negatif) : pi = inf, l = 0" << std::endl;
1418  return;
1419  }
1420 
1421  if (lmax == INF_) {
1422  msg_p_max = GUM_SCALAR(1.);
1423  } else if (max == 0. || lmax == 0.) {
1424  msg_p_max = GUM_SCALAR(0.);
1425  } else {
1426  msg_p_max = GUM_SCALAR(1. / (1. + ((1. / max - 1.) * 1. / lmax)));
1427  }
1428  }
1429 
1430  if (msg_p_min != msg_p_min && msg_p_max == msg_p_max) {
1431  msg_p_min = msg_p_max;
1432  std::cout << std::endl;
1433  std::cout << "msg_p_min is NaN" << std::endl;
1434  }
1435 
1436  if (msg_p_max != msg_p_max && msg_p_min == msg_p_min) {
1437  msg_p_max = msg_p_min;
1438  std::cout << std::endl;
1439  std::cout << "msg_p_max is NaN" << std::endl;
1440  }
1441 
1442  if (msg_p_max != msg_p_max && msg_p_min != msg_p_min) {
1443  std::cout << std::endl;
1444  std::cout << "Please check the observations (no proba can be computed)"
1445  << std::endl;
1446  return;
1447  }
1448 
1449  if (msg_p_min < 0.) { msg_p_min = 0.; }
1450 
1451  if (msg_p_max < 0.) { msg_p_max = 0.; }
1452 
1453  infE__::marginalMin_[node][0] = 1 - msg_p_max;
1454  infE__::marginalMax_[node][0] = 1 - msg_p_min;
1455  infE__::marginalMin_[node][1] = msg_p_min;
1456  infE__::marginalMax_[node][1] = msg_p_max;
1457  GUM_TRACE_VAR(node << ":" << infE__::marginalMin_[node]);
1458  GUM_TRACE_VAR(node << ":" << infE__::marginalMax_[node]);
1459  }
1460  }
#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.
const IBayesNet< GUM_SCALAR > * bnet__
A pointer to it&#39;s IBayesNet used as a DAG.
NodeProperty< GUM_SCALAR > NodesL_max_
"Upper" node information obtained by combinaison of children messages.
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 153 of file approximationScheme_inl.h.

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

153 { 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 525 of file inferenceEngine_tpl.h.

525  {
526  return marginalSets_[id];
527  }
credalSet marginalSets_
Credal sets vertices, if enabled.

Member Data Documentation

◆ 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 329 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 351 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 339 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 353 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 341 of file CNLoopyPropagation.h.

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

◆ 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 374 of file CNLoopyPropagation.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 69 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 142 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 96 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 93 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 102 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 89 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 86 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.

◆ inferenceType__

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

The choosen inference type.

nodeToNeighbours by Default.

Definition at line 371 of file CNLoopyPropagation.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 364 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 79 of file inferenceEngine.h.

◆ marginalMin_

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

Lower marginals.

Definition at line 77 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 82 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 99 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 336 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 333 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 356 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 344 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 360 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 348 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 74 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 72 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 104 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 128 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 138 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 124 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 112 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 119 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 149 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 326 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 322 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: