aGrUM  0.16.0
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 marginal (const Chain &chain, Potential< GUM_SCALAR > &m)
 Compute the marginal 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 _marginal (const Chain &chain, Potential< GUM_SCALAR > &m)=0
 Generic method to compute the marginal of given element. More...
 
virtual void _joint (const std::vector< Chain > &queries, Potential< GUM_SCALAR > &j)=0
 Generic method to compute the marginal 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 52 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 57 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 60 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 69 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 65 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 232 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 228 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 141 of file PRMInference_tpl.h.

142  :
143  _prm(&prm),
144  _sys(&system) {
145  GUM_CONSTRUCTOR(PRMInference);
146  }
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
PRM< GUM_SCALAR > const * _prm
The PRM<GUM_SCALAR> on which inference is done.
Definition: PRMInference.h:213
PRMSystem< GUM_SCALAR > const * _sys
The Model on which inference is done.
Definition: PRMInference.h:216

◆ PRMInference() [2/2]

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

Copy constructor.

Definition at line 48 of file PRMInference_tpl.h.

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

◆ ~PRMInference()

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

Destructor.

Definition at line 149 of file PRMInference_tpl.h.

149  {
150  GUM_DESTRUCTOR(PRMInference);
151  clearEvidence();
152  }
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 98 of file PRMInference_tpl.h.

98  {
99  if (__evidences.exists(i)) {
100  return *(__evidences[i]);
101  } else {
103  return *(__evidences[i]);
104  }
105  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> __evidences
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:235
NodeProperty< const Potential< GUM_SCALAR > *> EMap
Code alias.
Definition: PRMInference.h:60

◆ _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 >.

◆ _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 marginal 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 >.

◆ _marginal()

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

Generic method to compute the marginal of given element.

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

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

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

Referenced by gum::prm::o3prmr::O3prmrInterpreter::observe().

110  {
111  if (chain.first->exists(chain.second->id())) {
112  if ((p.nbrDim() != 1) || (!p.contains(chain.second->type().variable())))
113  GUM_ERROR(OperationNotAllowed,
114  "illegal evidence for the given PRMAttribute.");
115 
116  Potential< GUM_SCALAR >* e = new Potential< GUM_SCALAR >();
117  e->add(chain.second->type().variable());
118  Instantiation i(*e);
119 
120  for (i.setFirst(); !i.end(); i.inc())
121  e->set(i, p.get(i));
122 
123  PRMInference< GUM_SCALAR >::EMap& emap = __EMap(chain.first);
124 
125  if (emap.exists(chain.second->id())) {
126  delete emap[chain.second->id()];
127  emap[chain.second->id()] = e;
128  } else {
129  emap.insert(chain.second->id(), e);
130  }
131 
132  _evidenceAdded(chain);
133  } else {
134  GUM_ERROR(NotFound,
135  "the given PRMAttribute does not belong to this "
136  "Instance<GUM_SCALAR>.");
137  }
138  }
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:60
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ clearEvidence()

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

Remove all evidences.

Definition at line 36 of file PRMInference_tpl.h.

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

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

Referenced by gum::prm::SVED< GUM_SCALAR >::__insertEvidence(), gum::prm::SVE< GUM_SCALAR >::__insertEvidence(), gum::prm::StructuredInference< GUM_SCALAR >::__reduceAloneInstances(), and gum::prm::StructuredInference< GUM_SCALAR >::_marginal().

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:55
+ Here is the caller graph for this function:

◆ 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 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:55

◆ 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 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:55

◆ 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 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:55

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

Referenced by gum::prm::o3prmr::O3prmrInterpreter::observe(), and gum::prm::o3prmr::O3prmrInterpreter::unobserve().

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
+ Here is the caller graph for this function:

◆ 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 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

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

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

Definition at line 216 of file PRMInference_tpl.h.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__insertNodeInElimLists(), gum::prm::StructuredInference< GUM_SCALAR >::__reduceAloneInstances(), and gum::prm::StructuredInference< GUM_SCALAR >::_marginal().

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:48
+ Here is the caller 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 
)

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

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

◆ marginal()

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

Compute the marginal 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 marginal of chain.
Exceptions
NotFoundRaised if chain is invalid.
WrongTypeRaised 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.

Referenced by gum::prm::o3prmr::O3prmrInterpreter::query().

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 = std::make_pair(
252  chain.first, &(chain.first->get(chain.second->safeName())));
253  m.add(good_chain.second->type().variable());
254  _marginal(good_chain, m);
255  } else {
256  m.add(chain.second->type().variable());
257  _marginal(chain, m);
258  }
259  }
260  }
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
virtual void _marginal(const Chain &chain, Potential< GUM_SCALAR > &m)=0
Generic method to compute the marginal 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:57
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ name()

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

Returns the name of the current inference algorithm.

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

Referenced by gum::prm::GroundedInference< GUM_SCALAR >::_evidenceAdded(), gum::prm::GroundedInference< GUM_SCALAR >::_evidenceRemoved(), and gum::prm::GroundedInference< GUM_SCALAR >::_marginal().

+ Here is the caller graph for this function:

◆ operator=()

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

Copy operator.

Definition at line 72 of file PRMInference_tpl.h.

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

◆ 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.
WrongTypeRaised if the elt is not an PRMAttribute<GUM_SCALAR>.

Definition at line 221 of file PRMInference_tpl.h.

Referenced by gum::prm::o3prmr::O3prmrInterpreter::unobserve().

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.
+ Here is the caller graph for this function:

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 235 of file PRMInference.h.

Referenced by gum::prm::PRMInference< double >::operator=(), and gum::prm::PRMInference< double >::PRMInference().

◆ _prm

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

◆ _sys


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