aGrUM 2.3.2
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-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
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 < typename GUM_SCALAR >
61 class BayesNetFactory;
62
74 template < typename GUM_SCALAR >
75 class IBayesNet: public DAGmodel {
76 public:
77 // ===========================================================================
79 // ===========================================================================
81
85 IBayesNet();
86 explicit IBayesNet(std::string name);
87
91 virtual ~IBayesNet();
92
97
102
104 // ===========================================================================
106 // ===========================================================================
108
114 virtual const Tensor< GUM_SCALAR >& cpt(NodeId varId) const = 0;
115
119 virtual const VariableNodeMap& variableNodeMap() const = 0;
120
126 virtual const DiscreteVariable& variable(NodeId id) const = 0;
127
133 virtual NodeId nodeId(const DiscreteVariable& var) const = 0;
134
140 virtual NodeId idFromName(const std::string& name) const = 0;
141
147 virtual const DiscreteVariable& variableFromName(const std::string& name) const = 0;
149
150 // ===========================================================================
152 // ===========================================================================
154
159 GUM_SCALAR jointProbability(const Instantiation& i) const;
160
165 GUM_SCALAR log2JointProbability(const Instantiation& i) const;
166
169
175 std::vector< std::string > check() const;
176
184 bool operator==(const IBayesNet< GUM_SCALAR >& from) const;
185
187 bool operator!=(const IBayesNet< GUM_SCALAR >& from) const;
188
196 Size dim() const;
197
202 Size maxVarDomainSize() const;
203
208 GUM_SCALAR minParam() const;
209
214 GUM_SCALAR maxParam() const;
215
221 GUM_SCALAR minNonZeroParam() const;
222
228 GUM_SCALAR maxNonOneParam() const;
229
231 virtual std::string toDot() const;
232
234 std::string toString() const;
235
240 Tensor< GUM_SCALAR > evEq(const std::string& name, double value) const;
241
246 Tensor< GUM_SCALAR > evIn(const std::string& name, double val1, double val2) const;
247
252 Tensor< GUM_SCALAR > evLt(const std::string& name, double value) const;
253
254
259 Tensor< GUM_SCALAR > evGt(const std::string& name, double value) const;
260
261
266 Size memoryFootprint() const;
267 };
268
269
270#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
271 extern template class IBayesNet< double >;
272#endif
273
274
276 template < typename GUM_SCALAR >
277 std::ostream& operator<<(std::ostream& output, const IBayesNet< GUM_SCALAR >& bn);
278} /* namespace gum */
279
281
282#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
Base class for discrete random variable.
GUM_SCALAR minNonZeroParam() const
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.
Size memoryFootprint() const
compute the (approximated) footprint in memory of the model (the footprints of CPTs)
virtual const DiscreteVariable & variableFromName(const std::string &name) const =0
Getter by name.
GUM_SCALAR maxParam() const
std::string toString() const
std::vector< std::string > check() const
Check if the BayesNet is consistent (variables, CPT).
Tensor< GUM_SCALAR > evIn(const std::string &name, double val1, double val2) const
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
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it's node id.
GUM_SCALAR minParam() const
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of thisBN.
Tensor< GUM_SCALAR > evEq(const std::string &name, double value) const
Tensor< GUM_SCALAR > evGt(const std::string &name, double value) const
IBayesNet< GUM_SCALAR > & operator=(const IBayesNet< GUM_SCALAR > &source)
Copy operator.
Tensor< GUM_SCALAR > evLt(const std::string &name, double value) const
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node from discrete var pointer.
IBayesNet()
Default constructor.
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
virtual std::string toDot() 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.
bool operator!=(const IBayesNet< GUM_SCALAR > &from) const
virtual ~IBayesNet()
Destructor.
Class for assigning/browsing values to tuples of discrete variables.
Container used to map discrete variables with nodes.
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
Definition AVLTree.h:913
Header of the Tensor class.