aGrUM 2.3.2
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<typename GUM_SCALAR>
class gum::BNdistance< GUM_SCALAR >

Definition at line 86 of file BNdistance.h.

Constructor & Destructor Documentation

◆ BNdistance() [1/2]

template<typename 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 59 of file BNdistance_tpl.h.

60 :
61 p_(P), q_(Q), klPQ_(0.0), klQP_(0.0), errorPQ_(0), errorQP_(0),
63 _checkCompatibility_(); // may throw OperationNotAllowed
65
66 double diff = p_.log10DomainSize();
67
71 }
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<typename GUM_SCALAR>
gum::BNdistance< GUM_SCALAR >::BNdistance ( const BNdistance< GUM_SCALAR > & kl)

copy constructor

Definition at line 74 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<typename GUM_SCALAR>
gum::BNdistance< GUM_SCALAR >::~BNdistance ( )
virtual

destructor

Definition at line 81 of file BNdistance_tpl.h.

81 {
83 }

References BNdistance().

Here is the call graph for this function:

Member Function Documentation

◆ _checkCompatibility_()

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

Definition at line 144 of file BNdistance_tpl.h.

144 {
145 // should not be used
146 if (p_.size() != q_.size())
148 "BNdistance : the 2 BNs are not compatible (not the same size)")
149
150 for (auto node: p_.nodes()) {
151 const DiscreteVariable& vp = p_.variable(node);
152 try {
153 const DiscreteVariable& vq = q_.variableFromName(vp.name());
154 if (vp != vq)
156 "BNdistance : the 2 BNs are not compatible "
157 "(not the same variable for the same name : "
158 + vp.toString() + "and " + vq.toString() + ")");
159 } catch (NotFound const&) {
161 "BNdistance : the 2 BNs are not compatible (variable : " + vp.name() + ")");
162 }
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:72

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<typename GUM_SCALAR>
INLINE double gum::BNdistance< GUM_SCALAR >::bhattacharya ( )
Returns
Bhattacharya distance (
See also
http://en.wikipedia.org/wiki/Bhattacharya_distance)

Definition at line 109 of file BNdistance_tpl.h.

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

References bhattacharya_, and process_().

Here is the call graph for this function:

◆ computeKL_()

template<typename 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<typename 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 86 of file BNdistance_tpl.h.

86 {
87 return _difficulty_;
88 }

References _difficulty_.

◆ errorPQ()

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

Definition at line 121 of file BNdistance_tpl.h.

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

References errorPQ_, and process_().

Here is the call graph for this function:

◆ errorQP()

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

Definition at line 127 of file BNdistance_tpl.h.

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

References errorQP_, and process_().

Here is the call graph for this function:

◆ hellinger()

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

Definition at line 103 of file BNdistance_tpl.h.

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

References hellinger_, and process_().

Here is the call graph for this function:

◆ jsd()

template<typename GUM_SCALAR>
INLINE 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 115 of file BNdistance_tpl.h.

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

References jsd_, and process_().

Here is the call graph for this function:

◆ klPQ()

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

Definition at line 91 of file BNdistance_tpl.h.

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

References klPQ_, and process_().

Here is the call graph for this function:

◆ klQP()

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

Definition at line 97 of file BNdistance_tpl.h.

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

References klQP_, and process_().

Here is the call graph for this function:

◆ p()

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

Definition at line 133 of file BNdistance_tpl.h.

133 {
134 return p_;
135 }

References p_.

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

Here is the caller graph for this function:

◆ process_()

template<typename 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<typename GUM_SCALAR>
INLINE const IBayesNet< GUM_SCALAR > & gum::BNdistance< GUM_SCALAR >::q ( ) const
Returns
q

Definition at line 138 of file BNdistance_tpl.h.

138 {
139 return q_;
140 }

References q_.

Member Data Documentation

◆ _difficulty_

template<typename 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<typename 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<typename GUM_SCALAR>
GUM_SCALAR gum::BNdistance< GUM_SCALAR >::bhattacharya_
protected

◆ errorPQ_

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

◆ errorQP_

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

◆ hellinger_

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

◆ jsd_

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

◆ klPQ_

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

◆ klQP_

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

◆ p_

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

◆ q_

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

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