aGrUM 3.1.1
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-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_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 < GUM_Numeric GUM_SCALAR >
62
74 template < GUM_Numeric GUM_SCALAR >
76 public:
77 // ===========================================================================
79 // ===========================================================================
81
86 explicit IMarkovRandomField(std::string_view name);
87
91 ~IMarkovRandomField() override;
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(std::string_view name) const;
131
136 virtual const FactorTable< GUM_SCALAR >& factors() const = 0;
137
139
147 bool operator==(const IMarkovRandomField< GUM_SCALAR >& from) const;
148
156 Size dim() const;
157
162
163 Size maxVarDomainSize() const;
164
169 GUM_SCALAR minParam() const;
170
175 GUM_SCALAR maxParam() const;
176
181 GUM_SCALAR minNonZeroParam() const;
182
187 GUM_SCALAR maxNonOneParam() const;
188
190 virtual std::string toDot() const;
191
193 virtual std::string toDotAsFactorGraph() const;
194
196 std::string toString() const;
197
198 /***
199 * @return the minimal subset of soids that conditions the target
200 *
201 * i.e. P(target| soids)=P(target|@return)
202 */
203 NodeSet minimalCondSet(NodeId target, const NodeSet& soids) const;
204
205
206 /***
207 * @return the minimal subset of soids that conditions the targets
208 *
209 * i.e. P(targets| soids)=P(targets|@return)
210 */
211 NodeSet minimalCondSet(const NodeSet& targets, const NodeSet& soids) const;
212
213 private:
215 const NodeSet& soids,
216 NodeSet& minimal,
217 NodeSet& alreadyVisited) const;
218 };
219
220
221#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
222 extern template class IMarkovRandomField< double >;
223#endif
224
225
227 template < GUM_Numeric GUM_SCALAR >
228 std::ostream& operator<<(std::ostream& output, const IMarkovRandomField< GUM_SCALAR >& mn);
229
230} /* namespace gum */
231
233
234#endif /* GUM_SIMPLE_MARKOV_NET_H */
Template implementation of bns/bayesNet.h classes.
Class representing probabilistic undirected model.
The class for generic Hash Tables.
Definition hashTable.h:640
Class representing the minimal interface for Markov random field.
virtual std::string toDot() const
IMarkovRandomField()
Default constructor.
virtual const Tensor< GUM_SCALAR > & factor(const NodeSet &varIds) const =0
Returns the factor of a set of variable.
~IMarkovRandomField() override
Destructor.
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
Size dim() const
Returns the dimension (the number of free parameters) in this bayes net.
bool operator==(const IMarkovRandomField< GUM_SCALAR > &from) const
This operator compares 2 BNs !
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const
IMarkovRandomField< GUM_SCALAR > & operator=(const IMarkovRandomField< GUM_SCALAR > &source)
Copy operator.
virtual const NodeSet & smallestFactorFromNode(NodeId node) const =0
Returns the smallest factor that contains this variable.
UGmodel()
Default constructor.
Definition UGmodel.cpp:49
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
Header of the Tensor class.