aGrUM
3.3.2
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
BNdistance.h
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 by *
5
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
6
* - Christophe GONZALES(_at_AMU) *
7
* *
8
* The aGrUM/pyAgrum library is free software; you can redistribute it *
9
* and/or modify it under the terms of either : *
10
* *
11
* - the GNU Lesser General Public License as published by *
12
* the Free Software Foundation, either version 3 of the License, *
13
* or (at your option) any later version, *
14
* - the MIT license (MIT), *
15
* - or both in dual license, as here. *
16
* *
17
* (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18
* *
19
* This aGrUM/pyAgrum library is distributed in the hope that it will be *
20
* useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26
* OTHER DEALINGS IN THE SOFTWARE. *
27
* *
28
* See LICENCES for more details. *
29
* *
30
* SPDX-FileCopyrightText: Copyright 2005-2026 *
31
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
32
* - Christophe GONZALES(_at_AMU) *
33
* SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34
* *
35
* Contact : info_at_agrum_dot_org *
36
* homepage : http://agrum.gitlab.io *
37
* gitlab : https://gitlab.com/agrumery/agrum *
38
* *
39
****************************************************************************/
40
41
49
#ifndef GUM_KL_H
50
#define GUM_KL_H
51
52
#include <
agrum/BN/IBayesNet.h
>
53
54
namespace
gum
{
55
64
enum class
Complexity
:
char
{
Heavy
,
Difficult
,
Correct
};
65
85
template
< GUM_Numeric GUM_SCALAR >
86
class
BNdistance
{
87
// difficulty is chosen w.r.t the log10DomainSize of the BN
88
#define GAP_COMPLEXITY_KL_HEAVY_DIFFICULT double(12.0)
89
#define GAP_COMPLEXITY_KL_DIFFICULT_CORRECT double(7.0)
90
91
public
:
97
BNdistance
(
const
IBayesNet< GUM_SCALAR >& P,
const
IBayesNet< GUM_SCALAR >& Q);
98
101
BNdistance
(
const
BNdistance< GUM_SCALAR >
& kl);
102
104
virtual
~BNdistance
();
105
111
Complexity
difficulty
()
const
;
112
117
119
double
klPQ
();
120
122
Size
errorPQ
();
123
125
double
klQP
();
126
128
Size
errorQP
();
129
132
double
hellinger
();
133
136
double
bhattacharya
();
137
140
double
jsd
();
141
143
const
IBayesNet< GUM_SCALAR >&
p
()
const
;
144
146
const
IBayesNet< GUM_SCALAR >&
q
()
const
;
148
149
protected
:
150
// should be pure virtual but using BNdistance directly is a way to delay the
151
// choice between different computation scheme (@see ExactBNdistance)
152
virtual
void
computeKL_
();
153
154
void
process_
();
155
156
const
IBayesNet< GUM_SCALAR >
&
p_
;
157
const
IBayesNet< GUM_SCALAR >
&
q_
;
158
159
GUM_SCALAR
klPQ_
;
160
GUM_SCALAR
klQP_
;
161
162
Size
errorPQ_
;
163
Size
errorQP_
;
164
165
GUM_SCALAR
hellinger_
;
166
GUM_SCALAR
bhattacharya_
;
167
GUM_SCALAR
jsd_
;
168
169
private
:
170
bool
_checkCompatibility_
()
const
;
171
Complexity
_difficulty_
;
172
bool
_done_
;
173
};
174
175
176
#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
177
178
extern
template
class
GUM_PUBLIC_BN
BNdistance< double >
;
179
180
#endif
181
182
}
// namespace gum
183
184
#include <
agrum/BN/algorithms/divergence/BNdistance_tpl.h
>
185
186
#endif
// GUM_KL_H
BNdistance_tpl.h
KL divergence between BNs implementation.
IBayesNet.h
Class representing the minimal interface for Bayesian network with no numerical data.
gum::BNdistance::hellinger
double hellinger()
Definition
BNdistance_tpl.h:104
gum::BNdistance::process_
void process_()
Definition
BNdistance_tpl.h:177
gum::BNdistance::hellinger_
GUM_SCALAR hellinger_
Definition
BNdistance.h:165
gum::BNdistance::q
const IBayesNet< GUM_SCALAR > & q() const
Definition
BNdistance_tpl.h:139
gum::BNdistance::jsd
double jsd()
Definition
BNdistance_tpl.h:116
gum::BNdistance::klPQ_
GUM_SCALAR klPQ_
Definition
BNdistance.h:159
gum::BNdistance::_done_
bool _done_
Definition
BNdistance.h:172
gum::BNdistance::klQP
double klQP()
Definition
BNdistance_tpl.h:98
gum::BNdistance::BNdistance
BNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
Definition
BNdistance_tpl.h:60
gum::BNdistance::bhattacharya
double bhattacharya()
Definition
BNdistance_tpl.h:110
gum::BNdistance::_difficulty_
Complexity _difficulty_
Definition
BNdistance.h:171
gum::BNdistance::computeKL_
virtual void computeKL_()
Definition
BNdistance_tpl.h:186
gum::BNdistance::jsd_
GUM_SCALAR jsd_
Definition
BNdistance.h:167
gum::BNdistance::p
const IBayesNet< GUM_SCALAR > & p() const
Definition
BNdistance_tpl.h:134
gum::BNdistance::klQP_
GUM_SCALAR klQP_
Definition
BNdistance.h:160
gum::BNdistance::errorPQ_
Size errorPQ_
Definition
BNdistance.h:162
gum::BNdistance::klPQ
double klPQ()
Definition
BNdistance_tpl.h:92
gum::BNdistance::errorPQ
Size errorPQ()
Definition
BNdistance_tpl.h:122
gum::BNdistance::errorQP
Size errorQP()
Definition
BNdistance_tpl.h:128
gum::BNdistance::_checkCompatibility_
bool _checkCompatibility_() const
Definition
BNdistance_tpl.h:145
gum::BNdistance::errorQP_
Size errorQP_
Definition
BNdistance.h:163
gum::BNdistance::~BNdistance
virtual ~BNdistance()
destructor
Definition
BNdistance_tpl.h:82
gum::BNdistance::bhattacharya_
GUM_SCALAR bhattacharya_
Definition
BNdistance.h:166
gum::BNdistance::q_
const IBayesNet< GUM_SCALAR > & q_
Definition
BNdistance.h:157
gum::BNdistance::difficulty
Complexity difficulty() const
return KL::Complexity::Heavy,KL::Complexity::Difficult,KL::Complexity::Correct depending on the BNs p...
Definition
BNdistance_tpl.h:87
gum::BNdistance::p_
const IBayesNet< GUM_SCALAR > & p_
Definition
BNdistance.h:156
gum::IBayesNet
Class representing the minimal interface for Bayesian network with no numerical data.
Definition
IBayesNet.h:79
gum::Size
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition
types.h:74
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
gum::BNdistance< double >
template class GUM_PUBLIC_BN BNdistance< double >
Definition
BNdistance.cpp:55
gum::Complexity
Complexity
Complexity allows to characterize the awaited difficulty for an algorithm given a specific instance T...
Definition
BNdistance.h:64
gum::Complexity::Difficult
@ Difficult
Definition
BNdistance.h:64
gum::Complexity::Correct
@ Correct
Definition
BNdistance.h:64
gum::Complexity::Heavy
@ Heavy
Definition
BNdistance.h:64
aGrUM
3.3.2
© PHW&CG&others - 2022
DoXyGeN 1.18.0