58#define GIBBSKL_DEFAULT_MAXITER 10000000
59#define GIBBSKL_DEFAULT_EPSILON 1e-10
60#define GIBBSKL_DEFAULT_MIN_EPSILON_RATE 1e-10
61#define GIBBSKL_DEFAULT_PERIOD_SIZE 200
62#define GIBBSKL_DEFAULT_VERBOSITY false
63#define GIBBSKL_DEFAULT_BURNIN 2000
64#define GIBBSKL_DEFAULT_TIMEOUT 6000
66#define GIBBSKL_POURCENT_DRAWN_SAMPLE 10
67#define GIBBSKL_DRAWN_AT_RANDOM false
72 template <
typename GUM_SCALAR >
91 template <
typename GUM_SCALAR >
111 template <
typename GUM_SCALAR >
116 template <
typename GUM_SCALAR >
118 auto Iq =
q_.completeInstantiation();
125 for (
Idx ite = 0; ite < I.
nbrDim(); ++ite) {
138 GUM_SCALAR delta, ratio, error;
139 delta = ratio = error = (GUM_SCALAR)-1;
140 GUM_SCALAR oldPQ = 0.0;
141 GUM_SCALAR pp, pq, pmid;
149 Iq.setValsFrom(map, I);
151 pp =
p_.jointProbability(I);
152 pq =
q_.jointProbability(Iq);
153 pmid = (pp + pq) / 2.0;
155 if (pp != (GUM_SCALAR)0.0) {
156 hellinger_ += std::pow(std::sqrt(pp) - std::sqrt(pq), 2) / pp;
158 if (pq != (GUM_SCALAR)0.0) {
163 delta = (GUM_SCALAR)std::log2(ratio);
167 jsd_ -= std::log2(pp / pmid) + ratio * std::log2(pq / pmid);
173 if (pq != (GUM_SCALAR)0.0) {
174 if (pp != (GUM_SCALAR)0.0) {
178 klQP_ += (GUM_SCALAR)(-delta * ratio);
187 error = (GUM_SCALAR)std::abs(delta - oldPQ);
199 template <
typename GUM_SCALAR >
204 template <
typename GUM_SCALAR >
algorithm for approximated computation KL divergence between BNs using GIBBS sampling
#define GIBBSKL_DEFAULT_MAXITER
#define GIBBSKL_DEFAULT_MIN_EPSILON_RATE
#define GIBBSKL_DEFAULT_PERIOD_SIZE
#define GIBBSKL_DEFAULT_TIMEOUT
#define GIBBSKL_DEFAULT_BURNIN
#define GIBBSKL_DRAWN_AT_RANDOM
#define GIBBSKL_DEFAULT_VERBOSITY
#define GIBBSKL_POURCENT_DRAWN_SAMPLE
#define GIBBSKL_DEFAULT_EPSILON
Class representing the minimal interface for Bayesian network with no numerical data.
This file contains general scheme for iteratively convergent algorithms.
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
void setMaxIter(Size max) override
Stopping criterion on number of iterations.
void setMaxTime(double timeout) override
Stopping criterion on timeout.
void setMinEpsilonRate(double rate) override
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
void setPeriodSize(Size p) override
How many samples between two stopping is enable.
bool isEnabledMinEpsilonRate() const override
Returns true if stopping criterion on epsilon rate is enabled, false otherwise.
void disableMinEpsilonRate() override
Disable stopping criterion on epsilon rate.
ApproximationScheme(bool verbosity=false)
void initApproximationScheme()
Initialise the scheme.
Size nbrIterations() const override
Returns the number of iterations.
void enableMinEpsilonRate() override
Enable stopping criterion on epsilon rate.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
Size burn_in_
Number of iterations before checking stopping criteria.
void setVerbosity(bool v) override
Set the verbosity on (true) or off (false).
void setEpsilon(double eps) override
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
BNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
const IBayesNet< GUM_SCALAR > & q_
const IBayesNet< GUM_SCALAR > & p() const
const IBayesNet< GUM_SCALAR > & p_
Size burnIn() const
Returns the number of burn in.
void setBurnIn(Size b)
Number of burn in for one iteration.
GibbsBNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
~GibbsBNdistance()
destructor
Instantiation nextSample(Instantiation prev)
draws next sample of Gibbs sampling
Instantiation monteCarloSample()
draws a Monte Carlo sample
GibbsOperator(const IBayesNet< GUM_SCALAR > &BN, const NodeProperty< Idx > *hardEv, Size nbr=1, bool atRandom=false)
constructor
void updateSamplingNodes_()
The class for generic Hash Tables.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Class representing the minimal interface for Bayesian network with no numerical data.
Class for assigning/browsing values to tuples of discrete variables.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
const std::string & name() const
returns the name of the variable
This file contains Gibbs sampling (for BNs) class definitions.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Class hash tables iterators.
gum is the global namespace for all aGrUM entities