aGrUM  0.14.2
IBayesNetGenerator_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
30 
31 namespace gum {
32 
33  // Default constructor.
34  // Use the SimpleCPTGenerator for generating the BNs CPT.
35  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
37  Size nbrNodes, Size maxArcs, Size maxModality) :
38  _bayesNet() {
39  GUM_CONSTRUCTOR(IBayesNetGenerator);
41 
42  if (maxArcs < nbrNodes - 1 || maxArcs > (nbrNodes * (nbrNodes - 1)) / 2)
43  GUM_ERROR(OperationNotAllowed, " maxArcs value not possible ");
44 
45  if (maxModality < 2)
47  " maxModality must be at least equal to two ");
48 
49  _maxArcs = maxArcs;
51  }
52 
53  // Destructor.
54  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
56  GUM_DESTRUCTOR(IBayesNetGenerator);
57  // delete _cptGenerator;
58  }
59 
60  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
62  for (auto node : _bayesNet.nodes())
63  this->generateCPT(_bayesNet.cpt(node).pos(_bayesNet.variable(node)),
64  _bayesNet.cpt(node)); // TODO ASSERT THE LINE
65  }
66 
67  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
68  INLINE Size
70  return _maxModality;
71  }
72 
73  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
75  return _nbrNodes;
76  }
77 
78  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
80  return _maxArcs;
81  }
82 
83  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
85  Size maxModality) {
86  if (maxModality < 2)
88  " maxModality must be at least equal to two ");
89 
91  }
92  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
93  INLINE void
95  if ((_maxArcs < nbrNodes - 1) || (_maxArcs > (nbrNodes * (nbrNodes - 1)) / 2))
96  GUM_ERROR(OperationNotAllowed, " nbrNodes value not possible ");
97 
99  }
100 
101  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
102  INLINE void
104  if (maxArcs < _nbrNodes - 1 || maxArcs > (_nbrNodes * (_nbrNodes - 1)) / 2)
105  GUM_ERROR(OperationNotAllowed, " maxArcs value not possible ");
106 
107  _maxArcs = maxArcs;
108  }
109 
110  // Generates a bayesian network using floats.
111  // @param nbrNodes The number of nodes in the generated BN.
112  // @param density The probability of adding an arc between two nodes.
113  // @return A BNs randomly generated.
114 
115 } /* namespace gum */
void fillCPT()
function that insert random values in the CPT of each nodes according to the CPTGenerator.
Class for generating bayesian networks.
IBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality)
constructor.
void setNbrNodes(Size nbrNodes)
Modifies the value of the number of nodes imposed on the BayesGenerator.
Size nbrNodes() const
Return a constant reference to the number of nodes imposed on the IBayesNetGenerator.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
void setMaxArcs(Size maxArcs)
Modifies the value of the number of nodes imposed on the BayesGenerator.
BayesNet< GUM_SCALAR > _bayesNet
Size maxArcs() const
Return a constant reference to the maximum number of arcs imposed on the IBayesNetGenerator.
virtual ~IBayesNetGenerator()
Destructor.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Interface-like class for generating bayesian networks.
Size maxModality() const
Return a constant reference to the maximum modality imposed on the IBayesNetGenerator.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
void setMaxModality(Size maxModality)
Modifies the value of the number of nodes imposed on the BayesGenerator.