aGrUM 3.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-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
61 namespace dot {
62 class DotOptions;
63 } // namespace dot
64
65 template < GUM_Numeric GUM_SCALAR >
67
79 template < GUM_Numeric GUM_SCALAR >
81 public:
82 // ===========================================================================
84 // ===========================================================================
86
91 explicit IMarkovRandomField(std::string_view name);
92
96 ~IMarkovRandomField() override;
97
102
107
109
110
111 // ===========================================================================
113 // ===========================================================================
115
121 virtual const Tensor< GUM_SCALAR >& factor(const NodeSet& varIds) const = 0;
122
128 virtual const NodeSet& smallestFactorFromNode(NodeId node) const = 0;
129
135 virtual const NodeSet& smallestFactorFromNode(std::string_view name) const;
136
141 virtual const FactorTable< GUM_SCALAR >& factors() const = 0;
142
144
152 bool operator==(const IMarkovRandomField< GUM_SCALAR >& from) const;
153
161 Size dim() const;
162
167
168 Size maxVarDomainSize() const;
169
174 GUM_SCALAR minParam() const;
175
180 GUM_SCALAR maxParam() const;
181
186 GUM_SCALAR minNonZeroParam() const;
187
192 GUM_SCALAR maxNonOneParam() const;
193
195 virtual std::string toDot() const;
196
203 virtual std::string toDot(const dot::DotOptions& options) const;
204
206 virtual std::string toDotAsFactorGraph() const;
207
213 virtual std::string toDotAsFactorGraph(const dot::DotOptions& options) const;
214
216 std::string toString() const;
217
218 /***
219 * @return the minimal subset of soids that conditions the target
220 *
221 * i.e. P(target| soids)=P(target|@return)
222 */
223 NodeSet minimalCondSet(NodeId target, const NodeSet& soids) const;
224
225
226 /***
227 * @return the minimal subset of soids that conditions the targets
228 *
229 * i.e. P(targets| soids)=P(targets|@return)
230 */
231 NodeSet minimalCondSet(const NodeSet& targets, const NodeSet& soids) const;
232
233 private:
235 const NodeSet& soids,
236 NodeSet& minimal,
237 NodeSet& alreadyVisited) const;
238 };
239
240
241#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
242 extern template class GUM_PUBLIC_MRF IMarkovRandomField< double >;
243#endif
244
245
247 template < GUM_Numeric GUM_SCALAR >
248 std::ostream& operator<<(std::ostream& output, const IMarkovRandomField< GUM_SCALAR >& mn);
249
250} /* namespace gum */
251
253
254#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.
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
The options given to a toDot(const DotOptions&).
Definition dotOptions.h:110
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
template class GUM_PUBLIC_MRF IMarkovRandomField< double >
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Header of the Tensor class.