37 #define DEFAULT_MAXITER 10000000 38 #define DEFAULT_PERIOD_SIZE 100 39 #define DEFAULT_VERBOSITY false 40 #define DEFAULT_TIMEOUT 6000 41 #define DEFAULT_EPSILON 1e-2 42 #define DEFAULT_MIN_EPSILON_RATE 1e-5 47 template <
typename GUM_SCALAR >
51 __estimator(), __samplingBN(nullptr) {
62 template <
typename GUM_SCALAR >
72 template <
typename GUM_SCALAR >
81 template <
typename GUM_SCALAR >
87 template <
typename GUM_SCALAR >
95 template <
typename GUM_SCALAR >
101 template <
typename GUM_SCALAR >
107 template <
typename GUM_SCALAR >
113 template <
typename GUM_SCALAR >
124 for (
const auto elmt : this->
BN().dag().asNodeSet() - barren)
133 this->
BN().nodes().asNodeSet(),
139 auto nonRequisite = this->
BN().dag().asNodeSet() - requisite;
141 for (
const auto elmt : nonRequisite)
145 I.
add(this->
BN().variable(hard));
148 for (
const auto& child : this->
BN().children(hard)) {
150 *p = this->
BN().cpt(child).extract(I);
160 template <
typename GUM_SCALAR >
166 template <
typename GUM_SCALAR >
178 Ip = this->
_draw(&w, Ip);
187 template <
typename GUM_SCALAR >
197 template <
typename GUM_SCALAR >
202 template <
typename GUM_SCALAR >
204 bool isHardEvidence) {
205 if (!isHardEvidence) {
210 template <
typename GUM_SCALAR >
212 bool isHardEvidence) {}
214 template <
typename GUM_SCALAR >
216 bool contains_hard_evidence) {}
218 template <
typename GUM_SCALAR >
221 bool hasChangedSoftHard) {
222 if (hasChangedSoftHard) {
227 template <
typename GUM_SCALAR >
231 template <
typename GUM_SCALAR >
234 template <
typename GUM_SCALAR >
237 template <
typename GUM_SCALAR >
240 template <
typename GUM_SCALAR >
243 template <
typename GUM_SCALAR >
246 template <
typename GUM_SCALAR >
249 template <
typename GUM_SCALAR >
void _onAllEvidenceErased(bool contains_hard_evidence) override
fired before all the evidence are erased
aGrUM's Potential is a multi-dimensional array with tensor operators.
virtual void contextualize()
Simplifying the bayesian network with relevance reasonning to lighten the computational charge...
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.
the d-separation algorithm as described in Koller & Friedman (2009)
void setPeriodSize(Size p)
How many samples between two stopping is enable.
virtual void prepareInference() final
prepare the internal inference structures for the next inference
~SamplingInference() override
destructor
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
void _loopApproxInference()
void initApproximationScheme()
Initialise the scheme.
virtual void _setEstimatorFromBN()
Initializes the estimators object linked to the simulation.
Class representing the minimal interface for Bayesian Network.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void setMinEpsilonRate(double rate)
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
void _onMarginalTargetAdded(const NodeId id) override
fired after a new marginal target is inserted
void setVerbosity(bool v)
Set the verbosity on (true) or off (false).
#define DEFAULT_PERIOD_SIZE
void setMaxTime(double timeout)
Stopping criterion on timeout.
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
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
const NodeSet & softEvidenceNodes() const
returns the set of nodes with soft evidence
void _onEvidenceErased(const NodeId id, bool isHardEvidence) override
fired before an evidence is removed
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const NodeProperty< Idx > & hardEvidence() const
indicate for each node with hard evidence which value it took
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.
<agrum/BN/inference/loopyBeliefPropagation.h>
NodeSet barrenNodes()
returns the set of barren nodes
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.
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
#define DEFAULT_MIN_EPSILON_RATE
void _makeInference() override
makes the inference by generating samples
Class for assigning/browsing values to tuples of discrete variables.
void setMaxIter(Size max)
Stopping criterion on number of iterations.
void requisiteNodes(const DAG &dag, const NodeSet &query, const NodeSet &hardEvidence, const NodeSet &softEvidence, NodeSet &requisite)
Fill the 'requisite' nodeset with the requisite nodes in dag given a query and evidence.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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
virtual bool isInferenceReady() const noexcept final
returns whether the inference object is in a ready state
void setEpsilon(double eps)
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
void setTargets(const NodeSet *target_nodes)
sets the set of target nodes we are interested in
void setEvidence(const NodeSet *observed_nodes)
sets the observed nodes in the DAG
virtual void _onContextualize(BayesNetFragment< GUM_SCALAR > *bn)
fired when Bayesian network is contextualized
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
Detect barren nodes for inference in Bayesian networks.
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
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
Size NodeId
Type for node ids.
#define DEFAULT_VERBOSITY
const IBayesNet< GUM_SCALAR > & samplingBN()
get the BayesNet which is used to really perform the sampling
#define GUM_ERROR(type, msg)
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
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 ...