aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
jointTargetedMRFInference.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_JOINT_TARGETED_INFERENCE_H
51#define GUM_MARKOV_RANDOM_FIELD_JOINT_TARGETED_INFERENCE_H
52
53
54#include <agrum/agrum.h>
55
57
58namespace gum {
59
60
75 template < GUM_Numeric GUM_SCALAR >
76 class GUM_PUBLIC_MRF JointTargetedMRFInference:
77 public MarginalTargetedMRFInference< GUM_SCALAR > {
78 public:
79 // ############################################################################
81 // ############################################################################
83
85
88
91
93
94
95 // ############################################################################
97 // ############################################################################
99
101
117 virtual const Tensor< GUM_SCALAR >& jointPosterior(const NodeSet& nodes) final;
118
120
134 const Tensor< GUM_SCALAR >& posterior(NodeId node) final;
135
137
151 const Tensor< GUM_SCALAR >& posterior(std::string_view nodeName) final;
153
154
155 // ############################################################################
157 // ############################################################################
159
161
167 void eraseAllTargets() final;
168
170 virtual void eraseAllJointTargets() final;
171
173 virtual void eraseAllMarginalTargets() final;
174
177
180 virtual void addJointTarget(const NodeSet& joint_target) final;
181
183
185 virtual void eraseJointTarget(const NodeSet& joint_target) final;
186
188 virtual bool isJointTarget(const NodeSet& vars) const final;
189
191 virtual const Set< NodeSet >& jointTargets() const noexcept final;
192
194 virtual Size nbrJointTargets() const noexcept final;
196
208 Tensor< GUM_SCALAR > evidenceJointImpact(const NodeSet& targets, const NodeSet& evs);
209
221 Tensor< GUM_SCALAR > evidenceJointImpact(const std::vector< std::string >& targets,
222 const std::vector< std::string >& evs);
223
224 // ############################################################################
226 // ############################################################################
228
233 GUM_SCALAR jointMutualInformation(const NodeSet& targets);
234
239 GUM_SCALAR jointMutualInformation(const std::vector< std::string >& targets);
240
242
243
244 protected:
246 std::function< void() > stateRestorer_() override;
247
250 virtual bool isExactJointComputable_(const NodeSet& vars);
251 virtual NodeSet superForJointComputable_(const NodeSet& vars);
252
254 void onModelChanged_(const GraphicalModel* mn) override;
255
257
258 virtual void onJointTargetAdded_(const NodeSet& set) = 0;
259
261
262 virtual void onJointTargetErased_(const NodeSet& set) = 0;
263
265 virtual void onAllTargetsErased_() = 0;
266
268 virtual void onAllJointTargetsErased_() = 0;
269
270
272
274 virtual const Tensor< GUM_SCALAR >& jointPosterior_(const NodeSet& set) = 0;
275
283 virtual const Tensor< GUM_SCALAR >& jointPosterior_(const NodeSet& wanted_target,
284 const NodeSet& declared_target) = 0;
285
290 virtual Tensor< GUM_SCALAR >* unnormalizedJointPosterior_(const NodeSet& set) = 0;
291
293 virtual Tensor< GUM_SCALAR >* unnormalizedJointPosterior_(NodeId id) = 0;
294
295
296 private:
299 };
300
301
302} // namespace gum
303
305
306
307#endif // GUM_MARKOV_RANDOM_FIELD_JOINT_TARGETED_INFERENCE_H
Virtual base class for probabilistic graphical models.
Class representing the minimal interface for Markov random field.
virtual const Tensor< GUM_SCALAR > & jointPosterior_(const NodeSet &wanted_target, const NodeSet &declared_target)=0
asks derived classes for the joint posterior of a set of variables not declared as a joint target
virtual void eraseJointTarget(const NodeSet &joint_target) final
removes an existing joint target
GUM_SCALAR jointMutualInformation(const NodeSet &targets)
Mutual information between targets.
virtual const Set< NodeSet > & jointTargets() const noexcept final
returns the list of joint targets
virtual Size nbrJointTargets() const noexcept final
returns the number of joint targets
std::function< void() > stateRestorer_() override
returns a function restoring the current marginal and joint targets and evidence
Set< NodeSet > _joint_targets_
the set of joint targets
void eraseAllTargets() final
Clear all previously defined targets (marginal and joint targets).
virtual const Tensor< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
virtual void addJointTarget(const NodeSet &joint_target) final
Add a set of nodes as a new joint target. As a collateral effect, every node is added as a marginal t...
virtual Tensor< GUM_SCALAR > * unnormalizedJointPosterior_(NodeId id)=0
returns a fresh tensor equal to P(argument,evidence)
virtual void onJointTargetErased_(const NodeSet &set)=0
fired before a joint target is removed
virtual void eraseAllJointTargets() final
Clear all previously defined joint targets.
const Tensor< GUM_SCALAR > & posterior(NodeId node) final
Computes and returns the posterior of a node.
virtual const Tensor< GUM_SCALAR > & jointPosterior_(const NodeSet &set)=0
asks derived classes for the joint posterior of a declared target set
virtual void onAllJointTargetsErased_()=0
fired before a all the joint targets are removed
virtual void onAllTargetsErased_()=0
fired before a all the marginal and joint targets are removed
virtual void onJointTargetAdded_(const NodeSet &set)=0
fired after a new joint target is inserted
virtual bool isExactJointComputable_(const NodeSet &vars)
check if the vars form a possible computable joint (can be redefined by subclass)
virtual Tensor< GUM_SCALAR > * unnormalizedJointPosterior_(const NodeSet &set)=0
returns a fresh unnormalized joint posterior of a given set of variables
Tensor< GUM_SCALAR > evidenceJointImpact(const NodeSet &targets, const NodeSet &evs)
Create a gum::Tensor for P(joint targets|evs) (for all instantiation of targets and evs).
JointTargetedMRFInference(const IMarkovRandomField< GUM_SCALAR > *mn)
default constructor
virtual NodeSet superForJointComputable_(const NodeSet &vars)
virtual void eraseAllMarginalTargets() final
Clear all the previously defined marginal targets.
virtual bool isJointTarget(const NodeSet &vars) const final
return true if target is a joint target.
void onModelChanged_(const GraphicalModel *mn) override
fired after a new Markov net has been assigned to the engine
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
MarginalTargetedMRFInference(const IMarkovRandomField< GUM_SCALAR > *mn)
default constructor
Representation of a set.
Definition set.h:129
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 non pure virtual methods of class JointTargetedMRFInference.
This file contains the abstract inference class definition for computing (incrementally) marginal pos...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46