aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
structuredBayesBall.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
48
49#include <sstream>
50#include <string>
51#include <utility>
52
54
55#ifndef GUM_STRUCTURED_BB_H
56# define GUM_STRUCTURED_BB_H
57
58namespace gum {
59 namespace prm {
60
66 template < typename GUM_SCALAR >
68 public:
69 // ========================================================================
71 // ========================================================================
73
76
79
81 // ========================================================================
83 // ========================================================================
85
87 const std::string& key(const PRMInstance< GUM_SCALAR >* i) const;
88
90 const std::string& key(const PRMInstance< GUM_SCALAR >& i) const;
91
94
97
100 Size occurrence(const std::string& key) const;
101
104 float liftRatio() const;
105
107 bool exists(const PRMInstance< GUM_SCALAR >* i) const;
108
110 bool exists(const PRMInstance< GUM_SCALAR >& i) const;
111
113
117 void compute(const PRMInstance< GUM_SCALAR >* i, NodeId n);
118
122 void compute(const PRMInstance< GUM_SCALAR >& i, NodeId n);
123
126
127 private:
130
133
137
139 std::pair< bool, bool >&
143
145 void _clean_();
146
149
152
155
157 void _fillMaps_(InstanceMap& marks);
158
160 std::string _buildHashKey_(const PRMInstance< GUM_SCALAR >* i, Set< NodeId >& req_nodes);
161
164
169 HashTable< const PRMInstance< GUM_SCALAR >*, std::pair< std::string, Set< NodeId >* > >
171
175 };
176
177
178# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
179 extern template class StructuredBayesBall< double >;
180# endif
181
182
183 } /* namespace prm */
184} /* namespace gum */
185
187
188#endif /* GUM_STRUCTURED_BB_H */
Headers of PRMInference.
The class for generic Hash Tables.
Definition hashTable.h:637
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
Definition PRMInstance.h:79
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
<agrum/PRM/structuredBayesBall.h>
float liftRatio() const
Returns the ratio between the total number of instances and the number of instances with the same con...
HashTable< const PRMInstance< GUM_SCALAR > *, std::pair< std::string, Set< NodeId > * > > _keyMap_
Associate an PRMInstance<GUM_SCALAR> with a unique key w.r.t. d-separation and the set of requisite n...
const PRMInference< GUM_SCALAR > * _inf_
The PRM at which model belongs.
StructuredBayesBall(const StructuredBayesBall &source)
Copy constructor.
const Set< NodeId > & requisiteNodes(const PRMInstance< GUM_SCALAR > *i) const
Returns the set of requisite nodes w.r.t. d-separation for i.
const std::string & key(const PRMInstance< GUM_SCALAR > *i) const
Returns a unique key w.r.t. d-separation for i.
void _clean_()
Cleans this before a new computation.
HashTable< NodeId, std::pair< bool, bool > > MarkMap
Code alias.
HashTable< std::string, std::pair< Set< NodeId > *, Size > > _reqMap_
Associate a Key with the set of requisite nodes associated with it. The Size value is the number of i...
StructuredBayesBall & operator=(const StructuredBayesBall &source)
Copy operator.
void compute(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Compute the set or requisite nodes for each required instance given the current set of observations....
StructuredBayesBall(const PRMInference< GUM_SCALAR > &inference)
Default Constructor.
void _fillMaps_(InstanceMap &marks)
Fill keyMap and reqMap.
Size occurrence(const std::string &key) const
Returns the number of occurrence of the given key, which is the number of PRMInstance<GUM_SCALAR> sha...
void _fromParent_(const PRMInstance< GUM_SCALAR > *i, NodeId n, InstanceMap &marks)
When the ball is receive on i->get(n) from a parent.
void _fromChild_(const PRMInstance< GUM_SCALAR > *i, NodeId n, InstanceMap &marks)
When the ball is received on i->get(n) from a child.
bool exists(const PRMInstance< GUM_SCALAR > *i) const
Returns true if i has requisite nodes.
void _compute_(const PRMInstance< GUM_SCALAR > *i, NodeId n)
The real compute method.
std::string _buildHashKey_(const PRMInstance< GUM_SCALAR > *i, Set< NodeId > &req_nodes)
Builds the HashKey for the given instance and requisite nodes set.
HashTable< const PRMInstance< GUM_SCALAR > *, MarkMap * > InstanceMap
const PRMSlotChain< GUM_SCALAR > & _getSC_(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Code alias.
std::pair< bool, bool > & _getMark_(InstanceMap &marks, const PRMInstance< GUM_SCALAR > *i, NodeId n)
Code alias.
bool _isHardEvidence_(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Returns true if there is a hard evidence on i->get(n).
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Inline implementation of StructuredBayesBall.