aGrUM 2.3.2
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-2025 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-2025 *
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#pragma once
41
42
49
51
52namespace gum {
53#define MCBG MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >
54#define IBNG IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >
55
56 // Default constructor.
57 // Use the SimpleCPTGenerator for generating the BNs CPT.
58 template < typename GUM_SCALAR,
59 template < typename > class ICPTGenerator,
60 template < typename > class ICPTDisturber >
65 Size maxInducedWidth,
67 Idx p,
68 Idx q) :
70 if (maxInducedWidth == 0)
72 "maxInducedWidth must be at least equal "
73 "to 1 to have a connexe graph");
74
75 maxlog10InducedWidth_ = maxInducedWidth;
77 }
78
79 template < typename GUM_SCALAR,
80 template < typename > class ICPTGenerator,
81 template < typename > class ICPTDisturber >
83 MaxInducedWidthMCBayesNetGenerator(BayesNet< GUM_SCALAR > bayesNet,
84 Size maxInducedWidth,
86 Idx p,
87 Idx q) : MCBG(bayesNet, iteration, p, q) {
88 maxlog10InducedWidth_ = maxInducedWidth;
90 }
91
92 // Use this constructor if you want to use a different policy for generating
93 // CPT than the default one.
94 // The cptGenerator will be erased when the destructor is called.
95 // @param cptGenerator The policy used to generate CPT.
96 /*template<typename GUM_SCALAR, template<class> class ICPTGenerator,
97 template<class> class ICPDisturber>
98 MaxInducedWidthMCBayesNetGenerator<GUM_SCALAR,ICPTGenerator,ICPTDisturber>::MaxInducedWidthMCBayesNetGenerator(
99 CPTGenerator* cptGenerator,Size nbrNodes, Idx p,Idx q,Idx iteration,float
100 maxDensity , Size max_modality, Size maxInducedWidth):
101 MCBG<GUM_SCALAR,ICPTGenerator,ICPTDisturber>(cptGenerator,
102 nbrNodes,p,q,iteration, maxDensity,max_modality, maxInducedWidth){
103 GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
104 }*/
105
106 // Destructor.
107 template < typename GUM_SCALAR,
108 template < typename > class ICPTGenerator,
109 template < typename > class ICPTDisturber >
113 // delete BayesNetGenerator<GUM_SCALAR>::cptGenerator_;
114 }
115
116 template < typename GUM_SCALAR,
117 template < typename > class ICPTGenerator,
118 template < typename > class ICPTDisturber >
121 NodeProperty< Size > _modalitiesMap_;
122
123 for (auto node: this->dag_.nodes())
124 _modalitiesMap_.insert(node, 2); //@todo take modalities into account...by randomly add a
125 //_modalitiesMap_ for instance ...
126
127 const auto moralg = this->dag_.moralGraph();
128 DefaultTriangulation tri(&moralg, &_modalitiesMap_);
129
130 if (tri.maxLog10CliqueDomainSize() > maxlog10InducedWidth_) return false;
131
132 return MCBG::_checkConditions_();
133 }
134
135 template < typename GUM_SCALAR,
136 template < typename > class ICPTGenerator,
137 template < typename > class ICPTDisturber >
142
143 template < typename GUM_SCALAR,
144 template < typename > class ICPTGenerator,
145 template < typename > class ICPTDisturber >
155} /* 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.
Size maxlog10InducedWidth() const
Return a constant reference to the number of maximum parents imposed on the Markov Chain BayesNetGene...
void setMaxlog10InducedWidth(Size maxlog10InducedWidth)
Modifies the value of the number of maximum parents imposed on the BayesNetGenerator.
bool _checkConditions_() final
function to holding the the specification wanted for the Bayesian markov.
MaxInducedWidthMCBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality=2, Size maxInducedWidth=3, Idx iteration=NB_INIT_ITERATIONS, Idx p=30, Idx q=40)
Constructor.
Exception : operation not allowed.
double maxLog10CliqueDomainSize()
returns the max of log10DomainSize of the cliques in the junction tree.
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
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