aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
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
52
53namespace 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 >
66 Size maxInducedWidth,
68 Idx p,
69 Idx q) :
71 if (maxInducedWidth == 0)
73 "maxInducedWidth must be at least equal "
74 "to 1 to have a connexe graph");
75
76 maxlog10InducedWidth_ = maxInducedWidth;
78 }
79
80 template < GUM_Numeric GUM_SCALAR,
81 template < typename > class ICPTGenerator,
82 template < typename > class ICPTDisturber >
84 MaxInducedWidthMCBayesNetGenerator(BayesNet< GUM_SCALAR > bayesNet,
85 Size maxInducedWidth,
87 Idx p,
88 Idx q) : MCBG(bayesNet, iteration, p, q) {
89 maxlog10InducedWidth_ = maxInducedWidth;
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 >
116
117 template < GUM_Numeric GUM_SCALAR,
118 template < typename > class ICPTGenerator,
119 template < typename > class ICPTDisturber >
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 >
143
144 template < GUM_Numeric GUM_SCALAR,
145 template < typename > class ICPTGenerator,
146 template < typename > class ICPTDisturber >
156} /* namespace gum */
The default triangulation algorithm used by aGrUM.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
MaxInducedWidthMCBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality=2, Size maxInducedWidth=3, Idx iteration=NB_INIT_ITERATIONS, Idx p=30, Idx q=40)
Constructor.
bool _checkConditions_() final
function to holding the specification wanted for the Bayesian network.
void setMaxlog10InducedWidth(Size maxlog10InducedWidth)
Modifies the value of the number of maximum parents imposed on the BayesNetGenerator.
Size maxlog10InducedWidth() const
Return a constant reference to the number of maximum parents imposed on the Markov Chain BayesNetGene...
Exception : operation not allowed.
double maxLog10CliqueDomainSize()
returns the max of log10DomainSize of the cliques in the junction tree.
Complete concept for GUM_SCALAR template parameter.
Definition concepts.h:148
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Class for generating Bayesian networks using MC algorithm cf.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46