aGrUM
3.3.2
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
greedyHillClimbing_tpl.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
#pragma once
42
43
49
50
#include <
agrum/BN/learning/greedyHillClimbing.h
>
// to ease IDE parser
51
#include <
agrum/BN/learning/paramUtils/DAG2BNLearner.h
>
52
#include <
agrum/BN/learning/structureUtils/graphChange.h
>
53
54
namespace
gum
{
55
56
namespace
learning
{
57
59
template
<
typename
GRAPH_CHANGES_
SEL
ECTOR >
60
DAG
GreedyHillClimbing::learnStructure
(GRAPH_CHANGES_SELECTOR& selector,
DAG
dag) {
61
selector.setGraph(dag);
62
63
unsigned
int
nb_changes_applied = 1;
64
double
delta_score;
65
66
initApproximationScheme
();
67
68
do
{
69
nb_changes_applied = 0;
70
delta_score = 0;
71
72
try
{
73
const
auto
& change = selector.bestChange();
74
delta_score = selector.deltaScore(change,
true
);
75
76
if
((delta_score > 0) &&
continueApproximationScheme
(delta_score)) {
77
selector.applyChange(change);
78
nb_changes_applied = 1;
79
updateApproximationScheme
(nb_changes_applied);
80
}
81
}
catch
(
NotFound
&) {}
82
}
while
(nb_changes_applied);
83
84
stopApproximationScheme
();
// just to be sure of the approximationScheme
85
// has been notified of the end of loop
86
87
// here, we add to the dag the set of nodes that were removed by method
88
// setGraph because they did not belong to the database
89
selector.finalizeGraph(dag);
90
91
return
dag;
92
}
93
95
template
< GUM_Numeric GUM_SCALAR,
typename
GRAPH_CHANGES_
SEL
ECTOR,
typename
PARAM_ESTIMATOR >
96
BayesNet< GUM_SCALAR >
GreedyHillClimbing::learnBN
(GRAPH_CHANGES_SELECTOR& selector,
97
PARAM_ESTIMATOR& estimator,
98
DAG
initial_dag) {
99
return
DAG2BNLearner::createBN< GUM_SCALAR >
(estimator,
100
learnStructure
(selector, initial_dag));
101
}
102
103
}
/* namespace learning */
104
105
}
/* namespace gum */
DAG2BNLearner.h
A class that, given a structure and a parameter estimator returns a full Bayes net.
gum::ApproximationScheme::updateApproximationScheme
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
Definition
approximationScheme_inl.h:209
gum::ApproximationScheme::continueApproximationScheme
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
Definition
approximationScheme.cpp:107
gum::ApproximationScheme::initApproximationScheme
void initApproximationScheme()
Initialise the scheme.
Definition
approximationScheme_inl.h:190
gum::ApproximationScheme::stopApproximationScheme
void stopApproximationScheme()
Stop the approximation scheme.
Definition
approximationScheme_inl.h:222
gum::DAG
Base class for dag.
Definition
DAG.h:121
NotFound
Exception : the element we looked for cannot be found.
gum::learning::DAG2BNLearner::createBN
static BayesNet< GUM_SCALAR > createBN(ParamEstimator &estimator, const DAG &dag)
create a BN from a DAG using a one pass generator (typically ML)
Definition
DAG2BNLearner_tpl.h:76
gum::learning::GreedyHillClimbing::learnStructure
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
Definition
greedyHillClimbing_tpl.h:60
gum::learning::GreedyHillClimbing::learnBN
BayesNet< GUM_SCALAR > learnBN(GRAPH_CHANGES_SELECTOR &selector, PARAM_ESTIMATOR &estimator, DAG initial_dag=DAG())
learns the structure and the parameters of a BN
Definition
greedyHillClimbing_tpl.h:96
graphChange.h
the classes to account for structure changes in a graph
greedyHillClimbing.h
The greedy hill learning algorithm (for directed graphs).
gum::learning
include the inlined functions if necessary
Definition
CSVParser.h:55
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
aGrUM
3.3.2
© PHW&CG&others - 2022
DoXyGeN 1.18.0