aGrUM  0.14.2
gum::SimpleCPTGenerator< GUM_SCALAR > Class Template Reference

<agrum/BN/generator/simpleCPTGenerator.h> More...

#include <simpleCPTGenerator.h>

Inherits gum::ICPTGenerator< GUM_SCALAR >.

Public Member Functions

Constructors / Destructor
 SimpleCPTGenerator ()
 Default constructor. More...
 
 ~SimpleCPTGenerator () override
 Destructor. More...
 
CPT generation methods
void generateCPT (const Idx &varId, const Potential< GUM_SCALAR > &cpt) override
 Generates a CPT using floats. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::SimpleCPTGenerator< GUM_SCALAR >

<agrum/BN/generator/simpleCPTGenerator.h>

Class for generating Conditional Probability Tables.

This class implements a CPTGenerator CPT generation algorithm.

Definition at line 43 of file simpleCPTGenerator.h.

Constructor & Destructor Documentation

◆ SimpleCPTGenerator()

template<typename GUM_SCALAR >
INLINE gum::SimpleCPTGenerator< GUM_SCALAR >::SimpleCPTGenerator ( )

Default constructor.

Definition at line 34 of file simpleCPTGenerator_tpl.h.

34  :
35  ICPTGenerator< GUM_SCALAR >() {
36  GUM_CONSTRUCTOR(SimpleCPTGenerator);
37  }
SimpleCPTGenerator()
Default constructor.

◆ ~SimpleCPTGenerator()

template<typename GUM_SCALAR >
INLINE gum::SimpleCPTGenerator< GUM_SCALAR >::~SimpleCPTGenerator ( )
override

Destructor.

Definition at line 41 of file simpleCPTGenerator_tpl.h.

41  {
42  GUM_DESTRUCTOR(SimpleCPTGenerator);
43  }
SimpleCPTGenerator()
Default constructor.

Member Function Documentation

◆ generateCPT()

template<typename GUM_SCALAR >
void gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT ( const Idx varId,
const Potential< GUM_SCALAR > &  cpt 
)
override

Generates a CPT using floats.

Parameters
varIdThe variable id of the CPT owner.
cptA reference on the CPT to fill.

Definition at line 50 of file simpleCPTGenerator_tpl.h.

References gum::Instantiation::add(), gum::MultiDimDecorator< GUM_SCALAR >::domainSize(), gum::Instantiation::end(), gum::Potential< GUM_SCALAR >::fillWith(), gum::Instantiation::incIn(), gum::Instantiation::incOut(), gum::randomValue(), gum::MultiDimDecorator< GUM_SCALAR >::set(), gum::Instantiation::setFirstIn(), gum::Instantiation::setFirstOut(), gum::Instantiation::unsetEnd(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().

Referenced by gum::BayesNet< double >::generateCPT().

51  {
52  std::vector< GUM_SCALAR > v;
53 
54  v.reserve(cpt.domainSize());
55  for (Size i = 0; i < cpt.domainSize(); ++i) {
56  v.push_back((GUM_SCALAR)randomValue(10000));
57  }
58 
59  cpt.fillWith(v);
60  Instantiation varInst;
61  varInst.add(cpt.variable(varId));
62  Instantiation cptInst(cpt);
63 
64  for (cptInst.setFirstOut(varInst); !cptInst.end(); cptInst.incOut(varInst)) {
65  GUM_SCALAR sum = (GUM_SCALAR)0;
66 
67  for (cptInst.setFirstIn(varInst); !cptInst.end(); cptInst.incIn(varInst)) {
68  sum += cpt[cptInst];
69  }
70 
71  for (cptInst.setFirstIn(varInst); !cptInst.end(); cptInst.incIn(varInst)) {
72  cpt.set(cptInst, cpt[cptInst] / sum);
73  }
74 
75  cptInst.unsetEnd();
76  }
77  }
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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