aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
IBayesNet.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 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-2026 *
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
49#ifndef GUM_SIMPLE_BAYES_NET_H
50#define GUM_SIMPLE_BAYES_NET_H
51
52#include <utility>
53
54#include <agrum/agrum.h>
55
58
59namespace gum {
60 template < GUM_Numeric GUM_SCALAR >
61 class BayesNetFactory;
62
74 template < GUM_Numeric GUM_SCALAR >
75 class IBayesNet: public DAGmodel {
76 public:
77 // ===========================================================================
79 // ===========================================================================
81
85 IBayesNet();
86 explicit IBayesNet(std::string_view name);
87
91 ~IBayesNet() override;
92
97
102
107
112
114 // ===========================================================================
116 // ===========================================================================
118
124 virtual const Tensor< GUM_SCALAR >& cpt(NodeId varId) const = 0;
125
127
128 // ===========================================================================
130 // ===========================================================================
132
137 GUM_SCALAR jointProbability(const Instantiation& i) const;
138
143 GUM_SCALAR log2JointProbability(const Instantiation& i) const;
144
147
153 std::vector< std::string > check() const;
154
162 bool operator==(const IBayesNet< GUM_SCALAR >& from) const;
163
171 Size dim() const;
172
177 Size maxVarDomainSize() const;
178
183 GUM_SCALAR minParam() const;
184
189 GUM_SCALAR maxParam() const;
190
196 GUM_SCALAR minNonZeroParam() const;
197
203 GUM_SCALAR maxNonOneParam() const;
204
206 virtual std::string toDot() const;
207
209 std::string toString() const;
210
215 Tensor< GUM_SCALAR > evEq(std::string_view name, double value) const;
216
221 Tensor< GUM_SCALAR > evIn(std::string_view name, double val1, double val2) const;
222
227 Tensor< GUM_SCALAR > evLt(std::string_view name, double value) const;
228
229
234 Tensor< GUM_SCALAR > evGt(std::string_view name, double value) const;
235
236
241 Size memoryFootprint() const;
242 };
243
244
245#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
246 extern template class IBayesNet< double >;
247#endif
248
249
251 template < GUM_Numeric GUM_SCALAR >
252 std::ostream& operator<<(std::ostream& output, const IBayesNet< GUM_SCALAR >& bn);
253} /* namespace gum */
254
256
257#endif /* GUM_SIMPLE_BAYES_NET_H */
Class representing probabilistic DAG model.
Template implementation of bns/bayesNet.h classes.
A factory class to ease BayesNet construction.
DAGmodel()
Default constructor.
Definition DAGmodel.cpp:49
Class representing the minimal interface for Bayesian network with no numerical data.
Definition IBayesNet.h:75
Tensor< GUM_SCALAR > evGt(std::string_view name, double value) const
GUM_SCALAR minNonZeroParam() const
IBayesNet()
Default constructor.
GUM_SCALAR jointProbability(const Instantiation &i) const
Compute a parameter of the joint probability for the BN (given an instantiation of the vars).
Size dim() const
Returns the dimension (the number of free parameters) in this bayes net.
GUM_SCALAR maxParam() const
std::vector< std::string > check() const
Check if the BayesNet is consistent (variables, CPT).
~IBayesNet() override
Destructor.
Tensor< GUM_SCALAR > evIn(std::string_view name, double val1, double val2) const
Tensor< GUM_SCALAR > evLt(std::string_view name, double value) const
Size memoryFootprint() const
compute the (approximated) footprint in memory of the model (the footprints of CPTs)
Size maxVarDomainSize() const
GUM_SCALAR log2JointProbability(const Instantiation &i) const
Compute a parameter of the log joint probability for the BN (given an instantiation of the vars).
GUM_SCALAR maxNonOneParam() const
std::string toString() const
GUM_SCALAR minParam() const
IBayesNet< GUM_SCALAR > & operator=(const IBayesNet< GUM_SCALAR > &source)
Copy operator.
virtual std::string toDot() const
Tensor< GUM_SCALAR > evEq(std::string_view name, double value) const
bool operator==(const IBayesNet< GUM_SCALAR > &from) const
This operator compares 2 BNs !
virtual const Tensor< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
Class for assigning/browsing values to tuples of discrete variables.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Header of the Tensor class.