33 template <
typename GUM_SCALAR >
36 _wtotal = (GUM_SCALAR)0.;
42 template <
typename GUM_SCALAR >
48 iter != bn->
nodes().end();
52 std::vector< GUM_SCALAR >(bn->
variable(*iter).domainSize(), 0.0));
58 template <
typename GUM_SCALAR >
68 template <
typename GUM_SCALAR >
72 iter != bn->
nodes().end();
79 bn->
variable(*iter).domainSize(), (GUM_SCALAR)0.0);
82 std::vector< GUM_SCALAR >(
83 bn->
variable(*iter).domainSize(), (GUM_SCALAR)0.0));
90 template <
typename GUM_SCALAR >
94 GUM_SCALAR virtualLBPSize) {
95 for (
const auto& node : lbp->
BN().nodes()) {
97 std::vector< GUM_SCALAR > v;
102 v.push_back(p[inst] * virtualLBPSize);
114 template <
typename GUM_SCALAR >
127 template <
typename GUM_SCALAR >
152 template <
typename GUM_SCALAR >
160 template <
typename GUM_SCALAR >
162 GUM_SCALAR p =
EV(name, val);
170 template <
typename GUM_SCALAR >
172 GUM_SCALAR ic_max = 0;
175 for (
Idx i = 0; i < iter.val().size(); i++) {
176 GUM_SCALAR ic = GUM_SCALAR(
178 if (ic > ic_max) ic_max = ic;
185 template <
typename GUM_SCALAR >
192 __target_posteriors.clear();
iterator begin()
Returns an unsafe iterator pointing to the beginning of the hashtable.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
aGrUM's Potential is a multi-dimensional array with tensor operators.
void setFromBN(const IBayesNet< GUM_SCALAR > *bn, const NodeSet &hardEvidence)
estimator initializing
void clear()
refresh the estimator state as empty
const iterator & end() noexcept
Returns the unsafe iterator pointing to the end of the hashtable.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
const Potential< GUM_SCALAR > & posterior(const DiscreteVariable &var)
returns the posterior of a node
const Potential< GUM_SCALAR > & normalize() const
normalisation of this do nothing if sum is 0
HashTable< std::string, std::vector< GUM_SCALAR > > _estimator
estimator represented by hashtable between each variable name and a vector of cumulative sample weigh...
GUM_SCALAR _wtotal
cumulated weights of all samples
Size _ntotal
number of generated samples
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
void update(Instantiation I, GUM_SCALAR w)
updates the estimator with a given sample
Base class for discrete random variable.
Class representing the minimal interface for Bayesian Network.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
GUM_SCALAR EV(std::string name, Idx val)
returns expected value of Bernouilli variable (called by it's name) of given parameter ...
Idx val(Idx i) const
Returns the current value of the variable at position i.
void setFromLBP(LoopyBeliefPropagation< GUM_SCALAR > *lbp, const NodeSet &hardEvidence, GUM_SCALAR virtualLBPSize)
sets the estimatoor object with posteriors obtained by LoopyBeliefPropagation
Unsafe iterator on the node set of a graph.
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it's node id.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
const Potential< GUM_SCALAR > & fillWith(const Potential< GUM_SCALAR > &src) const
copy a Potential data using name of variables and labels (not necessarily the same variables in the s...
const IBayesNet< GUM_SCALAR > * _bn
bayesian network on which approximation is done
<agrum/BN/inference/loopyBeliefPropagation.h>
virtual const Potential< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
Class for assigning/browsing values to tuples of discrete variables.
GUM_SCALAR variance(std::string name, Idx val)
returns variance of Bernouilli variable (called by it's name) of given parameter
void clear()
Removes all the elements in the hash table.
void setFirst()
Assign the first values to the tuple of the Instantiation.
Size Idx
Type for indexes.
Estimator()
Default constructor.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
const std::string & name() const
returns the name of the variable
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
HashTable< std::string, Potential< GUM_SCALAR > *> __target_posteriors
the set of single posteriors computed during the last inference
#define GUM_ERROR(type, msg)
bool end() const
Returns true if the Instantiation reached the end.
GUM_SCALAR confidence()
computes the maximum length of confidence interval for each possible value of each variable ...