aGrUM  0.16.0
IBayesNetGenerator_tpl.h
Go to the documentation of this file.
1 
33 
34 namespace gum {
35 
36  // Default constructor.
37  // Use the SimpleCPTGenerator for generating the BNs CPT.
38  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
40  Size nbrNodes, Size maxArcs, Size maxModality) :
41  _bayesNet() {
42  GUM_CONSTRUCTOR(IBayesNetGenerator);
44 
45  if (maxArcs < nbrNodes - 1 || maxArcs > (nbrNodes * (nbrNodes - 1)) / 2)
46  GUM_ERROR(OperationNotAllowed, " maxArcs value not possible ");
47 
48  if (maxModality < 2)
50  " maxModality must be at least equal to two ");
51 
52  _maxArcs = maxArcs;
54  }
55 
56  // Destructor.
57  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
59  GUM_DESTRUCTOR(IBayesNetGenerator);
60  // delete _cptGenerator;
61  }
62 
63  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
65  for (auto node : _bayesNet.nodes())
66  this->generateCPT(_bayesNet.cpt(node).pos(_bayesNet.variable(node)),
67  _bayesNet.cpt(node)); // TODO ASSERT THE LINE
68  }
69 
70  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
71  INLINE Size
73  return _maxModality;
74  }
75 
76  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
78  return _nbrNodes;
79  }
80 
81  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
83  return _maxArcs;
84  }
85 
86  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
88  Size maxModality) {
89  if (maxModality < 2)
91  " maxModality must be at least equal to two ");
92 
94  }
95  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
96  INLINE void
98  if ((_maxArcs < nbrNodes - 1) || (_maxArcs > (nbrNodes * (nbrNodes - 1)) / 2))
99  GUM_ERROR(OperationNotAllowed, " nbrNodes value not possible ");
100 
102  }
103 
104  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
105  INLINE void
107  if (maxArcs < _nbrNodes - 1 || maxArcs > (_nbrNodes * (_nbrNodes - 1)) / 2)
108  GUM_ERROR(OperationNotAllowed, " maxArcs value not possible ");
109 
110  _maxArcs = maxArcs;
111  }
112 
113  // Generates a bayesian network using floats.
114  // @param nbrNodes The number of nodes in the generated BN.
115  // @param density The probability of adding an arc between two nodes.
116  // @return A BNs randomly generated.
117 
118 } /* 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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:48
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size maxModality() const
Return a constant reference to the maximum modality imposed on the IBayesNetGenerator.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
void setMaxModality(Size maxModality)
Modifies the value of the number of nodes imposed on the BayesGenerator.