aGrUM  0.15.1
samplingInference.h
Go to the documentation of this file.
1 
31 #ifndef GUM_SAMPLING_INFERENCE_H
32 #define GUM_SAMPLING_INFERENCE_H
33 
35 #include <agrum/BN/IBayesNet.h>
41 
42 namespace gum {
59  template < typename GUM_SCALAR >
60  class SamplingInference : public ApproximateInference< GUM_SCALAR > {
61  public:
62  // ############################################################################
64  // ############################################################################
66 
68 
72  explicit SamplingInference(const IBayesNet< GUM_SCALAR >* bn);
73 
75  ~SamplingInference() override;
76 
78 
90 
93 
106  const Potential< GUM_SCALAR >& currentPosterior(const std::string& name);
109 
110 
111  // ############################################################################
113  // ############################################################################
117 
119 
130  const Potential< GUM_SCALAR >& _posterior(NodeId id) override;
131 
133 
134 
137 
146  virtual void contextualize();
147 
148  // ############################################################################
150  // ############################################################################
152 
153 
155 
161  virtual void _setEstimatorFromBN();
162 
164 
174  GUM_SCALAR virtualLBPSize);
176 
177  protected:
180 
182  bool isSetEstimator = false;
183 
185  bool isContextualized = false;
186 
188  virtual Instantiation _burnIn() = 0;
189 
191 
196  virtual Instantiation _draw(GUM_SCALAR* w, Instantiation prev) = 0;
197 
199  void _makeInference() override;
200  void _loopApproxInference();
201 
203 
210  virtual void _addVarSample(NodeId nod, Instantiation* I);
211 
212 
214 
222 
223  void _onEvidenceAdded(const NodeId id, bool isHardEvidence) override;
224 
225  void _onEvidenceErased(const NodeId id, bool isHardEvidence) override;
226 
227  void _onAllEvidenceErased(bool contains_hard_evidence) override;
228 
229  void _onEvidenceChanged(const NodeId id, bool hasChangedSoftHard) override;
230 
231  void _onBayesNetChanged(const IBayesNet< GUM_SCALAR >* bn) override;
232 
233  void _updateOutdatedBNStructure() override;
234 
235  void _updateOutdatedBNPotentials() override;
236 
237  void _onMarginalTargetAdded(const NodeId id) override;
238 
239  void _onMarginalTargetErased(const NodeId id) override;
240 
241  void _onAllMarginalTargetsAdded() override;
242 
243  void _onAllMarginalTargetsErased() override;
244 
245  void _onStateChanged() override;
246 
247  private:
249  };
250 
251 
252 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
253  extern template class SamplingInference< double >;
254 #endif
255 
256 } // namespace gum
257 
259 #endif
void _onAllEvidenceErased(bool contains_hard_evidence) override
fired before all the evidence are erased
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void contextualize()
Simplifying the bayesian network with relevance reasonning to lighten the computational charge...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual Instantiation _draw(GUM_SCALAR *w, Instantiation prev)=0
draws a sample in the bayesian network given a previous one
SamplingInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
void _updateOutdatedBNStructure() override
prepares inference when the latter is in OutdatedBNStructure state
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
~SamplingInference() override
destructor
virtual void _setEstimatorFromBN()
Initializes the estimators object linked to the simulation.
Class representing the minimal interface for Bayesian Network.
Definition: IBayesNet.h:62
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void _onMarginalTargetAdded(const NodeId id) override
fired after a new marginal target is inserted
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void _onStateChanged() override
fired when the stage is changed
void _onAllMarginalTargetsAdded() override
fired after all the nodes of the BN are added as marginal targets
void _onEvidenceAdded(const NodeId id, bool isHardEvidence) override
fired after a new evidence is inserted
void _onEvidenceErased(const NodeId id, bool isHardEvidence) override
fired before an evidence is removed
const Potential< GUM_SCALAR > & currentPosterior(NodeId id)
Computes and returns the actual estimation of the posterior of a node.
virtual Instantiation _burnIn()=0
draws samples without updating the estimators
Estimator< GUM_SCALAR > __estimator
Estimator object designed to approximate target posteriors.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
<agrum/BN/inference/loopyBeliefPropagation.h>
Portion of a BN identified by the list of nodes and a BayesNet.
BayesNetFragment< GUM_SCALAR > * __samplingBN
const Potential< GUM_SCALAR > & _posterior(NodeId id) override
Computes and returns the posterior of a node.
void _makeInference() override
makes the inference by generating samples
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
virtual void _setEstimatorFromLBP(LoopyBeliefPropagation< GUM_SCALAR > *lbp, GUM_SCALAR virtualLBPSize)
Initializes the estimators object linked to the simulation.
void _onMarginalTargetErased(const NodeId id) override
fired before a marginal target is removed
bool isContextualized
whether the referenced Bayesian Network has been "contextualized"
void _onAllMarginalTargetsErased() override
fired before a all marginal targets are removed
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void _onContextualize(BayesNetFragment< GUM_SCALAR > *bn)
fired when Bayesian network is contextualized
void _updateOutdatedBNPotentials() override
prepares inference when the latter is in OutdatedBNPotentials state
bool isSetEstimator
whether the Estimator object has been initialized
virtual void _addVarSample(NodeId nod, Instantiation *I)
adds a node to current instantiation
void _onBayesNetChanged(const IBayesNet< GUM_SCALAR > *bn) override
fired after a new Bayes net has been assigned to the engine
Size NodeId
Type for node ids.
Definition: graphElements.h:98
const IBayesNet< GUM_SCALAR > & samplingBN()
get the BayesNet which is used to really perform the sampling
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void _onEvidenceChanged(const NodeId id, bool hasChangedSoftHard) override
fired after an evidence is changed, in particular when its status (soft/hard) changes ...