aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
estimator.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48#ifndef GUM_ESTIMATOR_H
49#define GUM_ESTIMATOR_H
50
51#include <vector>
52
54
55namespace gum {
56
57 template < typename GUM_SCALAR >
58 class Estimator {
59 public:
67
71 Estimator();
72
76 explicit Estimator(const IBayesNet< GUM_SCALAR >* bn);
77
78 /* Destructor */
79 ~Estimator();
80
84
89 void setFromBN(const IBayesNet< GUM_SCALAR >* bn, const NodeSet& hardEvidence);
90
95 void setFromLBP(LoopyBeliefPropagation< GUM_SCALAR >* lbp,
96 const NodeSet& hardEvidence,
97 GUM_SCALAR virtualLBPSize);
99
102
105 GUM_SCALAR confidence();
106
108
114 void update(Instantiation I, GUM_SCALAR w);
115
117
126 const Tensor< GUM_SCALAR >& posterior(const DiscreteVariable& var);
127
129
132 void clear();
133
134 private:
138
140 GUM_SCALAR wtotal_;
141
144
147
150
159 GUM_SCALAR EV(std::string name, Idx val);
160
163
171 GUM_SCALAR variance(std::string name, Idx val); // variance corrigée
172
173 private:
175
177 };
178
179#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
180 extern template class Estimator< double >;
181#endif
182
183} // namespace gum
184
186#endif
GUM_SCALAR wtotal_
cumulated weights of all samples
Definition estimator.h:140
HashTable< std::string, std::vector< GUM_SCALAR > > estimator_
estimator represented by hashtable between each variable name and a vector of cumulative sample weigh...
Definition estimator.h:137
void setFromLBP(LoopyBeliefPropagation< GUM_SCALAR > *lbp, const NodeSet &hardEvidence, GUM_SCALAR virtualLBPSize)
sets the estimatoor object with posteriors obtained by LoopyBeliefPropagation
GUM_SCALAR EV(std::string name, Idx val)
returns expected value of Bernouilli variable (called by it's name) of given parameter
void setFromBN(const IBayesNet< GUM_SCALAR > *bn, const NodeSet &hardEvidence)
estimator initializing
const IBayesNet< GUM_SCALAR > * bn_
Bayesian network on which approximation is done.
Definition estimator.h:146
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
Definition estimator.h:143
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
Definition estimator.h:176
GUM_SCALAR confidence()
computes the maximum length of confidence interval for each possible value of each variable
GUM_SCALAR variance(std::string name, Idx val)
returns variance of Bernouilli variable (called by it's name) of given parameter
The class for generic Hash Tables.
Definition hashTable.h:637
Class representing the minimal interface for Bayesian network with no numerical data.
Definition IBayesNet.h:75
Implementation of Estimator for approximate inference in bayesian networks.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
This file contains gibbs sampling (for BNs) class definitions.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46