aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
marginalTargetedMRFInference.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
50#ifndef GUM_MARKOV_RANDOM_FIELD_MARGINAL_TARGETED_INFERENCE_H
51#define GUM_MARKOV_RANDOM_FIELD_MARGINAL_TARGETED_INFERENCE_H
52
53#include <string>
54
55#include <agrum/agrum.h>
56
58
59#include <string_view>
60
61namespace gum {
62
63
77 template < GUM_Numeric GUM_SCALAR >
78 class MarginalTargetedMRFInference: public virtual MRFInference< GUM_SCALAR > {
79 public:
80 // ############################################################################
82 // ############################################################################
84
86
90
93
95
96
97 // ############################################################################
99 // ############################################################################
101
103
117 virtual const Tensor< GUM_SCALAR >& posterior(NodeId node);
118
120
135 virtual const Tensor< GUM_SCALAR >& posterior(std::string_view nodeName);
136
138
139
140 // ############################################################################
142 // ############################################################################
144
146 virtual void eraseAllTargets();
147
149 virtual void addAllTargets() final;
150
152
155 virtual void addTarget(NodeId target) final;
156
158
161 virtual void addTarget(std::string_view nodeName) final;
162
164
166 virtual void eraseTarget(NodeId target) final;
167
169
171 virtual void eraseTarget(std::string_view nodeName) final;
172
174 virtual bool isTarget(NodeId node) const final;
175
177 virtual bool isTarget(std::string_view nodeName) const final;
178
180 virtual Size nbrTargets() const noexcept final;
181
183 virtual const NodeSet& targets() const noexcept final;
184
186
187 // ############################################################################
189 // ############################################################################
191
196 virtual GUM_SCALAR H(NodeId X) final;
197
202 virtual GUM_SCALAR H(std::string_view nodeName) final;
203
205
206
218 Tensor< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet& evs);
219
230 Tensor< GUM_SCALAR > evidenceImpact(std::string_view target,
231 const std::vector< std::string >& evs);
232
233 protected:
235
236 virtual void onMarginalTargetAdded_(const NodeId id) = 0;
237
239
240 virtual void onMarginalTargetErased_(const NodeId id) = 0;
241
243 virtual void onAllMarginalTargetsAdded_() = 0;
244
246 virtual void onAllMarginalTargetsErased_() = 0;
247
249 void onModelChanged_(const GraphicalModel* mn) override;
250
252
253 virtual const Tensor< GUM_SCALAR >& posterior_(NodeId id) = 0;
254
255 protected:
256 void setTargetedMode_();
257 bool isTargetedMode_() const;
258
259 private:
262
265
266
267 /*/// remove all the marginal posteriors computed
268 void _invalidatePosteriors_() noexcept;*/
269
272 };
273
274
275} // namespace gum
276
278
279
280#endif // GUM_MARKOV_RANDOM_FIELD_MARGINAL_TARGETED_INFERENCE_H
This file contains abstract class definitions for Markov random fields inference classes.
Virtual base class for probabilistic graphical models.
Class representing the minimal interface for Markov random field.
MRFInference(const IMarkovRandomField< GUM_SCALAR > *mn)
default constructor
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
void _setAllMarginalTargets_()
sets all the nodes of the Markov net as targets
virtual Size nbrTargets() const noexcept final
returns the number of marginal targets
void onModelChanged_(const GraphicalModel *mn) override
fired after a new Markov net has been assigned to the engine
virtual void onAllMarginalTargetsAdded_()=0
fired after all the nodes of the MRF are added as marginal targets
virtual void onMarginalTargetErased_(const NodeId id)=0
fired before a marginal target is removed
bool _targeted_mode_
whether the actual targets are default
virtual void onAllMarginalTargetsErased_()=0
fired before a all marginal targets are removed
NodeSet _targets_
the set of marginal targets
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon's entropy of a node given the observation.
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target
virtual void eraseAllTargets()
Clear all previously defined targets.
Tensor< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet &evs)
Create a gum::Tensor for P(target|evs) (for all instantiation of target and evs).
virtual void addAllTargets() final
adds all nodes as targets
MarginalTargetedMRFInference(const IMarkovRandomField< GUM_SCALAR > *mn)
default constructor
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target
virtual void onMarginalTargetAdded_(const NodeId id)=0
fired after a new marginal target is inserted
virtual const Tensor< GUM_SCALAR > & posterior_(NodeId id)=0
asks derived classes for the posterior of a given variable
virtual const Tensor< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
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 ...
Implementation of the generic class for the computation of (possibly incrementally) marginal posterio...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46