aGrUM  0.16.0
SVED_tpl.h
Go to the documentation of this file.
1 
30 
31 namespace gum {
32  namespace prm {
33 
34  template < typename GUM_SCALAR >
36  GUM_DESTRUCTOR(SVED);
37 
38  for (const auto& elt : __elim_orders)
39  delete elt.second;
40 
41  if (__class_elim_order != nullptr) delete __class_elim_order;
42  }
43 
44  template < typename GUM_SCALAR >
45  void
47  NodeId node,
48  BucketSet& pool,
49  BucketSet& trash) {
51  ignore.insert(query);
52  // Extracting required attributes and slotchains
53  Set< NodeId >& attr_set = __getAttrSet(query);
54  Set< NodeId >& sc_set = __getSCSet(query);
55  // Downward elimination
57 
58  for (const auto attr : attr_set) {
59  try {
60  for (auto iter = query->getRefAttr(attr).begin();
61  iter != query->getRefAttr(attr).end();
62  ++iter)
63  if ((!ignore.exists(iter->first)) && (__bb.exists(iter->first)))
64  __eliminateNodesDownward(
65  query, iter->first, pool, trash, elim_list, ignore);
66  } catch (NotFound&) {
67  // Ok
68  }
69  }
70 
71  // Eliminating all nodes in query instance, except query
73  DefaultTriangulation t(&(bn.moralGraph()), &(bn.modalities()));
74  std::vector< const DiscreteVariable* > elim_order;
75 
76  if (this->hasEvidence(query)) __insertEvidence(query, pool);
77 
78  for (const auto attr : attr_set)
79  pool.insert(
80  &(const_cast< Potential< GUM_SCALAR >& >(query->get(attr).cpf())));
81 
82  for (size_t idx = 0; idx < t.eliminationOrder().size(); ++idx) {
83  if (t.eliminationOrder()[idx] != node) {
84  auto var_id = t.eliminationOrder()[idx];
85  const auto& var = bn.variable(var_id);
86  elim_order.push_back(&var);
87  }
88  }
89 
90  eliminateNodes(elim_order, pool, trash);
91  // Eliminating instance in elim_list
93  __reduceElimList(query, elim_list, tmp_list, ignore, pool, trash);
94 
95  while (!elim_list.empty()) {
96  if (__checkElimOrder(query, elim_list.front())) {
97  if ((!ignore.exists(elim_list.front()))
98  && (__bb.exists(elim_list.front())))
99  __eliminateNodesDownward(
100  query, elim_list.front(), pool, trash, elim_list, ignore);
101  } else if (__bb.exists(elim_list.front())) {
102  tmp_list.insert(elim_list.front());
103  }
104 
105  elim_list.popFront();
106  }
107 
108  // Upward elimination
109  for (const auto chain : sc_set)
110  for (const auto parent : query->getInstances(chain))
111  if ((!ignore.exists(parent)) && (__bb.exists(*parent)))
112  __eliminateNodesUpward(parent, pool, trash, tmp_list, ignore);
113  }
114 
115  template < typename GUM_SCALAR >
117  const PRMInstance< GUM_SCALAR >* from,
118  const PRMInstance< GUM_SCALAR >* i,
119  BucketSet& pool,
120  BucketSet& trash,
121  List< const PRMInstance< GUM_SCALAR >* >& elim_list,
122  Set< const PRMInstance< GUM_SCALAR >* >& ignore) {
123  ignore.insert(i);
124  // Extracting required attributes and slotchains
125  Set< NodeId >& attr_set = __getAttrSet(i);
126  Set< NodeId >& sc_set = __getSCSet(i);
127  // Calling elimination over child instance
129 
130  for (const auto attr : attr_set) {
131  try {
132  for (auto iter = i->getRefAttr(attr).begin();
133  iter != i->getRefAttr(attr).end();
134  ++iter)
135  if ((!ignore.exists(iter->first)) && (__bb.exists(iter->first)))
136  __eliminateNodesDownward(
137  i, iter->first, pool, trash, my_list, ignore);
138  } catch (NotFound&) {
139  // Ok
140  }
141  }
142 
143  // Eliminating all nodes in current instance
144  if (this->hasEvidence(i)) {
145  __eliminateNodesWithEvidence(i, pool, trash);
146  } else {
147  __insertLiftedNodes(i, pool, trash);
148 
149  for (const auto agg : i->type().aggregates())
150  if (__bb.requisiteNodes(i).exists(agg->id()))
151  pool.insert(__getAggPotential(i, agg));
152 
153  try {
155  std::vector< const DiscreteVariable* > elim_order;
156 
157  for (auto node : __getElimOrder(i->type())) {
158  const auto& var = bn.variable(node);
159  elim_order.push_back(&var);
160  }
161 
162  eliminateNodes(elim_order, pool, trash);
163  } catch (NotFound&) {
164  // Raised if there is no inner nodes to eliminate
165  }
166  }
167 
168  // Calling elimination over child's parents
169  while (!my_list.empty()) {
170  if (__checkElimOrder(i, my_list.front())) {
171  if ((!ignore.exists(my_list.front())) && (__bb.exists(my_list.front())))
172  __eliminateNodesDownward(
173  i, my_list.front(), pool, trash, my_list, ignore);
174  } else if (__bb.exists(my_list.front())) {
175  elim_list.insert(my_list.front());
176  }
177 
178  my_list.popFront();
179  }
180 
181  // Adding parents instance to elim_list
182  for (const auto chain : sc_set)
183  for (const auto parent : i->getInstances(chain))
184  if ((!ignore.exists(parent)) && __bb.exists(parent) && (parent != from))
185  elim_list.insert(parent);
186  }
187 
188  template < typename GUM_SCALAR >
190  const PRMInstance< GUM_SCALAR >* i,
191  BucketSet& pool,
192  BucketSet& trash,
193  List< const PRMInstance< GUM_SCALAR >* >& elim_list,
194  Set< const PRMInstance< GUM_SCALAR >* >& ignore) {
195  ignore.insert(i);
196  // Extracting required attributes and slotchains
197  Set< NodeId >& attr_set = __getAttrSet(i);
198  Set< NodeId >& sc_set = __getSCSet(i);
199 
200  // Downward elimination
201  for (const auto attr : attr_set) {
202  try {
203  for (auto iter = i->getRefAttr(attr).begin();
204  iter != i->getRefAttr(attr).end();
205  ++iter)
206  if ((!ignore.exists(iter->first)) && (__bb.exists(iter->first)))
207  __eliminateNodesDownward(
208  i, iter->first, pool, trash, elim_list, ignore);
209  } catch (NotFound&) {
210  // Ok
211  }
212  }
213 
214  // Eliminating all nodes in i instance
215  if (this->hasEvidence(i)) {
216  __eliminateNodesWithEvidence(i, pool, trash);
217  } else {
218  __insertLiftedNodes(i, pool, trash);
219 
220  for (const auto agg : i->type().aggregates())
221  if (__bb.requisiteNodes(i).exists(agg->id()))
222  pool.insert(__getAggPotential(i, agg));
223 
224  try {
226  std::vector< const DiscreteVariable* > elim_order;
227 
228  for (auto node : __getElimOrder(i->type())) {
229  const auto& var = bn.variable(node);
230  elim_order.push_back(&var);
231  }
232  eliminateNodes(elim_order, pool, trash);
233  } catch (NotFound&) {
234  // Raised if there is no inner nodes to eliminate
235  }
236  }
237 
238  // Eliminating instance in elim_list
240 
241  while (!elim_list.empty()) {
242  if (__checkElimOrder(i, elim_list.front())) {
243  if ((!ignore.exists(elim_list.front()))
244  && (__bb.exists(elim_list.front())))
245  __eliminateNodesDownward(
246  i, elim_list.front(), pool, trash, elim_list, ignore);
247  } else if (__bb.exists(elim_list.front())) {
248  ignore.insert(elim_list.front());
249  }
250 
251  elim_list.popFront();
252  }
253 
254  // Upward elimination
255  for (const auto chain : sc_set)
256  for (const auto parent : i->getInstances(chain))
257  if ((!ignore.exists(parent)) && (__bb.exists(parent)))
258  __eliminateNodesUpward(parent, pool, trash, tmp_list, ignore);
259  }
260 
261  template < typename GUM_SCALAR >
263  const PRMInstance< GUM_SCALAR >* i, BucketSet& pool, BucketSet& trash) {
264  // Adding required evidences
265  for (const auto& elt : this->evidence(i))
266  if (__bb.requisiteNodes(i).exists(elt.first))
267  pool.insert(const_cast< Potential< GUM_SCALAR >* >(elt.second));
268 
269  // Adding potentials and eliminating the remaining nodes
270  for (const auto& a : *i)
271  if (__bb.requisiteNodes(i).exists(a.first))
272  pool.insert(&(const_cast< Potential< GUM_SCALAR >& >(a.second->cpf())));
273 
275  DefaultTriangulation t(&(bn.moralGraph()), &(bn.modalities()));
276  const std::vector< NodeId >& full_elim_order = t.eliminationOrder();
277 
278  for (auto var = full_elim_order.begin(); var != full_elim_order.end(); ++var)
279  eliminateNode(&(i->get(*var).type().variable()), pool, trash);
280  }
281 
282  template < typename GUM_SCALAR >
284  const PRMInstance< GUM_SCALAR >* i, BucketSet& pool, BucketSet& trash) {
285  BucketSet* lifted_pool = nullptr;
286 
287  try {
288  lifted_pool = __lifted_pools[&(__bb.requisiteNodes(i))];
289  } catch (NotFound&) {
290  __initLiftedNodes(i, trash);
291  lifted_pool = __lifted_pools[&(__bb.requisiteNodes(i))];
292  }
293 
294  for (const auto lifted_pot : *lifted_pool) {
295  Potential< GUM_SCALAR >* pot = copyPotential(i->bijection(), *lifted_pot);
296  pool.insert(pot);
297  trash.insert(pot);
298  }
299  }
300 
301  template < typename GUM_SCALAR >
303  BucketSet& trash) {
304  PRMClass< GUM_SCALAR >& c = const_cast< PRMClass< GUM_SCALAR >& >(i->type());
305  BucketSet* lifted_pool = new BucketSet();
306  __lifted_pools.insert(&(__bb.requisiteNodes(i)), lifted_pool);
307 
308  for (const auto node : __bb.requisiteNodes(i))
310  lifted_pool->insert(
311  const_cast< Potential< GUM_SCALAR >* >(&(c.get(node).cpf())));
312 
313  NodeSet inners, outers, ignore;
314 
315  for (const auto& elt : *i) {
316  if (__bb.requisiteNodes(*i).exists(elt.first)) {
318  if (c.isOutputNode(c.get(elt.first)))
319  outers.insert(elt.first);
320  else if (!outers.exists(elt.first))
321  inners.insert(elt.first);
323  c.get(elt.first))) {
324  outers.insert(elt.first);
325 
326  // We need to put in the output_elim_order aggregator's parents
327  // which are
328  // innner nodes
329  for (const auto par : c.containerDag().parents(elt.first))
330  if (PRMClassElement< GUM_SCALAR >::isAttribute(i->type().get(par))
331  && i->type().isInnerNode(i->type().get(par))
332  && __bb.requisiteNodes(i).exists(par)) {
333  inners.erase(par);
334  outers.insert(par);
335  }
336  }
337  } else {
338  ignore.insert(elt.first);
339  }
340  }
341 
342  // Now we proceed with the elimination of inner attributes
344  List< NodeSet > partial_ordering;
345 
346  if (inners.size()) partial_ordering.pushBack(inners);
347 
348  if (outers.size()) partial_ordering.pushBack(outers);
349 
350  if (ignore.size()) partial_ordering.pushBack(ignore);
351 
352  GUM_ASSERT(inners.size() || outers.size());
354  &(bn.moralGraph()), &(bn.modalities()), &partial_ordering);
355 
356  for (size_t idx = 0; idx < inners.size(); ++idx)
357  eliminateNode(&(c.get(t.eliminationOrder()[idx]).type().variable()),
358  *lifted_pool,
359  trash);
360 
361  // If there is not only inner and input Attributes
362  if (outers.size()) {
363  __elim_orders.insert(
364  &c,
365  new std::vector< NodeId >(t.eliminationOrder().begin() + inners.size(),
366  t.eliminationOrder().end()));
367  }
368  }
369 
370  template < typename GUM_SCALAR >
372  ClassDependencyGraph< GUM_SCALAR > cdg(*(this->_prm));
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 
396  __class_elim_order = new Sequence< std::string >();
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&) {}
404  }
405  }
406 
407  template < typename GUM_SCALAR >
410  const PRMInstance< GUM_SCALAR >* i = chain.first;
411  const PRMAttribute< GUM_SCALAR >* elt = chain.second;
412  SVED< GUM_SCALAR >::BucketSet pool, trash;
413  __bb.compute(i, elt->id());
414  __eliminateNodes(i, elt->id(), pool, trash);
415 
416  std::vector< const Potential< GUM_SCALAR >* > result;
417  for (auto pot : pool) {
418  if (pot->contains(*(m.variablesSequence().atPos(0))))
419  result.push_back(pot);
420  }
421 
422  while (result.size() > 1) {
423  const auto& p1 = *(result.back());
424  result.pop_back();
425  const auto& p2 = *(result.back());
426  result.pop_back();
427  auto mult = new Potential< GUM_SCALAR >(p1 * p2);
428  result.push_back(mult);
429  trash.insert(mult);
430  }
431 
432  m = *(result.back());
433  m.normalize();
434 
435  GUM_ASSERT(m.nbrDim() == (Size)1);
436 
437  // cleaning up the mess
438  for (const auto pot : trash)
439  delete pot;
440 
441  for (const auto& elt : __lifted_pools)
442  delete elt.second;
443 
444  __lifted_pools.clear();
445 
446  for (const auto& elt : __req_set) {
447  delete elt.second.first;
448  delete elt.second.second;
449  }
450 
451  __req_set.clear();
452 
453  for (const auto elt : __elim_orders)
454  delete elt.second;
455 
456  __elim_orders.clear();
457  }
458 
459  template < typename GUM_SCALAR >
460  void SVED< GUM_SCALAR >::_joint(const std::vector< Chain >& queries,
462  GUM_ERROR(FatalError, "Not implemented.");
463  }
464 
465  template < typename GUM_SCALAR >
467  Set< NodeId >* attr_set = new Set< NodeId >();
468  Set< NodeId >* sc_set = new Set< NodeId >();
469 
470  for (const auto node : __bb.requisiteNodes(i)) {
471  switch (i->type().get(node).elt_type()) {
474  attr_set->insert(node);
475  break;
476  }
477 
479  sc_set->insert(node);
480  break;
481  }
482 
483  default: {
485  "There should not be elements other"
486  " than PRMAttribute<GUM_SCALAR> and SlotChain.");
487  }
488  }
489  }
490 
491  __req_set.insert(
492  &(__bb.requisiteNodes(i)),
493  std::pair< Set< NodeId >*, Set< NodeId >* >(attr_set, sc_set));
494  }
495 
496  template < typename GUM_SCALAR >
498  const PRMSystem< GUM_SCALAR >& model) :
499  PRMInference< GUM_SCALAR >(prm, model),
500  __class_elim_order(0), __bb(*this) {
501  GUM_CONSTRUCTOR(SVED);
502  }
503 
504 
505  template < typename GUM_SCALAR >
506  INLINE void
508  BucketSet& pool) {
509  for (const auto& elt : this->evidence(i))
510  pool.insert(const_cast< Potential< GUM_SCALAR >* >(elt.second));
511  }
512 
513  template < typename GUM_SCALAR >
514  INLINE std::vector< NodeId >&
516  return *(__elim_orders[&c]);
517  }
518 
519  template < typename GUM_SCALAR >
520  INLINE std::string SVED< GUM_SCALAR >::__trim(const std::string& s) {
521  auto pos = s.find_first_of("<");
522  if (pos != std::string::npos) { return s.substr(0, pos); }
523  return s;
524  }
525 
526  template < typename GUM_SCALAR >
528  const PRMInstance< GUM_SCALAR >* first,
529  const PRMInstance< GUM_SCALAR >* second) {
530  if (__class_elim_order == 0) { __initElimOrder(); }
531 
532  auto first_name = __trim(first->type().name());
533  auto second_name = __trim(second->type().name());
534  return (__class_elim_order->pos(first_name)
535  <= __class_elim_order->pos(second_name));
536  }
537 
538  template < typename GUM_SCALAR >
541  return &(
542  const_cast< Potential< GUM_SCALAR >& >(i->get(agg->safeName()).cpf()));
543  }
544 
545  template < typename GUM_SCALAR >
547  const typename SVED< GUM_SCALAR >::Chain& chain) {
548  // Do nothing
549  }
550 
551  template < typename GUM_SCALAR >
553  const typename SVED< GUM_SCALAR >::Chain& chain) {
554  // Do nothing
555  }
556 
557  template < typename GUM_SCALAR >
558  INLINE Set< NodeId >&
560  try {
561  return *(__req_set[&(__bb.requisiteNodes(i))].first);
562  } catch (NotFound&) {
563  __initReqSets(i);
564  return *(__req_set[&(__bb.requisiteNodes(i))].first);
565  }
566  }
567 
568  template < typename GUM_SCALAR >
569  INLINE Set< NodeId >&
571  try {
572  return *(__req_set[&(__bb.requisiteNodes(i))].second);
573  } catch (NotFound&) {
574  __initReqSets(i);
575  return *(__req_set[&(__bb.requisiteNodes(i))].second);
576  }
577  }
578 
579  template < typename GUM_SCALAR >
581  const PRMInstance< GUM_SCALAR >* i,
582  List< const PRMInstance< GUM_SCALAR >* >& elim_list,
583  List< const PRMInstance< GUM_SCALAR >* >& reduced_list,
584  Set< const PRMInstance< GUM_SCALAR >* >& ignore,
585  BucketSet& pool,
586  BucketSet& trash) {
587  while (!elim_list.empty()) {
588  if (__checkElimOrder(i, elim_list.front())) {
589  if ((!ignore.exists(elim_list.front()))
590  && (__bb.exists(elim_list.front()))) {
592  i, elim_list.front(), pool, trash, elim_list, ignore);
593  }
594  } else if (__bb.exists(elim_list.front())) {
595  reduced_list.insert(elim_list.front());
596  }
597 
598  elim_list.popFront();
599  }
600  }
601 
602  template < typename GUM_SCALAR >
603  INLINE std::string SVED< GUM_SCALAR >::name() const {
604  return "SVED";
605  }
606 
607  } /* namespace prm */
608 } /* namespace gum */
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:581
HashTable< const Set< NodeId > *, std::pair< Set< NodeId > *, Set< NodeId > *> > __req_set
First pair -> requisite Attributes Second pair -> requisite SlotChains.
Definition: SVED.h:138
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
Definition: list_tpl.h:1970
virtual std::string name() const
Returns the name of the current inference algorithm.
Definition: SVED_tpl.h:603
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
Idx pos(const Key &key) const
Returns the position of the object passed in argument (if it exists).
Definition: sequence_tpl.h:518
void __insertEvidence(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:507
virtual void _marginal(const Chain &chain, Potential< GUM_SCALAR > &m)
See PRMInference::_marginal().
Definition: SVED_tpl.h:408
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:46
const DAG & dag() const
Returns a constant reference over the graph of the DAG representing the ClassDependencyGraph<GUM_SCAL...
virtual const DiscreteVariable & variable(NodeId id) const
See gum::IBaseBayesNet::variable().
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
virtual void _evidenceRemoved(const Chain &chain)
See PRMInference::_evidenceRemoved().
Definition: SVED_tpl.h:552
SVED(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &model)
Default Constructor.
Definition: SVED_tpl.h:497
Set< NodeId > & __getSCSet(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:570
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
Definition: PRMInstance.h:63
const Potential< GUM_SCALAR > & normalize() const
normalisation of this do nothing if sum is 0
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1022
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
void __initElimOrder()
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:371
const NodeProperty< Size > & modalities() const
See gum::IBaseBayesNet::cpt().
Abstract class representing an element of PRM class.
Potential< GUM_SCALAR > * __getAggPotential(const PRMInstance< GUM_SCALAR > *i, const PRMAggregate< GUM_SCALAR > *agg)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:539
void __initReqSets(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:466
const EltPair & get(NodeId id) const
Returns a constant reference over the element assiociated with the node id in the ClassDependencyGrap...
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:656
Generic doubly linked lists.
Definition: list.h:372
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void popFront()
Removes the first element of a List, if any.
Definition: list_tpl.h:1964
void __initLiftedNodes(const PRMInstance< GUM_SCALAR > *i, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:302
std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & getRefAttr(NodeId id)
Returns a vector of pairs of refering attributes of id.
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:165
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
PRMInference< GUM_SCALAR >::Chain Chain
Code alias.
Definition: SVED.h:93
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:607
std::vector< NodeId > & __getElimOrder(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:515
This class decorates a gum::prm::Class<GUM_SCALAR> has an IBaseBayesNet.
Definition: classBayesNet.h:60
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...
void __insertLiftedNodes(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:283
This class is an implementation of the Structured Value Elimination algorithm on PRM<GUM_SCALAR>.
Definition: SVED.h:63
The default triangulation algorithm used by aGrUM.
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1592
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...
const std::vector< NodeId > & eliminationOrder()
returns an elimination ordering compatible with the triangulated graph
PRMClassElement< GUM_SCALAR > & get(NodeId id)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
Sequence< std::string > * __class_elim_order
Definition: SVED.h:130
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition: PRMObject.h:229
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:116
bool exists(const Key &k) const
Check the existence of k in the sequence.
Definition: sequence_tpl.h:402
StructuredBayesBall< GUM_SCALAR > __bb
Definition: SVED.h:132
Potential< GUM_SCALAR > * copyPotential(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const Potential< GUM_SCALAR > &source)
Returns a copy of a Potential after applying a bijection over the variables in source.
Definition: utils_prm_tpl.h:29
std::string __trim(const std::string &s)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:520
This class represent the dependencies of all classes in a PRM<GUM_SCALAR>.
void eliminateNode(const DiscreteVariable *var, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.
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:527
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
virtual bool isOutputNode(const PRMClassElement< GUM_SCALAR > &elt) const
Returns true if elt is an output node.
void eliminateNodes(const std::vector< const DiscreteVariable * > &elim_order, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > *> Chain
Code alias.
Definition: PRMInference.h:57
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Definition: list_tpl.h:1619
Val & front() const
Returns a reference to first element of a list, if any.
Definition: list_tpl.h:1831
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
Definition: PRMInference.h:52
const UndiGraph & moralGraph(bool clear=true) const
The node&#39;s id are coherent with the variables and nodes of the topology.
Definition: DAGmodel.cpp:101
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition: PRM.h:66
NodeId id() const
Returns the NodeId of this element in it&#39;s class DAG.
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
Definition: PRMClass.h:66
virtual void _joint(const std::vector< Chain > &queries, Potential< GUM_SCALAR > &j)
See PRMInference::_joint().
Definition: SVED_tpl.h:460
void __eliminateNodesWithEvidence(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:262
This class decorates an PRMInstance<GUM_SCALAR> as an IBaseBayesNet.
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > *> __elim_orders
Definition: SVED.h:121
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:189
virtual void _evidenceAdded(const Chain &chain)
See PRMInference::_evidenceAdded().
Definition: SVED_tpl.h:546
PRMAttribute is a member of a Class in a PRM.
Definition: PRMAttribute.h:61
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns a const ref to the sequence of DiscreteVariable*.
Set< NodeId > & __getAttrSet(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:559
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
~SVED()
Destructor.
Definition: SVED_tpl.h:35
virtual const DAG & containerDag() const
Returns the gum::DAG of this PRMClassElementContainer.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
const NodeProperty< Size > & modalities() const
See gum::IBaseBayesNet::modalities().
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
const Set< PRMInstance< GUM_SCALAR > *> & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
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:580
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:408