aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
MonteCarloSampling_tpl.h
Go to the documentation of this file.
1 
33 
34 
35 namespace gum {
36 
38  template < typename GUM_SCALAR >
40  const IBayesNet< GUM_SCALAR >* bn) :
41  SamplingInference< GUM_SCALAR >(bn) {
42  GUM_CONSTRUCTOR(MonteCarloSampling);
43  }
44 
46  template < typename GUM_SCALAR >
48  GUM_DESTRUCTOR(MonteCarloSampling);
49  }
50 
52  template < typename GUM_SCALAR >
55  return I;
56  }
57 
58 
59  template < typename GUM_SCALAR >
61  Instantiation prev) {
62  *w = 1.0f;
63  bool wrong_value = false;
64  do {
65  wrong_value = false;
66  prev.clear();
67  for (const auto nod: this->BN().topologicalOrder()) {
68  this->_addVarSample(nod, &prev);
69  if (this->hardEvidenceNodes().contains(nod)
70  && prev.val(this->BN().variable(nod)) != this->hardEvidence()[nod]) {
71  wrong_value = true;
72  break;
73  }
74  }
75  } while (wrong_value);
76  return prev;
77  }
78 } // namespace gum
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Class representing the minimal interface for Bayesian Network.
Definition: IBayesNet.h:62
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Definition: agrum.h:25
Instantiation _burnIn() override
draws a defined number of samples without updating the estimators
Idx val(Idx i) const
Returns the current value of the variable at position i.
<agrum/BN/inference/samplingInference.h>
void clear()
Erase all variables from an Instantiation.
const NodeProperty< Idx > & hardEvidence() const
indicate for each node with hard evidence which value it took
~MonteCarloSampling() override
Destructor.
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
virtual void _addVarSample(NodeId nod, Instantiation *I)
adds a node to current instantiation
Instantiation _draw(GUM_SCALAR *w, Instantiation prev) override
draws a sample according to classic Monte Carlo sampling
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
MonteCarloSampling(const IBayesNet< GUM_SCALAR > *bn)
Default constructor.