58 template < GUM_Numeric GUM_SCALAR >
65 template < GUM_Numeric GUM_SCALAR >
71 template < GUM_Numeric GUM_SCALAR >
76 template < GUM_Numeric GUM_SCALAR >
81 auto Ip =
p_.completeInstantiation();
82 auto Iq =
q_.completeInstantiation();
87 for (
Idx ite = 0; ite < Ip.nbrDim(); ++ite) {
88 map.
insert(&Ip.variable(ite), &
q_.variableFromName(Ip.variable(ite).name()));
90 GUM_SCALAR pp, pq, pmid, lpp, lpq, lpmid;
91 for (Ip.setFirst(); !Ip.end(); ++Ip) {
92 Iq.setValsFrom(map, Ip);
93 pp =
p_.jointProbability(Ip);
94 pq =
q_.jointProbability(Iq);
95 pmid = (pp + pq) / 2.0;
101 hellinger_ += std::pow(std::sqrt(pp) - std::sqrt(pq), 2);
104 if (pp != (GUM_SCALAR)0.0) {
105 if (pq != (GUM_SCALAR)0.0) {
106 klPQ_ -= pp * (lpq - lpp);
112 if (pq != (GUM_SCALAR)0.0) {
113 if (pp != (GUM_SCALAR)0.0) {
114 klQP_ -= pq * (lpp - lpq);
119 if (pmid != (GUM_SCALAR)0.0) {
120 jsd_ += pp * lpp + pq * lpq
algorithm for KL divergence between BNs
Class representing the minimal interface for Bayesian network with no numerical data.
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_
ExactBNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
~ExactBNdistance() override
destructor
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.
algorithm for exact computation KL divergence between BNs
Size Idx
Type for indexes.
gum is the global namespace for all aGrUM entities