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()) {
98 *p = bn->
cpt(nod).isNonZeroMap().scale(epsilon) + bn->
cpt(nod);
104 template <
typename GUM_SCALAR >
115 if (minParam < minAccepted) this->
_unsharpenBN(bn,
float(minAccepted));
~ImportanceSampling() override
Destructor.
aGrUM's Potential is a multi-dimensional array with tensor operators.
void uninstallCPT(NodeId id) noexcept
uninstall a local CPT.
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 for 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-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Instantiation _draw(GUM_SCALAR *w, Instantiation prev) override
draws a sample according to Importance sampling
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const override
Returns the CPT of a variable.
const Potential< GUM_SCALAR > & normalizeAsCPT() const
normalisation of this as a CPT
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-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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
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
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