aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
IBayesNetGenerator.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 Interface-like class for generating Bayesian networks.
24  *
25  * @author Christophe GONZALES(@AMU), Pierre-Henri WUILLEMIN(@LIP6), Lionel TORTI
26  * and Ariele-Paolo MAESANO
27  */
28 #ifndef GUM_I_BAYES_NET_GENERATOR_H
29 #define GUM_I_BAYES_NET_GENERATOR_H
30 
31 #include <climits>
32 #include <cstdio>
33 #include <cstdlib>
34 #include <iostream>
35 #include <vector>
36 
37 #include <agrum/BN/BayesNet.h>
38 #include <agrum/BN/generator/simpleCPTGenerator.h>
39 #include <agrum/agrum.h>
40 
41 #include <agrum/tools/variables/labelizedVariable.h>
42 
43 #include <agrum/BN/algorithms/divergence/BNdistance.h>
44 
45 namespace gum {
46 
47  /**
48  * @class IBayesNetGenerator
49  * @headerfile IBayesNetGenerator.h <agrum/BN/generator/IBayesNetGenerator.h>
50  * @brief Class for generating Bayesian networks.
51  * @ingroup bn_generator
52  *
53  * This class is the abstract class for randomly generating a bayesian
54  * network given three parameters: the number of nodes the wanted maximum
55  * number of arcs and the maximum number of modality for each node.
56  *
57  * @warning Be Careful when entering the parameters, high Values may cause
58  * the density of the Bayesian network to be too high resulting in the
59  * failure of most of the inference Methods.
60  */
61  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
62  class IBayesNetGenerator: public ICPTGenerator< GUM_SCALAR > {
63  public:
64  // ############################################################################
65  /// @name Constructors / Destructor
66  // ############################################################################
67  /// @{
68  /**
69  * constructor.
70  * Use by default the SimpleCPTGenerator for generating the BNs CPT.
71  * @param nbrNodes The number of nodes in the generated BN.
72  * @param maxArcs The number of maximum number of arcs imposed on the
73  * generator
74  * @param maxModality Each DRV has from 2 to maxModality modalities
75  * @throws OperationNotAllowed if the number of maximum arcs does not allow
76  * the
77  * generation of a connexe graph maxArcs < nbrNodes -1, is too big maxArcs >
78  * nbrNodes *(nbrNodes -1) /2 and if the maximum of modality is lower than
79  * 2.
80  */
81  IBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality);
82 
83  /**
84  * Destructor.
85  */
86 
87  virtual ~IBayesNetGenerator();
88  /// @}
89 
90  // ############################################################################
91  /// @name BN generation methods
92  // ############################################################################
93  /// @{
94 
95  /**
96  * Virtual function that Generates a Bayesian networks.
97  * @param bayesNet Bayesian network to be completed after initialisation
98  * @return null but modify inputed empty Bayesian network
99  */
100 
101  virtual void generateBN(BayesNet< GUM_SCALAR >& bayesNet) = 0;
102 
103  /**
104  * function that insert random values in the CPT of each nodes according to
105  * the
106  * @a CPTGenerator.
107  * @return null but modify inputed empty Bayesian network
108  */
109 
110  void fillCPT();
111 
112  /// @}
113  // ===========================================================================
114  /// @name Variable manipulation methods.
115  // ===========================================================================
116  /// @{
117  /**
118  * @name Getters
119  **/
120 
121  /**
122  * Return a constant reference to the number of nodes imposed on the
123  * IBayesNetGenerator.
124  */
125  Size nbrNodes() const;
126 
127  /**
128  * Return a constant reference to the maximum number of arcs imposed on the
129  * IBayesNetGenerator
130  */
131  Size maxArcs() const;
132 
133  /**
134  * Return a constant reference to the maximum modality imposed on the
135  * IBayesNetGenerator
136  */
137  Size maxModality() const;
138 
139  /**
140  * @name Setters
141  **/
142 
143  // void setcptGenerator(CPTGenerator * cptGenerator);
144  /**
145  * Modifies the value of the number of nodes imposed on the BayesGenerator
146  */
147  void setNbrNodes(Size nbrNodes);
148 
149  /**
150  * Modifies the value of the number of nodes imposed on the BayesGenerator
151  */
152  void setMaxArcs(Size maxArcs);
153 
154  /**
155  * Modifies the value of the number of nodes imposed on the BayesGenerator
156  */
157  void setMaxModality(Size maxModality);
158 
159  /// @}
160  protected:
161  // The Conditional Probability Table generator
162  // CPTGenerator * cptGenerator_;
163  Size nbrNodes_;
164  Size maxArcs_;
165  Size maxModality_;
166  BayesNet< GUM_SCALAR > bayesNet_;
167  };
168 
169 } /* namespace gum */
170 
171 #include <agrum/BN/generator/IBayesNetGenerator_tpl.h>
172 
173 #endif /* GUM_I_BAYES_NET_GENERATOR_H */