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

GibbsKL computes the KL divergence betweens 2 BNs using an approximation pattern: GIBBS sampling. More...

#include <GibbsBNdistance.h>

+ Inheritance diagram for gum::GibbsBNdistance< GUM_SCALAR >:
+ Collaboration diagram for gum::GibbsBNdistance< GUM_SCALAR >:

Public Attributes

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

Public Member Functions

 GibbsBNdistance (const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
 constructor must give 2 BNs More...
 
 GibbsBNdistance (const BNdistance< GUM_SCALAR > &kl)
 copy constructor More...
 
 ~GibbsBNdistance ()
 destructor More...
 
void setBurnIn (Size b)
 Number of burn in for one iteration. More...
 
Size burnIn () const
 Returns the number of burn in. More...
 
Complexity difficulty () const
 return KL::Complexity::Heavy,KL::Complexity::Difficult,KL::Complexity::Correct depending on the BNs p__ and q__ More...
 
Size nbrDrawnVar () const
 Getters and setters. More...
 
void setNbrDrawnVar (Size nbr)
 
bool isDrawnAtRandom () const
 
void setDrawnAtRandom (bool atRandom)
 
Instantiation monteCarloSample ()
 draws a Monte Carlo sample More...
 
Instantiation nextSample (Instantiation prev)
 draws next sample of Gibbs sampling More...
 
Accessors to results. The first call do the computations. The

others do not.

double klPQ ()
 
Size errorPQ ()
 
double klQP ()
 
Size errorQP ()
 
double hellinger ()
 
double bhattacharya ()
 
double jsd ()
 
const IBayesNet< GUM_SCALAR > & p () const
 
const IBayesNet< GUM_SCALAR > & q () const
 
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 IBayesNet< GUM_SCALAR > & p_
 
const IBayesNet< GUM_SCALAR > & q_
 
GUM_SCALAR klPQ_
 
GUM_SCALAR klQP_
 
GUM_SCALAR hellinger_
 
GUM_SCALAR bhattacharya_
 
GUM_SCALAR jsd_
 
Size errorPQ_
 
Size errorQP_
 
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...
 
Size counting_
 number of samples drawn More...
 
const IBayesNet< GUM_SCALAR > & sampling_bn_
 
const NodeProperty< Idx > * hardEv_
 
Sequence< NodeIdsamplingNodes_
 
Size nbr_
 
bool atRandom_
 

Protected Member Functions

void computeKL_ () final
 
void process_ ()
 

Detailed Description

template<typename GUM_SCALAR>
class gum::GibbsBNdistance< GUM_SCALAR >

GibbsKL computes the KL divergence betweens 2 BNs using an approximation pattern: GIBBS sampling.

KL.process() computes KL(P||Q) using klPQ() and KL(Q||P) using klQP(). The computations are made once. The second is for free :) GibbsKL allows as well to compute in the same time the Hellinger distance ( \( *\sqrt{\sum_i (\sqrt{p_i}-\sqrt{q_i})^2}\)) (Kokolakis and Nanopoulos, 2001) and Bhattacharya distance (Kaylath,T. 1967)

It may happen that P*ln(P/Q) is not computable (Q=0 and P!=0). In such a case, KL keeps working but trace this error (errorPQ() and errorQP()). In those cases, Hellinger distance approximation is under-evaluated.

Warning
: convergence and stop criteria are designed w.r.t the main computation : KL(P||Q). The 3 others have no guarantee.

snippets :

gum::KL base_kl(net1,net2);
if (base_kl.difficulty()!=KL::HEAVY) {
gum::ExactBNdistance kl(base_kl);
std::cout<<"KL net1||net2 :"<<kl.klPQ()<<std::endl;
} else {
gum::GibbsBNdistance kl(base_kl);
std::cout<<"KL net1||net2 :"<<kl.klPQ()<<std::endl;
}

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

◆ GibbsBNdistance() [1/2]

template<typename GUM_SCALAR >
gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance ( const IBayesNet< GUM_SCALAR > &  P,
const IBayesNet< GUM_SCALAR > &  Q 
)

constructor must give 2 BNs

Exceptions
gum::OperationNotAllowedif the 2 BNs have not the same domainSize or compatible node sets.

Definition at line 51 of file GibbsKL_tpl.h.

53  :
54  BNdistance< GUM_SCALAR >(P, Q),
56  GibbsOperator< GUM_SCALAR >(
57  P,
58  nullptr,
59  1 + (P.size() * GIBBSKL_POURCENT_DRAWN_SAMPLE / 100),
61  GUM_CONSTRUCTOR(GibbsBNdistance);
62 
70  }
#define GIBBSKL_DEFAULT_TIMEOUT
Definition: GibbsKL_tpl.h:42
#define GIBBSKL_DRAWN_AT_RANDOM
Definition: GibbsKL_tpl.h:45
#define GIBBSKL_DEFAULT_BURNIN
Definition: GibbsKL_tpl.h:41
void setPeriodSize(Size p)
How many samples between two stopping is enable.
#define GIBBSKL_POURCENT_DRAWN_SAMPLE
Definition: GibbsKL_tpl.h:44
void setMinEpsilonRate(double rate)
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
void setVerbosity(bool v)
Set the verbosity on (true) or off (false).
ApproximationScheme(bool verbosity=false)
void setMaxTime(double timeout)
Stopping criterion on timeout.
#define GIBBSKL_DEFAULT_EPSILON
Definition: GibbsKL_tpl.h:37
#define GIBBSKL_DEFAULT_PERIOD_SIZE
Definition: GibbsKL_tpl.h:39
void setBurnIn(Size b)
Number of burn in for one iteration.
Definition: GibbsKL_tpl.h:184
void setMaxIter(Size max)
Stopping criterion on number of iterations.
#define GIBBSKL_DEFAULT_MIN_EPSILON_RATE
Definition: GibbsKL_tpl.h:38
void setEpsilon(double eps)
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
#define GIBBSKL_DEFAULT_VERBOSITY
Definition: GibbsKL_tpl.h:40
GibbsBNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
Definition: GibbsKL_tpl.h:51
#define GIBBSKL_DEFAULT_MAXITER
Definition: GibbsKL_tpl.h:36

◆ GibbsBNdistance() [2/2]

template<typename GUM_SCALAR >
gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance ( const BNdistance< GUM_SCALAR > &  kl)
explicit

copy constructor

Definition at line 73 of file GibbsKL_tpl.h.

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

74  :
75  BNdistance< GUM_SCALAR >(kl),
77  // Gibbs operator with 10% of nodes changes at random between each samples
78  ,
79  GibbsOperator< GUM_SCALAR >(
80  kl.p(),
81  nullptr,
82  1 + (kl.p().size() * GIBBSKL_POURCENT_DRAWN_SAMPLE / 100),
83  true) {
84  GUM_CONSTRUCTOR(GibbsBNdistance);
85 
93  }
#define GIBBSKL_DEFAULT_TIMEOUT
Definition: GibbsKL_tpl.h:42
#define GIBBSKL_DEFAULT_BURNIN
Definition: GibbsKL_tpl.h:41
void setPeriodSize(Size p)
How many samples between two stopping is enable.
#define GIBBSKL_POURCENT_DRAWN_SAMPLE
Definition: GibbsKL_tpl.h:44
void setMinEpsilonRate(double rate)
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
void setVerbosity(bool v)
Set the verbosity on (true) or off (false).
ApproximationScheme(bool verbosity=false)
void setMaxTime(double timeout)
Stopping criterion on timeout.
#define GIBBSKL_DEFAULT_EPSILON
Definition: GibbsKL_tpl.h:37
#define GIBBSKL_DEFAULT_PERIOD_SIZE
Definition: GibbsKL_tpl.h:39
void setBurnIn(Size b)
Number of burn in for one iteration.
Definition: GibbsKL_tpl.h:184
void setMaxIter(Size max)
Stopping criterion on number of iterations.
#define GIBBSKL_DEFAULT_MIN_EPSILON_RATE
Definition: GibbsKL_tpl.h:38
void setEpsilon(double eps)
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
#define GIBBSKL_DEFAULT_VERBOSITY
Definition: GibbsKL_tpl.h:40
GibbsBNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
Definition: GibbsKL_tpl.h:51
#define GIBBSKL_DEFAULT_MAXITER
Definition: GibbsKL_tpl.h:36
+ Here is the call graph for this function:

◆ ~GibbsBNdistance()

template<typename GUM_SCALAR >
gum::GibbsBNdistance< GUM_SCALAR >::~GibbsBNdistance ( )

destructor

Definition at line 96 of file GibbsKL_tpl.h.

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

96  {
97  GUM_DESTRUCTOR(GibbsBNdistance);
98  }
GibbsBNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
Definition: GibbsKL_tpl.h:51
+ Here is the call graph for this function:

Member Function Documentation

◆ bhattacharya()

template<typename GUM_SCALAR >
INLINE double gum::BNdistance< GUM_SCALAR >::bhattacharya ( )
inherited
Returns
Bhattacharya distance (
See also
http://en.wikipedia.org/wiki/Bhattacharya_distance)

Definition at line 92 of file BNdistance_tpl.h.

92  {
93  process_();
94  return bhattacharya_;
95  }
GUM_SCALAR bhattacharya_
Definition: BNdistance.h:146

◆ burnIn()

template<typename GUM_SCALAR >
Size gum::GibbsBNdistance< GUM_SCALAR >::burnIn ( ) const

Returns the number of burn in.

Returns
Returns the number of burn in.

Definition at line 189 of file GibbsKL_tpl.h.

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

189  {
190  return this->burn_in_;
191  }
Size burn_in_
Number of iterations before checking stopping criteria.
+ Here is the call graph for this function:

◆ computeKL_()

template<typename GUM_SCALAR >
void gum::GibbsBNdistance< GUM_SCALAR >::computeKL_ ( )
finalprotectedvirtual

Reimplemented from gum::BNdistance< GUM_SCALAR >.

Definition at line 101 of file GibbsKL_tpl.h.

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

101  {
102  auto Iq = q_.completeInstantiation();
103 
106 
107  // map between particle() variables and q_ variables (using name of vars)
108  HashTable< const DiscreteVariable*, const DiscreteVariable* > map;
109 
110  for (Idx ite = 0; ite < I.nbrDim(); ++ite) {
111  map.insert(&I.variable(ite), &q_.variableFromName(I.variable(ite).name()));
112  }
113 
114  // BURN IN
115  for (Idx i = 0; i < burnIn(); i++)
116  I = this->nextSample(I);
117 
118  // SAMPLING
119  klPQ_ = klQP_ = hellinger_ = jsd_ = (GUM_SCALAR)0.0;
120  errorPQ_ = errorQP_ = 0;
122  GUM_SCALAR delta, ratio, error;
123  delta = ratio = error = (GUM_SCALAR)-1;
124  GUM_SCALAR oldPQ = 0.0;
125  GUM_SCALAR pp, pq, pmid;
126 
127  do {
128  this->disableMinEpsilonRate();
129  I = this->nextSample(I);
131 
132  //_p.synchroInstantiations( Ip,I);
133  Iq.setValsFrom(map, I);
134 
135  pp = p_.jointProbability(I);
136  pq = q_.jointProbability(Iq);
137  pmid = (pp + pq) / 2.0;
138 
139  if (pp != (GUM_SCALAR)0.0) {
140  hellinger_ += std::pow(std::sqrt(pp) - std::sqrt(pq), 2) / pp;
141 
142  if (pq != (GUM_SCALAR)0.0) {
143  bhattacharya_ += std::sqrt(pq / pp); // std::sqrt(pp*pq)/pp
145  this->enableMinEpsilonRate(); // replace check_rate=true;
146  ratio = pq / pp;
147  delta = (GUM_SCALAR)std::log2(ratio);
148  klPQ_ += delta;
149 
150  // pmid!=0
151  jsd_ -= std::log2(pp / pmid) + ratio * std::log2(pq / pmid);
152  } else {
153  errorPQ_++;
154  }
155  }
156 
157  if (pq != (GUM_SCALAR)0.0) {
158  if (pp != (GUM_SCALAR)0.0) {
159  // if we are here, it is certain that delta and ratio have been
160  // computed
161  // further lines above. (for now #112-113)
162  klQP_ += (GUM_SCALAR)(-delta * ratio);
163  } else {
164  errorQP_++;
165  }
166  }
167 
168  if (this->isEnabledMinEpsilonRate()) { // replace check_rate
169  // delta is used as a temporary variable
170  delta = klPQ_ / nbrIterations();
171  error = (GUM_SCALAR)std::abs(delta - oldPQ);
172  oldPQ = delta;
173  }
174  } while (continueApproximationScheme(error)); //
175 
176  klPQ_ = -klPQ_ / (nbrIterations());
177  klQP_ = -klQP_ / (nbrIterations());
178  jsd_ = -0.5 * jsd_ / (nbrIterations());
179  hellinger_ = std::sqrt(hellinger_ / nbrIterations());
180  bhattacharya_ = -std::log(bhattacharya_ / (nbrIterations()));
181  }
void disableMinEpsilonRate()
Disable stopping criterion on epsilon rate.
Potential< GUM_SCALAR > abs(const Potential< GUM_SCALAR > &arg)
Definition: potential.h:617
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
GUM_SCALAR klQP_
Definition: BNdistance.h:144
void enableMinEpsilonRate()
Enable stopping criterion on epsilon rate.
GUM_SCALAR klPQ_
Definition: BNdistance.h:143
void initApproximationScheme()
Initialise the scheme.
GUM_SCALAR hellinger_
Definition: BNdistance.h:145
GUM_SCALAR bhattacharya_
Definition: BNdistance.h:146
Size nbrIterations() const
Returns the number of iterations.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
bool isEnabledMinEpsilonRate() const
Returns true if stopping criterion on epsilon rate is enabled, false otherwise.
Instantiation nextSample(Instantiation prev)
draws next sample of Gibbs sampling
const IBayesNet< GUM_SCALAR > & p_
Definition: BNdistance.h:140
Size burnIn() const
Returns the number of burn in.
Definition: GibbsKL_tpl.h:189
GUM_SCALAR jsd_
Definition: BNdistance.h:147
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:82
Instantiation monteCarloSample()
draws a Monte Carlo sample
const IBayesNet< GUM_SCALAR > & q_
Definition: BNdistance.h:141
const std::string & name() const
returns the name of the variable
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
Potential< GUM_SCALAR > log2(const Potential< GUM_SCALAR > &arg)
Definition: potential.h:612
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
+ Here is the call graph for this function:

◆ continueApproximationScheme()

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

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

Test the stopping criterion that are enabled.

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

Definition at line 226 of file approximationScheme_inl.h.

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

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

◆ currentTime()

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

Returns the current running time in second.

Returns
Returns the current running time in second.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 127 of file approximationScheme_inl.h.

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

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

◆ difficulty()

template<typename GUM_SCALAR >
Complexity gum::BNdistance< GUM_SCALAR >::difficulty ( ) const
inherited

return KL::Complexity::Heavy,KL::Complexity::Difficult,KL::Complexity::Correct depending on the BNs p__ and q__

Definition at line 69 of file BNdistance_tpl.h.

69  {
70  return difficulty__;
71  }
Complexity difficulty__
Definition: BNdistance.h:154

◆ disableEpsilon()

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

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 53 of file approximationScheme_inl.h.

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

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

◆ disableMaxIter()

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

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 104 of file approximationScheme_inl.h.

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

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

◆ disableMaxTime()

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

Disable stopping criterion on timeout.

Returns
Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 130 of file approximationScheme_inl.h.

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

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

◆ disableMinEpsilonRate()

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

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 78 of file approximationScheme_inl.h.

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

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

◆ enableEpsilon()

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

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 56 of file approximationScheme_inl.h.

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

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

◆ enableMaxIter()

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

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 107 of file approximationScheme_inl.h.

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

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

◆ enableMaxTime()

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

Enable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 133 of file approximationScheme_inl.h.

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

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

◆ enableMinEpsilonRate()

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

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 83 of file approximationScheme_inl.h.

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

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

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

◆ errorPQ()

template<typename GUM_SCALAR >
INLINE Size gum::BNdistance< GUM_SCALAR >::errorPQ ( )
inherited
Returns
the number of errors while processing divergence KL(P||Q)

Definition at line 104 of file BNdistance_tpl.h.

104  {
105  process_();
106  return errorPQ_;
107  }

◆ errorQP()

template<typename GUM_SCALAR >
INLINE Size gum::BNdistance< GUM_SCALAR >::errorQP ( )
inherited
Returns
the number of errors while processing divergence KL(Q||P)

Definition at line 110 of file BNdistance_tpl.h.

110  {
111  process_();
112  return errorQP_;
113  }

◆ hellinger()

template<typename GUM_SCALAR >
INLINE double gum::BNdistance< GUM_SCALAR >::hellinger ( )
inherited
Returns
hellinger distance (
See also
http://en.wikipedia.org/wiki/Hellinger_distance)

Definition at line 86 of file BNdistance_tpl.h.

86  {
87  process_();
88  return hellinger_;
89  }
GUM_SCALAR hellinger_
Definition: BNdistance.h:145

◆ history()

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

Returns the scheme history.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 172 of file approximationScheme_inl.h.

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

172  {
174  GUM_ERROR(OperationNotAllowed,
175  "state of the approximation scheme is udefined");
176  }
177 
178  if (verbosity() == false) {
179  GUM_ERROR(OperationNotAllowed, "No history when verbosity=false");
180  }
181 
182  return history_;
183  }
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
std::vector< double > history_
The scheme history, used only if verbosity == true.
bool verbosity() const
Returns true if verbosity is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ initApproximationScheme()

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

Initialise the scheme.

Definition at line 186 of file approximationScheme_inl.h.

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

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

◆ isDrawnAtRandom()

template<typename GUM_SCALAR >
bool gum::GibbsOperator< GUM_SCALAR >::isDrawnAtRandom ( ) const
inlineinherited

Definition at line 69 of file gibbsOperator.h.

References gum::GibbsOperator< GUM_SCALAR >::atRandom_.

69 { return atRandom_; }

◆ isEnabledEpsilon()

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

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

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 60 of file approximationScheme_inl.h.

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

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

◆ isEnabledMaxIter()

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

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

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 111 of file approximationScheme_inl.h.

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

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

◆ isEnabledMaxTime()

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

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

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 137 of file approximationScheme_inl.h.

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

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

◆ isEnabledMinEpsilonRate()

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

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

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 89 of file approximationScheme_inl.h.

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

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

◆ jsd()

template<typename GUM_SCALAR >
INLINE double gum::BNdistance< GUM_SCALAR >::jsd ( )
inherited
Returns
Jensen-Shannon divergence(
See also
https://en.wikipedia.org/wiki/Jensen%E2%80%93Shannon_divergence)

Definition at line 98 of file BNdistance_tpl.h.

98  {
99  process_();
100  return jsd_;
101  }
GUM_SCALAR jsd_
Definition: BNdistance.h:147

◆ klPQ()

template<typename GUM_SCALAR >
INLINE double gum::BNdistance< GUM_SCALAR >::klPQ ( )
inherited
Returns
divergence KL(P||Q)

Definition at line 74 of file BNdistance_tpl.h.

74  {
75  process_();
76  return klPQ_;
77  }
GUM_SCALAR klPQ_
Definition: BNdistance.h:143

◆ klQP()

template<typename GUM_SCALAR >
INLINE double gum::BNdistance< GUM_SCALAR >::klQP ( )
inherited
Returns
divergence KL(Q||P)

Definition at line 80 of file BNdistance_tpl.h.

80  {
81  process_();
82  return klQP_;
83  }
GUM_SCALAR klQP_
Definition: BNdistance.h:144

◆ maxIter()

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

Returns the criterion on number of iterations.

Returns
Returns the criterion on number of iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 101 of file approximationScheme_inl.h.

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

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

◆ maxTime()

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

Returns the timeout (in seconds).

Returns
Returns the timeout (in seconds).

Implements gum::IApproximationSchemeConfiguration.

Definition at line 124 of file approximationScheme_inl.h.

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

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

◆ messageApproximationScheme()

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

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 39 of file IApproximationSchemeConfiguration_inl.h.

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

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

◆ minEpsilonRate()

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

Returns the value of the minimal epsilon rate.

Returns
Returns the value of the minimal epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 73 of file approximationScheme_inl.h.

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

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

◆ monteCarloSample()

template<typename GUM_SCALAR >
Instantiation gum::GibbsOperator< GUM_SCALAR >::monteCarloSample ( )
inherited

draws a Monte Carlo sample

returns a MC sample This is not a really sample since we take into account evidence without care about parent of evidence, etc. This is just a not-so-bad first sample for GibbsSampler

Definition at line 69 of file gibbsOperator_tpl.h.

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

69  {
71 
72  for (const auto nod: sampling_bn_.topologicalOrder()) {
73  I.add(sampling_bn_.variable(nod));
74  if (hardEv_ != nullptr && hardEv_->exists(nod)) {
75  I.chgVal(sampling_bn_.variable(nod), (*hardEv_)[nod]);
76  } else {
77  drawVarMonteCarlo__(nod, &I);
78  }
79  }
80  return I;
81  }
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
const IBayesNet< GUM_SCALAR > & sampling_bn_
Definition: gibbsOperator.h:82
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:82
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
void drawVarMonteCarlo__(NodeId nod, Instantiation *I)
const NodeProperty< Idx > * hardEv_
Definition: gibbsOperator.h:83
+ Here is the call graph for this function:

◆ nbrDrawnVar()

template<typename GUM_SCALAR >
Size gum::GibbsOperator< GUM_SCALAR >::nbrDrawnVar ( ) const
inlineinherited

Getters and setters.

Definition at line 65 of file gibbsOperator.h.

65 { return nbr_; }

◆ nbrIterations()

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

Returns the number of iterations.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 162 of file approximationScheme_inl.h.

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

162  {
164  GUM_ERROR(OperationNotAllowed,
165  "state of the approximation scheme is undefined");
166  }
167 
168  return current_step_;
169  }
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
Size current_step_
The current step.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ nextSample()

template<typename GUM_SCALAR >
Instantiation gum::GibbsOperator< GUM_SCALAR >::nextSample ( Instantiation  prev)
inherited

draws next sample of Gibbs sampling

Definition at line 94 of file gibbsOperator_tpl.h.

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

94  {
95  for (Idx i = 0; i < nbr_; i++) {
98  this->GibbsSample__(samplingNodes_[pos], &prev);
99  counting_++;
100  }
101  return prev;
102  }
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:37
void GibbsSample__(NodeId id, Instantiation *I)
change in Instantiation I a new drawn value for id
Size counting_
number of samples drawn
Definition: gibbsOperator.h:81
Sequence< NodeId > samplingNodes_
Definition: gibbsOperator.h:84
+ Here is the call graph for this function:

◆ p()

template<typename GUM_SCALAR >
INLINE const IBayesNet< GUM_SCALAR > & gum::BNdistance< GUM_SCALAR >::p ( ) const
inherited
Returns
p

Definition at line 116 of file BNdistance_tpl.h.

116  {
117  return p_;
118  }
const IBayesNet< GUM_SCALAR > & p_
Definition: BNdistance.h:140

◆ periodSize()

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

Returns the period size.

Returns
Returns the period size.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 148 of file approximationScheme_inl.h.

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

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

◆ process_()

template<typename GUM_SCALAR >
void gum::BNdistance< GUM_SCALAR >::process_ ( )
protectedinherited

Definition at line 177 of file BNdistance_tpl.h.

177  {
178  if (!done__) {
179  computeKL_();
180  done__ = true;
181  }
182  }
virtual void computeKL_()

◆ q()

template<typename GUM_SCALAR >
INLINE const IBayesNet< GUM_SCALAR > & gum::BNdistance< GUM_SCALAR >::q ( ) const
inherited
Returns
q

Definition at line 121 of file BNdistance_tpl.h.

121  {
122  return q_;
123  }
const IBayesNet< GUM_SCALAR > & q_
Definition: BNdistance.h:141

◆ remainingBurnIn()

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

Returns the remaining burn in.

Returns
Returns the remaining burn in.

Definition at line 209 of file approximationScheme_inl.h.

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

209  {
210  if (burn_in_ > current_step_) {
211  return burn_in_ - current_step_;
212  } else {
213  return 0;
214  }
215  }
Size burn_in_
Number of iterations before checking stopping criteria.
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ setBurnIn()

template<typename GUM_SCALAR >
void gum::GibbsBNdistance< GUM_SCALAR >::setBurnIn ( Size  b)

Number of burn in for one iteration.

Parameters
bThe number of burn in.
Exceptions
OutOfLowerBoundRaised if b < 1.

Definition at line 184 of file GibbsKL_tpl.h.

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

184  {
185  this->burn_in_ = b;
186  }
Size burn_in_
Number of iterations before checking stopping criteria.
+ Here is the call graph for this function:

◆ setDrawnAtRandom()

template<typename GUM_SCALAR >
void gum::GibbsOperator< GUM_SCALAR >::setDrawnAtRandom ( bool  atRandom)
inlineinherited

Definition at line 71 of file gibbsOperator.h.

References gum::GibbsOperator< GUM_SCALAR >::atRandom_.

71 { atRandom_ = atRandom; }

◆ setEpsilon()

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

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

If the criterion was disabled it will be enabled.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 42 of file approximationScheme_inl.h.

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

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

◆ setMaxIter()

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

Stopping criterion on number of iterations.

If the criterion was disabled it will be enabled.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 94 of file approximationScheme_inl.h.

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

94  {
95  if (max < 1) { GUM_ERROR(OutOfLowerBound, "max should be >=1"); }
96  max_iter_ = max;
97  enabled_max_iter_ = true;
98  }
bool enabled_max_iter_
If true, the maximum iterations stopping criterion is enabled.
Size max_iter_
The maximum iterations.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setMaxTime()

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

Stopping criterion on timeout.

If the criterion was disabled it will be enabled.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 117 of file approximationScheme_inl.h.

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

117  {
118  if (timeout <= 0.) { GUM_ERROR(OutOfLowerBound, "timeout should be >0."); }
119  max_time_ = timeout;
120  enabled_max_time_ = true;
121  }
double max_time_
The timeout.
bool enabled_max_time_
If true, the timeout is enabled.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setMinEpsilonRate()

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

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

If the criterion was disabled it will be enabled

Parameters
rateThe minimal epsilon rate.
Exceptions
OutOfLowerBoundif rate<0

Implements gum::IApproximationSchemeConfiguration.

Definition at line 65 of file approximationScheme_inl.h.

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

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

◆ setNbrDrawnVar()

template<typename GUM_SCALAR >
void gum::GibbsOperator< GUM_SCALAR >::setNbrDrawnVar ( Size  nbr)
inlineinherited

Definition at line 67 of file gibbsOperator.h.

67 { nbr_ = nbr; }

◆ setPeriodSize()

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

How many samples between two stopping is enable.

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 142 of file approximationScheme_inl.h.

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

142  {
143  if (p < 1) { GUM_ERROR(OutOfLowerBound, "p should be >=1"); }
144 
145  period_size_ = p;
146  }
Size period_size_
Checking criteria frequency.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ setVerbosity()

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

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

Parameters
vIf true, then verbosity is turned on.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 151 of file approximationScheme_inl.h.

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

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

◆ startOfPeriod()

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

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

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

Definition at line 196 of file approximationScheme_inl.h.

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

196  {
197  if (current_step_ < burn_in_) { return false; }
198 
199  if (period_size_ == 1) { return true; }
200 
201  return ((current_step_ - burn_in_) % period_size_ == 0);
202  }
Size burn_in_
Number of iterations before checking stopping criteria.
Size period_size_
Checking criteria frequency.
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ stateApproximationScheme()

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

Returns the approximation scheme state.

Returns
Returns the approximation scheme state.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 157 of file approximationScheme_inl.h.

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

157  {
158  return current_state_;
159  }
ApproximationSchemeSTATE current_state_
The current state.
+ Here is the call graph for this function:

◆ stopApproximationScheme()

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

Stop the approximation scheme.

Definition at line 218 of file approximationScheme_inl.h.

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

+ Here is the call graph for this function:

◆ updateApproximationScheme()

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

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

Parameters
incrThe new increment steps.

Definition at line 205 of file approximationScheme_inl.h.

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

205  {
206  current_step_ += incr;
207  }
Size current_step_
The current step.
+ Here is the call graph for this function:

◆ verbosity()

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

Returns true if verbosity is enabled.

Returns
Returns true if verbosity is enabled.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 153 of file approximationScheme_inl.h.

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

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

Member Data Documentation

◆ atRandom_

template<typename GUM_SCALAR >
bool gum::GibbsOperator< GUM_SCALAR >::atRandom_
protectedinherited

◆ bhattacharya_

template<typename GUM_SCALAR >
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::bhattacharya_
protectedinherited

Definition at line 146 of file BNdistance.h.

◆ burn_in_

Size gum::ApproximationScheme::burn_in_
protectedinherited

Number of iterations before checking stopping criteria.

Definition at line 413 of file approximationScheme.h.

◆ counting_

template<typename GUM_SCALAR >
Size gum::GibbsOperator< GUM_SCALAR >::counting_
protectedinherited

number of samples drawn

Definition at line 81 of file gibbsOperator.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.

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

◆ errorPQ_

template<typename GUM_SCALAR >
Size gum::BNdistance< GUM_SCALAR >::errorPQ_
protectedinherited

Definition at line 149 of file BNdistance.h.

◆ errorQP_

template<typename GUM_SCALAR >
Size gum::BNdistance< GUM_SCALAR >::errorQP_
protectedinherited

Definition at line 150 of file BNdistance.h.

◆ hardEv_

template<typename GUM_SCALAR >
const NodeProperty< Idx >* gum::GibbsOperator< GUM_SCALAR >::hardEv_
protectedinherited

Definition at line 83 of file gibbsOperator.h.

◆ hellinger_

template<typename GUM_SCALAR >
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::hellinger_
protectedinherited

Definition at line 145 of file BNdistance.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.

◆ jsd_

template<typename GUM_SCALAR >
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::jsd_
protectedinherited

Definition at line 147 of file BNdistance.h.

◆ klPQ_

template<typename GUM_SCALAR >
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::klPQ_
protectedinherited

Definition at line 143 of file BNdistance.h.

◆ klQP_

template<typename GUM_SCALAR >
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::klQP_
protectedinherited

Definition at line 144 of file BNdistance.h.

◆ last_epsilon_

double gum::ApproximationScheme::last_epsilon_
protectedinherited

Last epsilon value.

Definition at line 371 of file approximationScheme.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.

◆ nbr_

template<typename GUM_SCALAR >
Size gum::GibbsOperator< GUM_SCALAR >::nbr_
protectedinherited

Definition at line 86 of file gibbsOperator.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.

◆ p_

template<typename GUM_SCALAR >
const IBayesNet< GUM_SCALAR >& gum::BNdistance< GUM_SCALAR >::p_
protectedinherited

Definition at line 140 of file BNdistance.h.

◆ period_size_

Size gum::ApproximationScheme::period_size_
protectedinherited

Checking criteria frequency.

Definition at line 416 of file approximationScheme.h.

◆ q_

template<typename GUM_SCALAR >
const IBayesNet< GUM_SCALAR >& gum::BNdistance< GUM_SCALAR >::q_
protectedinherited

Definition at line 141 of file BNdistance.h.

◆ sampling_bn_

template<typename GUM_SCALAR >
const IBayesNet< GUM_SCALAR >& gum::GibbsOperator< GUM_SCALAR >::sampling_bn_
protectedinherited

Definition at line 82 of file gibbsOperator.h.

◆ samplingNodes_

template<typename GUM_SCALAR >
Sequence< NodeId > gum::GibbsOperator< GUM_SCALAR >::samplingNodes_
protectedinherited

Definition at line 84 of file gibbsOperator.h.

◆ timer_

Timer gum::ApproximationScheme::timer_
protectedinherited

The timer.

Definition at line 380 of file approximationScheme.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: