aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
maxInducedWidthMCBayesNetGenerator.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 Class for generating Bayesian networks using MC algorithm
24  * cf. [Ide and Cozman, 2002]
25  *
26  * @author Ariele MAESANO & Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef GUM_MAX_INDUCED_WIDTH_MC_BAYES_NET_GENERATOR
30 #define GUM_MAX_INDUCED_WIDTH_MC_BAYES_NET_GENERATOR
31 
32 #include <agrum/agrum.h>
33 
34 #include <fstream>
35 #include <iostream>
36 #include <set>
37 #include <vector>
38 
39 #include <sstream>
40 
41 #ifdef HAVE_DIRENT_H
42 # include <dirent.h>
43 #else
44 # include <agrum/tools/core/mvsc/dirent.h>
45 #endif
46 
47 #include <agrum/BN/BayesNet.h>
48 #include <agrum/BN/generator/MCBayesNetGenerator.h>
49 #include <agrum/BN/generator/simpleCPTDisturber.h>
50 #include <agrum/BN/generator/simpleCPTGenerator.h>
51 #include <agrum/tools/variables/labelizedVariable.h>
52 
53 namespace gum {
54  /**
55  * @class MaxInducedWidthMCBayesNetGenerator
56  *maxInducedWidthMCBayesNetGenerator.h
57  *<agrum/BN/generator/SimpleMCayesNetGenerator.h>
58  * @brief Class for generating Bayesian networks with Markov chains.
59  * @ingroup bn_generator
60  *
61  * This class is inherited from MCBayesNetGenerator and is an example of
62  *Markov
63  *Chain Bayesian network Generator that can be implemented.
64  * Here a constraint is added which is the maximum number of parents that
65  *nodes can
66  *have.
67  * @warning Be careful when entering the parameters, high Values may cause
68  *the
69  *density of the Bayesian network to be too high
70  * resulting in the failure of most of the inference Methods.
71  * */
72  template < typename GUM_SCALAR,
73  template < typename > class ICPTGenerator = SimpleCPTGenerator,
74  template < typename > class ICPTDisturber = SimpleCPTDisturber >
75  class MaxInducedWidthMCBayesNetGenerator:
76  public MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber > {
77  public:
78  // ############################################################################
79  /// @name Constructors / Destructor
80  // ############################################################################
81  /// @{
82 
83  /**
84  * Constructor.
85  * Use by default the SimpleCPTGenerator for generating the BNs CPT
86  * and the SimpleCPTDisturber to tweak the CPT when the dimension of the
87  * table
88  * changes.
89  * @param nbrNodes The number of nodes in the generated BN.
90  * @param maxArcs The maximum number of Arcs.
91  * @param maxModality Each DRV has from 2 to maxModality modalities
92  * @param maxInducedWidth The number of maximum variable allow in the cliques
93  * of
94  * the junction tree of the Bayesian network.
95  * @param iteration The number of iterations wanted to repeat the algorithm
96  * @param p probability for the change of the state (see \ref probability_p_q
97  * "use
98  * of p and q" )
99  * @param q probability for the change of the state (see \ref probability_p_q
100  * "use
101  * of p and q" )
102  */
103  MaxInducedWidthMCBayesNetGenerator(Size nbrNodes,
104  Size maxArcs,
105  Size maxModality = 2,
106  Size maxInducedWidth = 3,
107  Idx iteration = 5000,
108  Idx p = 30,
109  Idx q = 40);
110 
111  /**
112  * Constructor.
113  * Use by default the SimpleCPTGenerator for generating the BNs CPT
114  * and the SimpleCPTDisturber to tweak the CPT when the dimension of the
115  * table
116  * changes.
117  * @param bayesNet the IBayesNet used as reference to fill the parameters
118  * nbrNodes, maxArcs and maxModality
119  * @param maxInducedWidth The number of maximum variable allow in the cliques
120  * of
121  * the junction tree of the Bayesian network.
122  * @param iteration The number of iterations wanted to repeat the algorithm
123  * @param p probability for the change of the state (see \ref probability_p_q
124  * "use
125  * of p and q" )
126  * @param q probability for the change of the state (see \ref probability_p_q
127  * "use
128  * of p and q" )
129  */
130  explicit MaxInducedWidthMCBayesNetGenerator(BayesNet< GUM_SCALAR > bayesNet,
131  Size maxInducedWidth = 3,
132  Idx iteration = 5000,
133  Idx p = 30,
134  Idx q = 40);
135 
136  /**
137  * Destructor.
138  */
139  ~MaxInducedWidthMCBayesNetGenerator() final;
140 
141  /// @}
142 
143  // ############################################################################
144  /// @name Getters and Setters
145  // ############################################################################
146  /// @{
147  ///@name Getters
148 
149  /**
150  * Return a constant reference to the number of maximum parents imposed on
151  * the
152  * Markov Chain BayesNetGenerator.
153  */
154  Size maxlog10InducedWidth() const;
155 
156  ///@name Setters
157  /**
158  * Modifies the value of the number of maximum parents imposed on the
159  * BayesNetGenerator
160  */
161  void setMaxlog10InducedWidth(Size maxlog10InducedWidth);
162  /// @}
163 
164  protected:
165  Size maxlog10InducedWidth_;
166 
167  private:
168  /**
169  * function to holding the the specification wanted for the Bayesian markov.
170  * @return boolean state that verify the conditions
171  */
172 
173  bool _checkConditions_() final;
174  };
175 
176 
177 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
178  extern template class MaxInducedWidthMCBayesNetGenerator< double >;
179 #endif
180 
181 } /*namespace gum*/
182 
183 #include <agrum/BN/generator/maxInducedWidthMCBayesNetGenerator_tpl.h>
184 #endif // MCBAYESNETGENERATOR