aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
fusionContext_tpl.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#pragma once
42
43
51// =======================================================
53
55
56// =======================================================
57
58namespace gum {
59
60 // ############################################################################
61 // Constructors / Destructors
62 // ############################################################################
63
64 // ============================================================================
65 // Default constructor.
66 // ============================================================================
67 template < bool isInitial >
71
72 // ============================================================================
73 // Default constructor.
74 // ============================================================================
75 template < bool isInitial >
77 GUM_DESTRUCTOR(FusionContext);
78
79 for (auto leafIter = _leaf2Pair_.beginSafe(); leafIter != _leaf2Pair_.endSafe(); ++leafIter)
80 delete leafIter.val();
81
82 delete _leaf_;
83 }
84
85 // ############################################################################
86 //
87 // ############################################################################
89 // ============================================================================
90 //
91 // ============================================================================
92 template < bool isInitial >
94 LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
95 ;
96 LeafPair* p = new LeafPair(l, _leaf_);
97 _leaf2Pair_.insert(l, p);
98 _leaf2Pair_[l]->updateLikelyhood();
99 _pairsHeap_.insert(p, p->likelyhood());
100
101 return ptop != _pairsHeap_.top();
102 }
103
104 // ============================================================================
105 //
106 // ============================================================================
107 template < bool isInitial >
109 LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
110 ;
111 _leaf2Pair_[l]->updateLikelyhood();
112 _pairsHeap_.setPriority(_leaf2Pair_[l], _leaf2Pair_[l]->likelyhood());
113
114 return ptop != _pairsHeap_.top();
115 }
116
117 // ============================================================================
118 //
119 // ============================================================================
120 template < bool isInitial >
122 LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
123 ;
125 pairIter != _leaf2Pair_.cendSafe();
126 ++pairIter) {
127 pairIter.val()->updateLikelyhood();
128 _pairsHeap_.setPriority(pairIter.val(), pairIter.val()->likelyhood());
129 }
130 LeafPair* ctop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
131
132 return ptop != ctop;
134
135 // ============================================================================
136 //
137 // ============================================================================
138 template < bool isInitial >
140 LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
142 _leaf2Pair_.erase(l);
143
144 LeafPair* ctop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
145
146 return ptop != ctop;
147 }
148
149 // ############################################################################
150 //
151 // ############################################################################
152
153 // ============================================================================
154 //
155 // ============================================================================
156 template < bool isInitial >
158 LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
159 _pairsHeap_.insert(p, p->likelyhood());
160
161 return ptop != _pairsHeap_.top();
162 }
163
164 // ============================================================================
165 //
166 // ============================================================================
167 template < bool isInitial >
169 LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
170 _pairsHeap_.setPriority(p, p->likelyhood());
171
172 return ptop != _pairsHeap_.top();
174
175 // ============================================================================
176 //
177 // ============================================================================
178 template < bool isInitial >
180 LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
181 _pairsHeap_.erase(p);
182
183 LeafPair* ctop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
184
185 return ptop != ctop;
186 }
188 // ############################################################################
189 //
190 // ############################################################################
191
192 // ============================================================================
193 //
194 // ============================================================================
195 template < bool isInitial >
197 Set< LeafPair* > retBag;
198 for (auto pairIter = _leaf2Pair_.beginSafe(); pairIter != _leaf2Pair_.endSafe(); ++pairIter)
199 retBag << pairIter.val();
200
201 return retBag;
202 }
203
204 template < bool isInitial >
206 std::string ss;
207 if (_leaf_) ss = std::format("Associated Leaf : {}\nLeaves Heap : \n", _leaf_->toString());
208
209 // ss += std::format("{}\n", leafIter.key()->toString());
210 if (!_pairsHeap_.empty()) ss += std::format("Top pair : {}\n", _pairsHeap_.top()->toString());
211
212 return ss;
213 }
214
215 template < bool isInitial >
218 }
219
220 template < bool isInitial >
223 }
224
225 template < bool isInitial >
229
230 template < bool isInitial >
232 return _leaf2Pair_.exists(l);
233 }
234
235 template < bool isInitial >
239
240 template < bool isInitial >
244
245 template < bool isInitial >
249
250 template < bool isInitial >
254
255 template < bool isInitial >
259
260 template < bool isInitial >
264
265 template < bool isInitial >
269
270 template < bool isInitial >
274
275 template < bool isInitial >
279
280 template < bool isInitial >
282 return _pairsHeap_.allValues().beginSafe();
283 }
284
285 template < bool isInitial >
287 return _pairsHeap_.allValues().endSafe();
288 }
289
290 template < bool isInitial >
292 return !_pairsHeap_.empty() ? _pairsHeap_.top() : nullptr;
293 }
294
295 template < bool isInitial >
297 return !_pairsHeap_.empty() ? _pairsHeap_.topPriority() : 1.0;
298 }
299
300 template < bool isInitial >
304
305 template < bool isInitial >
307 return _leaf2Pair_.getWithDefault(l, nullptr);
308 }
309
310 template < bool isInitial >
314
315 template < bool isInitial >
319
320} // namespace gum
<agrum/FMDP/learning/datastructure/leaves/abstractLeaf.h>
bool _containsAssociatedLeaf_(AbstractLeaf *l, Int2Type< false >)
pair_iterator endPairs()
bool addPair(LeafPair *p)
bool removePair(LeafPair *p)
Set< LeafPair * > _associatedPairs_(Int2Type< false >)
FusionContext(AbstractLeaf *)
Default constructor.
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_
bool updatePair(LeafPair *p)
AbstractLeaf * leaf()
bool updateAssociatedLeaf(AbstractLeaf *l)
bool _deassociateLeaf_(AbstractLeaf *, Int2Type< false >)
LeafPair * leafAssociatedPair(AbstractLeaf *l)
bool _updateAllAssociatedLeaves_(Int2Type< false >)
bool containsAssociatedLeaf(AbstractLeaf *l)
~FusionContext()
Default destructor.
AbstractLeaf * _leaf_
bool deassociateLeaf(AbstractLeaf *l)
pair_iterator beginPairs()
Set< LeafPair * > associatedPairs()
bool _updateAssociatedLeaf_(AbstractLeaf *, Int2Type< false >)
bool associateLeaf(AbstractLeaf *l)
bool _associateLeaf_(AbstractLeaf *, Int2Type< false >)
HashTable< AbstractLeaf *, LeafPair * > _leaf2Pair_
Safe Const Iterators for hashtables.
Definition hashTable.h:1662
<agrum/FMDP/learning/datastructure/leaves/leafPair.h>
Definition leafPair.h:69
double likelyhood()
Updates GStatistic.
Definition leafPair.cpp:99
Representation of a set.
Definition set.h:129
static SmallObjectAllocator & instance()
void * allocate(const size_t &objectSize)
Allocates a block.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
Headers of the Fusion Context class.
Useful macros for maths.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
HashTableConstIteratorSafe< LeafPair *, std::vector< Size > > pair_iterator