37 #define GIBBSKL_DEFAULT_MAXITER 10000000 38 #define GIBBSKL_DEFAULT_EPSILON 1e-10 39 #define GIBBSKL_DEFAULT_MIN_EPSILON_RATE 1e-10 40 #define GIBBSKL_DEFAULT_PERIOD_SIZE 200 41 #define GIBBSKL_DEFAULT_VERBOSITY false 42 #define GIBBSKL_DEFAULT_BURNIN 2000 43 #define GIBBSKL_DEFAULT_TIMEOUT 6000 45 #define GIBBSKL_POURCENT_DRAWN_SAMPLE 10 // percent drawn 46 #define GIBBSKL_DRAWN_AT_RANDOM false 51 template <
typename GUM_SCALAR >
72 template <
typename GUM_SCALAR >
95 template <
typename GUM_SCALAR >
100 template <
typename GUM_SCALAR >
102 auto Iq =
_q.completeInstantiation();
110 for (
Idx ite = 0; ite < I.
nbrDim(); ++ite) {
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;
133 Iq.setValsFrom(map, I);
135 pp =
_p.jointProbability(I);
136 pq =
_q.jointProbability(Iq);
137 pmid = (pp + pq) / 2.0;
139 if (pp != (GUM_SCALAR)0.0) {
140 _hellinger += std::pow(std::sqrt(pp) - std::sqrt(pq), 2) / pp;
142 if (pq != (GUM_SCALAR)0.0) {
147 delta = (GUM_SCALAR)log2(ratio);
151 _jsd -= log2(pp / pmid) + ratio * log2(pq / pmid);
157 if (pq != (GUM_SCALAR)0.0) {
158 if (pp != (GUM_SCALAR)0.0) {
162 _klQP += (GUM_SCALAR)(-delta * ratio);
171 error = (GUM_SCALAR)std::abs(delta - oldPQ);
183 template <
typename GUM_SCALAR >
188 template <
typename GUM_SCALAR >
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
#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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const IBayesNet< GUM_SCALAR > & p() const
void initApproximationScheme()
Initialise the scheme.
Class representing the minimal interface for Bayesian Network.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void setMinEpsilonRate(double rate)
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
#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.