55 template < GUM_Numeric GUM_SCALAR >
63 template < GUM_Numeric GUM_SCALAR >
74 template < GUM_Numeric GUM_SCALAR >
83 template < GUM_Numeric GUM_SCALAR >
103 template < GUM_Numeric GUM_SCALAR >
106 GUM_SCALAR virtualLBPSize) {
107 for (
const auto& node: lbp->
BN().nodes()) {
109 std::vector< GUM_SCALAR > v;
114 v.push_back(p[inst] * virtualLBPSize);
126 template < GUM_Numeric GUM_SCALAR >
138 template < GUM_Numeric GUM_SCALAR >
140 Tensor< GUM_SCALAR >* p =
nullptr;
148 p =
new Tensor< GUM_SCALAR >();
160 template < GUM_Numeric GUM_SCALAR >
167 template < GUM_Numeric GUM_SCALAR >
169 GUM_SCALAR p =
EV(name, val);
176 template < GUM_Numeric GUM_SCALAR >
178 GUM_SCALAR ic_max = 0;
181 for (
Idx i = 0; i < iter.val().size(); i++) {
182 GUM_SCALAR ic = GUM_SCALAR(2 * 1.96 * std::sqrt(
variance(iter.key(), i) / (
ntotal_ - 1)));
183 if (ic > ic_max) ic_max = ic;
190 template < GUM_Numeric GUM_SCALAR >
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 named copy of the internal DAG: each node id is assigned the name of the corresponding vari...
const DiscreteVariable & variable(NodeId id) const override
Returns a constant reference over a variable given its node id.
Base class for discrete random variable.
virtual Size domainSize() const =0
GUM_SCALAR wtotal_
cumulated weights of all samples
HashTable< std::string, std::vector< GUM_SCALAR > > estimator_
estimator represented by hashtable between each variable name and a vector of cumulative sample weigh...
void setFromLBP(LoopyBeliefPropagation< GUM_SCALAR > *lbp, const NodeSet &hardEvidence, GUM_SCALAR virtualLBPSize)
sets the estimatoor object with posteriors obtained by LoopyBeliefPropagation
void setFromBN(const IBayesNet< GUM_SCALAR > *bn, const NodeSet &hardEvidence)
estimator initializing
const IBayesNet< GUM_SCALAR > * bn_
Bayesian network on which approximation is done.
const Tensor< GUM_SCALAR > & posterior(const DiscreteVariable &var)
returns the posterior of a node
Estimator()
Default constructor.
void clear()
refresh the estimator state as empty
Size ntotal_
number of generated samples
GUM_SCALAR variance(std::string_view name, Idx val)
returns variance of Bernouilli variable (called by it's name) of given parameter
GUM_SCALAR EV(std::string_view name, Idx val)
returns expected value of Bernouilli variable (called by it's name) of given parameter
void update(Instantiation I, GUM_SCALAR w)
updates the estimator with a given sample
HashTable< std::string, Tensor< GUM_SCALAR > * > _target_posteriors_
the set of single posteriors computed during the last inference
GUM_SCALAR confidence()
computes the maximum length of confidence interval for each possible value of each variable
Class representing the minimal interface for Bayesian network with no numerical data.
Class for assigning/browsing values to tuples of discrete variables.
bool end() const
Returns true if the Instantiation reached the end.
Idx val(Idx i) const
Returns the current value of the variable at position i.
void setFirst()
Assign the first values to the tuple of the Instantiation.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
<agrum/BN/inference/loopyBeliefPropagation.h>
virtual const Tensor< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
Unsafe iterator on the node set of a graph.
node_iterator begin() const noexcept
a begin iterator to parse the set of nodes contained in the NodeGraphPart
const node_iterator & end() const noexcept
the end iterator to parse the set of nodes contained in the NodeGraphPart
Exception : the element we looked for cannot be found.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
const std::string & name() const
returns the name of the variable
This file contains estimating tools for approximate inference.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities