aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
KTBNGenerator.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
54#ifndef GUM_KTBN_GENERATOR_H
55#define GUM_KTBN_GENERATOR_H
56
57#include <string>
58#include <vector>
59
60#include <agrum/agrum.h>
61
62#include <agrum/KTBN/KTBN.h>
63
65
66namespace gum {
67
113 template < GUM_Numeric GUM_SCALAR >
115 public:
116 // ===========================================================================
118 // ===========================================================================
120
133 explicit KTBNGenerator(Size k,
134 Size nbTemporal,
135 Size nbAtemporal = 0,
136 Size maxArcs = 0,
137 Size maxModality = 2);
138
141
143 // ===========================================================================
145 // ===========================================================================
147
150 void generateKTBN(KTBN< GUM_SCALAR >& out);
151
153 KTBN< GUM_SCALAR > generate();
154
156 // ===========================================================================
158 // ===========================================================================
160
165
168 KTBNGenerator< GUM_SCALAR >& setDomainRange(Size minModality, Size maxModality);
169
174
179
184
188 KTBNGenerator< GUM_SCALAR >& setNamePrefixes(const std::string& temporal,
189 const std::string& atemporal);
190
192 // ===========================================================================
194 // ===========================================================================
196
198 Size k() const;
199
203 Size nbLegalArcs() const;
204
206
207 private:
209 struct _Arc_ {
210 std::string tailBase;
212 std::string headBase;
214 };
215
223 double _density_{0.1};
225 bool _generateCPTs_{true};
226
227 std::string _temporalPrefix_{"X"};
228 std::string _atemporalPrefix_{"A"};
229
233 std::vector< _Arc_ > _legalArcs_(const std::vector< std::string >& temporal,
234 const std::vector< std::string >& atemporal,
235 const std::vector< Size >& tRank,
236 const std::vector< Size >& aRank) const;
237
240 template < typename T >
241 static void _shuffle_(std::vector< T >& v);
242 };
243
244#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
245 extern template class GUM_PUBLIC_KTBN KTBNGenerator< double >;
246#endif
247
248} // namespace gum
249
251
252#endif /* GUM_KTBN_GENERATOR_H */
Template implementation of gum::KTBNGenerator.
Class representing k-order dynamic Bayesian networks (k-DBN).
KTBNGenerator< GUM_SCALAR > & setMaxParents(Size maxParents)
Caps the number of parents of any node, which bounds CPT size. 0 (default) means unlimited — a dense ...
KTBN< GUM_SCALAR > generate()
Same, returning the model by value.
KTBNGenerator(Size k, Size nbTemporal, Size nbAtemporal=0, Size maxArcs=0, Size maxModality=2)
Constructor.
std::string _atemporalPrefix_
KTBNGenerator< GUM_SCALAR > & setGenerateCPTs(bool on)
Whether to fill the CPTs with random values (default true). When false only the structure is drawn an...
void generateKTBN(KTBN< GUM_SCALAR > &out)
Fills out with a freshly drawn model (its previous content is discarded). Seed it with gum::initRando...
static void _shuffle_(std::vector< T > &v)
Fisher-Yates through gum::randomValue, so gum::initRandom() alone makes a whole generation reproducib...
KTBNGenerator< GUM_SCALAR > & setDensity(double density)
Fraction of the legal arc set to draw, in . Ignored when a non-zero maxArcs was given to the construc...
KTBNGenerator< GUM_SCALAR > & setDomainRange(Size minModality, Size maxModality)
Domain sizes are drawn uniformly in .
std::string _temporalPrefix_
std::vector< _Arc_ > _legalArcs_(const std::vector< std::string > &temporal, const std::vector< std::string > &atemporal, const std::vector< Size > &tRank, const std::vector< Size > &aRank) const
Every arc the k-DBN's rules allow, with the two cycle-prone families (lag 0, atemporal→atemporal) alr...
KTBNGenerator< GUM_SCALAR > & setNamePrefixes(const std::string &temporal, const std::string &atemporal)
Name prefixes; variables are prefix0, prefix1, … Defaults are "X" (temporal) and "A" (atemporal).
KTBNGenerator< GUM_SCALAR > & setGuaranteeOrder(bool on)
Force one arc of lag into the kernel slice, so the model's effective order equals (see the class do...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
template class GUM_PUBLIC_KTBN KTBNGenerator< double >
A (tail, head) endpoint pair, each as (base, slice).
Contains useful methods for random stuff.