aGrUM  0.16.0
PRMInference.h
Go to the documentation of this file.
1 
30 #ifndef GUM_PRM_INFERENCE_H
31 #define GUM_PRM_INFERENCE_H
32 
33 #include <string>
34 
35 #include <agrum/core/hashTable.h>
37 
38 #include <agrum/PRM/PRM.h>
39 
40 namespace gum {
41  namespace prm {
51  template < typename GUM_SCALAR >
52  class PRMInference {
53  public:
55  typedef std::pair< const PRMInstance< GUM_SCALAR >*,
58 
61 
63  typedef
64  typename NodeProperty< const Potential< GUM_SCALAR >* >::iterator_safe
66 
68  typedef typename NodeProperty<
69  const Potential< GUM_SCALAR >* >::const_iterator_safe EMapConstIterator;
70 
71  // ========================================================================
73  // ========================================================================
75 
78  const PRMSystem< GUM_SCALAR >& system);
79 
81  PRMInference(const PRMInference& source);
82 
84  virtual ~PRMInference();
85 
87  PRMInference& operator=(const PRMInference& source);
88 
90  // ========================================================================
92  // ========================================================================
94 
96  virtual std::string name() const = 0;
97 
99  // ========================================================================
100  // ========================================================================
102  // ========================================================================
104 
116  void marginal(const Chain& chain, Potential< GUM_SCALAR >& m);
117 
129  void joint(const std::vector< Chain >& chains, Potential< GUM_SCALAR >& j);
130 
132  // ========================================================================
134  // ========================================================================
136 
139  EMap& evidence(const PRMInstance< GUM_SCALAR >& i);
140 
143  EMap& evidence(const PRMInstance< GUM_SCALAR >* i);
144 
147  const EMap& evidence(const PRMInstance< GUM_SCALAR >& i) const;
148 
151  const EMap& evidence(const PRMInstance< GUM_SCALAR >* i) const;
152 
154  bool hasEvidence(const PRMInstance< GUM_SCALAR >& i) const;
155 
157  bool hasEvidence(const PRMInstance< GUM_SCALAR >* i) const;
158 
160  bool hasEvidence(const Chain& chain) const;
161 
163  bool hasEvidence() const;
164 
171  void addEvidence(const Chain& chain, const Potential< GUM_SCALAR >& p);
172 
178  void removeEvidence(const Chain& chain);
179 
181  void clearEvidence();
182 
184  protected:
185  // ========================================================================
187  // ========================================================================
189 
192  virtual void _evidenceAdded(const Chain& chain) = 0;
193 
196  virtual void _evidenceRemoved(const Chain& chain) = 0;
197 
202  virtual void _marginal(const Chain& chain, Potential< GUM_SCALAR >& m) = 0;
203 
209  virtual void _joint(const std::vector< Chain >& queries,
210  Potential< GUM_SCALAR >& j) = 0;
211 
214 
217 
219 
220  private:
221  // ========================================================================
223  // ========================================================================
225 
228  EMap* >::iterator_safe EvidenceIterator;
230  typedef
231  typename HashTable< const PRMInstance< GUM_SCALAR >*,
232  EMap* >::const_iterator_safe EvidenceConstIterator;
233 
235  HashTable< const PRMInstance< GUM_SCALAR >*, EMap* > __evidences;
236 
238  EMap& __EMap(const PRMInstance< GUM_SCALAR >* i);
239 
241  };
242 
243 
244 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
245  extern template class PRMInference< double >;
246 #endif
247 
248 
249  } /* namespace prm */
250 } /* namespace gum */
251 
253 
254 #endif /* GUM_PRM_INFERENCE_H */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> __evidences
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:235
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
Definition: PRMInstance.h:63
virtual void _marginal(const Chain &chain, Potential< GUM_SCALAR > &m)=0
Generic method to compute the marginal of given element.
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *>::const_iterator_safe EvidenceConstIterator
Code alias.
Definition: PRMInference.h:232
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *>::iterator_safe EvidenceIterator
Code alias.
Definition: PRMInference.h:228
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
NodeProperty< const Potential< GUM_SCALAR > *>::iterator_safe EMapIterator
Code alias.
Definition: PRMInference.h:65
PRM< GUM_SCALAR > const * _prm
The PRM<GUM_SCALAR> on which inference is done.
Definition: PRMInference.h:213
virtual void _evidenceRemoved(const Chain &chain)=0
This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference...
The class for generic Hash Tables.
Definition: hashTable.h:679
void marginal(const Chain &chain, Potential< GUM_SCALAR > &m)
Compute the marginal of the formal attribute pointed by chain and stores it in m. ...
virtual void _evidenceAdded(const Chain &chain)=0
This method is called whenever an evidence is added, but AFTER any processing made by PRMInference...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
EMap & __EMap(const PRMInstance< GUM_SCALAR > *i)
Private getter over __evidences, if necessary creates an EMap for i.
void clearEvidence()
Remove all evidences.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition: PRMObject.h:229
NodeProperty< const Potential< GUM_SCALAR > *>::const_iterator_safe EMapConstIterator
Code alias.
Definition: PRMInference.h:69
bool hasEvidence() const
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
PRMSystem< GUM_SCALAR > const * _sys
The Model on which inference is done.
Definition: PRMInference.h:216
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > *> Chain
Code alias.
Definition: PRMInference.h:57
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
Definition: PRMInference.h:52
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition: PRM.h:66
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...
void addEvidence(const Chain &chain, const Potential< GUM_SCALAR > &p)
Add an evidence to the given instance&#39;s elt.
virtual std::string name() const =0
Returns the name of the current inference algorithm.
NodeProperty< const Potential< GUM_SCALAR > *> EMap
Code alias.
Definition: PRMInference.h:60
virtual void _joint(const std::vector< Chain > &queries, Potential< GUM_SCALAR > &j)=0
Generic method to compute the marginal of given element.
PRMAttribute is a member of a Class in a PRM.
Definition: PRMAttribute.h:61
void removeEvidence(const Chain &chain)
Remove evidence on the given instance&#39;s elt.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual ~PRMInference()
Destructor.
PRMInference & operator=(const PRMInference &source)
Copy operator.