aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator > Class Template Referenceabstract

Class for generating Bayesian networks. More...

#include <agrum/BN/generator/IBayesNetGenerator.h>

Inherits gum::ICPTGenerator< GUM_SCALAR >.

Collaboration diagram for gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >:

Public Member Functions

Constructors / Destructor
 IBayesNetGenerator (Size nbrNodes, Size maxArcs, Size maxModality)
 constructor.
virtual ~IBayesNetGenerator ()
 Destructor.
BN generation methods
virtual void generateBN (BayesNet< GUM_SCALAR > &bayesNet)=0
 Virtual function that Generates a Bayesian networks.
void fromDAG (BayesNet< GUM_SCALAR > &bayesNet)
 Virtual function that Generates a Bayesian networks.
void fillCPT (BayesNet< GUM_SCALAR > &bn) const
 function that insert random values in the CPT of each nodes according to the CPTGenerator.
Getters
Size nbrNodes () const
 Return a constant reference to the number of nodes imposed on the IBayesNetGenerator.
Size maxArcs () const
 Return a constant reference to the maximum number of arcs imposed on the IBayesNetGenerator.
Size maxModality () const
 Return a constant reference to the maximum modality imposed on the IBayesNetGenerator.
Setters
void setNbrNodes (Size nbrNodes)
 Modifies the value of the number of nodes imposed on the BayesGenerator.
void setMaxArcs (Size maxArcs)
 Modifies the value of the number of nodes imposed on the BayesGenerator.
void setMaxModality (Size maxModality)
 Modifies the value of the number of nodes imposed on the BayesGenerator.

Protected Attributes

Size nbrNodes_
Size maxArcs_
Size maxModality_
DAG dag_

Detailed Description

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
class gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >

Class for generating Bayesian networks.

This class is the abstract class for randomly generating a bayesian network given three parameters: the number of nodes the wanted maximum number of arcs and the maximum number of modality for each node.

Warning
Be Careful when entering the parameters, high Values may cause the density of the Bayesian network to be too high resulting in the failure of most of the inference Methods.

Definition at line 81 of file IBayesNetGenerator.h.

Constructor & Destructor Documentation

◆ IBayesNetGenerator()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
INLINE gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::IBayesNetGenerator ( Size nbrNodes,
Size maxArcs,
Size maxModality )

constructor.

Use by default the SimpleCPTGenerator for generating the BNs CPT.

Parameters
nbrNodesThe number of nodes in the generated BN.
maxArcsThe number of maximum number of arcs imposed on the generator
maxModalityEach DRV has from 2 to maxModality modalities
Exceptions
OperationNotAllowedif the number of maximum arcs does not allow the generation of a connexe graph maxArcs < nbrNodes -1, is too big maxArcs > nbrNodes *(nbrNodes -1) /2 and if the maximum of modality is lower than 2.

Definition at line 58 of file IBayesNetGenerator_tpl.h.

60 :
61 dag_() {
64
66 GUM_ERROR(OperationNotAllowed, " maxArcs value not possible ")
67
68 if (maxModality < 2) GUM_ERROR(OperationNotAllowed, " maxModality must be at least equal to 2 ")
69
72 }
Class for generating Bayesian networks.
Size maxModality() const
Return a constant reference to the maximum modality imposed on the IBayesNetGenerator.
Size nbrNodes() const
Return a constant reference to the number of nodes imposed on the IBayesNetGenerator.
Size maxArcs() const
Return a constant reference to the maximum number of arcs imposed on the IBayesNetGenerator.
IBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality)
constructor.
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References IBayesNetGenerator(), dag_, GUM_ERROR, maxArcs(), maxArcs_, maxModality(), maxModality_, nbrNodes(), and nbrNodes_.

Referenced by IBayesNetGenerator(), ~IBayesNetGenerator(), fromDAG(), and setNbrNodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~IBayesNetGenerator()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
INLINE gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::~IBayesNetGenerator ( )
virtual

Destructor.

Definition at line 76 of file IBayesNetGenerator_tpl.h.

76 {
78 // delete cptGenerator_;
79 }

References IBayesNetGenerator().

Here is the call graph for this function:

Member Function Documentation

◆ fillCPT()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
void gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::fillCPT ( BayesNet< GUM_SCALAR > & bn) const

function that insert random values in the CPT of each nodes according to the CPTGenerator.

Returns
null but modify inputed empty Bayesian network

Definition at line 82 of file IBayesNetGenerator_tpl.h.

82 {
83 for (auto node: bn.nodes())
84 this->generateCPT(bn.cpt(node).pos(bn.variable(node)), bn.cpt(node));
85 }

◆ fromDAG()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
INLINE void gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::fromDAG ( BayesNet< GUM_SCALAR > & bayesNet)

Virtual function that Generates a Bayesian networks.

Parameters
bayesNetBayesian network to be completed after initialisation
Returns
null but modify inputed empty Bayesian network

Definition at line 127 of file IBayesNetGenerator_tpl.h.

127 {
128 bn.clear();
129
130 const auto width = (this->dag_.size() >= 100) ? 3 : 2;
131 int n = 0;
132 const auto& topo = this->dag_.topologicalOrder();
133 for (const auto node: topo) {
135 strBuff << "X" << std::setfill('0') << std::setw(width) << n++;
136 bn.add(RangeVariable(strBuff.str(), "", 0, long(1 + randomValue(this->maxModality_ - 1))),
137 node);
138 }
139 bn.beginTopologyTransformation();
140 for (auto arc: this->dag_.arcs()) {
141 bn.addArc(arc.tail(), arc.head());
142 }
143 bn.endTopologyTransformation();
144 }

References IBayesNetGenerator(), and fromDAG().

Referenced by fromDAG().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateBN()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
virtual void gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::generateBN ( BayesNet< GUM_SCALAR > & bayesNet)
pure virtual

Virtual function that Generates a Bayesian networks.

Parameters
bayesNetBayesian network to be completed after initialisation
Returns
null but modify inputed empty Bayesian network

Implemented in gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >, gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >, and gum::SimpleBayesNetGenerator< GUM_SCALAR, ICPTGenerator >.

References maxArcs(), maxModality(), and nbrNodes().

Here is the call graph for this function:

◆ maxArcs()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
INLINE Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::maxArcs ( ) const

Return a constant reference to the maximum number of arcs imposed on the IBayesNetGenerator.

Definition at line 98 of file IBayesNetGenerator_tpl.h.

98 {
99 return maxArcs_;
100 }

References maxArcs_.

Referenced by IBayesNetGenerator(), generateBN(), and setMaxArcs().

Here is the caller graph for this function:

◆ maxModality()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
INLINE Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::maxModality ( ) const

Return a constant reference to the maximum modality imposed on the IBayesNetGenerator.

Definition at line 88 of file IBayesNetGenerator_tpl.h.

88 {
89 return maxModality_;
90 }

References maxModality_.

Referenced by IBayesNetGenerator(), generateBN(), and setMaxModality().

Here is the caller graph for this function:

◆ nbrNodes()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
INLINE Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::nbrNodes ( ) const

Return a constant reference to the number of nodes imposed on the IBayesNetGenerator.

Definition at line 93 of file IBayesNetGenerator_tpl.h.

93 {
94 return nbrNodes_;
95 }

References nbrNodes_.

Referenced by IBayesNetGenerator(), generateBN(), and setNbrNodes().

Here is the caller graph for this function:

◆ setMaxArcs()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
INLINE void gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::setMaxArcs ( Size maxArcs)

Modifies the value of the number of nodes imposed on the BayesGenerator.

Definition at line 119 of file IBayesNetGenerator_tpl.h.

119 {
121 GUM_ERROR(OperationNotAllowed, " maxArcs value not possible ")
122
124 }

References GUM_ERROR, maxArcs(), and nbrNodes_.

Here is the call graph for this function:

◆ setMaxModality()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
INLINE void gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::setMaxModality ( Size maxModality)

Modifies the value of the number of nodes imposed on the BayesGenerator.

Definition at line 103 of file IBayesNetGenerator_tpl.h.

103 {
104 if (maxModality < 2)
105 GUM_ERROR(OperationNotAllowed, " maxModality must be at least equal to two ")
106
108 }

References GUM_ERROR, and maxModality().

Here is the call graph for this function:

◆ setNbrNodes()

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
INLINE void gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::setNbrNodes ( Size nbrNodes)

Modifies the value of the number of nodes imposed on the BayesGenerator.

Definition at line 111 of file IBayesNetGenerator_tpl.h.

111 {
112 if ((maxArcs_ < nbrNodes - 1) || (maxArcs_ > (nbrNodes * (nbrNodes - 1)) / 2))
113 GUM_ERROR(OperationNotAllowed, " nbrNodes value not possible ")
114
116 }

References IBayesNetGenerator(), GUM_ERROR, maxArcs_, nbrNodes(), nbrNodes_, and setNbrNodes().

Referenced by setNbrNodes().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ dag_

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
DAG gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::dag_
protected

Definition at line 187 of file IBayesNetGenerator.h.

Referenced by IBayesNetGenerator().

◆ maxArcs_

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::maxArcs_
protected

Definition at line 185 of file IBayesNetGenerator.h.

Referenced by IBayesNetGenerator(), maxArcs(), and setNbrNodes().

◆ maxModality_

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::maxModality_
protected

Definition at line 186 of file IBayesNetGenerator.h.

Referenced by IBayesNetGenerator(), and maxModality().

◆ nbrNodes_

template<typename GUM_SCALAR, template< typename > class ICPTGenerator>
Size gum::IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::nbrNodes_
protected

Definition at line 184 of file IBayesNetGenerator.h.

Referenced by IBayesNetGenerator(), nbrNodes(), setMaxArcs(), and setNbrNodes().


The documentation for this class was generated from the following files: