aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
jointTargetedInference.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
50#ifndef GUM_BAYES_NET_JOINT_TARGETED_INFERENCE_H
51#define GUM_BAYES_NET_JOINT_TARGETED_INFERENCE_H
52
53
54#include <agrum/agrum.h>
55
57
58namespace gum {
59
60
75 template < typename GUM_SCALAR >
77 public:
78 // ############################################################################
80 // ############################################################################
82
84
87
90
92
93
94 // ############################################################################
96 // ############################################################################
98
100
114 virtual const Tensor< GUM_SCALAR >& jointPosterior(const NodeSet& nodes) final;
115
117
131 virtual const Tensor< GUM_SCALAR >& posterior(NodeId node) final;
132
134
148 virtual const Tensor< GUM_SCALAR >& posterior(const std::string& nodeName) final;
150
151
152 // ############################################################################
154 // ############################################################################
156
158
164 virtual void eraseAllTargets();
165
167 virtual void eraseAllJointTargets() final;
168
170 virtual void eraseAllMarginalTargets() final;
171
174
177 virtual void addJointTarget(const NodeSet& joint_target) final;
178
180
182 virtual void eraseJointTarget(const NodeSet& joint_target) final;
183
185 virtual bool isJointTarget(const NodeSet& vars) const final;
186
188 virtual const Set< NodeSet >& jointTargets() const noexcept final;
189
191 virtual Size nbrJointTargets() const noexcept final;
193
205 Tensor< GUM_SCALAR > evidenceJointImpact(const NodeSet& targets, const NodeSet& evs);
206
218 Tensor< GUM_SCALAR > evidenceJointImpact(const std::vector< std::string >& targets,
219 const std::vector< std::string >& evs);
220
221 // ############################################################################
223 // ############################################################################
225
233 GUM_SCALAR I(NodeId X, NodeId Y);
241 GUM_SCALAR I(const std::string& Xname, const std::string& Yname);
242
250 GUM_SCALAR VI(NodeId X, NodeId Y);
251
259 GUM_SCALAR VI(const std::string& Xname, const std::string& Yname);
260
265 GUM_SCALAR jointMutualInformation(const NodeSet& targets);
266
271 GUM_SCALAR jointMutualInformation(const std::vector< std::string >& targets);
272
274
275
276 protected:
278 virtual void onModelChanged_(const GraphicalModel* bn);
279
281
282 virtual void onJointTargetAdded_(const NodeSet& set) = 0;
283
285
286 virtual void onJointTargetErased_(const NodeSet& set) = 0;
287
289 virtual void onAllTargetsErased_() = 0;
290
292 virtual void onAllJointTargetsErased_() = 0;
293
294
296
298 virtual const Tensor< GUM_SCALAR >& jointPosterior_(const NodeSet& set) = 0;
299
307 virtual const Tensor< GUM_SCALAR >& jointPosterior_(const NodeSet& wanted_target,
308 const NodeSet& declared_target)
309 = 0;
310
315 virtual Tensor< GUM_SCALAR >* unnormalizedJointPosterior_(const NodeSet& set) = 0;
316
318 virtual Tensor< GUM_SCALAR >* unnormalizedJointPosterior_(NodeId id) = 0;
319
320
321 private:
324 };
325
326
327} // namespace gum
328
330
331
332#endif // GUM_BAYES_NET_JOINT_TARGETED_INFERENCE_H
Virtual base class for probabilistic graphical models.
Class representing the minimal interface for Bayesian network with no numerical data.
Definition IBayesNet.h:75
virtual const Tensor< GUM_SCALAR > & posterior(NodeId node) final
Computes and returns the posterior of a node.
GUM_SCALAR I(NodeId X, NodeId Y)
Mutual information between X and Y.
Tensor< GUM_SCALAR > evidenceJointImpact(const NodeSet &targets, const NodeSet &evs)
Create a gum::Tensor for P(joint targets|evs) (for all instanciation of targets and evs).
virtual void eraseAllMarginalTargets() final
Clear all the previously defined marginal targets.
GUM_SCALAR VI(NodeId X, NodeId Y)
Variation of information between X and Y.
GUM_SCALAR VI(const std::string &Xname, const std::string &Yname)
Variation of information between X and Y.
virtual void onModelChanged_(const GraphicalModel *bn)
fired after a new Bayes net has been assigned to the engine
virtual void onAllJointTargetsErased_()=0
fired before a all the joint targets are removed
virtual Tensor< GUM_SCALAR > * unnormalizedJointPosterior_(NodeId id)=0
returns a fresh tensor equal to P(argument,evidence)
Set< NodeSet > _joint_targets_
the set of joint targets
virtual bool isJointTarget(const NodeSet &vars) const final
return true if target is a joint target.
virtual const Set< NodeSet > & jointTargets() const noexcept final
returns the list of joint targets
virtual void eraseAllTargets()
Clear all previously defined targets (marginal and joint targets).
virtual void onJointTargetErased_(const NodeSet &set)=0
fired before a joint target is removed
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 void onJointTargetAdded_(const NodeSet &set)=0
fired after a new joint target is inserted
JointTargetedInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
GUM_SCALAR I(const std::string &Xname, const std::string &Yname)
Mutual information between X and Y.
virtual Tensor< GUM_SCALAR > * unnormalizedJointPosterior_(const NodeSet &set)=0
returns a fresh unnormalized joint posterior of a given set of variables
virtual const Tensor< GUM_SCALAR > & jointPosterior_(const NodeSet &set)=0
asks derived classes for the joint posterior of a declared target set
virtual void eraseAllJointTargets() final
Clear all previously defined joint targets.
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 const Tensor< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
virtual void onAllTargetsErased_()=0
fired before a all the marginal and joint targets are removed
virtual Size nbrJointTargets() const noexcept final
returns the number of joint targets
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 NodeSet & targets() const noexcept final
returns the list of marginal targets
MarginalTargetedInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
Representation of a set.
Definition set.h:131
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 JointTargetedInference.
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