aGrUM  0.16.0
simpleCPTDisturber_tpl.h
Go to the documentation of this file.
1 
30 
31 namespace gum {
32 
33  // Default constructor.
34  template < typename GUM_SCALAR >
36  ICPTDisturber< GUM_SCALAR >() {
37  GUM_CONSTRUCTOR(SimpleCPTDisturber);
38  }
39 
40  // Destructor.
41  template < typename GUM_SCALAR >
43  GUM_DESTRUCTOR(SimpleCPTDisturber);
44  }
45 
46  // Generates a CPT using GUM_SCALAR.
47  // @param varID The variable id of the CPT owner.
48  // @param cpt A reference on the CPT to fill.
49 
50  template < typename GUM_SCALAR >
52  NodeId node,
53  BayesNet< GUM_SCALAR >& bayesNet,
56  Instantiation i_src(src);
57  Instantiation i_dest(bayesNet.cpt(node));
58  Instantiation i_marg(marg);
59 
60  for (i_dest.setFirst(); !i_dest.end(); ++i_dest) {
61  GUM_SCALAR potval = 0;
62 
63  i_src.setVals(i_dest);
64  for (i_marg.setFirst(); !i_marg.end(); ++i_marg) {
65  i_src.setVals(i_marg);
66  potval += src.get(i_src) * marg.get(i_marg);
67  }
68 
69  bayesNet.cpt(node).set(i_dest, potval);
70  }
71 
72  bayesNet.cpt(node).normalizeAsCPT();
73  }
74 
75  template < typename GUM_SCALAR >
77  NodeId node,
78  BayesNet< GUM_SCALAR >& bayesNet,
80  GUM_SCALAR variation) {
81  Instantiation i(bayesNet.cpt(node));
82 
83  for (i.setFirst(); !i.end(); ++i)
84  bayesNet.cpt(node).set(i,
85  src.get(i) + GUM_SCALAR(randomProba()) * variation);
86 
87  bayesNet.cpt(node).normalizeAsCPT();
88  }
89 
90 } /* namespace gum */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
Class representing a Bayesian Network.
Definition: BayesNet.h:78
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual GUM_SCALAR get(const Instantiation &i) const final
Default implementation of MultiDimContainer::get().
double randomProba()
Returns a random double between 0 and 1 included (i.e.
<agrum/BN/generator/simpleCPTDisturber.h>
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Instantiation & setVals(const Instantiation &i)
Assign the values from i in the Instantiation.
const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
Definition: BayesNet_tpl.h:315
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
void disturbAugmCPT(NodeId node, BayesNet< GUM_SCALAR > &bayesNet, Potential< GUM_SCALAR > &src, GUM_SCALAR variation) override
Disturb a CPT using GUM_SCALAR when inserting a new parent new_parent.
SimpleCPTDisturber()
Default constructor.
~SimpleCPTDisturber() override
Destructor.
void disturbReducCPT(NodeId node, BayesNet< GUM_SCALAR > &bayesNet, Potential< GUM_SCALAR > &src, Potential< GUM_SCALAR > &marg) override
Disturb a CPT using GUM_SCALAR when removing parent varIdi.
Size NodeId
Type for node ids.
Definition: graphElements.h:98