aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
IBayesNetGenerator_tpl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright (c) 2005-2021 by 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 Source implementation of IBayesNetGenerator
24
*
25
* @author Christophe GONZALES(@AMU), Pierre-Henri WUILLEMIN(@LIP6), Lionel TORTI
26
*and Ariele-Paolo MAESANO
27
*
28
*/
29
30
#
include
<
agrum
/
BN
/
generator
/
IBayesNetGenerator
.
h
>
31
32
namespace
gum
{
33
34
// Default constructor.
35
// Use the SimpleCPTGenerator for generating the BNs CPT.
36
template
<
typename
GUM_SCALAR,
template
<
typename
>
class
ICPTGenerator >
37
INLINE IBayesNetGenerator<
GUM_SCALAR
,
ICPTGenerator
>::
IBayesNetGenerator
(
Size
nbrNodes
,
38
Size
maxArcs
,
39
Size
maxModality
) :
40
bayesNet_
() {
41
GUM_CONSTRUCTOR
(
IBayesNetGenerator
);
42
nbrNodes_
=
nbrNodes
;
43
44
if
(
maxArcs
<
nbrNodes
- 1 ||
maxArcs
> (
nbrNodes
* (
nbrNodes
- 1)) / 2)
45
GUM_ERROR
(
OperationNotAllowed
,
" maxArcs value not possible "
)
46
47
if
(
maxModality
< 2)
48
GUM_ERROR
(
OperationNotAllowed
,
" maxModality must be at least equal to two "
)
49
50
maxArcs_
=
maxArcs
;
51
maxModality_
=
maxModality
;
52
}
53
54
// Destructor.
55
template
<
typename
GUM_SCALAR
,
template
<
typename
>
class
ICPTGenerator
>
56
INLINE
IBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
>::~
IBayesNetGenerator
() {
57
GUM_DESTRUCTOR
(
IBayesNetGenerator
);
58
// delete cptGenerator_;
59
}
60
61
template
<
typename
GUM_SCALAR
,
template
<
typename
>
class
ICPTGenerator
>
62
void
IBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
>::
fillCPT
() {
63
for
(
auto
node
:
bayesNet_
.
nodes
())
64
this
->
generateCPT
(
bayesNet_
.
cpt
(
node
).
pos
(
bayesNet_
.
variable
(
node
)),
bayesNet_
.
cpt
(
node
));
65
}
66
67
template
<
typename
GUM_SCALAR
,
template
<
typename
>
class
ICPTGenerator
>
68
INLINE
Size
IBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
>::
maxModality
()
const
{
69
return
maxModality_
;
70
}
71
72
template
<
typename
GUM_SCALAR
,
template
<
typename
>
class
ICPTGenerator
>
73
INLINE
Size
IBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
>::
nbrNodes
()
const
{
74
return
nbrNodes_
;
75
}
76
77
template
<
typename
GUM_SCALAR
,
template
<
typename
>
class
ICPTGenerator
>
78
INLINE
Size
IBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
>::
maxArcs
()
const
{
79
return
maxArcs_
;
80
}
81
82
template
<
typename
GUM_SCALAR
,
template
<
typename
>
class
ICPTGenerator
>
83
INLINE
void
IBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
>::
setMaxModality
(
Size
maxModality
) {
84
if
(
maxModality
< 2)
85
GUM_ERROR
(
OperationNotAllowed
,
" maxModality must be at least equal to two "
)
86
87
maxModality_
=
maxModality
;
88
}
89
template
<
typename
GUM_SCALAR
,
template
<
typename
>
class
ICPTGenerator
>
90
INLINE
void
IBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
>::
setNbrNodes
(
Size
nbrNodes
) {
91
if
((
maxArcs_
<
nbrNodes
- 1) || (
maxArcs_
> (
nbrNodes
* (
nbrNodes
- 1)) / 2))
92
GUM_ERROR
(
OperationNotAllowed
,
" nbrNodes value not possible "
)
93
94
nbrNodes_
=
nbrNodes
;
95
}
96
97
template
<
typename
GUM_SCALAR
,
template
<
typename
>
class
ICPTGenerator
>
98
INLINE
void
IBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
>::
setMaxArcs
(
Size
maxArcs
) {
99
if
(
maxArcs
<
nbrNodes_
- 1 ||
maxArcs
> (
nbrNodes_
* (
nbrNodes_
- 1)) / 2)
100
GUM_ERROR
(
OperationNotAllowed
,
" maxArcs value not possible "
)
101
102
maxArcs_
=
maxArcs
;
103
}
104
105
// Generates a Bayesian network using floats.
106
// @param nbrNodes The number of nodes in the generated BN.
107
// @param density The probability of adding an arc between two nodes.
108
// @return A BNs randomly generated.
109
110
}
/* namespace gum */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643