aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
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 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 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 posterior_ (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 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...
 
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 46 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 56 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 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

◆ 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 88 of file groundedInference_tpl.h.

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

90  :
91  PRMInference< GUM_SCALAR >(prm, system),
92  inf__(0) {
93  GUM_CONSTRUCTOR(GroundedInference);
94  }
GroundedInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
MarginalTargetedInference< GUM_SCALAR > * inf__
The bayesnet inference engine used by this class.
+ Here is the call graph for this function:

◆ ~GroundedInference()

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

Destructor.

Definition at line 35 of file groundedInference_tpl.h.

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

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

◆ 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 97 of file groundedInference_tpl.h.

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

98  :
99  PRMInference< GUM_SCALAR >(source),
100  inf__(0) {
101  GUM_CONS_CPY(GroundedInference);
102  GUM_ERROR(FatalError, "illegal to copy constructor");
103  }
GroundedInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
MarginalTargetedInference< GUM_SCALAR > * inf__
The bayesnet inference engine used by this class.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ 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

◆ 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

◆ 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_() [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 49 of file groundedInference_tpl.h.

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

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

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

70  {
71  std::stringstream var_name;
72  var_name << chain.first->name() << "." << chain.second->safeName();
73  const DiscreteVariable& var = inf__->BN().variableFromName(var_name.str());
74 
75  for (auto iter = obs__.beginSafe(); iter != obs__.endSafe();
76  ++iter) { // safe iterator needed here
77  if ((**iter).contains(var)) {
78  inf__->eraseEvidence(var_name.str());
79  const Potential< GUM_SCALAR >* e = *iter;
80  obs__.erase(iter);
81  delete e;
82  break;
83  }
84  }
85  }
List< const Potential< GUM_SCALAR > *> obs__
MarginalTargetedInference< GUM_SCALAR > * inf__
The bayesnet inference engine used by this class.
+ 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 >.

◆ 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 114 of file groundedInference_tpl.h.

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

114  {
115  if (inf__ != 0) {
116  return *inf__;
117  } else {
118  GUM_ERROR(NotFound, "the inference engine is not yet defined");
119  }
120  }
MarginalTargetedInference< GUM_SCALAR > * inf__
The bayesnet inference engine used by this class.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ 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

◆ 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_() [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 153 of file groundedInference_tpl.h.

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

155  {
156  GUM_ERROR(FatalError, "not yet implemented");
157  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ 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 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 >
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 160 of file groundedInference_tpl.h.

160  {
161  return "grounded inference";
162  }

◆ 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 107 of file groundedInference_tpl.h.

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

108  {
109  GUM_ERROR(FatalError, "illegal call to copy operator");
110  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

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

template<typename GUM_SCALAR >
INLINE void gum::prm::GroundedInference< GUM_SCALAR >::posterior_ ( 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 131 of file groundedInference_tpl.h.

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

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

◆ posterior_() [2/2]

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

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

◆ 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 123 of file groundedInference_tpl.h.

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

124  {
125  if (inf__ != 0) { delete inf__; }
126 
127  inf__ = bn_inf;
128  }
MarginalTargetedInference< GUM_SCALAR > * inf__
The bayesnet inference engine used by this class.
+ Here is the call graph for this function:

Member Data Documentation

◆ inf__

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

The bayesnet inference engine used by this class.

Definition at line 131 of file groundedInference.h.

◆ obs__

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

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

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