30 template <
typename GUM_SCALAR >
33 _wtotal = (GUM_SCALAR)0.;
39 template <
typename GUM_SCALAR >
45 iter != bn->
nodes().end();
49 std::vector< GUM_SCALAR >(bn->
variable(*iter).domainSize(), 0.0));
55 template <
typename GUM_SCALAR >
65 template <
typename GUM_SCALAR >
69 iter != bn->
nodes().end();
76 bn->
variable(*iter).domainSize(), (GUM_SCALAR)0.0);
79 std::vector< GUM_SCALAR >(
80 bn->
variable(*iter).domainSize(), (GUM_SCALAR)0.0));
87 template <
typename GUM_SCALAR >
91 GUM_SCALAR virtualLBPSize) {
92 for (
const auto& node : lbp->
BN().nodes()) {
94 std::vector< GUM_SCALAR > v;
99 v.push_back(p[inst] * virtualLBPSize);
111 template <
typename GUM_SCALAR >
124 template <
typename GUM_SCALAR >
149 template <
typename GUM_SCALAR >
157 template <
typename GUM_SCALAR >
159 GUM_SCALAR p =
EV(name, val);
167 template <
typename GUM_SCALAR >
169 GUM_SCALAR ic_max = 0;
172 for (
Idx i = 0; i < iter.val().size(); i++) {
173 GUM_SCALAR ic = GUM_SCALAR(
175 if (ic > ic_max) ic_max = ic;
182 template <
typename GUM_SCALAR >
189 __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.
gum is the global namespace for all aGrUM entities
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 ...