aGrUM  0.13.2
KL.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 KL {
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  KL(const IBayesNet< GUM_SCALAR >& P, const IBayesNet< GUM_SCALAR >& Q);
76 
79  KL(const KL< GUM_SCALAR >& kl);
80 
82  virtual ~KL();
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 
117  const IBayesNet< GUM_SCALAR >& p() const;
118 
120  const IBayesNet< GUM_SCALAR >& q() const;
122 
123  protected:
124  // should be pure virtual but using KL directly is a way to delay the choice
125  // between different computation scheme (@see BruteForceKL)
126  virtual void _computeKL();
127  void _process();
128 
131 
132  GUM_SCALAR _klPQ;
133  GUM_SCALAR _klQP;
134  GUM_SCALAR _hellinger;
135  GUM_SCALAR _bhattacharya;
136 
139 
140  private:
141  bool __checkCompatibility() const;
143  bool __done;
144  };
145 
146 
147  extern template class KL< float >;
148  extern template class KL< double >;
149 
150 } // namespace gum
151 
153 
154 #endif // GUM_KL_H
GUM_SCALAR _klPQ
Definition: KL.h:132
Complexity __difficulty
Definition: KL.h:142
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
const IBayesNet< GUM_SCALAR > & _p
Definition: KL.h:129
GUM_SCALAR _bhattacharya
Definition: KL.h:135
Class representing Bayesian networks.
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: KL.h:43
const IBayesNet< GUM_SCALAR > & _q
Definition: KL.h:130
bool __done
Definition: KL.h:143
KL is the base class for KL computation betweens 2 BNs.
Definition: KL.h:65
Size _errorPQ
Definition: KL.h:137
KL divergence between BNs implementation.
GUM_SCALAR _klQP
Definition: KL.h:133
Size _errorQP
Definition: KL.h:138
GUM_SCALAR _hellinger
Definition: KL.h:134