aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DAG2BNLearner.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 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-2025 *
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
48#ifndef GUM_LEARNING_DAG_2_BN_LEARNER_H
49#define GUM_LEARNING_DAG_2_BN_LEARNER_H
50
51#include <algorithm>
52#include <string>
53#include <vector>
54
55#include <agrum/agrum.h>
56
59
60namespace gum {
61
62 namespace learning {
63
71 public:
72 // ##########################################################################
74 // ##########################################################################
76
79
82
85
87 virtual DAG2BNLearner* clone() const;
88
90 virtual ~DAG2BNLearner();
91
93
94
95 // ##########################################################################
97 // ##########################################################################
98
100
103
106
108
109
110 // ##########################################################################
112 // ##########################################################################
114
123 DAG2BNLearner& setNoise(const double noise);
124
126 template < typename GUM_SCALAR = double >
127 static BayesNet< GUM_SCALAR > createBN(ParamEstimator& estimator, const DAG& dag);
128
138 template < typename GUM_SCALAR = double >
139 BayesNet< GUM_SCALAR > createBNwithEM(ParamEstimator& bootstrap_estimator,
140 ParamEstimator& EM_estimator,
141 const DAG& dag);
142
161 template < typename GUM_SCALAR >
162 BayesNet< GUM_SCALAR > createBNwithEM(ParamEstimator& bootstrap_estimator,
163 ParamEstimator& EM_estimator,
164 const BayesNet< GUM_SCALAR >& bn);
165
183 template < typename GUM_SCALAR >
184 BayesNet< GUM_SCALAR > createBNwithEM(ParamEstimator& bootstrap_estimator,
185 ParamEstimator& EM_estimator,
186 BayesNet< GUM_SCALAR >&& bn);
187
190
192
193#ifndef DOXYGEN_SHOULD_SKIP_THIS
194
195 private:
204 double noiseEM_{0.1};
205
207
212 double log_likelihood_EM_{0.0};
213
223 unsigned int max_nb_dec_likelihood_iter_{3};
224
226
228 template < typename GUM_SCALAR = double >
229 static void _probaVarReordering_(gum::Tensor< GUM_SCALAR >& pot,
230 const gum::Tensor< GUM_SCALAR >& other_pot);
231
233
244 template < typename GUM_SCALAR = double >
245 BayesNet< GUM_SCALAR >
246 _createBN_(ParamEstimator& estimator, const DAG& dag, const bool compute_log_likelihood);
256 template < typename GUM_SCALAR >
257 BayesNet< GUM_SCALAR > _performEM_(ParamEstimator& bootstrap_estimator,
258 ParamEstimator& EM_estimator,
259 BayesNet< GUM_SCALAR >&& bn);
260
261
262#endif /* DOXYGEN_SHOULD_SKIP_THIS */
263 };
264
265 } /* namespace learning */
266
267} /* namespace gum */
268
271
272// include the inlined functions if necessary
273#ifndef GUM_NO_INLINE
275#endif /* GUM_NO_INLINE */
276
277#endif /* GUM_LEARNING_DAG_2_BN_LEARNER_H */
A class that, given a structure and a parameter estimator returns a full Bayes net.
A class that, given a structure and a parameter estimator returns a full Bayes net.
A class for parameterizing EM's parameter learning approximations.
Base class for dag.
Definition DAG.h:121
aGrUM's Tensor is a multi-dimensional array with tensor operators.
Definition tensor.h:85
EMApproximationScheme & approximationScheme()
returns the approximation policy of the EM learning algorithm
virtual DAG2BNLearner * clone() const
virtual copy constructor
DAG2BNLearner & setNoise(const double noise)
sets the noise amount used to perturb the initial CPTs used by EM
DAG2BNLearner()
default constructor
static BayesNet< GUM_SCALAR > createBN(ParamEstimator &estimator, const DAG &dag)
create a BN from a DAG using a one pass generator (typically ML)
DAG2BNLearner(const DAG2BNLearner &from)
copy constructor
BayesNet< GUM_SCALAR > createBNwithEM(ParamEstimator &bootstrap_estimator, ParamEstimator &EM_estimator, const BayesNet< GUM_SCALAR > &bn)
creates a BN using the EM algorithm with the structure specified by bn, initialized by the parameters...
DAG2BNLearner & operator=(DAG2BNLearner &&from)
move operator
BayesNet< GUM_SCALAR > createBNwithEM(ParamEstimator &bootstrap_estimator, ParamEstimator &EM_estimator, const DAG &dag)
creates a BN with a given structure (dag) using the EM algorithm
DAG2BNLearner(DAG2BNLearner &&from)
move constructor
DAG2BNLearner & operator=(const DAG2BNLearner &from)
copy operator
virtual ~DAG2BNLearner()
destructor
EMApproximationScheme(bool verbosity=false)
initializes the EM parameter learning approximation with the min rate criterion
The base class for estimating parameters of CPTs.
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
the base class for estimating parameters of CPTs