aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
K2_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/constraints/structuralConstraintTotalOrder.h
>
51
#include <
agrum/BN/learning/K2.h
>
// to ease IDE parser
52
#include <
agrum/BN/learning/paramUtils/DAG2BNLearner.h
>
53
#include <
agrum/BN/learning/structureUtils/graphChange.h
>
54
55
#include <type_traits>
56
57
namespace
gum
{
58
59
namespace
learning
{
60
62
template
<
typename
GRAPH_CHANGES_
SEL
ECTOR >
63
DAG
K2::learnStructure
(GRAPH_CHANGES_SELECTOR& selector,
DAG
initial_dag) {
64
// check that we used a selector compatible with the K2 algorithm
65
auto
& total_order_constraint
66
=
static_cast<
StructuralConstraintTotalOrder
&
>
(selector.invariableConstraints());
67
68
// check that the order passed in argument concerns all the nodes
69
// __checkOrder(modal);
70
71
// assign the order to the invariable constraints
72
total_order_constraint.
setTotalOrder
(
_order_
);
73
74
// forbid the use of arc deletions, reversals and triangle deletions
75
selector.useArcAdditions(
true
);
76
selector.useArcDeletions(
false
);
77
selector.useArcReversals(
false
);
78
selector.useArcTriangleDeletions(
false
);
79
80
// use the greedy hill climbing algorithm to perform the search
81
return
GreedyHillClimbing::learnStructure
(selector, initial_dag);
82
}
83
85
template
< GUM_Numeric GUM_SCALAR,
typename
GRAPH_CHANGES_
SEL
ECTOR,
typename
PARAM_ESTIMATOR >
86
BayesNet< GUM_SCALAR >
87
K2::learnBN
(GRAPH_CHANGES_SELECTOR& selector, PARAM_ESTIMATOR& estimator,
DAG
initial_dag) {
88
// check that we used a selector compatible with the K2 algorithm
89
auto
& total_order_constraint
90
=
static_cast<
StructuralConstraintTotalOrder
&
>
(selector.invariableConstraints());
91
92
// check that the order passed in argument concerns all the nodes
93
// __checkOrder(modal);
94
95
// assign the order to the invariable constraints
96
total_order_constraint.
setTotalOrder
(
_order_
);
97
98
// forbid the use of arc deletions, reversals and triangle deletions
99
selector.useArcAdditions(
true
);
100
selector.useArcDeletions(
false
);
101
selector.useArcReversals(
false
);
102
selector.useArcTriangleDeletions(
false
);
103
104
// use the greedy hill climbing algorithm to perform the search
105
return
GreedyHillClimbing::learnBN< GUM_SCALAR >
(selector, estimator, initial_dag);
106
}
107
108
}
/* namespace learning */
109
110
}
/* namespace gum */
DAG2BNLearner.h
A class that, given a structure and a parameter estimator returns a full Bayes net.
K2.h
The K2 algorithm.
gum::DAG
Base class for dag.
Definition
DAG.h:121
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
gum::learning::K2::_order_
Sequence< NodeId > _order_
the order on the variable used for learning
Definition
K2.h:132
gum::learning::K2::learnStructure
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
Definition
K2_tpl.h:63
gum::learning::K2::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
K2_tpl.h:87
gum::learning::StructuralConstraintTotalOrder
the structural constraint imposing a total order over some nodes
Definition
structuralConstraintTotalOrder.h:67
gum::learning::StructuralConstraintTotalOrder::setTotalOrder
void setTotalOrder(const Sequence< NodeId > &Total)
sets the Total order of all the nodes in the property
graphChange.h
the classes to account for structure changes in a graph
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
structuralConstraintTotalOrder.h
the structural constraint imposing a total ordering over some nodes
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0