34 #define GIBBSKL_DEFAULT_MAXITER 10000000 35 #define GIBBSKL_DEFAULT_EPSILON 1e-10 36 #define GIBBSKL_DEFAULT_MIN_EPSILON_RATE 1e-10 37 #define GIBBSKL_DEFAULT_PERIOD_SIZE 200 38 #define GIBBSKL_DEFAULT_VERBOSITY false 39 #define GIBBSKL_DEFAULT_BURNIN 2000 40 #define GIBBSKL_DEFAULT_TIMEOUT 6000 42 #define GIBBSKL_POURCENT_DRAWN_SAMPLE 10 // percent drawn 43 #define GIBBSKL_DRAWN_AT_RANDOM false 48 template <
typename GUM_SCALAR >
69 template <
typename GUM_SCALAR >
92 template <
typename GUM_SCALAR >
97 template <
typename GUM_SCALAR >
99 auto Iq =
_q.completeInstantiation();
107 for (
Idx ite = 0; ite < I.
nbrDim(); ++ite) {
119 GUM_SCALAR delta, ratio, error;
120 delta = ratio = error = (GUM_SCALAR)-1;
121 GUM_SCALAR oldPQ = 0.0;
122 GUM_SCALAR pp, pq, pmid;
130 Iq.setValsFrom(map, I);
132 pp =
_p.jointProbability(I);
133 pq =
_q.jointProbability(Iq);
134 pmid = (pp + pq) / 2.0;
136 if (pp != (GUM_SCALAR)0.0) {
137 _hellinger += std::pow(std::sqrt(pp) - std::sqrt(pq), 2) / pp;
139 if (pq != (GUM_SCALAR)0.0) {
144 delta = (GUM_SCALAR)log2(ratio);
148 _jsd -= log2(pp / pmid) + ratio * log2(pq / pmid);
154 if (pq != (GUM_SCALAR)0.0) {
155 if (pp != (GUM_SCALAR)0.0) {
159 _klQP += (GUM_SCALAR)(-delta * ratio);
168 error = (GUM_SCALAR)std::abs(delta - oldPQ);
180 template <
typename GUM_SCALAR >
185 template <
typename GUM_SCALAR >
This file contains Gibbs sampling (for BNs) class definitions.
This file contains general scheme for iteratively convergent algorithms.
#define GIBBSKL_DEFAULT_TIMEOUT
void disableMinEpsilonRate()
Disable stopping criterion on epsilon rate.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
#define GIBBSKL_DRAWN_AT_RANDOM
const IBayesNet< GUM_SCALAR > & _p
void enableMinEpsilonRate()
Enable stopping criterion on epsilon rate.
#define GIBBSKL_DEFAULT_BURNIN
void setPeriodSize(Size p)
How many samples between two stopping is enable.
#define GIBBSKL_POURCENT_DRAWN_SAMPLE
Class representing Bayesian networks.
const IBayesNet< GUM_SCALAR > & p() const
void initApproximationScheme()
Initialise the scheme.
Class representing the minimal interface for Bayesian Network.
gum is the global namespace for all aGrUM entities
void setMinEpsilonRate(double rate)
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
algorithm for approximated computation KL divergence between BNs using GIBBS sampling ...
void setVerbosity(bool v)
Set the verbosity on (true) or off (false).
The class for generic Hash Tables.
void setMaxTime(double timeout)
Stopping criterion on timeout.
Size _burn_in
Number of iterations before checking stopping criteria.
Size nbrIterations() const
Returns the number of iterations.
~GibbsBNdistance()
destructor
const IBayesNet< GUM_SCALAR > & _q
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
#define GIBBSKL_DEFAULT_EPSILON
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
GibbsKL computes the KL divergence betweens 2 BNs using an approximation pattern: GIBBS sampling...
#define GIBBSKL_DEFAULT_PERIOD_SIZE
Size burnIn() const
Returns the number of burn in.
Class for assigning/browsing values to tuples of discrete variables.
void setBurnIn(Size b)
Number of burn in for one iteration.
void setMaxIter(Size max)
Stopping criterion on number of iterations.
Instantiation monteCarloSample()
draws a Monte Carlo sample
#define GIBBSKL_DEFAULT_MIN_EPSILON_RATE
void setEpsilon(double eps)
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
Size Idx
Type for indexes.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
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.
Class hash tables iterators.
#define GIBBSKL_DEFAULT_VERBOSITY
class containing all variables and methods required for Gibbssampling
GibbsBNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
#define GIBBSKL_DEFAULT_MAXITER
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.