aGrUM  0.14.2
PRMInference.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef GUM_PRM_INFERENCE_H
28 #define GUM_PRM_INFERENCE_H
29 
30 #include <string>
31 
32 #include <agrum/core/hashTable.h>
34 
35 #include <agrum/PRM/PRM.h>
36 
37 namespace gum {
38  namespace prm {
48  template < typename GUM_SCALAR >
49  class PRMInference {
50  public:
52  typedef std::pair< const PRMInstance< GUM_SCALAR >*,
55 
58 
60  typedef
61  typename NodeProperty< const Potential< GUM_SCALAR >* >::iterator_safe
63 
65  typedef typename NodeProperty<
66  const Potential< GUM_SCALAR >* >::const_iterator_safe EMapConstIterator;
67 
68  // ========================================================================
70  // ========================================================================
72 
75  const PRMSystem< GUM_SCALAR >& system);
76 
78  PRMInference(const PRMInference& source);
79 
81  virtual ~PRMInference();
82 
84  PRMInference& operator=(const PRMInference& source);
85 
87  // ========================================================================
89  // ========================================================================
91 
93  virtual std::string name() const = 0;
94 
96  // ========================================================================
97  // ========================================================================
99  // ========================================================================
101 
113  void marginal(const Chain& chain, Potential< GUM_SCALAR >& m);
114 
126  void joint(const std::vector< Chain >& chains, Potential< GUM_SCALAR >& j);
127 
129  // ========================================================================
131  // ========================================================================
133 
136  EMap& evidence(const PRMInstance< GUM_SCALAR >& i);
137 
140  EMap& evidence(const PRMInstance< GUM_SCALAR >* i);
141 
144  const EMap& evidence(const PRMInstance< GUM_SCALAR >& i) const;
145 
148  const EMap& evidence(const PRMInstance< GUM_SCALAR >* i) const;
149 
151  bool hasEvidence(const PRMInstance< GUM_SCALAR >& i) const;
152 
154  bool hasEvidence(const PRMInstance< GUM_SCALAR >* i) const;
155 
157  bool hasEvidence(const Chain& chain) const;
158 
160  bool hasEvidence() const;
161 
168  void addEvidence(const Chain& chain, const Potential< GUM_SCALAR >& p);
169 
175  void removeEvidence(const Chain& chain);
176 
178  void clearEvidence();
179 
181  protected:
182  // ========================================================================
184  // ========================================================================
186 
189  virtual void _evidenceAdded(const Chain& chain) = 0;
190 
193  virtual void _evidenceRemoved(const Chain& chain) = 0;
194 
199  virtual void _marginal(const Chain& chain, Potential< GUM_SCALAR >& m) = 0;
200 
206  virtual void _joint(const std::vector< Chain >& queries,
207  Potential< GUM_SCALAR >& j) = 0;
208 
211 
214 
216 
217  private:
218  // ========================================================================
220  // ========================================================================
222 
225  EMap* >::iterator_safe EvidenceIterator;
227  typedef
228  typename HashTable< const PRMInstance< GUM_SCALAR >*,
229  EMap* >::const_iterator_safe EvidenceConstIterator;
230 
232  HashTable< const PRMInstance< GUM_SCALAR >*, EMap* > __evidences;
233 
235  EMap& __EMap(const PRMInstance< GUM_SCALAR >* i);
236 
238  };
239 
240 
241 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
242  extern template class PRMInference< double >;
243 #endif
244 
245 
246  } /* namespace prm */
247 } /* namespace gum */
248 
250 
251 #endif /* GUM_PRM_INFERENCE_H */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> __evidences
Mapping of evidence over PRMInstance<GUM_SCALAR>&#39;s nodes.
Definition: PRMInference.h:232
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:60
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:229
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *>::iterator_safe EvidenceIterator
Code alias.
Definition: PRMInference.h:225
Inline implementation of PRMInference.
Headers of PRM.
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
NodeProperty< const Potential< GUM_SCALAR > *>::iterator_safe EMapIterator
Code alias.
Definition: PRMInference.h:62
PRM< GUM_SCALAR > const * _prm
The PRM<GUM_SCALAR> on which inference is done.
Definition: PRMInference.h:210
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:676
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...
Header of the Potential class.
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:226
NodeProperty< const Potential< GUM_SCALAR > *>::const_iterator_safe EMapConstIterator
Code alias.
Definition: PRMInference.h:66
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:213
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > *> Chain
Code alias.
Definition: PRMInference.h:54
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
Definition: PRMInference.h:49
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition: PRM.h:63
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:57
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:58
void removeEvidence(const Chain &chain)
Remove evidence on the given instance&#39;s elt.
Class hash tables iterators.
virtual ~PRMInference()
Destructor.
PRMInference & operator=(const PRMInference &source)
Copy operator.