aGrUM  0.14.2
BNdistance.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef GUM_KL_H
28 #define GUM_KL_H
29 
30 #include <agrum/BN/IBayesNet.h>
31 #include <agrum/core/sequence.h>
32 
33 namespace gum {
34 
43  enum class Complexity : char { Heavy, Difficult, Correct };
44 
64  template < typename GUM_SCALAR >
65  class BNdistance {
66 // difficulty is chosen w.r.t the log10DomainSize of the BN
67 #define GAP_COMPLEXITY_KL_HEAVY_DIFFICULT double(12.0)
68 #define GAP_COMPLEXITY_KL_DIFFICULT_CORRECT double(7.0)
69  public:
75  BNdistance(const IBayesNet< GUM_SCALAR >& P, const IBayesNet< GUM_SCALAR >& Q);
76 
79  BNdistance(const BNdistance< GUM_SCALAR >& kl);
80 
82  virtual ~BNdistance();
83 
89  Complexity difficulty() const;
90 
95 
97  double klPQ();
98 
100  Size errorPQ();
101 
103  double klQP();
104 
106  Size errorQP();
107 
110  double hellinger();
111 
114  double bhattacharya();
115 
118  double jsd();
119 
121  const IBayesNet< GUM_SCALAR >& p() const;
122 
124  const IBayesNet< GUM_SCALAR >& q() const;
126 
127  protected:
128  // should be pure virtual but using BNdistance directly is a way to delay the
129  // choice between different computation scheme (@see ExactBNdistance)
130  virtual void _computeKL();
131  void _process();
132 
135 
136  GUM_SCALAR _klPQ;
137  GUM_SCALAR _klQP;
138  GUM_SCALAR _hellinger;
139  GUM_SCALAR _bhattacharya;
140  GUM_SCALAR _jsd;
141 
144 
145  private:
146  bool __checkCompatibility() const;
148  bool __done;
149  };
150 
151 
152 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
153  extern template class BNdistance< double >;
154 #endif
155 
156 } // namespace gum
157 
159 
160 #endif // GUM_KL_H
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
GUM_SCALAR _klPQ
Definition: BNdistance.h:136
GUM_SCALAR _bhattacharya
Definition: BNdistance.h:139
KL divergence between BNs implementation.
const IBayesNet< GUM_SCALAR > & _p
Definition: BNdistance.h:133
Class representing Bayesian networks.
GUM_SCALAR _jsd
Definition: BNdistance.h:140
Class representing the minimal interface for Bayesian Network.
Definition: IBayesNet.h:59
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Complexity
Complexity allows to characterize the awaited difficulty for an algorithm given a specific instance T...
Definition: BNdistance.h:43
const IBayesNet< GUM_SCALAR > & _q
Definition: BNdistance.h:134
GUM_SCALAR _hellinger
Definition: BNdistance.h:138
GUM_SCALAR _klQP
Definition: BNdistance.h:137
Complexity __difficulty
Definition: BNdistance.h:147
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45