aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::prm::SVED< GUM_SCALAR > Class Template Reference

This class is an implementation of the Structured Value Elimination algorithm on PRM<GUM_SCALAR>. More...

#include <agrum/PRM/SVED.h>

+ Inheritance diagram for gum::prm::SVED< GUM_SCALAR >:
+ Collaboration diagram for gum::prm::SVED< GUM_SCALAR >:

Public Member Functions

Constructors & destructor.
 SVED (const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &model)
 Default Constructor. More...
 
 ~SVED ()
 Destructor. More...
 
Getters & setters.
virtual std::string name () const
 Returns the name of the current inference algorithm. More...
 
Query methods.
void posterior (const Chain &chain, Potential< GUM_SCALAR > &m)
 Compute the posterior of the formal attribute pointed by chain and stores it in m. More...
 
void joint (const std::vector< Chain > &chains, Potential< GUM_SCALAR > &j)
 Compute the joint probability of the formals attributes pointed by chains and stores it in m. More...
 
Evidence handling.
EMapevidence (const PRMInstance< GUM_SCALAR > &i)
 Returns EMap of evidences over i. More...
 
EMapevidence (const PRMInstance< GUM_SCALAR > *i)
 Returns EMap of evidences over i. More...
 
const EMapevidence (const PRMInstance< GUM_SCALAR > &i) const
 Returns EMap of evidences over i. More...
 
const EMapevidence (const PRMInstance< GUM_SCALAR > *i) const
 Returns EMap of evidences over i. More...
 
bool hasEvidence (const PRMInstance< GUM_SCALAR > &i) const
 Returns true if i has evidence. More...
 
bool hasEvidence (const PRMInstance< GUM_SCALAR > *i) const
 Returns EMap of evidences over i. More...
 
bool hasEvidence (const Chain &chain) const
 Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a. More...
 
bool hasEvidence () const
 Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a. More...
 
void addEvidence (const Chain &chain, const Potential< GUM_SCALAR > &p)
 Add an evidence to the given instance's elt. More...
 
void removeEvidence (const Chain &chain)
 Remove evidence on the given instance's elt. More...
 
void clearEvidence ()
 Remove all evidences. More...
 

Public Types

typedef NodeProperty< const Potential< GUM_SCALAR > *> EMap
 Code alias. More...
 
typedef NodeProperty< const Potential< GUM_SCALAR > *>::iterator_safe EMapIterator
 Code alias. More...
 
typedef NodeProperty< const Potential< GUM_SCALAR > *>::const_iterator_safe EMapConstIterator
 Code alias. More...
 

Protected Attributes

Protected members.
PRM< GUM_SCALAR > const * prm_
 The PRM<GUM_SCALAR> on which inference is done. More...
 
PRMSystem< GUM_SCALAR > const * sys_
 The Model on which inference is done. More...
 

Query methods.

typedef PRMInference< GUM_SCALAR >::Chain Chain
 Code alias. More...
 
virtual void evidenceAdded_ (const Chain &chain)
 See PRMInference::evidenceAdded_(). More...
 
virtual void evidenceRemoved_ (const Chain &chain)
 See PRMInference::evidenceRemoved_(). More...
 
virtual void posterior_ (const Chain &chain, Potential< GUM_SCALAR > &m)
 See PRMInference::posterior_(). More...
 
virtual void joint_ (const std::vector< Chain > &queries, Potential< GUM_SCALAR > &j)
 See PRMInference::joint_(). More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::SVED< GUM_SCALAR >

This class is an implementation of the Structured Value Elimination algorithm on PRM<GUM_SCALAR>.

Definition at line 62 of file SVED.h.

Member Typedef Documentation

◆ ArraySetIterator

template<typename GUM_SCALAR >
typedef Set< MultiDimArray< GUM_SCALAR >* >::iterator_safe gum::prm::SVED< GUM_SCALAR >::ArraySetIterator
private

Code alias.

Definition at line 117 of file SVED.h.

◆ BucketSet

template<typename GUM_SCALAR >
typedef Set< Potential< GUM_SCALAR >* > gum::prm::SVED< GUM_SCALAR >::BucketSet
private

Code alias.

Definition at line 110 of file SVED.h.

◆ BucketSetIterator

template<typename GUM_SCALAR >
typedef Set< Potential< GUM_SCALAR >* >::iterator_safe gum::prm::SVED< GUM_SCALAR >::BucketSetIterator
private

Code alias.

Definition at line 113 of file SVED.h.

◆ Chain

template<typename GUM_SCALAR >
typedef PRMInference< GUM_SCALAR >::Chain gum::prm::SVED< GUM_SCALAR >::Chain
protected

Code alias.

Definition at line 92 of file SVED.h.

◆ EMap

template<typename GUM_SCALAR>
typedef NodeProperty< const Potential< GUM_SCALAR >* > gum::prm::PRMInference< GUM_SCALAR >::EMap
inherited

Code alias.

Definition at line 59 of file PRMInference.h.

◆ EMapConstIterator

template<typename GUM_SCALAR>
typedef NodeProperty< const Potential< GUM_SCALAR >* >::const_iterator_safe gum::prm::PRMInference< GUM_SCALAR >::EMapConstIterator
inherited

Code alias.

Definition at line 68 of file PRMInference.h.

◆ EMapIterator

template<typename GUM_SCALAR>
typedef NodeProperty< const Potential< GUM_SCALAR >* >::iterator_safe gum::prm::PRMInference< GUM_SCALAR >::EMapIterator
inherited

Code alias.

Definition at line 64 of file PRMInference.h.

Constructor & Destructor Documentation

◆ SVED()

template<typename GUM_SCALAR >
INLINE gum::prm::SVED< GUM_SCALAR >::SVED ( const PRM< GUM_SCALAR > &  prm,
const PRMSystem< GUM_SCALAR > &  model 
)

Default Constructor.

Definition at line 525 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

526  :
527  PRMInference< GUM_SCALAR >(prm, model),
528  class_elim_order__(0), bb__(*this) {
529  GUM_CONSTRUCTOR(SVED);
530  }
SVED(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &model)
Default Constructor.
Definition: SVED_tpl.h:525
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
Sequence< std::string > * class_elim_order__
Definition: SVED.h:129
+ Here is the call graph for this function:

◆ ~SVED()

template<typename GUM_SCALAR >
gum::prm::SVED< GUM_SCALAR >::~SVED ( )

Destructor.

Definition at line 34 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

34  {
35  GUM_DESTRUCTOR(SVED);
36 
37  for (const auto& elt: elim_orders__)
38  delete elt.second;
39 
40  if (class_elim_order__ != nullptr) delete class_elim_order__;
41  }
SVED(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &model)
Default Constructor.
Definition: SVED_tpl.h:525
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > *> elim_orders__
Definition: SVED.h:120
Sequence< std::string > * class_elim_order__
Definition: SVED.h:129
+ Here is the call graph for this function:

Member Function Documentation

◆ addEvidence()

template<typename GUM_SCALAR>
void gum::prm::PRMInference< GUM_SCALAR >::addEvidence ( const Chain chain,
const Potential< GUM_SCALAR > &  p 
)
inherited

Add an evidence to the given instance's elt.

Parameters
chainThe variable being observed.
pThe Potential added (by copy) as evidence.
Exceptions
NotFoundRaised if elt does not belong to i.
OperationNotAllowedRaised if p is inconsistent with elt.

Definition at line 108 of file PRMInference_tpl.h.

109  {
110  if (chain.first->exists(chain.second->id())) {
111  if ((p.nbrDim() != 1) || (!p.contains(chain.second->type().variable())))
112  GUM_ERROR(OperationNotAllowed,
113  "illegal evidence for the given PRMAttribute.");
114 
115  Potential< GUM_SCALAR >* e = new Potential< GUM_SCALAR >();
116  e->add(chain.second->type().variable());
117  Instantiation i(*e);
118 
119  for (i.setFirst(); !i.end(); i.inc())
120  e->set(i, p.get(i));
121 
122  PRMInference< GUM_SCALAR >::EMap& emap = EMap__(chain.first);
123 
124  if (emap.exists(chain.second->id())) {
125  delete emap[chain.second->id()];
126  emap[chain.second->id()] = e;
127  } else {
128  emap.insert(chain.second->id(), e);
129  }
130 
131  evidenceAdded_(chain);
132  } else {
133  GUM_ERROR(NotFound,
134  "the given PRMAttribute does not belong to this "
135  "Instance<GUM_SCALAR>.");
136  }
137  }
virtual void evidenceAdded_(const Chain &chain)=0
This method is called whenever an evidence is added, but AFTER any processing made by PRMInference...
EMap & EMap__(const PRMInstance< GUM_SCALAR > *i)
Private getter over evidences__, if necessary creates an EMap for i.
NodeProperty< const Potential< GUM_SCALAR > *> EMap
Code alias.
Definition: PRMInference.h:59
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ checkElimOrder__()

template<typename GUM_SCALAR >
INLINE bool gum::prm::SVED< GUM_SCALAR >::checkElimOrder__ ( const PRMInstance< GUM_SCALAR > *  first,
const PRMInstance< GUM_SCALAR > *  second 
)
private

Returns true if second can be eliminated before first.

Definition at line 555 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

557  {
558  if (class_elim_order__ == 0) { initElimOrder__(); }
559 
560  auto first_name = trim__(first->type().name());
561  auto second_name = trim__(second->type().name());
562  return (class_elim_order__->pos(first_name)
563  <= class_elim_order__->pos(second_name));
564  }
void initElimOrder__()
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:399
Idx pos(const Key &key) const
Returns the position of the object passed in argument (if it exists).
Definition: sequence_tpl.h:519
std::string trim__(const std::string &s)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:548
Sequence< std::string > * class_elim_order__
Definition: SVED.h:129
+ Here is the call graph for this function:

◆ clearEvidence()

template<typename GUM_SCALAR >
void gum::prm::PRMInference< GUM_SCALAR >::clearEvidence ( )
inherited

Remove all evidences.

Definition at line 35 of file PRMInference_tpl.h.

35  {
36  for (const auto& elt: evidences__) {
37  for (const auto& elt2: *elt.second)
38  delete elt2.second;
39 
40  delete elt.second;
41  }
42 
43  evidences__.clear();
44  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> evidences__
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:235

◆ eliminateNodes__()

template<typename GUM_SCALAR >
void gum::prm::SVED< GUM_SCALAR >::eliminateNodes__ ( const PRMInstance< GUM_SCALAR > *  query,
NodeId  id,
BucketSet pool,
BucketSet trash 
)
private

Returns true if second can be eliminated before first.

Definition at line 45 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

48  {
49  Set< const PRMInstance< GUM_SCALAR >* > ignore;
50  ignore.insert(query);
51  // Extracting required attributes and slotchains
52  Set< NodeId >& attr_set = getAttrSet__(query);
53  Set< NodeId >& sc_set = getSCSet__(query);
54  // Downward elimination
55  List< const PRMInstance< GUM_SCALAR >* > elim_list;
56 
57  for (const auto attr: attr_set) {
58  try {
59  for (auto iter = query->getRefAttr(attr).begin();
60  iter != query->getRefAttr(attr).end();
61  ++iter)
62  if ((!ignore.exists(iter->first)) && (bb__.exists(iter->first)))
64  iter->first,
65  pool,
66  trash,
67  elim_list,
68  ignore);
69  } catch (NotFound&) {
70  // Ok
71  }
72  }
73 
74  // Eliminating all nodes in query instance, except query
75  InstanceBayesNet< GUM_SCALAR > bn(*query);
76  DefaultTriangulation t(&(bn.moralGraph()), &(bn.modalities()));
77  std::vector< const DiscreteVariable* > elim_order;
78 
79  if (this->hasEvidence(query)) insertEvidence__(query, pool);
80 
81  for (const auto attr: attr_set)
82  pool.insert(
83  &(const_cast< Potential< GUM_SCALAR >& >(query->get(attr).cpf())));
84 
85  for (size_t idx = 0; idx < t.eliminationOrder().size(); ++idx) {
86  if (t.eliminationOrder()[idx] != node) {
87  auto var_id = t.eliminationOrder()[idx];
88  const auto& var = bn.variable(var_id);
89  elim_order.push_back(&var);
90  }
91  }
92 
93  eliminateNodes(elim_order, pool, trash);
94  // Eliminating instance in elim_list
95  List< const PRMInstance< GUM_SCALAR >* > tmp_list;
96  reduceElimList__(query, elim_list, tmp_list, ignore, pool, trash);
97 
98  while (!elim_list.empty()) {
99  if (checkElimOrder__(query, elim_list.front())) {
100  if ((!ignore.exists(elim_list.front()))
101  && (bb__.exists(elim_list.front())))
103  elim_list.front(),
104  pool,
105  trash,
106  elim_list,
107  ignore);
108  } else if (bb__.exists(elim_list.front())) {
109  tmp_list.insert(elim_list.front());
110  }
111 
112  elim_list.popFront();
113  }
114 
115  // Upward elimination
116  for (const auto chain: sc_set)
117  for (const auto parent: query->getInstances(chain))
118  if ((!ignore.exists(parent)) && (bb__.exists(*parent)))
119  eliminateNodesUpward__(parent, pool, trash, tmp_list, ignore);
120  }
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:123
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:609
Set< NodeId > & getSCSet__(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:599
void insertEvidence__(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:535
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:555
bool hasEvidence() const
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
void eliminateNodes(const std::vector< const DiscreteVariable * > &elim_order, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
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:204
Set< NodeId > & getAttrSet__(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:588
+ Here is the call graph for this function:

◆ eliminateNodesDownward__()

template<typename GUM_SCALAR >
void gum::prm::SVED< GUM_SCALAR >::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 
)
private

Returns true if second can be eliminated before first.

Definition at line 123 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

129  {
130  ignore.insert(i);
131  // Extracting required attributes and slotchains
132  Set< NodeId >& attr_set = getAttrSet__(i);
133  Set< NodeId >& sc_set = getSCSet__(i);
134  // Calling elimination over child instance
135  List< const PRMInstance< GUM_SCALAR >* > my_list;
136 
137  for (const auto attr: attr_set) {
138  try {
139  for (auto iter = i->getRefAttr(attr).begin();
140  iter != i->getRefAttr(attr).end();
141  ++iter)
142  if ((!ignore.exists(iter->first)) && (bb__.exists(iter->first)))
144  iter->first,
145  pool,
146  trash,
147  my_list,
148  ignore);
149  } catch (NotFound&) {
150  // Ok
151  }
152  }
153 
154  // Eliminating all nodes in current instance
155  if (this->hasEvidence(i)) {
156  eliminateNodesWithEvidence__(i, pool, trash);
157  } else {
158  insertLiftedNodes__(i, pool, trash);
159 
160  for (const auto agg: i->type().aggregates())
161  if (bb__.requisiteNodes(i).exists(agg->id()))
162  pool.insert(getAggPotential__(i, agg));
163 
164  try {
165  InstanceBayesNet< GUM_SCALAR > bn(*i);
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&) {
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())))
184  my_list.front(),
185  pool,
186  trash,
187  my_list,
188  ignore);
189  } else if (bb__.exists(my_list.front())) {
190  elim_list.insert(my_list.front());
191  }
192 
193  my_list.popFront();
194  }
195 
196  // Adding parents instance to elim_list
197  for (const auto chain: sc_set)
198  for (const auto parent: i->getInstances(chain))
199  if ((!ignore.exists(parent)) && bb__.exists(parent) && (parent != from))
200  elim_list.insert(parent);
201  }
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:123
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:567
Set< NodeId > & getSCSet__(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:599
void insertLiftedNodes__(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:309
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:555
void eliminateNodesWithEvidence__(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:285
bool hasEvidence() const
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
void eliminateNodes(const std::vector< const DiscreteVariable * > &elim_order, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
std::vector< NodeId > & getElimOrder__(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:543
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
Set< NodeId > & getAttrSet__(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:588
+ Here is the call graph for this function:

◆ eliminateNodesUpward__()

template<typename GUM_SCALAR >
void gum::prm::SVED< GUM_SCALAR >::eliminateNodesUpward__ ( const PRMInstance< GUM_SCALAR > *  i,
BucketSet pool,
BucketSet trash,
List< const PRMInstance< GUM_SCALAR > * > &  elim_list,
Set< const PRMInstance< GUM_SCALAR > * > &  ignore 
)
private

Returns true if second can be eliminated before first.

Definition at line 204 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

209  {
210  ignore.insert(i);
211  // Extracting required attributes and slotchains
212  Set< NodeId >& attr_set = getAttrSet__(i);
213  Set< NodeId >& sc_set = getSCSet__(i);
214 
215  // Downward elimination
216  for (const auto attr: attr_set) {
217  try {
218  for (auto iter = i->getRefAttr(attr).begin();
219  iter != i->getRefAttr(attr).end();
220  ++iter)
221  if ((!ignore.exists(iter->first)) && (bb__.exists(iter->first)))
223  iter->first,
224  pool,
225  trash,
226  elim_list,
227  ignore);
228  } catch (NotFound&) {
229  // Ok
230  }
231  }
232 
233  // Eliminating all nodes in i instance
234  if (this->hasEvidence(i)) {
235  eliminateNodesWithEvidence__(i, pool, trash);
236  } else {
237  insertLiftedNodes__(i, pool, trash);
238 
239  for (const auto agg: i->type().aggregates())
240  if (bb__.requisiteNodes(i).exists(agg->id()))
241  pool.insert(getAggPotential__(i, agg));
242 
243  try {
244  InstanceBayesNet< GUM_SCALAR > bn(*i);
245  std::vector< const DiscreteVariable* > elim_order;
246 
247  for (auto node: getElimOrder__(i->type())) {
248  const auto& var = bn.variable(node);
249  elim_order.push_back(&var);
250  }
251  eliminateNodes(elim_order, pool, trash);
252  } catch (NotFound&) {
253  // Raised if there is no inner nodes to eliminate
254  }
255  }
256 
257  // Eliminating instance in elim_list
258  List< const PRMInstance< GUM_SCALAR >* > tmp_list;
259 
260  while (!elim_list.empty()) {
261  if (checkElimOrder__(i, elim_list.front())) {
262  if ((!ignore.exists(elim_list.front()))
263  && (bb__.exists(elim_list.front())))
265  elim_list.front(),
266  pool,
267  trash,
268  elim_list,
269  ignore);
270  } else if (bb__.exists(elim_list.front())) {
271  ignore.insert(elim_list.front());
272  }
273 
274  elim_list.popFront();
275  }
276 
277  // Upward elimination
278  for (const auto chain: sc_set)
279  for (const auto parent: i->getInstances(chain))
280  if ((!ignore.exists(parent)) && (bb__.exists(parent)))
281  eliminateNodesUpward__(parent, pool, trash, tmp_list, ignore);
282  }
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:123
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:567
Set< NodeId > & getSCSet__(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:599
void insertLiftedNodes__(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:309
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:555
void eliminateNodesWithEvidence__(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:285
bool hasEvidence() const
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
void eliminateNodes(const std::vector< const DiscreteVariable * > &elim_order, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
std::vector< NodeId > & getElimOrder__(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:543
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
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:204
Set< NodeId > & getAttrSet__(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:588
+ Here is the call graph for this function:

◆ eliminateNodesWithEvidence__()

template<typename GUM_SCALAR >
void gum::prm::SVED< GUM_SCALAR >::eliminateNodesWithEvidence__ ( const PRMInstance< GUM_SCALAR > *  i,
BucketSet pool,
BucketSet trash 
)
private

Returns true if second can be eliminated before first.

Definition at line 285 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

288  {
289  // Adding required evidences
290  for (const auto& elt: this->evidence(i))
291  if (bb__.requisiteNodes(i).exists(elt.first))
292  pool.insert(const_cast< Potential< GUM_SCALAR >* >(elt.second));
293 
294  // Adding potentials and eliminating the remaining nodes
295  for (const auto& a: *i)
296  if (bb__.requisiteNodes(i).exists(a.first))
297  pool.insert(&(const_cast< Potential< GUM_SCALAR >& >(a.second->cpf())));
298 
299  InstanceBayesNet< GUM_SCALAR > bn(*i);
300  DefaultTriangulation t(&(bn.moralGraph()), &(bn.modalities()));
301  const std::vector< NodeId >& full_elim_order = t.eliminationOrder();
302 
303  for (auto var = full_elim_order.begin(); var != full_elim_order.end(); ++var)
304  eliminateNode(&(i->get(*var).type().variable()), pool, trash);
305  }
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
void eliminateNode(const DiscreteVariable *var, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
+ Here is the call graph for this function:

◆ evidence() [1/4]

template<typename GUM_SCALAR>
INLINE PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > &  i)
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 156 of file PRMInference_tpl.h.

156  {
157  try {
158  return *(evidences__[&i]);
159  } catch (NotFound&) {
160  GUM_ERROR(NotFound, "this instance has no evidence.");
161  }
162  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> evidences__
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:235
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ evidence() [2/4]

template<typename GUM_SCALAR>
INLINE PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > *  i)
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 177 of file PRMInference_tpl.h.

177  {
178  try {
179  return *(evidences__[i]);
180  } catch (NotFound&) {
181  GUM_ERROR(NotFound, "this instance has no evidence.");
182  }
183  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> evidences__
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:235
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ evidence() [3/4]

template<typename GUM_SCALAR>
INLINE const PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > &  i) const
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 166 of file PRMInference_tpl.h.

167  {
168  try {
169  return *(evidences__[&i]);
170  } catch (NotFound&) {
171  GUM_ERROR(NotFound, "this instance has no evidence.");
172  }
173  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> evidences__
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:235
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ evidence() [4/4]

template<typename GUM_SCALAR>
INLINE const PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > *  i) const
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 187 of file PRMInference_tpl.h.

188  {
189  try {
190  return *(evidences__[i]);
191  } catch (NotFound&) {
192  GUM_ERROR(NotFound, "this instance has no evidence.");
193  }
194  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> evidences__
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:235
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ evidenceAdded_()

template<typename GUM_SCALAR >
INLINE void gum::prm::SVED< GUM_SCALAR >::evidenceAdded_ ( const Chain chain)
protectedvirtual

See PRMInference::evidenceAdded_().

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 575 of file SVED_tpl.h.

576  {
577  // Do nothing
578  }

◆ evidenceRemoved_()

template<typename GUM_SCALAR >
INLINE void gum::prm::SVED< GUM_SCALAR >::evidenceRemoved_ ( const Chain chain)
protectedvirtual

See PRMInference::evidenceRemoved_().

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 581 of file SVED_tpl.h.

582  {
583  // Do nothing
584  }

◆ getAggPotential__()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > * gum::prm::SVED< GUM_SCALAR >::getAggPotential__ ( const PRMInstance< GUM_SCALAR > *  i,
const PRMAggregate< GUM_SCALAR > *  agg 
)
private

Returns true if second can be eliminated before first.

Definition at line 567 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

569  {
570  return &(
571  const_cast< Potential< GUM_SCALAR >& >(i->get(agg->safeName()).cpf()));
572  }
+ Here is the call graph for this function:

◆ getAttrSet__()

template<typename GUM_SCALAR >
INLINE Set< NodeId > & gum::prm::SVED< GUM_SCALAR >::getAttrSet__ ( const PRMInstance< GUM_SCALAR > *  i)
private

Returns true if second can be eliminated before first.

Definition at line 588 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

588  {
589  try {
590  return *(req_set__[&(bb__.requisiteNodes(i))].first);
591  } catch (NotFound&) {
592  initReqSets__(i);
593  return *(req_set__[&(bb__.requisiteNodes(i))].first);
594  }
595  }
HashTable< const Set< NodeId > *, std::pair< Set< NodeId > *, Set< NodeId > *> > req_set__
First pair -> requisite Attributes Second pair -> requisite SlotChains.
Definition: SVED.h:137
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
void initReqSets__(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:494
+ Here is the call graph for this function:

◆ getElimOrder__()

template<typename GUM_SCALAR >
INLINE std::vector< NodeId > & gum::prm::SVED< GUM_SCALAR >::getElimOrder__ ( const PRMClass< GUM_SCALAR > &  c)
private

Returns true if second can be eliminated before first.

Definition at line 543 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

543  {
544  return *(elim_orders__[&c]);
545  }
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > *> elim_orders__
Definition: SVED.h:120
+ Here is the call graph for this function:

◆ getSCSet__()

template<typename GUM_SCALAR >
INLINE Set< NodeId > & gum::prm::SVED< GUM_SCALAR >::getSCSet__ ( const PRMInstance< GUM_SCALAR > *  i)
private

Returns true if second can be eliminated before first.

Definition at line 599 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

599  {
600  try {
601  return *(req_set__[&(bb__.requisiteNodes(i))].second);
602  } catch (NotFound&) {
603  initReqSets__(i);
604  return *(req_set__[&(bb__.requisiteNodes(i))].second);
605  }
606  }
HashTable< const Set< NodeId > *, std::pair< Set< NodeId > *, Set< NodeId > *> > req_set__
First pair -> requisite Attributes Second pair -> requisite SlotChains.
Definition: SVED.h:137
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
void initReqSets__(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:494
+ Here is the call graph for this function:

◆ hasEvidence() [1/4]

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( const PRMInstance< GUM_SCALAR > &  i) const
inherited

Returns true if i has evidence.

Definition at line 197 of file PRMInference_tpl.h.

198  {
199  return evidences__.exists(&i);
200  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> evidences__
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:235

◆ hasEvidence() [2/4]

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( const PRMInstance< GUM_SCALAR > *  i) const
inherited

Returns EMap of evidences over i.

Definition at line 203 of file PRMInference_tpl.h.

204  {
205  return evidences__.exists(i);
206  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> evidences__
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:235

◆ hasEvidence() [3/4]

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( const Chain chain) const
inherited

Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.

Definition at line 209 of file PRMInference_tpl.h.

209  {
210  return (hasEvidence(chain.first))
211  ? evidence(chain.first).exists(chain.second->id())
212  : false;
213  }
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
bool hasEvidence() const
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.

◆ hasEvidence() [4/4]

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( ) const
inherited

Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.

Definition at line 216 of file PRMInference_tpl.h.

216  {
217  return (evidences__.size() != (Size)0);
218  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> evidences__
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:235
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

◆ initElimOrder__()

template<typename GUM_SCALAR >
void gum::prm::SVED< GUM_SCALAR >::initElimOrder__ ( )
private

Returns true if second can be eliminated before first.

Definition at line 399 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

399  {
400  ClassDependencyGraph< GUM_SCALAR > cdg(*(this->prm_));
401  Sequence< const PRMClassElementContainer< GUM_SCALAR >* > class_elim_order;
402  std::list< NodeId > l;
403 
404  for (const auto node: cdg.dag().nodes()) {
405  if (cdg.dag().parents(node).empty()) { l.push_back(node); }
406  }
407 
408  Set< NodeId > visited_node;
409 
410  while (!l.empty()) {
411  visited_node.insert(l.front());
412 
413  if (!class_elim_order.exists(cdg.get(l.front()).first)) {
414  class_elim_order.insert(cdg.get(l.front()).first);
415  }
416 
417  for (const auto child: cdg.dag().children(l.front())) {
418  if (!visited_node.contains(child)) { l.push_back(child); }
419  }
420 
421  l.pop_front();
422  }
423 
425  for (auto c: class_elim_order) {
426  std::string name = c->name();
427  auto pos = name.find_first_of("<");
428  if (pos != std::string::npos) { name = name.substr(0, pos); }
429  try {
430  class_elim_order__->insert(name);
431  } catch (DuplicateElement&) {}
432  }
433  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:580
virtual std::string name() const
Returns the name of the current inference algorithm.
Definition: SVED_tpl.h:636
PRM< GUM_SCALAR > const * prm_
The PRM<GUM_SCALAR> on which inference is done.
Definition: PRMInference.h:213
Sequence< std::string > * class_elim_order__
Definition: SVED.h:129
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:409
+ Here is the call graph for this function:

◆ initLiftedNodes__()

template<typename GUM_SCALAR >
void gum::prm::SVED< GUM_SCALAR >::initLiftedNodes__ ( const PRMInstance< GUM_SCALAR > *  i,
BucketSet trash 
)
private

Returns true if second can be eliminated before first.

Definition at line 329 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

330  {
331  PRMClass< GUM_SCALAR >& c = const_cast< PRMClass< GUM_SCALAR >& >(i->type());
332  BucketSet* lifted_pool = new BucketSet();
333  lifted_pools__.insert(&(bb__.requisiteNodes(i)), lifted_pool);
334 
335  for (const auto node: bb__.requisiteNodes(i))
337  lifted_pool->insert(
338  const_cast< Potential< GUM_SCALAR >* >(&(c.get(node).cpf())));
339 
340  NodeSet inners, outers, ignore;
341 
342  for (const auto& elt: *i) {
343  if (bb__.requisiteNodes(*i).exists(elt.first)) {
344  if (PRMClassElement< GUM_SCALAR >::isAttribute(c.get(elt.first))) {
345  if (c.isOutputNode(c.get(elt.first)))
346  outers.insert(elt.first);
347  else if (!outers.exists(elt.first))
348  inners.insert(elt.first);
350  c.get(elt.first))) {
351  outers.insert(elt.first);
352 
353  // We need to put in the output_elim_order aggregator's parents
354  // which are
355  // innner nodes
356  for (const auto par: c.containerDag().parents(elt.first))
357  if (PRMClassElement< GUM_SCALAR >::isAttribute(i->type().get(par))
358  && i->type().isInnerNode(i->type().get(par))
359  && bb__.requisiteNodes(i).exists(par)) {
360  inners.erase(par);
361  outers.insert(par);
362  }
363  }
364  } else {
365  ignore.insert(elt.first);
366  }
367  }
368 
369  // Now we proceed with the elimination of inner attributes
370  ClassBayesNet< GUM_SCALAR > bn(c);
371  List< NodeSet > partial_ordering;
372 
373  if (inners.size()) partial_ordering.pushBack(inners);
374 
375  if (outers.size()) partial_ordering.pushBack(outers);
376 
377  if (ignore.size()) partial_ordering.pushBack(ignore);
378 
379  GUM_ASSERT(inners.size() || outers.size());
380  PartialOrderedTriangulation t(&(bn.moralGraph()),
381  &(bn.modalities()),
382  &partial_ordering);
383 
384  for (size_t idx = 0; idx < inners.size(); ++idx)
385  eliminateNode(&(c.get(t.eliminationOrder()[idx]).type().variable()),
386  *lifted_pool,
387  trash);
388 
389  // If there is not only inner and input Attributes
390  if (outers.size()) {
391  elim_orders__.insert(
392  &c,
393  new std::vector< NodeId >(t.eliminationOrder().begin() + inners.size(),
394  t.eliminationOrder().end()));
395  }
396  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Set< Potential< GUM_SCALAR > *> BucketSet
Code alias.
Definition: SVED.h:110
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > *> elim_orders__
Definition: SVED.h:120
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:127
void eliminateNode(const DiscreteVariable *var, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ Here is the call graph for this function:

◆ initReqSets__()

template<typename GUM_SCALAR >
void gum::prm::SVED< GUM_SCALAR >::initReqSets__ ( const PRMInstance< GUM_SCALAR > *  i)
private

Returns true if second can be eliminated before first.

Definition at line 494 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

494  {
495  Set< NodeId >* attr_set = new Set< NodeId >();
496  Set< NodeId >* sc_set = new Set< NodeId >();
497 
498  for (const auto node: bb__.requisiteNodes(i)) {
499  switch (i->type().get(node).elt_type()) {
502  attr_set->insert(node);
503  break;
504  }
505 
507  sc_set->insert(node);
508  break;
509  }
510 
511  default: {
512  GUM_ERROR(FatalError,
513  "There should not be elements other"
514  " than PRMAttribute<GUM_SCALAR> and SlotChain.");
515  }
516  }
517  }
518 
519  req_set__.insert(
520  &(bb__.requisiteNodes(i)),
521  std::pair< Set< NodeId >*, Set< NodeId >* >(attr_set, sc_set));
522  }
HashTable< const Set< NodeId > *, std::pair< Set< NodeId > *, Set< NodeId > *> > req_set__
First pair -> requisite Attributes Second pair -> requisite SlotChains.
Definition: SVED.h:137
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ insertEvidence__()

template<typename GUM_SCALAR >
INLINE void gum::prm::SVED< GUM_SCALAR >::insertEvidence__ ( const PRMInstance< GUM_SCALAR > *  i,
BucketSet pool 
)
private

Returns true if second can be eliminated before first.

Definition at line 535 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

536  {
537  for (const auto& elt: this->evidence(i))
538  pool.insert(const_cast< Potential< GUM_SCALAR >* >(elt.second));
539  }
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
+ Here is the call graph for this function:

◆ insertLiftedNodes__()

template<typename GUM_SCALAR >
void gum::prm::SVED< GUM_SCALAR >::insertLiftedNodes__ ( const PRMInstance< GUM_SCALAR > *  i,
BucketSet pool,
BucketSet trash 
)
private

Returns true if second can be eliminated before first.

Definition at line 309 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

311  {
312  BucketSet* lifted_pool = nullptr;
313 
314  try {
315  lifted_pool = lifted_pools__[&(bb__.requisiteNodes(i))];
316  } catch (NotFound&) {
317  initLiftedNodes__(i, trash);
318  lifted_pool = lifted_pools__[&(bb__.requisiteNodes(i))];
319  }
320 
321  for (const auto lifted_pot: *lifted_pool) {
322  Potential< GUM_SCALAR >* pot = copyPotential(i->bijection(), *lifted_pot);
323  pool.insert(pot);
324  trash.insert(pot);
325  }
326  }
void initLiftedNodes__(const PRMInstance< GUM_SCALAR > *i, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVED_tpl.h:329
Set< Potential< GUM_SCALAR > *> BucketSet
Code alias.
Definition: SVED.h:110
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:28
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:127
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
+ Here is the call graph for this function:

◆ joint()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMInference< GUM_SCALAR >::joint ( const std::vector< Chain > &  chains,
Potential< GUM_SCALAR > &  j 
)
inherited

Compute the joint probability of the formals attributes pointed by chains and stores it in m.

Parameters
chainsA Set of strings of the form instance.attribute.
jAn empty CPF which will be filed by the joint probability over chains.
Exceptions
NotFoundRaised if some chain in chains does not point to a formal attribute.
OperationNotAllowedRaise if m is not empty.

Definition at line 264 of file PRMInference_tpl.h.

266  {
267  if (j.nbrDim() > 0) {
268  GUM_ERROR(OperationNotAllowed, "the given Potential is not empty.");
269  }
270 
271  for (auto chain = chains.begin(); chain != chains.end(); ++chain) {
272  j.add(chain->second->type().variable());
273  }
274 
275  joint_(chains, j);
276  }
virtual void joint_(const std::vector< Chain > &queries, Potential< GUM_SCALAR > &j)=0
Generic method to compute the posterior of given element.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ joint_()

template<typename GUM_SCALAR >
void gum::prm::SVED< GUM_SCALAR >::joint_ ( const std::vector< Chain > &  queries,
Potential< GUM_SCALAR > &  j 
)
protectedvirtual

See PRMInference::joint_().

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 488 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

489  {
490  GUM_ERROR(FatalError, "Not implemented.");
491  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ name()

template<typename GUM_SCALAR >
INLINE std::string gum::prm::SVED< GUM_SCALAR >::name ( ) const
virtual

Returns the name of the current inference algorithm.

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 636 of file SVED_tpl.h.

636  {
637  return "SVED";
638  }

◆ posterior()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMInference< GUM_SCALAR >::posterior ( const Chain chain,
Potential< GUM_SCALAR > &  m 
)
inherited

Compute the posterior of the formal attribute pointed by chain and stores it in m.

Parameters
chainA string of the form instance.attribute.
mAn empty CPF which will be filed by the posterior of chain.
Exceptions
NotFoundRaised if chain is invalid.
TypeErrorRaised if chain does not point to an PRMAttribute<GUM_SCALAR>.
OperationNotAllowedRaise if m is not empty.

Definition at line 234 of file PRMInference_tpl.h.

236  {
237  if (m.nbrDim() > 0) {
238  GUM_ERROR(OperationNotAllowed, "the given Potential is not empty.");
239  }
240 
241  if (hasEvidence(chain)) {
242  m.add(chain.second->type().variable());
243  const Potential< GUM_SCALAR >& e
244  = *(evidence(chain.first)[chain.second->id()]);
245  Instantiation i(m), j(e);
246 
247  for (i.setFirst(), j.setFirst(); !i.end(); i.inc(), j.inc())
248  m.set(i, e.get(j));
249  } else {
250  if (chain.second != &(chain.first->get(chain.second->safeName()))) {
251  typename PRMInference< GUM_SCALAR >::Chain good_chain
252  = std::make_pair(chain.first,
253  &(chain.first->get(chain.second->safeName())));
254  m.add(good_chain.second->type().variable());
255  posterior_(good_chain, m);
256  } else {
257  m.add(chain.second->type().variable());
258  posterior_(chain, m);
259  }
260  }
261  }
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
virtual void posterior_(const Chain &chain, Potential< GUM_SCALAR > &m)=0
Generic method to compute the posterior of given element.
bool hasEvidence() const
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > *> Chain
Code alias.
Definition: PRMInference.h:56
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ posterior_()

template<typename GUM_SCALAR >
void gum::prm::SVED< GUM_SCALAR >::posterior_ ( const Chain chain,
Potential< GUM_SCALAR > &  m 
)
protectedvirtual

See PRMInference::posterior_().

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 436 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

437  {
438  const PRMInstance< GUM_SCALAR >* i = chain.first;
439  const PRMAttribute< GUM_SCALAR >* elt = chain.second;
440  SVED< GUM_SCALAR >::BucketSet pool, trash;
441  bb__.compute(i, elt->id());
442  eliminateNodes__(i, elt->id(), pool, trash);
443 
444  std::vector< const Potential< GUM_SCALAR >* > result;
445  for (auto pot: pool) {
446  if (pot->contains(*(m.variablesSequence().atPos(0))))
447  result.push_back(pot);
448  }
449 
450  while (result.size() > 1) {
451  const auto& p1 = *(result.back());
452  result.pop_back();
453  const auto& p2 = *(result.back());
454  result.pop_back();
455  auto mult = new Potential< GUM_SCALAR >(p1 * p2);
456  result.push_back(mult);
457  trash.insert(mult);
458  }
459 
460  m = *(result.back());
461  m.normalize();
462 
463  GUM_ASSERT(m.nbrDim() == (Size)1);
464 
465  // cleaning up the mess
466  for (const auto pot: trash)
467  delete pot;
468 
469  for (const auto& elt: lifted_pools__)
470  delete elt.second;
471 
472  lifted_pools__.clear();
473 
474  for (const auto& elt: req_set__) {
475  delete elt.second.first;
476  delete elt.second.second;
477  }
478 
479  req_set__.clear();
480 
481  for (const auto elt: elim_orders__)
482  delete elt.second;
483 
484  elim_orders__.clear();
485  }
Set< Potential< GUM_SCALAR > *> BucketSet
Code alias.
Definition: SVED.h:110
HashTable< const Set< NodeId > *, std::pair< Set< NodeId > *, Set< NodeId > *> > req_set__
First pair -> requisite Attributes Second pair -> requisite SlotChains.
Definition: SVED.h:137
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:45
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > *> elim_orders__
Definition: SVED.h:120
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:127
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ reduceElimList__()

template<typename GUM_SCALAR >
INLINE void gum::prm::SVED< GUM_SCALAR >::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 
)
private

Returns true if second can be eliminated before first.

Definition at line 609 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

615  {
616  while (!elim_list.empty()) {
617  if (checkElimOrder__(i, elim_list.front())) {
618  if ((!ignore.exists(elim_list.front()))
619  && (bb__.exists(elim_list.front()))) {
621  elim_list.front(),
622  pool,
623  trash,
624  elim_list,
625  ignore);
626  }
627  } else if (bb__.exists(elim_list.front())) {
628  reduced_list.insert(elim_list.front());
629  }
630 
631  elim_list.popFront();
632  }
633  }
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:123
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:555
StructuredBayesBall< GUM_SCALAR > bb__
Definition: SVED.h:131
+ Here is the call graph for this function:

◆ removeEvidence()

template<typename GUM_SCALAR >
INLINE void gum::prm::PRMInference< GUM_SCALAR >::removeEvidence ( const Chain chain)
inherited

Remove evidence on the given instance's elt.

Parameters
chainThe variable being observed.
Exceptions
NotFoundRaised if the given names are not found.
TypeErrorRaised if the elt is not an PRMAttribute<GUM_SCALAR>.

Definition at line 221 of file PRMInference_tpl.h.

221  {
222  try {
223  if (EMap__(chain.first).exists(chain.second->id())) {
224  evidenceRemoved_(chain);
225  delete EMap__(chain.first)[chain.second->id()];
226  EMap__(chain.first).erase(chain.second->id());
227  }
228  } catch (NotFound&) {
229  // Ok, we are only removing
230  }
231  }
void erase(const Key &key)
Removes a given element from the hash table.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
virtual void evidenceRemoved_(const Chain &chain)=0
This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference...
EMap & EMap__(const PRMInstance< GUM_SCALAR > *i)
Private getter over evidences__, if necessary creates an EMap for i.

◆ trim__()

template<typename GUM_SCALAR >
INLINE std::string gum::prm::SVED< GUM_SCALAR >::trim__ ( const std::string &  s)
private

Returns true if second can be eliminated before first.

Definition at line 548 of file SVED_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

548  {
549  auto pos = s.find_first_of("<");
550  if (pos != std::string::npos) { return s.substr(0, pos); }
551  return s;
552  }
+ Here is the call graph for this function:

Member Data Documentation

◆ bb__

template<typename GUM_SCALAR >
StructuredBayesBall< GUM_SCALAR > gum::prm::SVED< GUM_SCALAR >::bb__
private

Definition at line 131 of file SVED.h.

◆ class_elim_order__

template<typename GUM_SCALAR >
Sequence< std::string >* gum::prm::SVED< GUM_SCALAR >::class_elim_order__
private

Definition at line 129 of file SVED.h.

◆ elim_orders__

template<typename GUM_SCALAR >
HashTable< const PRMClass< GUM_SCALAR >*, std::vector< NodeId >* > gum::prm::SVED< GUM_SCALAR >::elim_orders__
private

Definition at line 120 of file SVED.h.

◆ lifted_pools__

template<typename GUM_SCALAR >
HashTable< const Set< NodeId >*, BucketSet* > gum::prm::SVED< GUM_SCALAR >::lifted_pools__
private

The Set<NodeId> returned by StructuredBayesBall<GUM_SCALAR> is unique for each family of instances with the same requisite set (thus the same lifted potentials).

Definition at line 127 of file SVED.h.

◆ prm_

template<typename GUM_SCALAR>
PRM< GUM_SCALAR > const* gum::prm::PRMInference< GUM_SCALAR >::prm_
protectedinherited

The PRM<GUM_SCALAR> on which inference is done.

Definition at line 213 of file PRMInference.h.

◆ req_set__

template<typename GUM_SCALAR >
HashTable< const Set< NodeId >*, std::pair< Set< NodeId >*, Set< NodeId >* > > gum::prm::SVED< GUM_SCALAR >::req_set__
private

First pair -> requisite Attributes Second pair -> requisite SlotChains.

Definition at line 137 of file SVED.h.

◆ sys_

template<typename GUM_SCALAR>
PRMSystem< GUM_SCALAR > const* gum::prm::PRMInference< GUM_SCALAR >::sys_
protectedinherited

The Model on which inference is done.

Definition at line 216 of file PRMInference.h.


The documentation for this class was generated from the following files: