62 template < GUM_Numeric GUM_SCALAR >
72 template < GUM_Numeric GUM_SCALAR >
81 template < GUM_Numeric GUM_SCALAR >
86 template < GUM_Numeric GUM_SCALAR >
88 auto Iq =
q_.completeInstantiation();
95 for (
Idx ite = 0; ite < I.
nbrDim(); ++ite) {
108 GUM_SCALAR delta, ratio, error;
109 delta = ratio = error = (GUM_SCALAR)-1;
110 GUM_SCALAR oldPQ = 0.0;
111 GUM_SCALAR pp, pq, pmid;
119 Iq.setValsFrom(map, I);
121 pp =
p_.jointProbability(I);
122 pq =
q_.jointProbability(Iq);
123 pmid = (pp + pq) / 2.0;
125 if (pp != (GUM_SCALAR)0.0) {
126 hellinger_ += std::pow(std::sqrt(pp) - std::sqrt(pq), 2) / pp;
128 if (pq != (GUM_SCALAR)0.0) {
133 delta = (GUM_SCALAR)std::log2(ratio);
137 jsd_ -= std::log2(pp / pmid) + ratio * std::log2(pq / pmid);
143 if (pq != (GUM_SCALAR)0.0) {
144 if (pp != (GUM_SCALAR)0.0) {
148 klQP_ += (GUM_SCALAR)(-delta * ratio);
157 error = (GUM_SCALAR)std::abs(delta - oldPQ);
169 template < GUM_Numeric GUM_SCALAR >
174 template < GUM_Numeric GUM_SCALAR >
algorithm for approximated computation KL divergence between BNs using GIBBS sampling
Class representing the minimal interface for Bayesian network with no numerical data.
This file contains general scheme for iteratively convergent algorithms.
ApproximationScheme()
Build a scheme whose parameters are read from the configuration.
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
void setFromConfiguration_(const std::string §ion, bool withMaxTime, bool withVerbosity=true)
Set the parameters of the scheme from a section of gum::Configuration.
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.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
void initApproximationScheme()
Initialise the scheme.
Size nbrIterations() const override
Returns the number of iterations.
void enableMinEpsilonRate() override
Enable stopping criterion on epsilon rate.
Size burn_in_
Number of iterations before checking stopping criteria.
BNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
const IBayesNet< GUM_SCALAR > & p() const
const IBayesNet< GUM_SCALAR > & q_
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() override
destructor
Instantiation nextSample(Instantiation prev)
draws next sample of Gibbs sampling
Instantiation monteCarloSample()
draws a first sample with a positive probability (starting point of a Gibbs chain)
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