aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
maxInducedWidthMCBayesNetGenerator_tpl.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 Source implementation of MaxInducedWidthMCBayesNetGenerator
24
*
25
* @author Pierre-Henri WUILLEMIN(@LIP6) and Ariele Maesano
26
*
27
*/
28
29
#
include
<
agrum
/
BN
/
generator
/
maxInducedWidthMCBayesNetGenerator
.
h
>
30
31
namespace
gum
{
32
#
ifdef
_MSC_VER
33
#
define
MCBG
MCBayesNetGenerator
34
#
define
IBNG
IBayesNetGenerator
35
#
else
36
#
define
MCBG
MCBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
,
ICPTDisturber
>
37
#
define
IBNG
IBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
>
38
#
endif
39
// Default constructor.
40
// Use the SimpleCPTGenerator for generating the BNs CPT.
41
template
<
typename
GUM_SCALAR,
42
template
<
typename
>
43
class
ICPTGenerator,
44
template
<
typename
>
45
class
ICPTDisturber >
46
INLINE MaxInducedWidthMCBayesNetGenerator<
47
GUM_SCALAR
,
48
ICPTGenerator
,
49
ICPTDisturber
>::
MaxInducedWidthMCBayesNetGenerator
(
Size
nbrNodes
,
50
Size
maxArcs
,
51
Size
maxModality
,
52
Size
maxInducedWidth
,
53
Idx
iteration
,
54
Idx
p
,
55
Idx
q
) :
56
MCBG
(
nbrNodes
,
maxArcs
,
maxModality
,
iteration
,
p
,
q
) {
57
if
(
maxInducedWidth
== 0)
58
GUM_ERROR
(
OperationNotAllowed
,
59
"maxInducedWidth must be at least equal "
60
"to 1 to have a connexe graph"
);
61
62
maxlog10InducedWidth_
=
maxInducedWidth
;
63
GUM_CONSTRUCTOR
(
MaxInducedWidthMCBayesNetGenerator
);
64
}
65
66
template
<
typename
GUM_SCALAR
,
67
template
<
typename
>
68
class
ICPTGenerator
,
69
template
<
typename
>
70
class
ICPTDisturber
>
71
INLINE
MaxInducedWidthMCBayesNetGenerator
<
GUM_SCALAR
,
72
ICPTGenerator
,
73
ICPTDisturber
>::
74
MaxInducedWidthMCBayesNetGenerator
(
BayesNet
<
GUM_SCALAR
>
bayesNet
,
75
Size
maxInducedWidth
,
76
Idx
iteration
,
77
Idx
p
,
78
Idx
q
) :
79
MCBG
(
bayesNet
,
iteration
,
p
,
q
) {
80
maxlog10InducedWidth_
=
maxInducedWidth
;
81
GUM_CONSTRUCTOR
(
MaxInducedWidthMCBayesNetGenerator
);
82
}
83
84
// Use this constructor if you want to use a different policy for generating
85
// CPT than the default one.
86
// The cptGenerator will be erased when the destructor is called.
87
// @param cptGenerator The policy used to generate CPT.
88
/*template<typename GUM_SCALAR, template<class> class ICPTGenerator,
89
template<class> class ICPDisturber>
90
MaxInducedWidthMCBayesNetGenerator<GUM_SCALAR,ICPTGenerator,ICPTDisturber>::MaxInducedWidthMCBayesNetGenerator(
91
CPTGenerator* cptGenerator,Size nbrNodes, Idx p,Idx q,Idx iteration,float
92
maxDensity , Size max_modality, Size maxInducedWidth):
93
MCBG<GUM_SCALAR,ICPTGenerator,ICPTDisturber>(cptGenerator,
94
nbrNodes,p,q,iteration, maxDensity,max_modality, maxInducedWidth){
95
GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
96
}*/
97
98
// Destructor.
99
template
<
typename
GUM_SCALAR
,
100
template
<
typename
>
101
class
ICPTGenerator
,
102
template
<
typename
>
103
class
ICPTDisturber
>
104
INLINE
MaxInducedWidthMCBayesNetGenerator
<
105
GUM_SCALAR
,
106
ICPTGenerator
,
107
ICPTDisturber
>::~
MaxInducedWidthMCBayesNetGenerator
() {
108
GUM_DESTRUCTOR
(
MaxInducedWidthMCBayesNetGenerator
);
109
// delete BayesNetGenerator<GUM_SCALAR>::cptGenerator_;
110
}
111
112
template
<
typename
GUM_SCALAR
,
113
template
<
typename
>
114
class
ICPTGenerator
,
115
template
<
typename
>
116
class
ICPTDisturber
>
117
bool
MaxInducedWidthMCBayesNetGenerator
<
GUM_SCALAR
,
118
ICPTGenerator
,
119
ICPTDisturber
>::
checkConditions__
() {
120
NodeProperty
<
Size
>
modalitiesMap__
;
121
122
for
(
auto
node
:
this
->
bayesNet_
.
nodes
())
123
modalitiesMap__
.
insert
(
node
,
this
->
bayesNet_
.
variable
(
node
).
domainSize
());
124
125
DefaultTriangulation
tri
(&(
this
->
bayesNet_
.
moralGraph
()), &
modalitiesMap__
);
126
127
if
(
tri
.
maxLog10CliqueDomainSize
() >
maxlog10InducedWidth_
)
return
false
;
128
129
return
MCBG
::
checkConditions__
();
130
}
131
132
template
<
typename
GUM_SCALAR
,
133
template
<
typename
>
134
class
ICPTGenerator
,
135
template
<
typename
>
136
class
ICPTDisturber
>
137
INLINE
Size
138
MaxInducedWidthMCBayesNetGenerator
<
GUM_SCALAR
,
139
ICPTGenerator
,
140
ICPTDisturber
>::
maxlog10InducedWidth
()
141
const
{
142
return
maxlog10InducedWidth_
;
143
}
144
template
<
typename
GUM_SCALAR
,
145
template
<
typename
>
146
class
ICPTGenerator
,
147
template
<
typename
>
148
class
ICPTDisturber
>
149
INLINE
void
MaxInducedWidthMCBayesNetGenerator
<
150
GUM_SCALAR
,
151
ICPTGenerator
,
152
ICPTDisturber
>::
setMaxlog10InducedWidth
(
Size
maxlog10InducedWidth
) {
153
if
(
maxlog10InducedWidth
== 0)
154
GUM_ERROR
(
OperationNotAllowed
,
155
"maxInducedWidth must be at least equal "
156
"to 1 to have a connexe graph"
);
157
158
maxlog10InducedWidth_
=
maxlog10InducedWidth
;
159
}
160
}
/* namespace gum */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669
MCBG
#define MCBG
Definition:
maxInducedWidthMCBayesNetGenerator_tpl.h:36