aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::prm::PRMInference< GUM_SCALAR > Class Template Referenceabstract

This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>. More...

#include <agrum/PRM/PRMInference.h>

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

Public Member Functions

Constructor & destructor.
 PRMInference (const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
 Default constructor. More...
 
 PRMInference (const PRMInference &source)
 Copy constructor. More...
 
virtual ~PRMInference ()
 Destructor. More...
 
PRMInferenceoperator= (const PRMInference &source)
 Copy operator. More...
 
Getters & setters.
virtual std::string name () const =0
 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 std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > *> Chain
 Code alias. More...
 
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 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...
 
virtual void evidenceAdded_ (const Chain &chain)=0
 This method is called whenever an evidence is added, but AFTER any processing made by PRMInference. More...
 
virtual void evidenceRemoved_ (const Chain &chain)=0
 This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference. More...
 
virtual void posterior_ (const Chain &chain, Potential< GUM_SCALAR > &m)=0
 Generic method to compute the posterior of given element. More...
 
virtual void joint_ (const std::vector< Chain > &queries, Potential< GUM_SCALAR > &j)=0
 Generic method to compute the posterior of given element. More...
 

Private evidence handling methods and members.

typedef HashTable< const PRMInstance< GUM_SCALAR > *, EMap *>::iterator_safe EvidenceIterator
 Code alias. More...
 
typedef HashTable< const PRMInstance< GUM_SCALAR > *, EMap *>::const_iterator_safe EvidenceConstIterator
 Code alias. More...
 
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> _evidences_
 Mapping of evidence over PRMInstance<GUM_SCALAR>'s nodes. More...
 
EMap_EMap_ (const PRMInstance< GUM_SCALAR > *i)
 Private getter over evidences, if necessary creates an EMap for i. More...
 

Detailed Description

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

This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.

The main purpose of this class is to give a common interface between all inference algorithms and to handle evidences.

Definition at line 51 of file PRMInference.h.

Member Typedef Documentation

◆ Chain

template<typename GUM_SCALAR>
typedef std::pair< const PRMInstance< GUM_SCALAR >*, const PRMAttribute< GUM_SCALAR >* > gum::prm::PRMInference< GUM_SCALAR >::Chain

Code alias.

Definition at line 55 of file PRMInference.h.

◆ EMap

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

Code alias.

Definition at line 58 of file PRMInference.h.

◆ EMapConstIterator

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

Code alias.

Definition at line 65 of file PRMInference.h.

◆ EMapIterator

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

Code alias.

Definition at line 61 of file PRMInference.h.

◆ EvidenceConstIterator

template<typename GUM_SCALAR>
typedef HashTable< const PRMInstance< GUM_SCALAR >*, EMap* >::const_iterator_safe gum::prm::PRMInference< GUM_SCALAR >::EvidenceConstIterator
private

Code alias.

Definition at line 225 of file PRMInference.h.

◆ EvidenceIterator

template<typename GUM_SCALAR>
typedef HashTable< const PRMInstance< GUM_SCALAR >*, EMap* >::iterator_safe gum::prm::PRMInference< GUM_SCALAR >::EvidenceIterator
private

Code alias.

Definition at line 222 of file PRMInference.h.

Constructor & Destructor Documentation

◆ PRMInference() [1/2]

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

Default constructor.

Definition at line 136 of file PRMInference_tpl.h.

137  :
138  prm_(&prm),
139  sys_(&system) {
140  GUM_CONSTRUCTOR(PRMInference);
141  }
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
PRMSystem< GUM_SCALAR > const * sys_
The Model on which inference is done.
Definition: PRMInference.h:210
PRM< GUM_SCALAR > const * prm_
The PRM<GUM_SCALAR> on which inference is done.
Definition: PRMInference.h:207

◆ PRMInference() [2/2]

template<typename GUM_SCALAR>
gum::prm::PRMInference< GUM_SCALAR >::PRMInference ( const PRMInference< GUM_SCALAR > &  source)

Copy constructor.

Definition at line 47 of file PRMInference_tpl.h.

47  :
48  prm_(source.prm_), sys_(source.sys_) {
49  GUM_CONS_CPY(PRMInference);
50 
51  for (const auto& elt: source._evidences_) {
52  _evidences_.insert(elt.first, new PRMInference< GUM_SCALAR >::EMap());
53 
54  for (const auto& elt2: *elt.second) {
55  Potential< GUM_SCALAR >* e = new Potential< GUM_SCALAR >();
56  e->add(*(elt2.second->variablesSequence().front()));
57  Instantiation i(*e);
58 
59  for (i.setFirst(); !i.end(); i.inc())
60  e->set(i, elt2.second->get(i));
61 
62  _evidences_[elt.first]->insert(elt2.first, e);
63  }
64  }
65  }
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
PRMSystem< GUM_SCALAR > const * sys_
The Model on which inference is done.
Definition: PRMInference.h:210
PRM< GUM_SCALAR > const * prm_
The PRM<GUM_SCALAR> on which inference is done.
Definition: PRMInference.h:207
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> _evidences_
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:228
NodeProperty< const Potential< GUM_SCALAR > *> EMap
Code alias.
Definition: PRMInference.h:58

◆ ~PRMInference()

template<typename GUM_SCALAR >
INLINE gum::prm::PRMInference< GUM_SCALAR >::~PRMInference ( )
virtual

Destructor.

Definition at line 144 of file PRMInference_tpl.h.

144  {
145  GUM_DESTRUCTOR(PRMInference);
146  clearEvidence();
147  }
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
void clearEvidence()
Remove all evidences.

Member Function Documentation

◆ _EMap_()

template<typename GUM_SCALAR>
PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::_EMap_ ( const PRMInstance< GUM_SCALAR > *  i)
private

Private getter over evidences, if necessary creates an EMap for i.

Definition at line 95 of file PRMInference_tpl.h.

95  {
96  if (_evidences_.exists(i)) {
97  return *(_evidences_[i]);
98  } else {
100  return *(_evidences_[i]);
101  }
102  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> _evidences_
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:228
NodeProperty< const Potential< GUM_SCALAR > *> EMap
Code alias.
Definition: PRMInference.h:58

◆ addEvidence()

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

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 105 of file PRMInference_tpl.h.

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

◆ clearEvidence()

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

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:228

◆ evidence() [1/4]

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

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 151 of file PRMInference_tpl.h.

151  {
152  try {
153  return *(_evidences_[&i]);
154  } catch (NotFound&) { GUM_ERROR(NotFound, "this instance has no evidence.") }
155  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> _evidences_
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:228
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ evidence() [2/4]

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

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 167 of file PRMInference_tpl.h.

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

◆ 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

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 159 of file PRMInference_tpl.h.

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

◆ 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

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 175 of file PRMInference_tpl.h.

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

◆ evidenceAdded_()

template<typename GUM_SCALAR>
virtual void gum::prm::PRMInference< GUM_SCALAR >::evidenceAdded_ ( const Chain chain)
protectedpure virtual

This method is called whenever an evidence is added, but AFTER any processing made by PRMInference.

Implemented in gum::prm::SVE< GUM_SCALAR >, and gum::prm::SVED< GUM_SCALAR >.

◆ evidenceRemoved_()

template<typename GUM_SCALAR>
virtual void gum::prm::PRMInference< GUM_SCALAR >::evidenceRemoved_ ( const Chain chain)
protectedpure virtual

This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference.

Implemented in gum::prm::SVE< GUM_SCALAR >, and gum::prm::SVED< GUM_SCALAR >.

◆ hasEvidence() [1/4]

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

Returns true if i has evidence.

Definition at line 182 of file PRMInference_tpl.h.

182  {
183  return _evidences_.exists(&i);
184  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> _evidences_
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:228

◆ hasEvidence() [2/4]

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

Returns EMap of evidences over i.

Definition at line 187 of file PRMInference_tpl.h.

187  {
188  return _evidences_.exists(i);
189  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> _evidences_
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:228

◆ hasEvidence() [3/4]

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

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

Definition at line 192 of file PRMInference_tpl.h.

192  {
193  return (hasEvidence(chain.first)) ? evidence(chain.first).exists(chain.second->id()) : false;
194  }
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

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

Definition at line 197 of file PRMInference_tpl.h.

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

◆ joint()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMInference< GUM_SCALAR >::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.

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 241 of file PRMInference_tpl.h.

243  {
244  if (j.nbrDim() > 0) { GUM_ERROR(OperationNotAllowed, "the given Potential is not empty.") }
245 
246  for (auto chain = chains.begin(); chain != chains.end(); ++chain) {
247  j.add(chain->second->type().variable());
248  }
249 
250  joint_(chains, j);
251  }
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:51

◆ joint_()

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

Generic method to compute the posterior of given element.

Parameters
queriesSet of pairs of PRMInstance<GUM_SCALAR> and PRMAttribute<GUM_SCALAR>.
jCPF filled with the joint probability of queries. It is initialized properly.

Implemented in gum::prm::SVE< GUM_SCALAR >, and gum::prm::SVED< GUM_SCALAR >.

◆ name()

template<typename GUM_SCALAR>
virtual std::string gum::prm::PRMInference< GUM_SCALAR >::name ( ) const
pure virtual

◆ operator=()

template<typename GUM_SCALAR >
PRMInference< GUM_SCALAR > & gum::prm::PRMInference< GUM_SCALAR >::operator= ( const PRMInference< GUM_SCALAR > &  source)

Copy operator.

Definition at line 69 of file PRMInference_tpl.h.

69  {
70  clearEvidence();
71  prm_ = source.prm_;
72  sys_ = source.sys_;
73 
74  for (const auto& elt: source._evidences_) {
75  _evidences_.insert(elt.first, new PRMInference< GUM_SCALAR >::EMap());
76 
77  for (const auto& elt2: *elt.second) {
78  Potential< GUM_SCALAR >* e = new Potential< GUM_SCALAR >();
79  e->add(*(elt2.second->variablesSequence().front()));
80  Instantiation i(*e);
81 
82  for (i.setFirst(); !i.end(); i.inc()) {
83  e->set(i, elt2.second->get(i));
84  }
85 
86  _evidences_[elt.first]->insert(elt2.first, e);
87  }
88  }
89 
90  return *this;
91  }
PRMSystem< GUM_SCALAR > const * sys_
The Model on which inference is done.
Definition: PRMInference.h:210
PRM< GUM_SCALAR > const * prm_
The PRM<GUM_SCALAR> on which inference is done.
Definition: PRMInference.h:207
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> _evidences_
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:228
void clearEvidence()
Remove all evidences.
NodeProperty< const Potential< GUM_SCALAR > *> EMap
Code alias.
Definition: PRMInference.h:58

◆ posterior()

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

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 215 of file PRMInference_tpl.h.

217  {
218  if (m.nbrDim() > 0) { GUM_ERROR(OperationNotAllowed, "the given Potential is not empty.") }
219 
220  if (hasEvidence(chain)) {
221  m.add(chain.second->type().variable());
222  const Potential< GUM_SCALAR >& e = *(evidence(chain.first)[chain.second->id()]);
223  Instantiation i(m), j(e);
224 
225  for (i.setFirst(), j.setFirst(); !i.end(); i.inc(), j.inc())
226  m.set(i, e.get(j));
227  } else {
228  if (chain.second != &(chain.first->get(chain.second->safeName()))) {
229  typename PRMInference< GUM_SCALAR >::Chain good_chain
230  = std::make_pair(chain.first, &(chain.first->get(chain.second->safeName())));
231  m.add(good_chain.second->type().variable());
232  posterior_(good_chain, m);
233  } else {
234  m.add(chain.second->type().variable());
235  posterior_(chain, m);
236  }
237  }
238  }
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:55
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ posterior_()

template<typename GUM_SCALAR>
virtual void gum::prm::PRMInference< GUM_SCALAR >::posterior_ ( const Chain chain,
Potential< GUM_SCALAR > &  m 
)
protectedpure virtual

Generic method to compute the posterior of given element.

Parameters
chain
mCPF filled with the posterior of elt. It is initialized properly.

Implemented in gum::prm::SVE< GUM_SCALAR >, and gum::prm::SVED< GUM_SCALAR >.

◆ removeEvidence()

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

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 202 of file PRMInference_tpl.h.

202  {
203  try {
204  if (_EMap_(chain.first).exists(chain.second->id())) {
205  evidenceRemoved_(chain);
206  delete _EMap_(chain.first)[chain.second->id()];
207  _EMap_(chain.first).erase(chain.second->id());
208  }
209  } catch (NotFound&) {
210  // Ok, we are only removing
211  }
212  }
EMap & _EMap_(const PRMInstance< GUM_SCALAR > *i)
Private getter over evidences, if necessary creates an EMap for i.
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...

Member Data Documentation

◆ _evidences_

template<typename GUM_SCALAR>
HashTable< const PRMInstance< GUM_SCALAR >*, EMap* > gum::prm::PRMInference< GUM_SCALAR >::_evidences_
private

Mapping of evidence over PRMInstance<GUM_SCALAR>'s nodes.

Definition at line 228 of file PRMInference.h.

◆ prm_

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

The PRM<GUM_SCALAR> on which inference is done.

Definition at line 207 of file PRMInference.h.

◆ sys_

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

The Model on which inference is done.

Definition at line 210 of file PRMInference.h.


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