![]() |
aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
|
#include <estimator.h>
Public Member Functions | |
| Estimator () | |
| Default constructor. | |
| Estimator (const IBayesNet< GUM_SCALAR > *bn) | |
| Constructor with Bayesian network. | |
| ~Estimator () | |
| GUM_SCALAR | confidence () |
| computes the maximum length of confidence interval for each possible value of each variable | |
| bool | isPriorOutweighed () const |
| returns true if the generated samples outnumber the virtual ones of the prior (if any) | |
| void | update (Instantiation I, GUM_SCALAR w) |
| updates the estimator with a given sample | |
| const Tensor< GUM_SCALAR > & | posterior (const DiscreteVariable &var) |
| returns the posterior of a node | |
| void | clear () |
| refresh the estimator state as empty | |
| void | setFromBN (const IBayesNet< GUM_SCALAR > *bn, const NodeSet &hardEvidence) |
| estimator initializing | |
| void | setFromLBP (LoopyBeliefPropagation< GUM_SCALAR > *lbp, const NodeSet &hardEvidence, GUM_SCALAR virtualLBPSize) |
| sets the estimatoor object with posteriors obtained by LoopyBeliefPropagation | |
Private Member Functions | |
| GUM_SCALAR | EV (std::string_view name, Idx val) |
| returns expected value of Bernouilli variable (called by it's name) of given parameter | |
| GUM_SCALAR | variance (std::string_view name, Idx val) |
| returns variance of Bernouilli variable (called by it's name) of given parameter | |
Private Attributes | |
| HashTable< std::string, std::vector< GUM_SCALAR > > | estimator_ |
| estimator represented by hashtable between each variable name and a vector of cumulative sample weights (generated samples only) | |
| HashTable< std::string, std::vector< GUM_SCALAR > > | prior_ |
| prior distribution of each variable (e.g. LBP posteriors), if any | |
| GUM_SCALAR | wtotal_ |
| cumulated weights of the generated samples | |
| Size | ntotal_ |
| number of generated samples | |
| GUM_SCALAR | nvirtual_ |
| size of the prior as a number of virtual samples (0 if no prior) | |
| const IBayesNet< GUM_SCALAR > * | bn_ |
| Bayesian network on which approximation is done. | |
| HashTable< std::string, Tensor< GUM_SCALAR > * > | _target_posteriors_ |
| the set of single posteriors computed during the last inference | |
Definition at line 60 of file estimator.h.
| Estimator::Estimator | ( | ) |
Default constructor.
Definition at line 56 of file estimator_tpl.h.
References Estimator(), bn_, ntotal_, nvirtual_, and wtotal_.
Referenced by Estimator(), Estimator(), and ~Estimator().
|
explicit |
Constructor with Bayesian network.
Definition at line 65 of file estimator_tpl.h.
References Estimator(), gum::NodeGraphPart::begin(), bn_, gum::DiscreteVariable::domainSize(), gum::NodeGraphPart::end(), estimator_, gum::HashTable< Key, Val >::insert(), gum::Variable::name(), gum::DAGmodel::nodes(), and gum::DiscreteGraphicalModel::variable().
| Estimator::~Estimator | ( | ) |
Definition at line 76 of file estimator_tpl.h.
References Estimator(), and clear().
| void Estimator::clear | ( | ) |
refresh the estimator state as empty
this function remove all the statistics in order to restart the computations.
Definition at line 222 of file estimator_tpl.h.
References _target_posteriors_, estimator_, ntotal_, nvirtual_, prior_, and wtotal_.
Referenced by ~Estimator().
| GUM_SCALAR Estimator::confidence | ( | ) |
computes the maximum length of confidence interval for each possible value of each variable
Definition at line 206 of file estimator_tpl.h.
References estimator_, ntotal_, nvirtual_, and variance().
|
private |
returns expected value of Bernouilli variable (called by it's name) of given parameter
| name | variable's name, considered as a Bernouilli variable |
| val | the parameter of the Bernouilli variable |
computes the amount of cumulative weights for paramater val over the amount of total cumulative weights
Definition at line 179 of file estimator_tpl.h.
References estimator_, ntotal_, nvirtual_, prior_, and wtotal_.
Referenced by posterior(), and variance().
| bool Estimator::isPriorOutweighed | ( | ) | const |
returns true if the generated samples outnumber the virtual ones of the prior (if any)
When the estimator is initialized from a prior (e.g. by setFromLBP), this prior counts as virtual samples, each with the mean weight of the generated samples. As long as they outnumber the generated samples, the estimation hardly moves and the convergence criteria are meaningless.
Definition at line 131 of file estimator_tpl.h.
| const Tensor< GUM_SCALAR > & Estimator::posterior | ( | const DiscreteVariable & | var | ) |
returns the posterior of a node
| var | the variable node which we want posterior for |
returns the vector of cumulated weight bias for each value of the variable normalized as a CPT
| NotFound | if variable node is not in estimator. |
Definition at line 150 of file estimator_tpl.h.
References _target_posteriors_, gum::DiscreteVariable::domainSize(), estimator_, EV(), GUM_ERROR, gum::Variable::name(), nvirtual_, and prior_.
| void Estimator::setFromBN | ( | const IBayesNet< GUM_SCALAR > * | bn, |
| const NodeSet & | hardEvidence ) |
estimator initializing
sets the estimator object with 0-filled vectors corresponding to each non evidence node
Definition at line 85 of file estimator_tpl.h.
References gum::NodeGraphPart::begin(), gum::Set< Key >::contains(), gum::DiscreteVariable::domainSize(), gum::NodeGraphPart::end(), estimator_, gum::Variable::name(), gum::DAGmodel::nodes(), nvirtual_, prior_, and gum::DiscreteGraphicalModel::variable().
| void Estimator::setFromLBP | ( | LoopyBeliefPropagation< GUM_SCALAR > * | lbp, |
| const NodeSet & | hardEvidence, | ||
| GUM_SCALAR | virtualLBPSize ) |
sets the estimatoor object with posteriors obtained by LoopyBeliefPropagation
Definition at line 107 of file estimator_tpl.h.
References gum::BayesNetInference< GUM_SCALAR >::BN(), gum::Set< Key >::contains(), gum::Instantiation::end(), estimator_, ntotal_, nvirtual_, gum::MarginalTargetedInference< GUM_SCALAR >::posterior(), prior_, gum::Instantiation::setFirst(), and wtotal_.
| void Estimator::update | ( | Instantiation | I, |
| GUM_SCALAR | w ) |
updates the estimator with a given sample
| I | the sample used to update the estimators |
| weight | bias for the given sample |
adds the sample weight to each node's given value in the estimator
Definition at line 138 of file estimator_tpl.h.
References estimator_, gum::Variable::name(), gum::Instantiation::nbrDim(), ntotal_, gum::Instantiation::val(), gum::Instantiation::variable(), and wtotal_.
|
private |
returns variance of Bernouilli variable (called by it's name) of given parameter
| name | variable's name, considered as a Bernouilli variable |
| val | the parameter of the Bernouilli variable |
computes variance for Bernouilli law using EV(name, val)
Definition at line 197 of file estimator_tpl.h.
References EV().
Referenced by confidence().
|
private |
the set of single posteriors computed during the last inference
the posteriors are owned by LazyPropagation.
Definition at line 193 of file estimator.h.
Referenced by clear(), and posterior().
|
private |
Bayesian network on which approximation is done.
Definition at line 163 of file estimator.h.
Referenced by Estimator(), and Estimator().
|
private |
estimator represented by hashtable between each variable name and a vector of cumulative sample weights (generated samples only)
Definition at line 148 of file estimator.h.
Referenced by Estimator(), clear(), confidence(), EV(), posterior(), setFromBN(), setFromLBP(), and update().
|
private |
number of generated samples
Definition at line 157 of file estimator.h.
Referenced by Estimator(), clear(), confidence(), EV(), isPriorOutweighed(), setFromLBP(), and update().
|
private |
size of the prior as a number of virtual samples (0 if no prior)
Definition at line 160 of file estimator.h.
Referenced by Estimator(), clear(), confidence(), EV(), isPriorOutweighed(), posterior(), setFromBN(), and setFromLBP().
|
private |
prior distribution of each variable (e.g. LBP posteriors), if any
Definition at line 151 of file estimator.h.
Referenced by clear(), EV(), posterior(), setFromBN(), and setFromLBP().
|
private |
cumulated weights of the generated samples
Definition at line 154 of file estimator.h.
Referenced by Estimator(), clear(), EV(), setFromLBP(), and update().