aGrUM  0.14.2
gum::prm::GroundedInference< GUM_SCALAR > Class Template Referenceabstract

<agrum/PRM/groundedInference.h> More...

#include <groundedInference.h>

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

Public Member Functions

Constructor & destructor.
 GroundedInference (const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
 Default constructor. More...
 
virtual ~GroundedInference ()
 Destructor. More...
 
Getters & setters.
MarginalTargetedInference< GUM_SCALAR > & getBNInference ()
 Returns the bayesnet inference engine used by this class. More...
 
void setBNInference (MarginalTargetedInference< GUM_SCALAR > *bn_inf)
 Defines the bayesnet inference engine used by this class. More...
 
virtual std::string name () const
 Returns the bayesnet inference engine used by this class. 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 Member Functions

Private evidence handling methods and members.
virtual void _evidenceAdded (const typename PRMInference< GUM_SCALAR >::Chain &chain)
 This method is called whenever an evidence is added, but AFTER any processing made by PRMInference. More...
 
virtual void _evidenceRemoved (const typename PRMInference< GUM_SCALAR >::Chain &chain)
 This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference. More...
 
virtual void _marginal (const typename PRMInference< GUM_SCALAR >::Chain &chain, Potential< GUM_SCALAR > &m)
 Generic method to compute the marginal of given element. More...
 
virtual void _joint (const std::vector< typename PRMInference< GUM_SCALAR >::Chain > &queries, Potential< GUM_SCALAR > &j)
 Generic method to compute the marginal of given element. More...
 

Protected members.

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

Detailed Description

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

<agrum/PRM/groundedInference.h>

This class is used to realise grounded inference in a PRM<GUM_SCALAR>.

The best way to build this class is to use the static creation methods.

Definition at line 44 of file groundedInference.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
inherited

Code alias.

Definition at line 54 of file PRMInference.h.

◆ EMap

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

Code alias.

Definition at line 57 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 66 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 62 of file PRMInference.h.

Constructor & Destructor Documentation

◆ GroundedInference() [1/2]

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

Default constructor.

Definition at line 86 of file groundedInference_tpl.h.

87  :
88  PRMInference< GUM_SCALAR >(prm, system),
89  __inf(0) {
90  GUM_CONSTRUCTOR(GroundedInference);
91  }
MarginalTargetedInference< GUM_SCALAR > * __inf
The bayesnet inference engine used by this class.
GroundedInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.

◆ ~GroundedInference()

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

Destructor.

Definition at line 33 of file groundedInference_tpl.h.

33  {
34  GUM_DESTRUCTOR(GroundedInference);
35 
36  if (__inf != nullptr) delete __inf;
37 
38  if (!__obs.empty())
39  for (const auto pot : __obs)
40  // We used const ptrs only because of
41  // MarginalTargetedInference::addEvidence()
42  // requires it
43  delete const_cast< Potential< GUM_SCALAR >* >(pot);
44  }
MarginalTargetedInference< GUM_SCALAR > * __inf
The bayesnet inference engine used by this class.
GroundedInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
List< const Potential< GUM_SCALAR > *> __obs

◆ GroundedInference() [2/2]

template<typename GUM_SCALAR >
INLINE gum::prm::GroundedInference< GUM_SCALAR >::GroundedInference ( const GroundedInference< GUM_SCALAR > &  source)
private

Copy constructor.

Definition at line 94 of file groundedInference_tpl.h.

References GUM_ERROR, and gum::prm::GroundedInference< GUM_SCALAR >::operator=().

95  :
96  PRMInference< GUM_SCALAR >(source),
97  __inf(0) {
98  GUM_CONS_CPY(GroundedInference);
99  GUM_ERROR(FatalError, "illegal to copy constructor");
100  }
MarginalTargetedInference< GUM_SCALAR > * __inf
The bayesnet inference engine used by this class.
GroundedInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

Member Function Documentation

◆ _evidenceAdded() [1/2]

template<typename GUM_SCALAR >
void gum::prm::GroundedInference< GUM_SCALAR >::_evidenceAdded ( const typename PRMInference< GUM_SCALAR >::Chain chain)
protectedvirtual

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

Definition at line 47 of file groundedInference_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::add(), gum::MultiDimDecorator< GUM_SCALAR >::get(), gum::Instantiation::inc(), gum::prm::PRMInference< GUM_SCALAR >::name(), gum::MultiDimDecorator< GUM_SCALAR >::set(), and gum::Instantiation::setFirst().

48  {
49  Potential< GUM_SCALAR >* bn_obs = new Potential< GUM_SCALAR >();
50  // Retrieving the BN's variable
51  std::stringstream var_name;
52  var_name << chain.first->name() << "." << chain.second->safeName();
53  bn_obs->add(__inf->BN().variableFromName(var_name.str()));
54  // Retrievin the PRM<GUM_SCALAR>'s evidence and copying it in bn_obs
55  const Potential< GUM_SCALAR >* prm_obs =
56  this->evidence(chain.first)[chain.second->id()];
57  Instantiation i(*bn_obs), j(*prm_obs);
58 
59  for (i.setFirst(), j.setFirst(); !i.end(); i.inc(), j.inc()) {
60  bn_obs->set(i, prm_obs->get(j));
61  }
62 
63  __obs.insert(bn_obs);
64  }
MarginalTargetedInference< GUM_SCALAR > * __inf
The bayesnet inference engine used by this class.
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
List< const Potential< GUM_SCALAR > *> __obs
+ Here is the call graph for this function:

◆ _evidenceAdded() [2/2]

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

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() [1/2]

template<typename GUM_SCALAR >
void gum::prm::GroundedInference< GUM_SCALAR >::_evidenceRemoved ( const typename PRMInference< GUM_SCALAR >::Chain chain)
protectedvirtual

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

Definition at line 67 of file groundedInference_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::erase(), and gum::prm::PRMInference< GUM_SCALAR >::name().

68  {
69  std::stringstream var_name;
70  var_name << chain.first->name() << "." << chain.second->safeName();
71  const DiscreteVariable& var = __inf->BN().variableFromName(var_name.str());
72 
73  for (auto iter = __obs.beginSafe(); iter != __obs.endSafe();
74  ++iter) { // safe iterator needed here
75  if ((**iter).contains(var)) {
76  __inf->eraseEvidence(var_name.str());
77  const Potential< GUM_SCALAR >* e = *iter;
78  __obs.erase(iter);
79  delete e;
80  break;
81  }
82  }
83  }
MarginalTargetedInference< GUM_SCALAR > * __inf
The bayesnet inference engine used by this class.
List< const Potential< GUM_SCALAR > *> __obs
+ Here is the call graph for this function:

◆ _evidenceRemoved() [2/2]

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

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() [1/2]

template<typename GUM_SCALAR >
INLINE void gum::prm::GroundedInference< GUM_SCALAR >::_joint ( const std::vector< typename PRMInference< GUM_SCALAR >::Chain > &  queries,
Potential< GUM_SCALAR > &  j 
)
protectedvirtual

Generic method to compute the marginal of given element.

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

Definition at line 149 of file groundedInference_tpl.h.

References GUM_ERROR.

151  {
152  GUM_ERROR(FatalError, "not yet implemented");
153  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52

◆ _joint() [2/2]

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

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() [1/2]

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

Generic method to compute the marginal of given element.

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

Definition at line 127 of file groundedInference_tpl.h.

References gum::prm::GroundedInference< GUM_SCALAR >::__inf, gum::prm::GroundedInference< GUM_SCALAR >::__obs, GUM_ERROR, and gum::prm::PRMInference< GUM_SCALAR >::name().

129  {
130  if (__inf == 0) {
131  GUM_ERROR(OperationNotAllowed, "no inference engine defined");
132  }
133 
134  std::stringstream sBuff;
135 
136  if (!__obs.empty()) {
137  for (auto e : __obs) {
138  try {
139  __inf->addEvidence(*e);
140  } catch (InvalidArgument&) { __inf->chgEvidence(*e); }
141  }
142  }
143 
144  sBuff << chain.first->name() << "." << chain.second->safeName();
145  m = __inf->posterior(__inf->BN().idFromName(sBuff.str()));
146  }
MarginalTargetedInference< GUM_SCALAR > * __inf
The bayesnet inference engine used by this class.
List< const Potential< GUM_SCALAR > *> __obs
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ _marginal() [2/2]

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

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

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

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

◆ clearEvidence()

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

Remove all evidences.

Definition at line 33 of file PRMInference_tpl.h.

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

◆ 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 153 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().

153  {
154  try {
155  return *(__evidences[&i]);
156  } catch (NotFound&) {
157  GUM_ERROR(NotFound, "this instance has no evidence.");
158  }
159  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> __evidences
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:232
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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)
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 174 of file PRMInference_tpl.h.

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

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

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

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

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

◆ getBNInference()

template<typename GUM_SCALAR >
INLINE MarginalTargetedInference< GUM_SCALAR > & gum::prm::GroundedInference< GUM_SCALAR >::getBNInference ( )

Returns the bayesnet inference engine used by this class.

Returns
the bayesnet inference engine used by this class.
Exceptions
NotFoundRaised if no inference engine have been defined for this class.

Definition at line 110 of file groundedInference_tpl.h.

References gum::prm::GroundedInference< GUM_SCALAR >::__inf, and GUM_ERROR.

110  {
111  if (__inf != 0) {
112  return *__inf;
113  } else {
114  GUM_ERROR(NotFound, "the inference engine is not yet defined");
115  }
116  }
MarginalTargetedInference< GUM_SCALAR > * __inf
The bayesnet inference engine used by this class.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52

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

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

195  {
196  return __evidences.exists(&i);
197  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> __evidences
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:232
+ 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
inherited

Returns EMap of evidences over i.

Definition at line 200 of file PRMInference_tpl.h.

201  {
202  return __evidences.exists(i);
203  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> __evidences
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:232

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

206  {
207  return (hasEvidence(chain.first))
208  ? evidence(chain.first).exists(chain.second->id())
209  : false;
210  }
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 213 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().

213  {
214  return (__evidences.size() != (Size)0);
215  }
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> __evidences
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:232
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
+ 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 
)
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 260 of file PRMInference_tpl.h.

262  {
263  if (j.nbrDim() > 0) {
264  GUM_ERROR(OperationNotAllowed, "the given Potential is not empty.");
265  }
266 
267  for (auto chain = chains.begin(); chain != chains.end(); ++chain) {
268  j.add(chain->second->type().variable());
269  }
270 
271  _joint(chains, j);
272  }
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:52

◆ marginal()

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

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

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

233  {
234  if (m.nbrDim() > 0) {
235  GUM_ERROR(OperationNotAllowed, "the given Potential is not empty.");
236  }
237 
238  if (hasEvidence(chain)) {
239  m.add(chain.second->type().variable());
240  const Potential< GUM_SCALAR >& e =
241  *(evidence(chain.first)[chain.second->id()]);
242  Instantiation i(m), j(e);
243 
244  for (i.setFirst(), j.setFirst(); !i.end(); i.inc(), j.inc())
245  m.set(i, e.get(j));
246  } else {
247  if (chain.second != &(chain.first->get(chain.second->safeName()))) {
248  typename PRMInference< GUM_SCALAR >::Chain good_chain = std::make_pair(
249  chain.first, &(chain.first->get(chain.second->safeName())));
250  m.add(good_chain.second->type().variable());
251  _marginal(good_chain, m);
252  } else {
253  m.add(chain.second->type().variable());
254  _marginal(chain, m);
255  }
256  }
257  }
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:54
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the caller graph for this function:

◆ name()

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

Returns the bayesnet inference engine used by this class.

Returns
the bayesnet inference engine used by this class.
Exceptions
NotFoundRaised if no inference engine have been defined for this class.

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

Definition at line 156 of file groundedInference_tpl.h.

156  {
157  return "grounded inference";
158  }

◆ operator=()

template<typename GUM_SCALAR >
INLINE GroundedInference< GUM_SCALAR > & gum::prm::GroundedInference< GUM_SCALAR >::operator= ( const GroundedInference< GUM_SCALAR > &  source)
private

Copy operator.

Definition at line 104 of file groundedInference_tpl.h.

References GUM_ERROR.

Referenced by gum::prm::GroundedInference< GUM_SCALAR >::GroundedInference().

104  {
105  GUM_ERROR(FatalError, "illegal call to copy operator");
106  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the caller 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.
WrongTypeRaised if the elt is not an PRMAttribute<GUM_SCALAR>.

Definition at line 218 of file PRMInference_tpl.h.

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

218  {
219  try {
220  if (__EMap(chain.first).exists(chain.second->id())) {
221  _evidenceRemoved(chain);
222  delete __EMap(chain.first)[chain.second->id()];
223  __EMap(chain.first).erase(chain.second->id());
224  }
225  } catch (NotFound&) {
226  // Ok, we are only removing
227  }
228  }
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:

◆ setBNInference()

template<typename GUM_SCALAR >
INLINE void gum::prm::GroundedInference< GUM_SCALAR >::setBNInference ( MarginalTargetedInference< GUM_SCALAR > *  bn_inf)

Defines the bayesnet inference engine used by this class.

The inference engine is given to this class, it will be deleted when ~GroundedInference() is called.

Parameters
bn_infThe bayesnet inference engine used by this class.
Exceptions
OperationNotAllowedIf bn_inf does not inference over the SystemBayesNet of this class.
Todo:
MarginalTargetedInference should have copy constructors.

Definition at line 119 of file groundedInference_tpl.h.

References gum::prm::GroundedInference< GUM_SCALAR >::__inf.

120  {
121  if (__inf != 0) { delete __inf; }
122 
123  __inf = bn_inf;
124  }
MarginalTargetedInference< GUM_SCALAR > * __inf
The bayesnet inference engine used by this class.

Member Data Documentation

◆ __inf

template<typename GUM_SCALAR>
MarginalTargetedInference< GUM_SCALAR >* gum::prm::GroundedInference< GUM_SCALAR >::__inf
private

◆ __obs

template<typename GUM_SCALAR>
List< const Potential< GUM_SCALAR >* > gum::prm::GroundedInference< GUM_SCALAR >::__obs
private

◆ _prm

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

◆ _sys


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