aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
IMarkovRandomField.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_MARKOV_NET_H
50#define GUM_SIMPLE_MARKOV_NET_H
51
52#include <utility>
53
54#include <agrum/agrum.h>
55
58
59namespace gum {
60 template < typename GUM_SCALAR >
62
74 template < typename GUM_SCALAR >
76 public:
77 // ===========================================================================
79 // ===========================================================================
81
86 explicit IMarkovRandomField(std::string name);
87
91 virtual ~IMarkovRandomField();
92
97
102
104
105
106 // ===========================================================================
108 // ===========================================================================
110
116 virtual const Tensor< GUM_SCALAR >& factor(const NodeSet& varIds) const = 0;
117
123 virtual const NodeSet& smallestFactorFromNode(NodeId node) const = 0;
124
130 virtual const NodeSet& smallestFactorFromNode(const std::string& name) const;
131
136 virtual const FactorTable< GUM_SCALAR >& factors() const = 0;
137
141 virtual const VariableNodeMap& variableNodeMap() const = 0;
142
148 virtual const DiscreteVariable& variable(NodeId id) const = 0;
149
155 virtual NodeId nodeId(const DiscreteVariable& var) const = 0;
156
162 virtual NodeId idFromName(const std::string& name) const = 0;
163
169 virtual const DiscreteVariable& variableFromName(const std::string& name) const = 0;
171
179 bool operator==(const IMarkovRandomField< GUM_SCALAR >& from) const;
180
182 bool operator!=(const IMarkovRandomField< GUM_SCALAR >& from) const;
183
191 Size dim() const;
192
197
198 Size maxVarDomainSize() const;
199
204 GUM_SCALAR minParam() const;
205
210 GUM_SCALAR maxParam() const;
211
216 GUM_SCALAR minNonZeroParam() const;
217
222 GUM_SCALAR maxNonOneParam() const;
223
225 virtual std::string toDot() const;
226
228 virtual std::string toDotAsFactorGraph() const;
229
231 std::string toString() const;
232
233 /***
234 * @return the minimal subset of soids that conditions the target
235 *
236 * i.e. P(target| soids)=P(target|@return)
237 */
238 NodeSet minimalCondSet(NodeId target, const NodeSet& soids) const;
239
240
241 /***
242 * @return the minimal subset of soids that conditions the targets
243 *
244 * i.e. P(targets| soids)=P(targets|@return)
245 */
246 NodeSet minimalCondSet(const NodeSet& targets, const NodeSet& soids) const;
247
248 private:
250 const NodeSet& soids,
251 NodeSet& minimal,
252 NodeSet& alreadyVisited) const;
253 };
254
255
256#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
257 extern template class IMarkovRandomField< double >;
258#endif
259
260
262 template < typename GUM_SCALAR >
263 std::ostream& operator<<(std::ostream& output, const IMarkovRandomField< GUM_SCALAR >& mn);
264
265} /* namespace gum */
266
268
269#endif /* GUM_SIMPLE_MARKOV_NET_H */
Template implementation of bns/bayesNet.h classes.
Class representing probabilistic undirected model.
Base class for discrete random variable.
The class for generic Hash Tables.
Definition hashTable.h:637
Class representing the minimal interface for Markov random field.
IMarkovRandomField()
Default constructor.
virtual std::string toDot() const
virtual const DiscreteVariable & variableFromName(const std::string &name) const =0
Getter by name.
virtual const VariableNodeMap & variableNodeMap() const =0
Returns a constant reference to the VariableNodeMap of thisBN.
virtual const Tensor< GUM_SCALAR > & factor(const NodeSet &varIds) const =0
Returns the factor of a set of variable.
bool operator!=(const IMarkovRandomField< GUM_SCALAR > &from) const
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable given it's node id.
virtual const FactorTable< GUM_SCALAR > & factors() const =0
Returns the set of factors as a IMarkovRandomField::FactorTable.
virtual std::string toDotAsFactorGraph() const
void _minimalCondSetVisit_(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisited) const
bool operator==(const IMarkovRandomField< GUM_SCALAR > &from) const
This operator compares 2 BNs !
virtual ~IMarkovRandomField()
Destructor.
virtual NodeId nodeId(const DiscreteVariable &var) const =0
Return id node from discrete var pointer.
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const
IMarkovRandomField< GUM_SCALAR > & operator=(const IMarkovRandomField< GUM_SCALAR > &source)
Copy operator.
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
Size dim() const
Returns the dimension (the number of free parameters) in this bayes net.
virtual const NodeSet & smallestFactorFromNode(NodeId node) const =0
Returns the smallest factor that contains this variable.
UGmodel()
Default constructor.
Definition UGmodel.cpp:49
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.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
HashTable< NodeSet, const Tensor< GUM_SCALAR > * > FactorTable
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.