56 template <
typename GUM_SCALAR >
63 template <
typename GUM_SCALAR >
69 template <
typename GUM_SCALAR >
75 template <
typename GUM_SCALAR >
83 prev.
add(this->
BN().variable(ev));
87 for (
const auto nod: this->
BN().topologicalOrder()) {
89 auto probaP = this->
BN().cpt(nod).get(prev);
90 auto probaQ = this->
samplingBN().cpt(nod).get(prev);
91 if ((probaP == 0) || (probaQ == 0)) {
94 pSurQ = probaP / probaQ;
102 }
while (pSurQ == 0);
108 template <
typename GUM_SCALAR >
112 auto p = bn->
cpt(nod).isNonZeroMap().scale(
epsilon) + bn->
cpt(nod);
118 template <
typename GUM_SCALAR >
128 if (minParam < minAccepted) this->
unsharpenBN_(bn,
float(minAccepted));
double epsilon() const override
Returns the value of epsilon.
Portion of a BN identified by the list of nodes and a BayesNet.
const Tensor< GUM_SCALAR > & cpt(NodeId varId) const final
Returns the CPT of a variable.
void uninstallCPT(NodeId id)
uninstall a local CPT.
void installCPT(NodeId id, const Tensor< GUM_SCALAR > &pot)
install a local cpt BY COPYfor a node into the fragment.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
const NodeGraphPart & nodes() const final
Returns a constant reference to the dag of this Bayes Net.
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
const NodeProperty< const Tensor< GUM_SCALAR > * > & evidence() const
returns the set of evidence
const NodeProperty< Idx > & hardEvidence() const
indicate for each node with hard evidence which value it took
Class representing the minimal interface for Bayesian network with no numerical data.
GUM_SCALAR minNonZeroParam() const
Size maxVarDomainSize() const
void onContextualize_(BayesNetFragment< GUM_SCALAR > *bn) override
fired when Bayesian network is contextualized
Instantiation burnIn_() override
draws a defined number of samples without updating the estimators
void unsharpenBN_(BayesNetFragment< GUM_SCALAR > *bn, float epsilon)
modifies the cpts of a BN in order to tend to uniform distributions
ImportanceSampling(const IBayesNet< GUM_SCALAR > *bn)
Default constructor.
~ImportanceSampling() override
Destructor.
Instantiation draw_(GUM_SCALAR *w, Instantiation prev) override
draws a sample according to Importance sampling
Class for assigning/browsing values to tuples of discrete variables.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
void clear()
Erase all variables from an Instantiation.
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
NodeSet asNodeSet() const
returns a copy of the set of nodes represented by the NodeGraphPart
const IBayesNet< GUM_SCALAR > & samplingBN()
get the BayesNet which is used to really perform the sampling
virtual void addVarSample_(NodeId nod, Instantiation *I)
adds a node to current instantiation
SamplingInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
This file contains Importance sampling class definition.
gum is the global namespace for all aGrUM entities