aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
gum::BNdistance< GUM_SCALAR > Class Template Reference

#include <BNdistance.h>

Inheritance diagram for gum::BNdistance< GUM_SCALAR >:
Collaboration diagram for gum::BNdistance< GUM_SCALAR >:

Public Member Functions

 BNdistance (const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
 constructor must give 2 BNs
 BNdistance (const BNdistance< GUM_SCALAR > &kl)
 copy constructor
virtual ~BNdistance ()
 destructor
Complexity difficulty () const
 return KL::Complexity::Heavy,KL::Complexity::Difficult,KL::Complexity::Correct depending on the BNs p and q
Accessors to results. The first call do the computations. The

others do not.

double klPQ ()
Size errorPQ ()
double klQP ()
Size errorQP ()
double hellinger ()
double bhattacharya ()
double jsd ()
const IBayesNet< GUM_SCALAR > & p () const
const IBayesNet< GUM_SCALAR > & q () const

Protected Member Functions

virtual void computeKL_ ()
void process_ ()

Protected Attributes

const IBayesNet< GUM_SCALAR > & p_
const IBayesNet< GUM_SCALAR > & q_
GUM_SCALAR klPQ_
GUM_SCALAR klQP_
Size errorPQ_
Size errorQP_
GUM_SCALAR hellinger_
GUM_SCALAR bhattacharya_
GUM_SCALAR jsd_

Private Member Functions

bool _checkCompatibility_ () const

Private Attributes

Complexity _difficulty_
bool _done_

Detailed Description

template<GUM_Numeric GUM_SCALAR>
class gum::BNdistance< GUM_SCALAR >

Definition at line 86 of file BNdistance.h.

Constructor & Destructor Documentation

◆ BNdistance() [1/2]

template<GUM_Numeric GUM_SCALAR>
gum::BNdistance< GUM_SCALAR >::BNdistance ( const IBayesNet< GUM_SCALAR > & P,
const IBayesNet< GUM_SCALAR > & Q )

constructor must give 2 BNs

Exceptions
gum::OperationNotAllowedif the 2 BNs have not the same domainSize or compatible node sets.

Definition at line 60 of file BNdistance_tpl.h.

61 :
62 p_(P), q_(Q), klPQ_(0.0), klQP_(0.0), errorPQ_(0), errorQP_(0),
64 _checkCompatibility_(); // may throw OperationNotAllowed
66
67 double diff = p_.log10DomainSize();
68
72 }
GUM_SCALAR klPQ_
Definition BNdistance.h:159
BNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
Complexity _difficulty_
Definition BNdistance.h:171
GUM_SCALAR klQP_
Definition BNdistance.h:160
bool _checkCompatibility_() const
const IBayesNet< GUM_SCALAR > & q_
Definition BNdistance.h:157
const IBayesNet< GUM_SCALAR > & p_
Definition BNdistance.h:156

References BNdistance(), _checkCompatibility_(), _difficulty_, _done_, gum::Correct, gum::Difficult, errorPQ_, errorQP_, GAP_COMPLEXITY_KL_DIFFICULT_CORRECT, GAP_COMPLEXITY_KL_HEAVY_DIFFICULT, gum::Heavy, klPQ_, klQP_, p_, and q_.

Referenced by BNdistance(), BNdistance(), gum::ExactBNdistance< GUM_SCALAR >::ExactBNdistance(), gum::ExactBNdistance< GUM_SCALAR >::ExactBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance(), and ~BNdistance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BNdistance() [2/2]

template<GUM_Numeric GUM_SCALAR>
gum::BNdistance< GUM_SCALAR >::BNdistance ( const BNdistance< GUM_SCALAR > & kl)

copy constructor

Definition at line 75 of file BNdistance_tpl.h.

References BNdistance(), _difficulty_, _done_, errorPQ_, errorQP_, klPQ_, klQP_, p_, and q_.

Here is the call graph for this function:

◆ ~BNdistance()

template<GUM_Numeric GUM_SCALAR>
gum::BNdistance< GUM_SCALAR >::~BNdistance ( )
virtual

destructor

Definition at line 82 of file BNdistance_tpl.h.

82 {
84 }

References BNdistance().

Here is the call graph for this function:

Member Function Documentation

◆ _checkCompatibility_()

template<GUM_Numeric GUM_SCALAR>
bool gum::BNdistance< GUM_SCALAR >::_checkCompatibility_ ( ) const
private

Definition at line 145 of file BNdistance_tpl.h.

145 {
146 // should not be used
147 if (p_.size() != q_.size())
149 "BNdistance : the 2 BNs are not compatible (not the same size)")
150
151 for (auto node: p_.nodes()) {
152 const DiscreteVariable& vp = p_.variable(node);
153 if (!q_.exists(vp.name())) {
154 GUM_ERROR(OperationNotAllowed,
155 "BNdistance : the 2 BNs are not compatible (variable : " + vp.name() + ")");
156 }
157 const DiscreteVariable& vq = q_.variableFromName(vp.name());
158 if (vp != vq)
160 "BNdistance : the 2 BNs are not compatible "
161 "(not the same variable for the same name : "
162 + vp.toString() + "and " + vq.toString() + ")");
163 }
164
165 if (std::fabs(p_.log10DomainSize() - q_.log10DomainSize()) > 1e-14) {
167 "BNdistance : the 2 BNs are not compatible (not the same domainSize) : p="
168 << p_.log10DomainSize() << " q=" << q_.log10DomainSize() << " => "
169 << p_.log10DomainSize() - q_.log10DomainSize());
170 }
171
172 return true;
173 }
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References GUM_ERROR, gum::Variable::name(), p_, q_, and gum::DiscreteVariable::toString().

Referenced by BNdistance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bhattacharya()

template<GUM_Numeric GUM_SCALAR>
double gum::BNdistance< GUM_SCALAR >::bhattacharya ( )
Returns
Bhattacharya distance (
See also
http://en.wikipedia.org/wiki/Bhattacharya_distance)

Definition at line 110 of file BNdistance_tpl.h.

110 {
111 process_();
112 return bhattacharya_;
113 }
GUM_SCALAR bhattacharya_
Definition BNdistance.h:166

References bhattacharya_, and process_().

Here is the call graph for this function:

◆ computeKL_()

template<GUM_Numeric GUM_SCALAR>
void gum::BNdistance< GUM_SCALAR >::computeKL_ ( )
protectedvirtual

Reimplemented in gum::ExactBNdistance< GUM_SCALAR >, and gum::GibbsBNdistance< GUM_SCALAR >.

Definition at line 186 of file BNdistance_tpl.h.

186 {
187 GUM_ERROR(OperationNotAllowed, "No default computations")
188 }

References GUM_ERROR.

Referenced by process_().

Here is the caller graph for this function:

◆ difficulty()

template<GUM_Numeric GUM_SCALAR>
Complexity gum::BNdistance< GUM_SCALAR >::difficulty ( ) const

return KL::Complexity::Heavy,KL::Complexity::Difficult,KL::Complexity::Correct depending on the BNs p and q

Definition at line 87 of file BNdistance_tpl.h.

87 {
88 return _difficulty_;
89 }

References _difficulty_.

◆ errorPQ()

template<GUM_Numeric GUM_SCALAR>
Size gum::BNdistance< GUM_SCALAR >::errorPQ ( )
Returns
the number of errors while processing divergence KL(P||Q)

Definition at line 122 of file BNdistance_tpl.h.

122 {
123 process_();
124 return errorPQ_;
125 }

References errorPQ_, and process_().

Here is the call graph for this function:

◆ errorQP()

template<GUM_Numeric GUM_SCALAR>
Size gum::BNdistance< GUM_SCALAR >::errorQP ( )
Returns
the number of errors while processing divergence KL(Q||P)

Definition at line 128 of file BNdistance_tpl.h.

128 {
129 process_();
130 return errorQP_;
131 }

References errorQP_, and process_().

Here is the call graph for this function:

◆ hellinger()

template<GUM_Numeric GUM_SCALAR>
double gum::BNdistance< GUM_SCALAR >::hellinger ( )
Returns
hellinger distance (
See also
http://en.wikipedia.org/wiki/Hellinger_distance)

Definition at line 104 of file BNdistance_tpl.h.

104 {
105 process_();
106 return hellinger_;
107 }
GUM_SCALAR hellinger_
Definition BNdistance.h:165

References hellinger_, and process_().

Here is the call graph for this function:

◆ jsd()

template<GUM_Numeric GUM_SCALAR>
double gum::BNdistance< GUM_SCALAR >::jsd ( )
Returns
Jensen-Shannon divergence(
See also
https://en.wikipedia.org/wiki/Jensen%E2%80%93Shannon_divergence)

Definition at line 116 of file BNdistance_tpl.h.

116 {
117 process_();
118 return jsd_;
119 }
GUM_SCALAR jsd_
Definition BNdistance.h:167

References jsd_, and process_().

Here is the call graph for this function:

◆ klPQ()

template<GUM_Numeric GUM_SCALAR>
double gum::BNdistance< GUM_SCALAR >::klPQ ( )
Returns
divergence KL(P||Q)

Definition at line 92 of file BNdistance_tpl.h.

92 {
93 process_();
94 return klPQ_;
95 }

References klPQ_, and process_().

Here is the call graph for this function:

◆ klQP()

template<GUM_Numeric GUM_SCALAR>
double gum::BNdistance< GUM_SCALAR >::klQP ( )
Returns
divergence KL(Q||P)

Definition at line 98 of file BNdistance_tpl.h.

98 {
99 process_();
100 return klQP_;
101 }

References klQP_, and process_().

Here is the call graph for this function:

◆ p()

template<GUM_Numeric GUM_SCALAR>
const IBayesNet< GUM_SCALAR > & gum::BNdistance< GUM_SCALAR >::p ( ) const
Returns
p

Definition at line 134 of file BNdistance_tpl.h.

134 {
135 return p_;
136 }

References p_.

Referenced by gum::GibbsBNdistance< GUM_SCALAR >::GibbsBNdistance().

Here is the caller graph for this function:

◆ process_()

template<GUM_Numeric GUM_SCALAR>
void gum::BNdistance< GUM_SCALAR >::process_ ( )
protected

Definition at line 177 of file BNdistance_tpl.h.

177 {
178 if (!_done_) {
179 computeKL_();
180 _done_ = true;
181 }
182 }
virtual void computeKL_()

References _done_, and computeKL_().

Referenced by bhattacharya(), errorPQ(), errorQP(), hellinger(), jsd(), klPQ(), and klQP().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ q()

template<GUM_Numeric GUM_SCALAR>
const IBayesNet< GUM_SCALAR > & gum::BNdistance< GUM_SCALAR >::q ( ) const
Returns
q

Definition at line 139 of file BNdistance_tpl.h.

139 {
140 return q_;
141 }

References q_.

Member Data Documentation

◆ _difficulty_

template<GUM_Numeric GUM_SCALAR>
Complexity gum::BNdistance< GUM_SCALAR >::_difficulty_
private

Definition at line 171 of file BNdistance.h.

Referenced by BNdistance(), BNdistance(), and difficulty().

◆ _done_

template<GUM_Numeric GUM_SCALAR>
bool gum::BNdistance< GUM_SCALAR >::_done_
private

Definition at line 172 of file BNdistance.h.

Referenced by BNdistance(), BNdistance(), and process_().

◆ bhattacharya_

template<GUM_Numeric GUM_SCALAR>
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::bhattacharya_
protected

◆ errorPQ_

template<GUM_Numeric GUM_SCALAR>
Size gum::BNdistance< GUM_SCALAR >::errorPQ_
protected

◆ errorQP_

template<GUM_Numeric GUM_SCALAR>
Size gum::BNdistance< GUM_SCALAR >::errorQP_
protected

◆ hellinger_

template<GUM_Numeric GUM_SCALAR>
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::hellinger_
protected

◆ jsd_

template<GUM_Numeric GUM_SCALAR>
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::jsd_
protected

◆ klPQ_

template<GUM_Numeric GUM_SCALAR>
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::klPQ_
protected

◆ klQP_

template<GUM_Numeric GUM_SCALAR>
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::klQP_
protected

◆ p_

template<GUM_Numeric GUM_SCALAR>
const IBayesNet< GUM_SCALAR >& gum::BNdistance< GUM_SCALAR >::p_
protected

◆ q_

template<GUM_Numeric GUM_SCALAR>
const IBayesNet< GUM_SCALAR >& gum::BNdistance< GUM_SCALAR >::q_
protected

The documentation for this class was generated from the following files: