aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
maxInducedWidthMCBayesNetGenerator_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 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<
GUM_SCALAR
,
ICPTGenerator
,
ICPTDisturber
>::
47
MaxInducedWidthMCBayesNetGenerator
(
Size
nbrNodes
,
48
Size
maxArcs
,
49
Size
maxModality
,
50
Size
maxInducedWidth
,
51
Idx
iteration
,
52
Idx
p
,
53
Idx
q
) :
54
MCBG
(
nbrNodes
,
maxArcs
,
maxModality
,
iteration
,
p
,
q
) {
55
if
(
maxInducedWidth
== 0)
56
GUM_ERROR
(
OperationNotAllowed
,
57
"maxInducedWidth must be at least equal "
58
"to 1 to have a connexe graph"
);
59
60
maxlog10InducedWidth_
=
maxInducedWidth
;
61
GUM_CONSTRUCTOR
(
MaxInducedWidthMCBayesNetGenerator
);
62
}
63
64
template
<
typename
GUM_SCALAR
,
65
template
<
typename
>
66
class
ICPTGenerator
,
67
template
<
typename
>
68
class
ICPTDisturber
>
69
INLINE
MaxInducedWidthMCBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
,
ICPTDisturber
>::
70
MaxInducedWidthMCBayesNetGenerator
(
BayesNet
<
GUM_SCALAR
>
bayesNet
,
71
Size
maxInducedWidth
,
72
Idx
iteration
,
73
Idx
p
,
74
Idx
q
) :
75
MCBG
(
bayesNet
,
iteration
,
p
,
q
) {
76
maxlog10InducedWidth_
=
maxInducedWidth
;
77
GUM_CONSTRUCTOR
(
MaxInducedWidthMCBayesNetGenerator
);
78
}
79
80
// Use this constructor if you want to use a different policy for generating
81
// CPT than the default one.
82
// The cptGenerator will be erased when the destructor is called.
83
// @param cptGenerator The policy used to generate CPT.
84
/*template<typename GUM_SCALAR, template<class> class ICPTGenerator,
85
template<class> class ICPDisturber>
86
MaxInducedWidthMCBayesNetGenerator<GUM_SCALAR,ICPTGenerator,ICPTDisturber>::MaxInducedWidthMCBayesNetGenerator(
87
CPTGenerator* cptGenerator,Size nbrNodes, Idx p,Idx q,Idx iteration,float
88
maxDensity , Size max_modality, Size maxInducedWidth):
89
MCBG<GUM_SCALAR,ICPTGenerator,ICPTDisturber>(cptGenerator,
90
nbrNodes,p,q,iteration, maxDensity,max_modality, maxInducedWidth){
91
GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
92
}*/
93
94
// Destructor.
95
template
<
typename
GUM_SCALAR
,
96
template
<
typename
>
97
class
ICPTGenerator
,
98
template
<
typename
>
99
class
ICPTDisturber
>
100
INLINE
MaxInducedWidthMCBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
,
ICPTDisturber
>::
101
~
MaxInducedWidthMCBayesNetGenerator
() {
102
GUM_DESTRUCTOR
(
MaxInducedWidthMCBayesNetGenerator
);
103
// delete BayesNetGenerator<GUM_SCALAR>::cptGenerator_;
104
}
105
106
template
<
typename
GUM_SCALAR
,
107
template
<
typename
>
108
class
ICPTGenerator
,
109
template
<
typename
>
110
class
ICPTDisturber
>
111
bool
MaxInducedWidthMCBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
,
ICPTDisturber
>::
112
_checkConditions_
() {
113
NodeProperty
<
Size
>
_modalitiesMap_
;
114
115
for
(
auto
node
:
this
->
bayesNet_
.
nodes
())
116
_modalitiesMap_
.
insert
(
node
,
this
->
bayesNet_
.
variable
(
node
).
domainSize
());
117
118
DefaultTriangulation
tri
(&(
this
->
bayesNet_
.
moralGraph
()), &
_modalitiesMap_
);
119
120
if
(
tri
.
maxLog10CliqueDomainSize
() >
maxlog10InducedWidth_
)
return
false
;
121
122
return
MCBG
::
_checkConditions_
();
123
}
124
125
template
<
typename
GUM_SCALAR
,
126
template
<
typename
>
127
class
ICPTGenerator
,
128
template
<
typename
>
129
class
ICPTDisturber
>
130
INLINE
Size
MaxInducedWidthMCBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
,
ICPTDisturber
>::
131
maxlog10InducedWidth
()
const
{
132
return
maxlog10InducedWidth_
;
133
}
134
template
<
typename
GUM_SCALAR
,
135
template
<
typename
>
136
class
ICPTGenerator
,
137
template
<
typename
>
138
class
ICPTDisturber
>
139
INLINE
void
MaxInducedWidthMCBayesNetGenerator
<
GUM_SCALAR
,
ICPTGenerator
,
ICPTDisturber
>::
140
setMaxlog10InducedWidth
(
Size
maxlog10InducedWidth
) {
141
if
(
maxlog10InducedWidth
== 0)
142
GUM_ERROR
(
OperationNotAllowed
,
143
"maxInducedWidth must be at least equal "
144
"to 1 to have a connexe graph"
);
145
146
maxlog10InducedWidth_
=
maxlog10InducedWidth
;
147
}
148
}
/* namespace gum */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643
MCBG
#define MCBG
Definition:
maxInducedWidthMCBayesNetGenerator_tpl.h:36