aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
MCBNDistance.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
50
51
52#ifndef GUM_MC_KL_H
53#define GUM_MC_KL_H
54
57
58namespace gum {
59
95
96 template < GUM_Numeric GUM_SCALAR >
97 class MCBNDistance: public BNdistance< GUM_SCALAR >, public ApproximationScheme {
98 public:
99 /* no default constructor */
100
107
110 explicit MCBNDistance(const BNdistance< GUM_SCALAR >& kl);
111
113 ~MCBNDistance() override;
114
115 protected:
116 void computeKL_() final;
117
120 Instantiation drawSample_(const Sequence< NodeId >& topoOrder) const;
121
122 using BNdistance< GUM_SCALAR >::p_;
123 using BNdistance< GUM_SCALAR >::q_;
124 using BNdistance< GUM_SCALAR >::hellinger_;
125 using BNdistance< GUM_SCALAR >::bhattacharya_;
126 using BNdistance< GUM_SCALAR >::jsd_;
127
128 using BNdistance< GUM_SCALAR >::klPQ_;
129 using BNdistance< GUM_SCALAR >::klQP_;
130
131 using BNdistance< GUM_SCALAR >::errorPQ_;
132 using BNdistance< GUM_SCALAR >::errorQP_;
133 };
134
135
136#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
137 extern template class MCBNDistance< double >;
138#endif
139
140} // namespace gum
141
143
144#endif
algorithm for KL divergence between BNs
KL divergence between BNs – implementation using independent Monte Carlo sampling.
This file contains general scheme for iteratively convergent algorithms.
ApproximationScheme(bool verbosity=false)
GUM_SCALAR hellinger_
Definition BNdistance.h:165
GUM_SCALAR klPQ_
Definition BNdistance.h:159
BNdistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
GUM_SCALAR jsd_
Definition BNdistance.h:167
GUM_SCALAR klQP_
Definition BNdistance.h:160
GUM_SCALAR bhattacharya_
Definition BNdistance.h:166
const IBayesNet< GUM_SCALAR > & q_
Definition BNdistance.h:157
const IBayesNet< GUM_SCALAR > & p_
Definition BNdistance.h:156
Class representing the minimal interface for Bayesian network with no numerical data.
Definition IBayesNet.h:75
Class for assigning/browsing values to tuples of discrete variables.
MCBNDistance computes the KL divergence betweens 2 BNs using an approximation pattern: independent (f...
void computeKL_() final
Instantiation drawSample_(const Sequence< NodeId > &topoOrder) const
draws an instantiation of p_'s variables, independently, following topoOrder (no evidence to handle i...
MCBNDistance(const IBayesNet< GUM_SCALAR > &P, const IBayesNet< GUM_SCALAR > &Q)
constructor must give 2 BNs
~MCBNDistance() override
destructor
gum is the global namespace for all aGrUM entities
Definition agrum.h:46