aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
SVED_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-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#pragma once
41
42
50
51namespace gum {
52 namespace prm {
53
54 template < typename GUM_SCALAR >
56 GUM_DESTRUCTOR(SVED);
57
58 for (const auto& elt: _elim_orders_)
59 delete elt.second;
60
61 if (_class_elim_order_ != nullptr) delete _class_elim_order_;
62 }
63
64 template < typename GUM_SCALAR >
66 NodeId node,
67 BucketSet& pool,
68 BucketSet& trash) {
70 ignore.insert(query);
71 // Extracting required attributes and slotchains
72 Set< NodeId >& attr_set = _getAttrSet_(query);
73 Set< NodeId >& sc_set = _getSCSet_(query);
74 // Downward elimination
76
77 for (const auto attr: attr_set) {
78 try {
79 for (auto iter = query->getRefAttr(attr).begin(); iter != query->getRefAttr(attr).end();
80 ++iter)
81 if ((!ignore.exists(iter->first)) && (_bb_.exists(iter->first)))
82 _eliminateNodesDownward_(query, iter->first, pool, trash, elim_list, ignore);
83 } catch (NotFound const&) {
84 // Ok
85 }
86 }
87
88 // Eliminating all nodes in query instance, except query
90 const auto moralg = bn.moralGraph();
91 DefaultTriangulation t(&moralg, &(bn.modalities()));
92 std::vector< const DiscreteVariable* > elim_order;
93
94 if (this->hasEvidence(query)) _insertEvidence_(query, pool);
95
96 for (const auto attr: attr_set)
97 pool.insert(&(const_cast< Tensor< GUM_SCALAR >& >(query->get(attr).cpf())));
98
99 for (size_t idx = 0; idx < t.eliminationOrder().size(); ++idx) {
100 if (t.eliminationOrder()[idx] != node) {
101 auto var_id = t.eliminationOrder()[idx];
102 const auto& var = bn.variable(var_id);
103 elim_order.push_back(&var);
104 }
105 }
106
107 eliminateNodes(elim_order, pool, trash);
108 // Eliminating instance in elim_list
110 _reduceElimList_(query, elim_list, tmp_list, ignore, pool, trash);
111
112 while (!elim_list.empty()) {
113 if (_checkElimOrder_(query, elim_list.front())) {
114 if ((!ignore.exists(elim_list.front())) && (_bb_.exists(elim_list.front())))
115 _eliminateNodesDownward_(query, elim_list.front(), pool, trash, elim_list, ignore);
116 } else if (_bb_.exists(elim_list.front())) {
117 tmp_list.insert(elim_list.front());
118 }
119
120 elim_list.popFront();
121 }
122
123 // Upward elimination
124 for (const auto chain: sc_set)
125 for (const auto parent: query->getInstances(chain))
126 if ((!ignore.exists(parent)) && (_bb_.exists(*parent)))
127 _eliminateNodesUpward_(parent, pool, trash, tmp_list, ignore);
128 }
129
130 template < typename GUM_SCALAR >
132 const PRMInstance< GUM_SCALAR >* from,
134 BucketSet& pool,
135 BucketSet& trash,
136 List< const PRMInstance< GUM_SCALAR >* >& elim_list,
137 Set< const PRMInstance< GUM_SCALAR >* >& ignore) {
138 ignore.insert(i);
139 // Extracting required attributes and slotchains
140 Set< NodeId >& attr_set = _getAttrSet_(i);
141 Set< NodeId >& sc_set = _getSCSet_(i);
142 // Calling elimination over child instance
144
145 for (const auto attr: attr_set) {
146 try {
147 for (auto iter = i->getRefAttr(attr).begin(); iter != i->getRefAttr(attr).end(); ++iter)
148 if ((!ignore.exists(iter->first)) && (_bb_.exists(iter->first)))
149 _eliminateNodesDownward_(i, iter->first, pool, trash, my_list, ignore);
150 } catch (NotFound const&) {
151 // Ok
152 }
153 }
154
155 // Eliminating all nodes in current instance
156 if (this->hasEvidence(i)) {
157 _eliminateNodesWithEvidence_(i, pool, trash);
158 } else {
159 _insertLiftedNodes_(i, pool, trash);
160
161 for (const auto agg: i->type().aggregates())
162 if (_bb_.requisiteNodes(i).exists(agg->id())) pool.insert(_getAggTensor_(i, agg));
163
164 try {
166 std::vector< const DiscreteVariable* > elim_order;
167
168 for (auto node: _getElimOrder_(i->type())) {
169 const auto& var = bn.variable(node);
170 elim_order.push_back(&var);
171 }
172
173 eliminateNodes(elim_order, pool, trash);
174 } catch (NotFound const&) {
175 // Raised if there is no inner nodes to eliminate
176 }
177 }
178
179 // Calling elimination over child's parents
180 while (!my_list.empty()) {
181 if (_checkElimOrder_(i, my_list.front())) {
182 if ((!ignore.exists(my_list.front())) && (_bb_.exists(my_list.front())))
183 _eliminateNodesDownward_(i, my_list.front(), pool, trash, my_list, ignore);
184 } else if (_bb_.exists(my_list.front())) {
185 elim_list.insert(my_list.front());
186 }
187
188 my_list.popFront();
189 }
190
191 // Adding parents instance to elim_list
192 for (const auto chain: sc_set)
193 for (const auto parent: i->getInstances(chain))
194 if ((!ignore.exists(parent)) && _bb_.exists(parent) && (parent != from))
195 elim_list.insert(parent);
196 }
197
198 template < typename GUM_SCALAR >
201 BucketSet& pool,
202 BucketSet& trash,
203 List< const PRMInstance< GUM_SCALAR >* >& elim_list,
204 Set< const PRMInstance< GUM_SCALAR >* >& ignore) {
205 ignore.insert(i);
206 // Extracting required attributes and slotchains
207 Set< NodeId >& attr_set = _getAttrSet_(i);
208 Set< NodeId >& sc_set = _getSCSet_(i);
209
210 // Downward elimination
211 for (const auto attr: attr_set) {
212 try {
213 for (auto iter = i->getRefAttr(attr).begin(); iter != i->getRefAttr(attr).end(); ++iter)
214 if ((!ignore.exists(iter->first)) && (_bb_.exists(iter->first)))
215 _eliminateNodesDownward_(i, iter->first, pool, trash, elim_list, ignore);
216 } catch (NotFound const&) {
217 // Ok
218 }
219 }
220
221 // Eliminating all nodes in i instance
222 if (this->hasEvidence(i)) {
223 _eliminateNodesWithEvidence_(i, pool, trash);
224 } else {
225 _insertLiftedNodes_(i, pool, trash);
226
227 for (const auto agg: i->type().aggregates())
228 if (_bb_.requisiteNodes(i).exists(agg->id())) pool.insert(_getAggTensor_(i, agg));
229
230 try {
232 std::vector< const DiscreteVariable* > elim_order;
233
234 for (auto node: _getElimOrder_(i->type())) {
235 const auto& var = bn.variable(node);
236 elim_order.push_back(&var);
237 }
238 eliminateNodes(elim_order, pool, trash);
239 } catch (NotFound const&) {
240 // Raised if there is no inner nodes to eliminate
241 }
242 }
243
244 // Eliminating instance in elim_list
246
247 while (!elim_list.empty()) {
248 if (_checkElimOrder_(i, elim_list.front())) {
249 if ((!ignore.exists(elim_list.front())) && (_bb_.exists(elim_list.front())))
250 _eliminateNodesDownward_(i, elim_list.front(), pool, trash, elim_list, ignore);
251 } else if (_bb_.exists(elim_list.front())) {
252 ignore.insert(elim_list.front());
253 }
254
255 elim_list.popFront();
256 }
257
258 // Upward elimination
259 for (const auto chain: sc_set)
260 for (const auto parent: i->getInstances(chain))
261 if ((!ignore.exists(parent)) && (_bb_.exists(parent)))
262 _eliminateNodesUpward_(parent, pool, trash, tmp_list, ignore);
263 }
264
265 template < typename GUM_SCALAR >
267 BucketSet& pool,
268 BucketSet& trash) {
269 // Adding required evidences
270 for (const auto& elt: this->evidence(i))
271 if (_bb_.requisiteNodes(i).exists(elt.first))
272 pool.insert(const_cast< Tensor< GUM_SCALAR >* >(elt.second));
273
274 // Adding tensors and eliminating the remaining nodes
275 for (const auto& a: *i)
276 if (_bb_.requisiteNodes(i).exists(a.first))
277 pool.insert(&(const_cast< Tensor< GUM_SCALAR >& >(a.second->cpf())));
278
280 const auto moralg = bn.moralGraph();
281 DefaultTriangulation t(&moralg, &(bn.modalities()));
282 const std::vector< NodeId >& full_elim_order = t.eliminationOrder();
283
284 for (auto var = full_elim_order.begin(); var != full_elim_order.end(); ++var)
285 eliminateNode(&(i->get(*var).type().variable()), pool, trash);
286 }
287
288 template < typename GUM_SCALAR >
290 BucketSet& pool,
291 BucketSet& trash) {
292 BucketSet* lifted_pool = nullptr;
293
294 try {
295 lifted_pool = _lifted_pools_[&(_bb_.requisiteNodes(i))];
296 } catch (NotFound const&) {
297 _initLiftedNodes_(i, trash);
298 lifted_pool = _lifted_pools_[&(_bb_.requisiteNodes(i))];
299 }
300
301 for (const auto lifted_pot: *lifted_pool) {
302 Tensor< GUM_SCALAR >* pot = copyTensor(i->bijection(), *lifted_pot);
303 pool.insert(pot);
304 trash.insert(pot);
305 }
306 }
307
308 template < typename GUM_SCALAR >
310 BucketSet& trash) {
311 PRMClass< GUM_SCALAR >& c = const_cast< PRMClass< GUM_SCALAR >& >(i->type());
312 BucketSet* lifted_pool = new BucketSet();
313 _lifted_pools_.insert(&(_bb_.requisiteNodes(i)), lifted_pool);
314
315 for (const auto node: _bb_.requisiteNodes(i))
317 lifted_pool->insert(const_cast< Tensor< GUM_SCALAR >* >(&(c.get(node).cpf())));
318
319 NodeSet inners, outers, ignore;
320
321 for (const auto& elt: *i) {
322 if (_bb_.requisiteNodes(*i).exists(elt.first)) {
324 if (c.isOutputNode(c.get(elt.first))) outers.insert(elt.first);
325 else if (!outers.exists(elt.first)) inners.insert(elt.first);
326 } else if (PRMClassElement< GUM_SCALAR >::isAggregate(c.get(elt.first))) {
327 outers.insert(elt.first);
328
329 // We need to put in the output_elim_order aggregator's parents
330 // which are
331 // innner nodes
332 for (const auto par: c.containerDag().parents(elt.first))
334 && i->type().isInnerNode(i->type().get(par))
335 && _bb_.requisiteNodes(i).exists(par)) {
336 inners.erase(par);
337 outers.insert(par);
338 }
339 }
340 } else {
341 ignore.insert(elt.first);
342 }
343 }
344
345 // Now we proceed with the elimination of inner attributes
347 List< NodeSet > partial_ordering;
348
349 if (inners.size()) partial_ordering.pushBack(inners);
350
351 if (outers.size()) partial_ordering.pushBack(outers);
352
353 if (ignore.size()) partial_ordering.pushBack(ignore);
354
355 GUM_ASSERT(inners.size() || outers.size());
356 const auto moralg = bn.moralGraph();
357 PartialOrderedTriangulation t(&moralg, &(bn.modalities()), &partial_ordering);
358
359 for (size_t idx = 0; idx < inners.size(); ++idx)
360 eliminateNode(&(c.get(t.eliminationOrder()[idx]).type().variable()), *lifted_pool, trash);
361
362 // If there is not only inner and input Attributes
363 if (outers.size()) {
364 _elim_orders_.insert(&c,
365 new std::vector< NodeId >(t.eliminationOrder().begin() + inners.size(),
366 t.eliminationOrder().end()));
367 }
368 }
369
370 template < typename GUM_SCALAR >
374 std::list< NodeId > l;
375
376 for (const auto node: cdg.dag().nodes()) {
377 if (cdg.dag().parents(node).empty()) { l.push_back(node); }
378 }
379
380 Set< NodeId > visited_node;
381
382 while (!l.empty()) {
383 visited_node.insert(l.front());
384
385 if (!class_elim_order.exists(cdg.get(l.front()).first)) {
386 class_elim_order.insert(cdg.get(l.front()).first);
387 }
388
389 for (const auto child: cdg.dag().children(l.front())) {
390 if (!visited_node.contains(child)) { l.push_back(child); }
391 }
392
393 l.pop_front();
394 }
395
397 for (auto c: class_elim_order) {
398 std::string name = c->name();
399 auto pos = name.find_first_of("<");
400 if (pos != std::string::npos) { name = name.substr(0, pos); }
401 try {
402 _class_elim_order_->insert(name);
403 } catch (DuplicateElement const&) {}
404 }
405 }
406
407 template < typename GUM_SCALAR >
408 void SVED< GUM_SCALAR >::posterior_(const Chain& chain, Tensor< GUM_SCALAR >& m) {
409 const PRMInstance< GUM_SCALAR >* i = chain.first;
410 const PRMAttribute< GUM_SCALAR >* elt = chain.second;
412 _bb_.compute(i, elt->id());
413 _eliminateNodes_(i, elt->id(), pool, trash);
414
415 std::vector< const Tensor< GUM_SCALAR >* > result;
416 for (auto pot: pool) {
417 if (pot->contains(*(m.variablesSequence().atPos(0)))) result.push_back(pot);
418 }
419
420 while (result.size() > 1) {
421 const auto& p1 = *(result.back());
422 result.pop_back();
423 const auto& p2 = *(result.back());
424 result.pop_back();
425 auto mult = new Tensor< GUM_SCALAR >(p1 * p2);
426 result.push_back(mult);
427 trash.insert(mult);
428 }
429
430 m = *(result.back());
431 m.normalize();
432
433 GUM_ASSERT(m.nbrDim() == (Size)1);
434
435 // cleaning up the mess
436 for (const auto pot: trash)
437 delete pot;
438
439 for (const auto& elt: _lifted_pools_)
440 delete elt.second;
441
442 _lifted_pools_.clear();
443
444 for (const auto& elt: _req_set_) {
445 delete elt.second.first;
446 delete elt.second.second;
447 }
448
449 _req_set_.clear();
450
451 for (const auto& elt: _elim_orders_)
452 delete elt.second;
453
454 _elim_orders_.clear();
455 }
456
457 template < typename GUM_SCALAR >
458 void SVED< GUM_SCALAR >::joint_(const std::vector< Chain >& queries, Tensor< GUM_SCALAR >& j) {
459 GUM_ERROR(FatalError, "Not implemented.")
460 }
461
462 template < typename GUM_SCALAR >
464 Set< NodeId >* attr_set = new Set< NodeId >();
465 Set< NodeId >* sc_set = new Set< NodeId >();
466
467 for (const auto node: _bb_.requisiteNodes(i)) {
468 switch (i->type().get(node).elt_type()) {
471 attr_set->insert(node);
472 break;
473 }
474
476 sc_set->insert(node);
477 break;
478 }
479
480 default : {
482 "There should not be elements other"
483 " than PRMAttribute<GUM_SCALAR> and SlotChain.");
484 }
485 }
486 }
487
488 _req_set_.insert(&(_bb_.requisiteNodes(i)),
489 std::pair< Set< NodeId >*, Set< NodeId >* >(attr_set, sc_set));
490 }
491
492 template < typename GUM_SCALAR >
494 const PRMSystem< GUM_SCALAR >& model) :
495 PRMInference< GUM_SCALAR >(prm, model), _class_elim_order_(0), _bb_(*this) {
496 GUM_CONSTRUCTOR(SVED);
497 }
498
499 template < typename GUM_SCALAR >
501 BucketSet& pool) {
502 for (const auto& elt: this->evidence(i))
503 pool.insert(const_cast< Tensor< GUM_SCALAR >* >(elt.second));
504 }
505
506 template < typename GUM_SCALAR >
507 INLINE std::vector< NodeId >&
511
512 template < typename GUM_SCALAR >
513 INLINE std::string SVED< GUM_SCALAR >::_trim_(const std::string& s) {
514 auto pos = s.find_first_of("<");
515 if (pos != std::string::npos) { return s.substr(0, pos); }
516 return s;
517 }
518
519 template < typename GUM_SCALAR >
521 const PRMInstance< GUM_SCALAR >* second) {
522 if (_class_elim_order_ == 0) { _initElimOrder_(); }
523
524 auto first_name = _trim_(first->type().name());
525 auto second_name = _trim_(second->type().name());
526 return (_class_elim_order_->pos(first_name) <= _class_elim_order_->pos(second_name));
527 }
528
529 template < typename GUM_SCALAR >
530 INLINE Tensor< GUM_SCALAR >*
532 const PRMAggregate< GUM_SCALAR >* agg) {
533 return &(const_cast< Tensor< GUM_SCALAR >& >(i->get(agg->safeName()).cpf()));
534 }
535
536 template < typename GUM_SCALAR >
537 INLINE void
539 // Do nothing
540 }
541
542 template < typename GUM_SCALAR >
543 INLINE void
545 // Do nothing
546 }
547
548 template < typename GUM_SCALAR >
550 try {
551 return *(_req_set_[&(_bb_.requisiteNodes(i))].first);
552 } catch (NotFound const&) {
553 _initReqSets_(i);
554 return *(_req_set_[&(_bb_.requisiteNodes(i))].first);
555 }
556 }
557
558 template < typename GUM_SCALAR >
560 try {
561 return *(_req_set_[&(_bb_.requisiteNodes(i))].second);
562 } catch (NotFound const&) {
563 _initReqSets_(i);
564 return *(_req_set_[&(_bb_.requisiteNodes(i))].second);
565 }
566 }
567
568 template < typename GUM_SCALAR >
569 INLINE void
571 List< const PRMInstance< GUM_SCALAR >* >& elim_list,
572 List< const PRMInstance< GUM_SCALAR >* >& reduced_list,
573 Set< const PRMInstance< GUM_SCALAR >* >& ignore,
574 BucketSet& pool,
575 BucketSet& trash) {
576 while (!elim_list.empty()) {
577 if (_checkElimOrder_(i, elim_list.front())) {
578 if ((!ignore.exists(elim_list.front())) && (_bb_.exists(elim_list.front()))) {
579 _eliminateNodesDownward_(i, elim_list.front(), pool, trash, elim_list, ignore);
580 }
581 } else if (_bb_.exists(elim_list.front())) {
582 reduced_list.insert(elim_list.front());
583 }
584
585 elim_list.popFront();
586 }
587 }
588
589 template < typename GUM_SCALAR >
590 INLINE std::string SVED< GUM_SCALAR >::name() const {
591 return "SVED";
592 }
593
594 } /* namespace prm */
595} /* namespace gum */
Headers of SVED (Structured Value Elimination with d-seperation).
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
UndiGraph moralGraph() const
The node's id are coherent with the variables and nodes of the topology.
Definition DAGmodel.cpp:64
The default triangulation algorithm used by aGrUM.
Exception : a similar element already exists.
Exception : fatal (unknown ?) error.
Generic doubly linked lists.
Definition list.h:379
Val & front() const
Returns a reference to first element of a list, if any.
Definition list_tpl.h:1703
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
Definition list_tpl.h:1831
void popFront()
Removes the first element of a List, if any.
Definition list_tpl.h:1825
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Definition list_tpl.h:1515
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition list_tpl.h:1488
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
Exception : the element we looked for cannot be found.
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...
bool exists(const Key &k) const
Check the existence of k in the sequence.
void insert(const Key &k)
Insert an element at the end of the sequence.
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:972
Representation of a set.
Definition set.h:131
Size size() const noexcept
Returns the number of elements in the set.
Definition set_tpl.h:636
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition set_tpl.h:533
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition set_tpl.h:497
void insert(const Key &k)
Inserts a new element into the set.
Definition set_tpl.h:539
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition set_tpl.h:642
void erase(const Key &k)
Erases an element from the set.
Definition set_tpl.h:582
const std::vector< NodeId > & eliminationOrder()
returns an elimination ordering compatible with the triangulated graph
This class decorates a gum::prm::Class<GUM_SCALAR> has an IBaseBayesNet.
const NodeProperty< Size > & modalities() const
See gum::IBaseBayesNet::modalities().
This class represent the dependencies of all classes in a PRM<GUM_SCALAR>.
const EltPair & get(NodeId id) const
Returns a constant reference over the element assiociated with the node id in the ClassDependencyGrap...
const DAG & dag() const
Returns a constant reference over the graph of the DAG representing the ClassDependencyGraph<GUM_SCAL...
This class decorates an PRMInstance<GUM_SCALAR> as an IBaseBayesNet.
virtual const DiscreteVariable & variable(NodeId id) const
See gum::IBaseBayesNet::variable().
const NodeProperty< Size > & modalities() const
See gum::IBaseBayesNet::cpt().
PRMAttribute is a member of a Class in a PRM.
virtual const DAG & containerDag() const
Returns the gum::DAG of this PRMClassElementContainer.
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
Definition PRMClass.h:75
PRMClassElement< GUM_SCALAR > & get(NodeId id)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
virtual bool isOutputNode(const PRMClassElement< GUM_SCALAR > &elt) const
Returns true if elt is an output node.
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
PRM< GUM_SCALAR > const * prm_
The PRM<GUM_SCALAR> on which inference is done.
bool hasEvidence(const PRMInstance< GUM_SCALAR > &i) const
Returns true if i has evidence.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
Definition PRMInstance.h:79
const Bijection< const DiscreteVariable *, const DiscreteVariable * > & bijection() const
Returns a mapping between DiscreteVariable used in this and the ones used in this PRMInstance<GUM_SCA...
std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & getRefAttr(NodeId id)
Returns a vector of pairs of refering attributes of id.
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
const Set< PRMInstance< GUM_SCALAR > * > & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition PRMSystem.h:70
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition PRM.h:74
~SVED()
Destructor.
Definition SVED_tpl.h:55
std::string _trim_(const std::string &s)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:513
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > * > _elim_orders_
Definition SVED.h:125
virtual void evidenceAdded_(const Chain &chain)
See PRMInference::evidenceAdded_().
Definition SVED_tpl.h:538
Set< Tensor< GUM_SCALAR > * > BucketSet
Code alias.
Definition SVED.h:121
virtual void joint_(const std::vector< Chain > &queries, Tensor< GUM_SCALAR > &j)
See PRMInference::joint_().
Definition SVED_tpl.h:458
void _eliminateNodesUpward_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:199
std::vector< NodeId > & _getElimOrder_(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:508
void _insertEvidence_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:500
virtual void evidenceRemoved_(const Chain &chain)
See PRMInference::evidenceRemoved_().
Definition SVED_tpl.h:544
virtual void posterior_(const Chain &chain, Tensor< GUM_SCALAR > &m)
See PRMInference::posterior_().
Definition SVED_tpl.h:408
void _initLiftedNodes_(const PRMInstance< GUM_SCALAR > *i, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:309
void _reduceElimList_(const PRMInstance< GUM_SCALAR > *i, List< const PRMInstance< GUM_SCALAR > * > &elim_list, List< const PRMInstance< GUM_SCALAR > * > &reduced_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:570
HashTable< const Set< NodeId > *, BucketSet * > _lifted_pools_
The Set<NodeId> returned by StructuredBayesBall<GUM_SCALAR> is unique for each family of instances wi...
Definition SVED.h:132
Set< NodeId > & _getAttrSet_(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:549
Sequence< std::string > * _class_elim_order_
Definition SVED.h:134
void _eliminateNodesWithEvidence_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:266
Tensor< GUM_SCALAR > * _getAggTensor_(const PRMInstance< GUM_SCALAR > *i, const PRMAggregate< GUM_SCALAR > *agg)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:531
void _initElimOrder_()
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:371
virtual std::string name() const
Returns the name of the current inference algorithm.
Definition SVED_tpl.h:590
HashTable< const Set< NodeId > *, std::pair< Set< NodeId > *, Set< NodeId > * > > _req_set_
First pair -> requisite Attributes Second pair -> requisite SlotChains.
Definition SVED.h:140
SVED(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &model)
Default Constructor.
Definition SVED_tpl.h:493
Set< NodeId > & _getSCSet_(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:559
bool _checkElimOrder_(const PRMInstance< GUM_SCALAR > *first, const PRMInstance< GUM_SCALAR > *second)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:520
void _insertLiftedNodes_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:289
void _eliminateNodes_(const PRMInstance< GUM_SCALAR > *query, NodeId id, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:65
typename PRMInference< GUM_SCALAR >::Chain Chain
Code alias.
Definition SVED.h:103
void _eliminateNodesDownward_(const PRMInstance< GUM_SCALAR > *from, const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:131
StructuredBayesBall< GUM_SCALAR > _bb_
Definition SVED.h:136
void _initReqSets_(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:463
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
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 ...
namespace for all probabilistic relational models entities
Definition agrum.h:68
void eliminateNode(const DiscreteVariable *var, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.
void eliminateNodes(const std::vector< const DiscreteVariable * > &elim_order, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)
Tensor< GUM_SCALAR > * copyTensor(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const Tensor< GUM_SCALAR > &source)
Returns a copy of a Tensor after applying a bijection over the variables in source.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46