aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::credal::InferenceEngine< GUM_SCALAR > Class Template Referenceabstract

Abstract class template representing a CredalNet inference engine. More...

#include <agrum/CN/inferenceEngine.h>

+ Inheritance diagram for gum::credal::InferenceEngine< GUM_SCALAR >:
+ Collaboration diagram for gum::credal::InferenceEngine< GUM_SCALAR >:

Public Attributes

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

Public Member Functions

Constructors / Destructors
 InferenceEngine (const CredalNet< GUM_SCALAR > &credalNet)
 Construtor. More...
 
virtual ~InferenceEngine ()
 Destructor. More...
 
Pure virtual methods
virtual void makeInference ()=0
 To be redefined by each credal net algorithm. 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)
 
void storeBNOpt (const bool value)
 
bool repetitiveInd () const
 Get the current independence status. More...
 
bool storeVertices () const
 Get the number of iterations without changes used to stop some algorithms. More...
 
bool storeBNOpt () const
 
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...
 
virtual void insertEvidenceFile (const std::string &path)
 Insert evidence from file. 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
virtual void eraseAllEvidence ()
 Erase all inference related data to perform another one. More...
 
Potential< GUM_SCALAR > marginalMin (const NodeId id) const
 Get the lower marginals of a given node id. More...
 
Potential< GUM_SCALAR > marginalMax (const NodeId id) const
 Get the upper 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 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 & expectationMax (const NodeId id) const
 Get the upper 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 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  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

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 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::InferenceEngine< GUM_SCALAR >

Abstract class template representing a CredalNet inference engine.

Used by credal network inference algorithms such as CNLoopyPropagation (inner multi-threading) or CNMonteCarloSampling (outer multi-threading).

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

Definition at line 54 of file inferenceEngine.h.

Member Typedef Documentation

◆ cluster

template<typename GUM_SCALAR >
using gum::credal::InferenceEngine< GUM_SCALAR >::cluster = NodeProperty< std::vector< NodeId > >
private

Definition at line 64 of file inferenceEngine.h.

◆ credalSet

template<typename GUM_SCALAR >
using gum::credal::InferenceEngine< GUM_SCALAR >::credalSet = NodeProperty< std::vector< std::vector< GUM_SCALAR > > >
private

Definition at line 57 of file inferenceEngine.h.

◆ dynExpe

template<typename GUM_SCALAR >
using gum::credal::InferenceEngine< GUM_SCALAR >::dynExpe = typename gum::HashTable< std::string, std::vector< GUM_SCALAR > >
private

Definition at line 61 of file inferenceEngine.h.

◆ expe

template<typename GUM_SCALAR >
using gum::credal::InferenceEngine< GUM_SCALAR >::expe = NodeProperty< GUM_SCALAR >
private

Definition at line 59 of file inferenceEngine.h.

◆ margi

template<typename GUM_SCALAR >
using gum::credal::InferenceEngine< GUM_SCALAR >::margi = NodeProperty< std::vector< GUM_SCALAR > >
private

Definition at line 58 of file inferenceEngine.h.

◆ query

template<typename GUM_SCALAR >
using gum::credal::InferenceEngine< GUM_SCALAR >::query = NodeProperty< std::vector< bool > >
private

Definition at line 63 of file inferenceEngine.h.

Member Enumeration Documentation

◆ ApproximationSchemeSTATE

The different state of an approximation scheme.

Enumerator
Undefined 
Continue 
Epsilon 
Rate 
Limit 
TimeLimit 
Stopped 

Definition at line 64 of file IApproximationSchemeConfiguration.h.

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

Constructor & Destructor Documentation

◆ InferenceEngine()

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

Construtor.

Parameters
credalNetThe credal net to be used with this inference engine.

Definition at line 40 of file inferenceEngine_tpl.h.

40  :
43 
44  dbnOpt_.setCNet(credalNet);
45 
47 
48  GUM_CONSTRUCTOR(InferenceEngine);
49  }
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
ApproximationScheme(bool verbosity=false)
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.
const CredalNet< GUM_SCALAR > & credalNet() const
Get this creadal network.
void initMarginals_()
Initialize lower and upper old marginals and marginals before inference, with the lower marginal bein...
VarMod2BNsMap< GUM_SCALAR > dbnOpt_
Object used to efficiently store optimal bayes net during inference, for some algorithms.

◆ ~InferenceEngine()

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

Destructor.

Definition at line 52 of file inferenceEngine_tpl.h.

52  {
53  GUM_DESTRUCTOR(InferenceEngine);
54  }
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.

Member Function Documentation

◆ computeEpsilon_()

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

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

Highest delta on either lower or upper marginal is epsilon.

Also updates oldMarginals to current marginals.

Returns
Epsilon.

Definition at line 987 of file inferenceEngine_tpl.h.

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

◆ continueApproximationScheme()

INLINE bool gum::ApproximationScheme::continueApproximationScheme ( double  error)
inherited

Update the scheme w.r.t the new error.

Test the stopping criterion that are enabled.

Parameters
errorThe new error value.
Returns
false if state become != ApproximationSchemeSTATE::Continue
Exceptions
OperationNotAllowedRaised if state != ApproximationSchemeSTATE::Continue.

Definition at line 208 of file approximationScheme_inl.h.

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

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

◆ credalNet()

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

Get this creadal network.

Returns
A constant reference to this CredalNet.

Definition at line 57 of file inferenceEngine_tpl.h.

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

◆ currentTime()

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

Returns the current running time in second.

Returns
Returns the current running time in second.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 115 of file approximationScheme_inl.h.

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

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

◆ disableEpsilon()

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

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 53 of file approximationScheme_inl.h.

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

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

◆ disableMaxIter()

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

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 94 of file approximationScheme_inl.h.

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

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

◆ disableMaxTime()

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

Disable stopping criterion on timeout.

Returns
Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 118 of file approximationScheme_inl.h.

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

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

◆ disableMinEpsilonRate()

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

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 74 of file approximationScheme_inl.h.

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

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

◆ dynamicExpectations()

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

Compute dynamic expectations.

See also
dynamicExpectations_ Only call this if an algorithm does not call it by itself.

Definition at line 699 of file inferenceEngine_tpl.h.

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

◆ dynamicExpectations_()

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

Rearrange lower and upper expectations to suit dynamic networks.

Definition at line 704 of file inferenceEngine_tpl.h.

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

◆ dynamicExpMax()

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

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

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

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

Definition at line 497 of file inferenceEngine_tpl.h.

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

◆ dynamicExpMin()

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

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

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

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

Definition at line 481 of file inferenceEngine_tpl.h.

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

◆ enableEpsilon()

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

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 56 of file approximationScheme_inl.h.

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

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

◆ enableMaxIter()

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

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 97 of file approximationScheme_inl.h.

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

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

◆ enableMaxTime()

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

Enable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 121 of file approximationScheme_inl.h.

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

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

◆ enableMinEpsilonRate()

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

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 77 of file approximationScheme_inl.h.

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

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

◆ 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::InferenceEngine< 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 in gum::credal::MultipleInferenceEngine< GUM_SCALAR, BNInferenceEngine >, and gum::credal::CNLoopyPropagation< GUM_SCALAR >.

Definition at line 62 of file inferenceEngine_tpl.h.

62  {
63  evidence_.clear();
64  query_.clear();
65  /*
66  marginalMin_.clear();
67  marginalMax_.clear();
68  oldMarginalMin_.clear();
69  oldMarginalMax_.clear();
70  */
72  /*
73  expectationMin_.clear();
74  expectationMax_.clear();
75  */
77 
78  // marginalSets_.clear();
80 
81  dynamicExpMin_.clear();
82  dynamicExpMax_.clear();
83 
84  //_modal.clear();
85 
86  //_t0.clear();
87  //_t1.clear();
88  }
void initExpectations_()
Initialize lower and upper expectations before inference, with the lower expectation being initialize...
dynExpe dynamicExpMin_
Lower dynamic expectations.
void initMarginalSets_()
Initialize credal set vertices with empty sets.
margi evidence_
Holds observed variables states.
void initMarginals_()
Initialize lower and upper old marginals and marginals before inference, with the lower marginal bein...
query query_
Holds the query nodes states.
dynExpe dynamicExpMax_
Upper dynamic expectations.
void clear()
Removes all the elements in the hash table.

◆ expectationMax() [1/2]

template<typename GUM_SCALAR >
const GUM_SCALAR & gum::credal::InferenceEngine< GUM_SCALAR >::expectationMax ( const NodeId  id) const

Get the upper expectation of a given node id.

Parameters
idThe node id which upper expectation we want.
Returns
A constant reference to this node upper expectation.

Definition at line 473 of file inferenceEngine_tpl.h.

473  {
474  try {
475  return expectationMax_[id];
476  } catch (NotFound& err) { throw(err); }
477  }
expe expectationMax_
Upper expectations, if some variables modalities were inserted.

◆ expectationMax() [2/2]

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

Get the upper expectation of a given variable name.

Parameters
varNameThe variable name which upper expectation we want.
Returns
A constant reference to this variable upper expectation.

Definition at line 459 of file inferenceEngine_tpl.h.

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

◆ expectationMin() [1/2]

template<typename GUM_SCALAR >
const GUM_SCALAR & gum::credal::InferenceEngine< GUM_SCALAR >::expectationMin ( const NodeId  id) const

Get the lower expectation of a given node id.

Parameters
idThe node id which lower expectation we want.
Returns
A constant reference to this node lower expectation.

Definition at line 466 of file inferenceEngine_tpl.h.

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

◆ expectationMin() [2/2]

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

Get the lower expectation of a given variable name.

Parameters
varNameThe variable name which lower expectation we want.
Returns
A constant reference to this variable lower expectation.

Definition at line 451 of file inferenceEngine_tpl.h.

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

◆ getApproximationSchemeMsg()

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

Get approximation scheme state.

Returns
A constant string about approximation scheme state.

Definition at line 500 of file inferenceEngine.h.

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

◆ getT0Cluster()

template<typename GUM_SCALAR >
const NodeProperty< std::vector< NodeId > > & gum::credal::InferenceEngine< GUM_SCALAR >::getT0Cluster ( ) const

Get the t0_ cluster.

Returns
A constant reference to the t0_ cluster.

Definition at line 976 of file inferenceEngine_tpl.h.

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

◆ getT1Cluster()

template<typename GUM_SCALAR >
const NodeProperty< std::vector< NodeId > > & gum::credal::InferenceEngine< GUM_SCALAR >::getT1Cluster ( ) const

Get the t1_ cluster.

Returns
A constant reference to the t1_ cluster.

Definition at line 982 of file inferenceEngine_tpl.h.

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

◆ getVarMod2BNsMap()

template<typename GUM_SCALAR >
VarMod2BNsMap< GUM_SCALAR > * gum::credal::InferenceEngine< GUM_SCALAR >::getVarMod2BNsMap ( )

Get optimum IBayesNet.

Returns
A pointer to the optimal net object.

Definition at line 138 of file inferenceEngine_tpl.h.

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

◆ history()

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

Returns the scheme history.

Returns
Returns the scheme history.
Exceptions
OperationNotAllowedRaised if the scheme did not performed or if verbosity is set to false.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 157 of file approximationScheme_inl.h.

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

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

◆ initApproximationScheme()

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

Initialise the scheme.

Definition at line 168 of file approximationScheme_inl.h.

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

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

◆ initExpectations_()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::initExpectations_ ( )
protected

Initialize lower and upper expectations before inference, with the lower expectation being initialized on the highest modality and the upper expectation being initialized on the lowest modality.

Definition at line 678 of file inferenceEngine_tpl.h.

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

◆ initMarginals_()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::initMarginals_ ( )
protected

Initialize lower and upper old marginals and marginals before inference, with the lower marginal being 1 and the upper 0.

Definition at line 646 of file inferenceEngine_tpl.h.

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

◆ initMarginalSets_()

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

Initialize credal set vertices with empty sets.

Definition at line 663 of file inferenceEngine_tpl.h.

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

◆ insertEvidence() [1/2]

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::insertEvidence ( const std::map< std::string, std::vector< GUM_SCALAR > > &  eviMap)

Insert evidence from map.

Parameters
eviMapThe map variable name - likelihood.

Definition at line 226 of file inferenceEngine_tpl.h.

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

◆ insertEvidence() [2/2]

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

Insert evidence from Property.

Parameters
evidenceThe on nodes Property containing likelihoods.

Definition at line 248 of file inferenceEngine_tpl.h.

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

◆ insertEvidenceFile()

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

Insert evidence from file.

Parameters
pathThe path to the evidence file.

Reimplemented in gum::credal::CNLoopyPropagation< GUM_SCALAR >, and gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >.

Definition at line 266 of file inferenceEngine_tpl.h.

266  {
267  std::ifstream evi_stream(path.c_str(), std::ios::in);
268 
269  if (!evi_stream.good()) {
270  GUM_ERROR(IOError,
271  "void InferenceEngine< GUM_SCALAR "
272  ">::insertEvidence(const std::string & path) : could not "
273  "open input file : "
274  << path);
275  }
276 
277  if (!evidence_.empty()) evidence_.clear();
278 
279  std::string line, tmp;
280  char * cstr, *p;
281 
282  while (evi_stream.good() && std::strcmp(line.c_str(), "[EVIDENCE]") != 0) {
283  getline(evi_stream, line);
284  }
285 
286  while (evi_stream.good()) {
287  getline(evi_stream, line);
288 
289  if (std::strcmp(line.c_str(), "[QUERY]") == 0) break;
290 
291  if (line.size() == 0) continue;
292 
293  cstr = new char[line.size() + 1];
294  strcpy(cstr, line.c_str());
295 
296  p = strtok(cstr, " ");
297  tmp = p;
298 
299  // if user input is wrong
300  NodeId node = -1;
301 
302  try {
303  node = credalNet_->current_bn().idFromName(tmp);
304  } catch (NotFound& err) {
305  GUM_SHOWERROR(err);
306  continue;
307  }
308 
309  std::vector< GUM_SCALAR > values;
310  p = strtok(nullptr, " ");
311 
312  while (p != nullptr) {
313  values.push_back(GUM_SCALAR(atof(p)));
314  p = strtok(nullptr, " ");
315  } // end of : line
316 
317  evidence_.insert(node, values);
318 
319  delete[] p;
320  delete[] cstr;
321  } // end of : file
322 
323  evi_stream.close();
324  }
#define GUM_SHOWERROR(e)
Definition: exceptions.h:57
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
margi evidence_
Holds observed variables states.
void clear()
Removes all the elements in the hash table.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
bool empty() const noexcept
Indicates whether the hash table is empty.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ insertModals()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::insertModals ( const std::map< std::string, std::vector< GUM_SCALAR > > &  modals)

Insert variables modalities from map to compute expectations.

Parameters
modalsThe map variable name - modalities.

Definition at line 190 of file inferenceEngine_tpl.h.

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

◆ insertModalsFile()

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

Insert variables modalities from file to compute expectations.

Parameters
pathThe path to the modalities file.

Definition at line 143 of file inferenceEngine_tpl.h.

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

◆ insertQuery()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::insertQuery ( const NodeProperty< std::vector< bool > > &  query)

Insert query variables and states from Property.

Parameters
queryThe on nodes Property containing queried variables states.

Definition at line 327 of file inferenceEngine_tpl.h.

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

◆ insertQueryFile()

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

Insert query variables states from file.

Parameters
pathThe path to the query file.

Definition at line 344 of file inferenceEngine_tpl.h.

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

◆ isEnabledEpsilon()

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

Returns true if stopping criterion on epsilon is enabled, false otherwise.

Returns
Returns true if stopping criterion on epsilon is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 60 of file approximationScheme_inl.h.

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

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

◆ isEnabledMaxIter()

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

Returns true if stopping criterion on max iterations is enabled, false otherwise.

Returns
Returns true if stopping criterion on max iterations is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 101 of file approximationScheme_inl.h.

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

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

◆ isEnabledMaxTime()

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

Returns true if stopping criterion on timeout is enabled, false otherwise.

Returns
Returns true if stopping criterion on timeout is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 125 of file approximationScheme_inl.h.

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

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

◆ isEnabledMinEpsilonRate()

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

Returns true if stopping criterion on epsilon rate is enabled, false otherwise.

Returns
Returns true if stopping criterion on epsilon rate is enabled, false otherwise.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 81 of file approximationScheme_inl.h.

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

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

◆ makeInference()

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

◆ marginalMax() [1/2]

template<typename GUM_SCALAR >
gum::Potential< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax ( const NodeId  id) const

Get the upper marginals of a given node id.

Parameters
idThe node id which upper marginals we want.
Returns
A constant reference to this node upper marginals.

Definition at line 440 of file inferenceEngine_tpl.h.

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

◆ marginalMax() [2/2]

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::marginalMax ( const std::string &  varName) const

Get the upper marginals of a given variable name.

Parameters
varNameThe variable name which upper marginals we want.
Returns
A constant reference to this variable upper marginals.

Definition at line 425 of file inferenceEngine_tpl.h.

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

◆ marginalMin() [1/2]

template<typename GUM_SCALAR >
gum::Potential< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin ( const NodeId  id) const

Get the lower marginals of a given node id.

Parameters
idThe node id which lower marginals we want.
Returns
A constant reference to this node lower marginals.

Definition at line 430 of file inferenceEngine_tpl.h.

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

◆ marginalMin() [2/2]

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::marginalMin ( const std::string &  varName) const

Get the lower marginals of a given variable name.

Parameters
varNameThe variable name which lower marginals we want.
Returns
A constant reference to this variable lower marginals.

Definition at line 419 of file inferenceEngine_tpl.h.

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

◆ maxIter()

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

Returns the criterion on number of iterations.

Returns
Returns the criterion on number of iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 91 of file approximationScheme_inl.h.

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

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

◆ maxTime()

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

Returns the timeout (in seconds).

Returns
Returns the timeout (in seconds).

Implements gum::IApproximationSchemeConfiguration.

Definition at line 112 of file approximationScheme_inl.h.

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

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

◆ messageApproximationScheme()

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

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 38 of file IApproximationSchemeConfiguration_inl.h.

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

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

◆ minEpsilonRate()

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

Returns the value of the minimal epsilon rate.

Returns
Returns the value of the minimal epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 71 of file approximationScheme_inl.h.

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

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

◆ nbrIterations()

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

Returns the number of iterations.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 148 of file approximationScheme_inl.h.

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

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

◆ periodSize()

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

Returns the period size.

Returns
Returns the period size.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 134 of file approximationScheme_inl.h.

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

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

◆ remainingBurnIn()

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

Returns the remaining burn in.

Returns
Returns the remaining burn in.

Definition at line 191 of file approximationScheme_inl.h.

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

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

◆ repetitiveInd()

template<typename GUM_SCALAR >
bool gum::credal::InferenceEngine< GUM_SCALAR >::repetitiveInd ( ) const

Get the current independence status.

Returns
True if repetitive, False otherwise.

Definition at line 118 of file inferenceEngine_tpl.h.

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

◆ repetitiveInit_()

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

Initialize t0_ and t1_ clusters.

Definition at line 767 of file inferenceEngine_tpl.h.

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

◆ saveExpectations()

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

Saves expectations to file.

Parameters
pathThe path to the file to be used.

Definition at line 542 of file inferenceEngine_tpl.h.

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

◆ saveMarginals()

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

Saves marginals to file.

Parameters
pathThe path to the file to be used.

Definition at line 518 of file inferenceEngine_tpl.h.

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

◆ saveVertices()

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

Saves vertices to file.

Parameters
pathThe path to the file to be used.

Definition at line 612 of file inferenceEngine_tpl.h.

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

◆ setEpsilon()

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

Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.

If the criterion was disabled it will be enabled.

Parameters
epsThe new epsilon value.
Exceptions
OutOfLowerBoundRaised if eps < 0.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 42 of file approximationScheme_inl.h.

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

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

◆ setMaxIter()

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

Stopping criterion on number of iterations.

If the criterion was disabled it will be enabled.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 84 of file approximationScheme_inl.h.

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

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

◆ setMaxTime()

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

Stopping criterion on timeout.

If the criterion was disabled it will be enabled.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 105 of file approximationScheme_inl.h.

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

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

◆ setMinEpsilonRate()

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

Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).

If the criterion was disabled it will be enabled

Parameters
rateThe minimal epsilon rate.
Exceptions
OutOfLowerBoundif rate<0

Implements gum::IApproximationSchemeConfiguration.

Definition at line 63 of file approximationScheme_inl.h.

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

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

◆ setPeriodSize()

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

How many samples between two stopping is enable.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 128 of file approximationScheme_inl.h.

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

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

◆ setRepetitiveInd()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::setRepetitiveInd ( const bool  repetitive)
Parameters
repetitiveTrue if repetitive independence is to be used, false otherwise. Only usefull with dynamic networks.

Definition at line 109 of file inferenceEngine_tpl.h.

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

◆ setVerbosity()

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

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

Parameters
vIf true, then verbosity is turned on.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 137 of file approximationScheme_inl.h.

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

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

◆ startOfPeriod()

INLINE bool gum::ApproximationScheme::startOfPeriod ( )
inherited

Returns true if we are at the beginning of a period (compute error is mandatory).

Returns
Returns true if we are at the beginning of a period (compute error is mandatory).

Definition at line 178 of file approximationScheme_inl.h.

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

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

◆ stateApproximationScheme()

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

Returns the approximation scheme state.

Returns
Returns the approximation scheme state.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 143 of file approximationScheme_inl.h.

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

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

◆ stopApproximationScheme()

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

Stop the approximation scheme.

Definition at line 200 of file approximationScheme_inl.h.

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

+ Here is the call graph for this function:

◆ storeBNOpt() [1/2]

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::storeBNOpt ( const bool  value)
Parameters
valueTrue if optimal Bayesian networks are to be stored for each variable and each modality.

Definition at line 97 of file inferenceEngine_tpl.h.

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

◆ storeBNOpt() [2/2]

template<typename GUM_SCALAR >
bool gum::credal::InferenceEngine< GUM_SCALAR >::storeBNOpt ( ) const
Returns
True if optimal bayes net are stored for each variable and each modality, False otherwise.

Definition at line 133 of file inferenceEngine_tpl.h.

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

◆ storeVertices() [1/2]

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::storeVertices ( const bool  value)
Parameters
valueTrue if vertices are to be stored, false otherwise.

Definition at line 102 of file inferenceEngine_tpl.h.

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

◆ storeVertices() [2/2]

template<typename GUM_SCALAR >
bool gum::credal::InferenceEngine< GUM_SCALAR >::storeVertices ( ) const

Get the number of iterations without changes used to stop some algorithms.

Returns
the number of iterations.int iterStop () const;
True if vertice are stored, False otherwise.

Definition at line 128 of file inferenceEngine_tpl.h.

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

◆ toString()

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

Print all nodes marginals to standart output.

Definition at line 586 of file inferenceEngine_tpl.h.

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

◆ updateApproximationScheme()

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

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

Parameters
incrThe new increment steps.

Definition at line 187 of file approximationScheme_inl.h.

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

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

◆ updateCredalSets_()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::updateCredalSets_ ( const NodeId id,
const std::vector< GUM_SCALAR > &  vertex,
const bool elimRedund = false 
)
inlineprotected

Given a node id and one of it's possible vertex, update it's credal set.

To maximise efficiency, don't pass a vertex we know is inside the polytope (i.e. not at an extreme value for any modality)

Parameters
idThe id of the node to be updated
vertexA (potential) vertex of the node credal set
elimRedundremove redundant vertex (inside a facet)

Definition at line 902 of file inferenceEngine_tpl.h.

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

◆ updateExpectations_()

template<typename GUM_SCALAR >
void gum::credal::InferenceEngine< GUM_SCALAR >::updateExpectations_ ( const NodeId id,
const std::vector< GUM_SCALAR > &  vertex 
)
inlineprotected

Given a node id and one of it's possible vertex obtained during inference, update this node lower and upper expectations.

Parameters
idThe id of the node to be updated
vertexA (potential) vertex of the node credal set

Definition at line 881 of file inferenceEngine_tpl.h.

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

◆ verbosity()

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

Returns true if verbosity is enabled.

Returns
Returns true if verbosity is enabled.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 139 of file approximationScheme_inl.h.

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

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

◆ vertices()

template<typename GUM_SCALAR >
const std::vector< std::vector< GUM_SCALAR > > & gum::credal::InferenceEngine< GUM_SCALAR >::vertices ( const NodeId  id) const

Get the vertice of a given node id.

Parameters
idThe node id which vertice we want.
Returns
A constant reference to this node vertice.

Definition at line 513 of file inferenceEngine_tpl.h.

513  {
514  return marginalSets_[id];
515  }
credalSet marginalSets_
Credal sets vertices, if enabled.

Member Data Documentation

◆ burn_in_

Size gum::ApproximationScheme::burn_in_
protectedinherited

Number of iterations before checking stopping criteria.

Definition at line 413 of file approximationScheme.h.

◆ credalNet_

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

A pointer to the Credal Net used.

Definition at line 68 of file inferenceEngine.h.

◆ current_epsilon_

double gum::ApproximationScheme::current_epsilon_
protectedinherited

Current epsilon.

Definition at line 368 of file approximationScheme.h.

◆ current_rate_

double gum::ApproximationScheme::current_rate_
protectedinherited

Current rate.

Definition at line 374 of file approximationScheme.h.

◆ current_state_

ApproximationSchemeSTATE gum::ApproximationScheme::current_state_
protectedinherited

The current state.

Definition at line 383 of file approximationScheme.h.

◆ current_step_

Size gum::ApproximationScheme::current_step_
protectedinherited

The current step.

Definition at line 377 of file approximationScheme.h.

◆ dbnOpt_

template<typename GUM_SCALAR >
VarMod2BNsMap< GUM_SCALAR > gum::credal::InferenceEngine< GUM_SCALAR >::dbnOpt_
protected

Object used to efficiently store optimal bayes net during inference, for some algorithms.

Definition at line 141 of file inferenceEngine.h.

◆ dynamicExpMax_

template<typename GUM_SCALAR >
dynExpe gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpMax_
protected

Upper dynamic expectations.

If the network if not dynamic it's content is the same as expectationMax_.

Definition at line 95 of file inferenceEngine.h.

◆ dynamicExpMin_

template<typename GUM_SCALAR >
dynExpe gum::credal::InferenceEngine< GUM_SCALAR >::dynamicExpMin_
protected

Lower dynamic expectations.

If the network is not dynamic it's content is the same as expectationMin_.

Definition at line 92 of file inferenceEngine.h.

◆ enabled_eps_

bool gum::ApproximationScheme::enabled_eps_
protectedinherited

If true, the threshold convergence is enabled.

Definition at line 392 of file approximationScheme.h.

◆ enabled_max_iter_

bool gum::ApproximationScheme::enabled_max_iter_
protectedinherited

If true, the maximum iterations stopping criterion is enabled.

Definition at line 410 of file approximationScheme.h.

◆ enabled_max_time_

bool gum::ApproximationScheme::enabled_max_time_
protectedinherited

If true, the timeout is enabled.

Definition at line 404 of file approximationScheme.h.

◆ enabled_min_rate_eps_

bool gum::ApproximationScheme::enabled_min_rate_eps_
protectedinherited

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

Definition at line 398 of file approximationScheme.h.

◆ eps_

double gum::ApproximationScheme::eps_
protectedinherited

Threshold for convergence.

Definition at line 389 of file approximationScheme.h.

◆ evidence_

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

Holds observed variables states.

Definition at line 101 of file inferenceEngine.h.

◆ expectationMax_

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

Upper expectations, if some variables modalities were inserted.

Definition at line 88 of file inferenceEngine.h.

◆ expectationMin_

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

Lower expectations, if some variables modalities were inserted.

Definition at line 85 of file inferenceEngine.h.

◆ history_

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

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

Definition at line 386 of file approximationScheme.h.

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

Upper marginals.

Definition at line 78 of file inferenceEngine.h.

◆ marginalMin_

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

Lower marginals.

Definition at line 76 of file inferenceEngine.h.

◆ marginalSets_

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

Credal sets vertices, if enabled.

Definition at line 81 of file inferenceEngine.h.

◆ max_iter_

Size gum::ApproximationScheme::max_iter_
protectedinherited

The maximum iterations.

Definition at line 407 of file approximationScheme.h.

◆ max_time_

double gum::ApproximationScheme::max_time_
protectedinherited

The timeout.

Definition at line 401 of file approximationScheme.h.

◆ min_rate_eps_

double gum::ApproximationScheme::min_rate_eps_
protectedinherited

Threshold for the epsilon rate.

Definition at line 395 of file approximationScheme.h.

◆ modal_

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

Variables modalities used to compute expectations.

Definition at line 98 of file inferenceEngine.h.

◆ oldMarginalMax_

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

Old upper marginals used to compute epsilon.

Definition at line 73 of file inferenceEngine.h.

◆ oldMarginalMin_

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

Old lower marginals used to compute epsilon.

Definition at line 71 of file inferenceEngine.h.

◆ onProgress

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

Progression, error and time.

Definition at line 58 of file IApproximationSchemeConfiguration.h.

◆ onStop

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

Criteria messageApproximationScheme.

Definition at line 61 of file IApproximationSchemeConfiguration.h.

◆ period_size_

Size gum::ApproximationScheme::period_size_
protectedinherited

Checking criteria frequency.

Definition at line 416 of file approximationScheme.h.

◆ query_

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

Holds the query nodes states.

Definition at line 103 of file inferenceEngine.h.

◆ repetitiveInd_

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

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

False by default.

Definition at line 127 of file inferenceEngine.h.

◆ storeBNOpt_

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

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

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

Definition at line 137 of file inferenceEngine.h.

◆ storeVertices_

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

True if credal sets vertices are stored, False otherwise.

False by default.

Definition at line 123 of file inferenceEngine.h.

◆ t0_

template<typename GUM_SCALAR >
cluster gum::credal::InferenceEngine< GUM_SCALAR >::t0_
protected

Clusters of nodes used with dynamic networks.

Any node key in t0_ is present at \( t=0 \) and any node belonging to the node set of this key share the same CPT than the key. Used for sampling with repetitive independence.

Definition at line 111 of file inferenceEngine.h.

◆ t1_

template<typename GUM_SCALAR >
cluster gum::credal::InferenceEngine< GUM_SCALAR >::t1_
protected

Clusters of nodes used with dynamic networks.

Any node key in t1_ is present at \( t=1 \) and any node belonging to the node set of this key share the same CPT than the key. Used for sampling with repetitive independence.

Definition at line 118 of file inferenceEngine.h.

◆ timer_

Timer gum::ApproximationScheme::timer_
protectedinherited

The timer.

Definition at line 380 of file approximationScheme.h.

◆ timeSteps_

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

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

Deprecated:

Definition at line 148 of file inferenceEngine.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: