37 template <
typename GUM_SCALAR >
46 template <
typename GUM_SCALAR >
52 template <
typename GUM_SCALAR >
58 template <
typename GUM_SCALAR >
67 prev.
add(this->
BN().variable(ev));
71 for (
const auto nod: this->
BN().topologicalOrder()) {
73 auto probaP = this->
BN().cpt(nod).get(prev);
74 auto probaQ = this->
samplingBN().cpt(nod).get(prev);
75 if ((probaP == 0) || (probaQ == 0)) {
78 pSurQ = probaP / probaQ;
93 template <
typename GUM_SCALAR >
96 for (
const auto nod: bn->
nodes().asNodeSet()) {
97 auto p = bn->
cpt(nod).isNonZeroMap().scale(epsilon) + bn->
cpt(nod);
103 template <
typename GUM_SCALAR >
114 if (minParam < minAccepted) this->
_unsharpenBN(bn,
float(minAccepted));
~ImportanceSampling() override
Destructor.
const NodeProperty< const Potential< GUM_SCALAR > *> & evidence() const
returns the set of evidence
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
Instantiation _burnIn() override
draws a defined number of samples without updating the estimators
void installCPT(NodeId id, const Potential< GUM_SCALAR > &pot)
install a local cpt BY COPYfor a node into the fragment.
ImportanceSampling(const IBayesNet< GUM_SCALAR > *bn)
Default constructor.
GUM_SCALAR minNonZeroParam() const
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
Class representing the minimal interface for Bayesian Network.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Instantiation _draw(GUM_SCALAR *w, Instantiation prev) override
draws a sample according to Importance sampling
<agrum/BN/inference/samplingInference.h>
void clear()
Erase all variables from an Instantiation.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
const NodeProperty< Idx > & hardEvidence() const
indicate for each node with hard evidence which value it took
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Portion of a BN identified by the list of nodes and a BayesNet.
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
Class for assigning/browsing values to tuples of discrete variables.
void _unsharpenBN(BayesNetFragment< GUM_SCALAR > *bn, float epsilon)
modifies the cpts of a BN in order to tend to uniform distributions
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
double epsilon() const
Returns the value of epsilon.
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
virtual void _addVarSample(NodeId nod, Instantiation *I)
adds a node to current instantiation
void uninstallCPT(NodeId id)
uninstall a local CPT.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
Size maxVarDomainSize() const
void _onContextualize(BayesNetFragment< GUM_SCALAR > *bn) override
fired when Bayesian network is contextualized
const IBayesNet< GUM_SCALAR > & samplingBN()
get the BayesNet which is used to really perform the sampling