aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
K2_inl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4
* info_at_agrum_dot_org
5
*
6
* This library is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
*
19
*/
20
21
22
/** @file
23
* @brief The K2 algorithm
24
*
25
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26
*/
27
28
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
29
30
namespace
gum
{
31
32
namespace
learning
{
33
34
/// default constructor
35
INLINE
K2
::
K2
() {
GUM_CONSTRUCTOR
(
K2
); }
36
37
/// copy constructor
38
INLINE
K2
::
K2
(
const
K2
&
from
) :
39
GreedyHillClimbing
(
from
),
order__
(
from
.
order__
) {
40
GUM_CONS_CPY
(
K2
);
41
}
42
43
/// move constructor
44
INLINE
K2
::
K2
(
K2
&&
from
) :
45
GreedyHillClimbing
(
std
::
move
(
from
)),
order__
(
std
::
move
(
from
.
order__
)) {
46
GUM_CONS_MOV
(
K2
);
47
}
48
49
/// destructor
50
INLINE
K2
::~
K2
() {
GUM_DESTRUCTOR
(
K2
); }
51
52
/// copy operator
53
INLINE K2&
K2
::
operator
=(
const
K2
&
from
) {
54
if
(
this
!= &
from
) {
55
GreedyHillClimbing
::
operator
=(
from
);
56
order__
=
from
.
order__
;
57
}
58
return
*
this
;
59
}
60
61
/// move operator
62
INLINE
K2
&
K2
::
operator
=(
K2
&&
from
) {
63
if
(
this
!= &
from
) {
64
GreedyHillClimbing
::
operator
=(
std
::
move
(
from
));
65
order__
=
std
::
move
(
from
.
order__
);
66
}
67
return
*
this
;
68
}
69
70
/// sets the order on the variables
71
INLINE
void
K2
::
setOrder
(
const
Sequence
<
NodeId
>&
order
) {
order__
=
order
; }
72
73
/// sets the order on the variables
74
INLINE
void
K2
::
setOrder
(
const
std
::
vector
<
NodeId
>&
order
) {
75
order__
.
clear
();
76
for
(
const
auto
node
:
order
) {
77
order__
.
insert
(
node
);
78
}
79
}
80
81
/// returns the current order
82
INLINE
const
Sequence
<
NodeId
>&
K2
::
order
()
const
noexcept
{
return
order__
; }
83
84
/** @brief checks that the order passed to K2 is coherent with the variables
85
* as specified by their modalities */
86
INLINE
void
K2
::
checkOrder__
(
const
std
::
vector
<
Size
>&
modal
) {
87
if
(
modal
.
size
() !=
order__
.
size
()) {
88
GUM_ERROR
(
InvalidArgument
,
89
"the number of elements in the order given "
90
"to K2 is not the same as the number of nodes"
);
91
}
92
bool
order_ok
=
true
;
93
for
(
const
auto
node
:
order__
) {
94
if
(
node
>=
order__
.
size
()) {
95
order_ok
=
false
;
96
break
;
97
}
98
}
99
if
(!
order_ok
) {
100
GUM_ERROR
(
InvalidArgument
,
101
"there exist at least one node in the order "
102
"given to K2 that has no domain size"
);
103
}
104
}
105
106
/// returns the approximation policy of the learning algorithm
107
INLINE
ApproximationScheme
&
K2
::
approximationScheme
() {
108
return
GreedyHillClimbing
::
approximationScheme
();
109
}
110
111
}
/* namespace learning */
112
113
}
/* namespace gum */
114
115
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669
gum::learning::genericBNLearner::Database::Database
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
Definition:
genericBNLearner_tpl.h:31