![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
GibbsKL computes the KL divergence betweens 2 BNs using an approximation pattern: GIBBS sampling. More...
#include <GibbsBNdistance.h>
Public Attributes | |
Signaler3< Size, double, double > | onProgress |
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_ |
Size | errorPQ_ |
Size | errorQP_ |
GUM_SCALAR | hellinger_ |
GUM_SCALAR | bhattacharya_ |
GUM_SCALAR | jsd_ |
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< double > | history_ |
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_ |
const IBayesNet< GUM_SCALAR > & | samplingBn_ |
const NodeProperty< Idx > * | hardEv_ |
Sequence< NodeId > | samplingNodes_ |
Size | nbr_ |
bool | atRandom_ |
Protected Member Functions | |
void | computeKL_ () final |
void | process_ () |
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.
snippets :
Definition at line 78 of file GibbsBNdistance.h.
|
stronginherited |
The different state of an approximation scheme.
Enumerator | |
---|---|
Undefined | |
Continue | |
Epsilon | |
Rate | |
Limit | |
TimeLimit | |
Stopped |
Definition at line 64 of file IApproximationSchemeConfiguration.h.
gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance | ( | const IBayesNet< GUM_SCALAR > & | P, |
const IBayesNet< GUM_SCALAR > & | Q | ||
) |
constructor must give 2 BNs
gum::OperationNotAllowed | if the 2 BNs have not the same domainSize or compatible node sets. |
Definition at line 51 of file GibbsKL_tpl.h.
|
explicit |
copy constructor
Definition at line 71 of file GibbsKL_tpl.h.
References gum::Set< Key, Alloc >::emplace().
gum::GibbsBNdistance< GUM_SCALAR >::~GibbsBNdistance | ( | ) |
destructor
Definition at line 91 of file GibbsKL_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Size gum::GibbsBNdistance< GUM_SCALAR >::burnIn | ( | ) | const |
Returns the number of burn in.
Definition at line 184 of file GibbsKL_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
finalprotectedvirtual |
Reimplemented from gum::BNdistance< GUM_SCALAR >.
Definition at line 96 of file GibbsKL_tpl.h.
References gum::Set< Key, Alloc >::emplace().
Update the scheme w.r.t the new error.
Test the stopping criterion that are enabled.
error | The new error value. |
OperationNotAllowed | Raised if state != ApproximationSchemeSTATE::Continue. |
Definition at line 208 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
virtualinherited |
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().
|
inherited |
return KL::Complexity::Heavy,KL::Complexity::Difficult,KL::Complexity::Correct depending on the BNs p and q
Definition at line 68 of file BNdistance_tpl.h.
|
virtualinherited |
Disable stopping criterion on epsilon.
Implements gum::IApproximationSchemeConfiguration.
Definition at line 53 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
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().
|
virtualinherited |
Disable stopping criterion on timeout.
Implements gum::IApproximationSchemeConfiguration.
Definition at line 118 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
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().
|
virtualinherited |
Enable stopping criterion on epsilon.
Implements gum::IApproximationSchemeConfiguration.
Definition at line 56 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
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().
|
virtualinherited |
Enable stopping criterion on timeout.
Implements gum::IApproximationSchemeConfiguration.
Definition at line 121 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
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().
|
virtualinherited |
Returns the value of epsilon.
Implements gum::IApproximationSchemeConfiguration.
Definition at line 50 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Definition at line 103 of file BNdistance_tpl.h.
|
inherited |
Definition at line 109 of file BNdistance_tpl.h.
|
inherited |
|
virtualinherited |
Returns the scheme history.
OperationNotAllowed | Raised 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().
|
inherited |
Initialise the scheme.
Definition at line 168 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inlineinherited |
Definition at line 69 of file gibbsOperator.h.
References gum::GibbsOperator< GUM_SCALAR >::atRandom_.
|
virtualinherited |
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().
|
virtualinherited |
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().
|
virtualinherited |
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().
|
virtualinherited |
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().
|
inherited |
|
inherited |
|
inherited |
|
virtualinherited |
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().
|
virtualinherited |
Returns the timeout (in seconds).
Implements gum::IApproximationSchemeConfiguration.
Definition at line 112 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Returns the approximation scheme message.
Definition at line 38 of file IApproximationSchemeConfiguration_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
virtualinherited |
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().
|
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 67 of file gibbsOperator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inlineinherited |
|
virtualinherited |
Returns the number of iterations.
OperationNotAllowed | Raised if the scheme did not perform. |
Implements gum::IApproximationSchemeConfiguration.
Definition at line 148 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
draws next sample of Gibbs sampling
Definition at line 90 of file gibbsOperator_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
|
virtualinherited |
Returns the period size.
Implements gum::IApproximationSchemeConfiguration.
Definition at line 134 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
Definition at line 175 of file BNdistance_tpl.h.
|
inherited |
|
inherited |
Returns the remaining burn in.
Definition at line 191 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
void gum::GibbsBNdistance< GUM_SCALAR >::setBurnIn | ( | Size | b | ) |
Number of burn in for one iteration.
b | The number of burn in. |
OutOfLowerBound | Raised if b < 1. |
Definition at line 179 of file GibbsKL_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inlineinherited |
Definition at line 71 of file gibbsOperator.h.
References gum::GibbsOperator< GUM_SCALAR >::atRandom_.
|
virtualinherited |
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
If the criterion was disabled it will be enabled.
eps | The new epsilon value. |
OutOfLowerBound | Raised if eps < 0. |
Implements gum::IApproximationSchemeConfiguration.
Definition at line 42 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
virtualinherited |
Stopping criterion on number of iterations.
If the criterion was disabled it will be enabled.
max | The maximum number of iterations. |
OutOfLowerBound | Raised if max <= 1. |
Implements gum::IApproximationSchemeConfiguration.
Definition at line 84 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
virtualinherited |
Stopping criterion on timeout.
If the criterion was disabled it will be enabled.
timeout | The timeout value in seconds. |
OutOfLowerBound | Raised if timeout <= 0.0. |
Implements gum::IApproximationSchemeConfiguration.
Definition at line 105 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
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
rate | The minimal epsilon rate. |
OutOfLowerBound | if rate<0 |
Implements gum::IApproximationSchemeConfiguration.
Definition at line 63 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inlineinherited |
Definition at line 67 of file gibbsOperator.h.
|
virtualinherited |
How many samples between two stopping is enable.
p | The new period value. |
OutOfLowerBound | Raised if p < 1. |
Implements gum::IApproximationSchemeConfiguration.
Definition at line 128 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
virtualinherited |
Set the verbosity on (true) or off (false).
v | If true, then verbosity is turned on. |
Implements gum::IApproximationSchemeConfiguration.
Definition at line 137 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
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().
|
virtualinherited |
Returns the approximation scheme state.
Implements gum::IApproximationSchemeConfiguration.
Definition at line 143 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Stop the approximation scheme.
Definition at line 200 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Update the scheme w.r.t the new error and increment steps.
incr | The new increment steps. |
Definition at line 187 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
virtualinherited |
Returns true if verbosity is enabled.
Implements gum::IApproximationSchemeConfiguration.
Definition at line 139 of file approximationScheme_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
protectedinherited |
Definition at line 86 of file gibbsOperator.h.
Referenced by gum::GibbsOperator< GUM_SCALAR >::isDrawnAtRandom(), and gum::GibbsOperator< GUM_SCALAR >::setDrawnAtRandom().
|
protectedinherited |
Definition at line 151 of file BNdistance.h.
|
protectedinherited |
Number of iterations before checking stopping criteria.
Definition at line 413 of file approximationScheme.h.
|
protectedinherited |
Definition at line 80 of file gibbsOperator.h.
|
protectedinherited |
Current epsilon.
Definition at line 368 of file approximationScheme.h.
|
protectedinherited |
Current rate.
Definition at line 374 of file approximationScheme.h.
|
protectedinherited |
The current state.
Definition at line 383 of file approximationScheme.h.
|
protectedinherited |
The current step.
Definition at line 377 of file approximationScheme.h.
|
protectedinherited |
If true, the threshold convergence is enabled.
Definition at line 392 of file approximationScheme.h.
|
protectedinherited |
If true, the maximum iterations stopping criterion is enabled.
Definition at line 410 of file approximationScheme.h.
|
protectedinherited |
If true, the timeout is enabled.
Definition at line 404 of file approximationScheme.h.
|
protectedinherited |
If true, the minimal threshold for epsilon rate is enabled.
Definition at line 398 of file approximationScheme.h.
|
protectedinherited |
Threshold for convergence.
Definition at line 389 of file approximationScheme.h.
|
protectedinherited |
Definition at line 147 of file BNdistance.h.
|
protectedinherited |
Definition at line 148 of file BNdistance.h.
|
protectedinherited |
Definition at line 82 of file gibbsOperator.h.
|
protectedinherited |
Definition at line 150 of file BNdistance.h.
|
protectedinherited |
The scheme history, used only if verbosity == true.
Definition at line 386 of file approximationScheme.h.
|
protectedinherited |
Definition at line 152 of file BNdistance.h.
|
protectedinherited |
Definition at line 144 of file BNdistance.h.
|
protectedinherited |
Definition at line 145 of file BNdistance.h.
|
protectedinherited |
Last epsilon value.
Definition at line 371 of file approximationScheme.h.
|
protectedinherited |
The maximum iterations.
Definition at line 407 of file approximationScheme.h.
|
protectedinherited |
The timeout.
Definition at line 401 of file approximationScheme.h.
|
protectedinherited |
Threshold for the epsilon rate.
Definition at line 395 of file approximationScheme.h.
|
protectedinherited |
Definition at line 85 of file gibbsOperator.h.
Progression, error and time.
Definition at line 58 of file IApproximationSchemeConfiguration.h.
|
inherited |
Criteria messageApproximationScheme.
Definition at line 61 of file IApproximationSchemeConfiguration.h.
|
protectedinherited |
Definition at line 141 of file BNdistance.h.
|
protectedinherited |
Checking criteria frequency.
Definition at line 416 of file approximationScheme.h.
|
protectedinherited |
Definition at line 142 of file BNdistance.h.
|
protectedinherited |
Definition at line 81 of file gibbsOperator.h.
|
protectedinherited |
Definition at line 83 of file gibbsOperator.h.
|
protectedinherited |
The timer.
Definition at line 380 of file approximationScheme.h.
|
protectedinherited |
If true, verbosity is enabled.
Definition at line 419 of file approximationScheme.h.