aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
maxInducedWidthMCBayesNetGenerator_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
50
51
#include <
agrum/BN/generator/maxInducedWidthMCBayesNetGenerator.h
>
52
53
namespace
gum
{
54
#define MCBG MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >
55
#define IBNG IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >
56
57
// Default constructor.
58
// Use the SimpleCPTGenerator for generating the BNs CPT.
59
template
< GUM_Numeric GUM_SCALAR,
60
template
<
typename
>
class
ICPTGenerator,
61
template
<
typename
>
class
ICPTDisturber >
62
MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::
63
MaxInducedWidthMCBayesNetGenerator
(
Size
nbrNodes
,
64
Size
maxArcs
,
65
Size
maxModality
,
66
Size
maxInducedWidth,
67
Idx
iteration
,
68
Idx
p
,
69
Idx
q
) :
70
MCBG
(
nbrNodes
,
maxArcs
,
maxModality
,
iteration
,
p
,
q
) {
71
if
(maxInducedWidth == 0)
72
GUM_ERROR
(
OperationNotAllowed
,
73
"maxInducedWidth must be at least equal "
74
"to 1 to have a connexe graph"
);
75
76
maxlog10InducedWidth_
= maxInducedWidth;
77
GUM_CONSTRUCTOR(
MaxInducedWidthMCBayesNetGenerator
);
78
}
79
80
template
<
GUM_Numeric
GUM_SCALAR,
81
template
<
typename
>
class
ICPTGenerator,
82
template
<
typename
>
class
ICPTDisturber >
83
MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::
84
MaxInducedWidthMCBayesNetGenerator
(BayesNet< GUM_SCALAR > bayesNet,
85
Size
maxInducedWidth,
86
Idx
iteration
,
87
Idx
p
,
88
Idx
q
) :
MCBG
(bayesNet,
iteration
,
p
,
q
) {
89
maxlog10InducedWidth_
= maxInducedWidth;
90
GUM_CONSTRUCTOR(
MaxInducedWidthMCBayesNetGenerator
);
91
}
92
93
// Use this constructor if you want to use a different policy for generating
94
// CPT than the default one.
95
// The cptGenerator will be erased when the destructor is called.
96
// @param cptGenerator The policy used to generate CPT.
97
/*template<GumScalar GUM_SCALAR, template<class> class ICPTGenerator,
98
template<class> class ICPDisturber>
99
MaxInducedWidthMCBayesNetGenerator<GUM_SCALAR,ICPTGenerator,ICPTDisturber>::MaxInducedWidthMCBayesNetGenerator(
100
CPTGenerator* cptGenerator,Size nbrNodes, Idx p,Idx q,Idx iteration,float
101
maxDensity , Size max_modality, Size maxInducedWidth):
102
MCBG<GUM_SCALAR,ICPTGenerator,ICPTDisturber>(cptGenerator,
103
nbrNodes,p,q,iteration, maxDensity,max_modality, maxInducedWidth){
104
GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
105
}*/
106
107
// Destructor.
108
template
<
GUM_Numeric
GUM_SCALAR,
109
template
<
typename
>
class
ICPTGenerator,
110
template
<
typename
>
class
ICPTDisturber >
111
MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::
112
~MaxInducedWidthMCBayesNetGenerator
() {
113
GUM_DESTRUCTOR(
MaxInducedWidthMCBayesNetGenerator
);
114
// delete BayesNetGenerator<GUM_SCALAR>::cptGenerator_;
115
}
116
117
template
<
GUM_Numeric
GUM_SCALAR,
118
template
<
typename
>
class
ICPTGenerator,
119
template
<
typename
>
class
ICPTDisturber >
120
bool
MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::
121
_checkConditions_
() {
122
NodeProperty< Size >
_modalitiesMap_;
123
124
for
(
auto
node: this->
dag_
.nodes())
125
_modalitiesMap_.
insert
(node, 2);
//@todo take modalities into account...by randomly add a
126
//_modalitiesMap_ for instance ...
127
128
const
auto
moralg = this->
dag_
.moralGraph();
129
DefaultTriangulation
tri(&moralg, &_modalitiesMap_);
130
131
if
(tri.
maxLog10CliqueDomainSize
() >
maxlog10InducedWidth_
)
return
false
;
132
133
return
MCBG::_checkConditions_();
134
}
135
136
template
<
GUM_Numeric
GUM_SCALAR,
137
template
<
typename
>
class
ICPTGenerator,
138
template
<
typename
>
class
ICPTDisturber >
139
Size
MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::
140
maxlog10InducedWidth
()
const
{
141
return
maxlog10InducedWidth_
;
142
}
143
144
template
<
GUM_Numeric
GUM_SCALAR,
145
template
<
typename
>
class
ICPTGenerator,
146
template
<
typename
>
class
ICPTDisturber >
147
void
MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::
148
setMaxlog10InducedWidth
(
Size
maxlog10InducedWidth
) {
149
if
(
maxlog10InducedWidth
== 0)
150
GUM_ERROR
(
OperationNotAllowed
,
151
"maxInducedWidth must be at least equal "
152
"to 1 to have a connexe graph"
);
153
154
maxlog10InducedWidth_
=
maxlog10InducedWidth
;
155
}
156
}
/* namespace gum */
gum::DefaultTriangulation
The default triangulation algorithm used by aGrUM.
Definition
defaultTriangulation.h:81
gum::HashTable::insert
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Definition
hashTable_tpl.h:754
gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::nbrNodes
Size nbrNodes() const
Definition
IBayesNetGenerator_tpl.h:93
gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::dag_
DAG dag_
Definition
IBayesNetGenerator.h:187
gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::maxArcs
Size maxArcs() const
Definition
IBayesNetGenerator_tpl.h:98
gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::maxModality
Size maxModality() const
Definition
IBayesNetGenerator_tpl.h:88
gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::p
Idx p() const
Definition
MCBayesNetGenerator_tpl.h:603
gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::q
Idx q() const
Definition
MCBayesNetGenerator_tpl.h:610
gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::iteration
Size iteration() const
Definition
MCBayesNetGenerator_tpl.h:596
gum::MaxInducedWidthMCBayesNetGenerator::~MaxInducedWidthMCBayesNetGenerator
~MaxInducedWidthMCBayesNetGenerator() override
Destructor.
Definition
maxInducedWidthMCBayesNetGenerator_tpl.h:112
gum::MaxInducedWidthMCBayesNetGenerator::MaxInducedWidthMCBayesNetGenerator
MaxInducedWidthMCBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality=2, Size maxInducedWidth=3, Idx iteration=NB_INIT_ITERATIONS, Idx p=30, Idx q=40)
Constructor.
Definition
maxInducedWidthMCBayesNetGenerator_tpl.h:63
gum::MaxInducedWidthMCBayesNetGenerator::maxlog10InducedWidth_
Size maxlog10InducedWidth_
Definition
maxInducedWidthMCBayesNetGenerator.h:174
gum::MaxInducedWidthMCBayesNetGenerator::_checkConditions_
bool _checkConditions_() final
function to holding the specification wanted for the Bayesian network.
Definition
maxInducedWidthMCBayesNetGenerator_tpl.h:121
gum::MaxInducedWidthMCBayesNetGenerator::setMaxlog10InducedWidth
void setMaxlog10InducedWidth(Size maxlog10InducedWidth)
Modifies the value of the number of maximum parents imposed on the BayesNetGenerator.
Definition
maxInducedWidthMCBayesNetGenerator_tpl.h:148
gum::MaxInducedWidthMCBayesNetGenerator::maxlog10InducedWidth
Size maxlog10InducedWidth() const
Return a constant reference to the number of maximum parents imposed on the Markov Chain BayesNetGene...
Definition
maxInducedWidthMCBayesNetGenerator_tpl.h:140
OperationNotAllowed
Exception : operation not allowed.
gum::Triangulation::maxLog10CliqueDomainSize
double maxLog10CliqueDomainSize()
returns the max of log10DomainSize of the cliques in the junction tree.
Definition
triangulation.cpp:86
gum::GUM_Numeric
Complete concept for GUM_SCALAR template parameter.
Definition
concepts.h:148
GUM_ERROR
#define GUM_ERROR(type, msg)
Definition
exceptions.h:76
gum::Size
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition
types.h:74
gum::Idx
Size Idx
Type for indexes.
Definition
types.h:79
gum::NodeProperty
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Definition
graphElements.h:407
maxInducedWidthMCBayesNetGenerator.h
Class for generating Bayesian networks using MC algorithm cf.
MCBG
#define MCBG
Definition
maxInducedWidthMCBayesNetGenerator_tpl.h:54
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0