aGrUM  0.14.2
SVE.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_SVE_H
28 #define GUM_SVE_H
29 
30 #include <vector>
31 
32 #include <agrum/core/set.h>
33 
36 
38 
43 
44 #include <agrum/PRM/utils_prm.h>
45 
47 
50 
51 namespace gum {
52  namespace prm {
53 
62  template < typename GUM_SCALAR >
63  class SVE : public PRMInference< GUM_SCALAR > {
64  public:
65  // ========================================================================
67  // ========================================================================
69 
71  SVE(const PRM< GUM_SCALAR >& prm, const PRMSystem< GUM_SCALAR >& system);
72 
74  ~SVE();
75 
77  // ========================================================================
79  // ========================================================================
81 
83  virtual std::string name() const;
84 
86  protected:
87  // ========================================================================
89  // ========================================================================
91 
94 
96  virtual void _evidenceAdded(const Chain& chain);
97 
99  virtual void _evidenceRemoved(const Chain& chain);
100 
102  virtual void _marginal(const Chain& chain, Potential< GUM_SCALAR >& m);
103 
105  virtual void _joint(const std::vector< Chain >& queries,
107 
109  private:
113  typedef
115 
117  typedef typename Set< MultiDimArray< GUM_SCALAR >* >::iterator_safe
119 
120  HashTable< const PRMClass< GUM_SCALAR >*, std::vector< NodeId >* >
122 
124 
126 
130 
137 
138  BucketSet __lifted_trash;
139 
141 
143 
145  NodeId id,
146  BucketSet& pool,
147  BucketSet& trash);
148 
150  const PRMInstance< GUM_SCALAR >* from,
151  const PRMInstance< GUM_SCALAR >* i,
152  BucketSet& pool,
153  BucketSet& trash,
154  List< const PRMInstance< GUM_SCALAR >* >& elim_list,
155  Set< const PRMInstance< GUM_SCALAR >* >& ignore,
156  Set< const PRMInstance< GUM_SCALAR >* >& eliminated);
157 
159  const PRMInstance< GUM_SCALAR >* i,
160  BucketSet& pool,
161  BucketSet& trash,
162  List< const PRMInstance< GUM_SCALAR >* >& elim_list,
163  Set< const PRMInstance< GUM_SCALAR >* >& ignore,
164  Set< const PRMInstance< GUM_SCALAR >* >& eliminated);
165 
167  BucketSet& pool,
168  BucketSet& trash,
169  Set< NodeId >* delayedVars = 0);
170 
172  BucketSet& pool,
173  BucketSet& trash);
174 
176  BucketSet& pool,
177  BucketSet& trash);
178 
180  BucketSet& pool,
181  BucketSet& trash,
182  Set< NodeId >* delayedVars = 0);
183 
186  const PRMInstance< GUM_SCALAR >* second);
187 
188  void __initElimOrder();
189 
190  void __insertEvidence(const PRMInstance< GUM_SCALAR >* i, BucketSet& pool);
191 
199  const PRMInstance< GUM_SCALAR >* j,
200  NodeId id);
201 
202  std::vector< NodeId >& __getElimOrder(const PRMClass< GUM_SCALAR >& c);
203 
206  const PRMAggregate< GUM_SCALAR >* agg);
207 
209  std::string __trim(const std::string& s);
210 
212  };
213 
214 
215 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
216  extern template class SVE< double >;
217 #endif
218 
219 
220  } /* namespace prm */
221 } /* namespace gum */
222 
224 
225 #endif /* GUM_SVE_H */
Set< MultiDimArray< GUM_SCALAR > *>::iterator_safe ArraySetIterator
Code alias.
Definition: SVE.h:118
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
Set< Potential< GUM_SCALAR > *> BucketSet
Code alias.
Definition: SVE.h:111
void __addDelayedVariable(const PRMInstance< GUM_SCALAR > *i, const PRMInstance< GUM_SCALAR > *j, NodeId id)
When there is a loop in the references some variable elimination must be delayed, this methods add su...
Definition: SVE_tpl.h:675
~SVE()
Destructor.
Definition: SVE_tpl.h:105
HashTable< std::string, Size > __delayedVariablesCounters
Some variable must be delayed for more than one PRMInstance<GUM_SCALAR>, when the delayed variable co...
Definition: SVE.h:136
void __insertEvidence(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:626
BucketSet __lifted_trash
Definition: SVE.h:138
Sets of elements (i.e.
std::vector< NodeId > & __getElimOrder(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:634
void __initLiftedNodes(const PRMClass< GUM_SCALAR > &c)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:487
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
Definition: PRMInstance.h:60
void __eliminateNodesUpward(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore, Set< const PRMInstance< GUM_SCALAR > * > &eliminated)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:328
virtual void _marginal(const Chain &chain, Potential< GUM_SCALAR > &m)
See PRMInference<GUM_SCALAR>::_marginal().
Definition: SVE_tpl.h:578
Headers of MultiDimSparse.
bool __checkElimOrder(const PRMInstance< GUM_SCALAR > *first, const PRMInstance< GUM_SCALAR > *second)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:646
Sequence< std::string > * __class_elim_order
Definition: SVE.h:125
Generic doubly linked lists.
Definition: list.h:369
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
void __eliminateNodes(const PRMInstance< GUM_SCALAR > *query, NodeId id, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:125
Implementation of a variable elimination algorithm for inference in Bayesian Networks.
Potential< GUM_SCALAR > * __getAggPotential(const PRMInstance< GUM_SCALAR > *i, const PRMAggregate< GUM_SCALAR > *agg)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:658
The class for generic Hash Tables.
Definition: hashTable.h:676
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > *> __elim_orders
Definition: SVE.h:121
Headers of ClassBayesNet<GUM_SCALAR>.
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:162
PRMInference< GUM_SCALAR >::Chain Chain
Code alias.
Definition: SVE.h:93
Header of the Potential class.
virtual void _evidenceRemoved(const Chain &chain)
See PRMInference<GUM_SCALAR>::_evidenceRemoved().
Definition: SVE_tpl.h:669
void __insertLiftedNodes(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:467
SVE(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default Constructor.
Definition: SVE_tpl.h:617
void __variableElimination(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, Set< NodeId > *delayedVars=0)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:286
void __eliminateNodesDownward(const PRMInstance< GUM_SCALAR > *from, const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore, Set< const PRMInstance< GUM_SCALAR > * > &eliminated)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:233
Headers of PRMInference.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition: PRMObject.h:226
void __initElimOrder()
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:541
virtual void _evidenceAdded(const Chain &chain)
See PRMInference<GUM_SCALAR>::_evidenceAdded().
Definition: SVE_tpl.h:664
Headers of InstanceBayesNet.
Inline implementation of SVE.
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > *> Chain
Code alias.
Definition: PRMInference.h:54
virtual std::string name() const
Returns the name of the current inference algorithm.
Definition: SVE_tpl.h:698
void __eliminateNodesWithEvidence(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, Set< NodeId > *delayedVars=0)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:379
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
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...
void __eliminateDelayedVariables(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:207
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
Definition: PRMClass.h:63
Headers of the MultiDimBucket class.
Class for computing default triangulations of graphs.
HashTable< const PRMClass< GUM_SCALAR > *, BucketSet *> __lifted_pools
Definition: SVE.h:123
std::string __trim(const std::string &s)
Returns true if second can be eliminated before first.
Definition: SVE_tpl.h:639
Header of the MultiDimArray class.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
HashTable< const PRMInstance< GUM_SCALAR > *, Set< const DiscreteVariable *> *> __delayedVariables
Definition: SVE.h:129
virtual void _joint(const std::vector< Chain > &queries, Potential< GUM_SCALAR > &j)
See PRMInference<GUM_SCALAR>::_joint().
Definition: SVE_tpl.h:611
This class is an implementation of the Structured Variable Elimination algorithm on PRM<GUM_SCALAR>...
Definition: SVE.h:63
Set< Potential< GUM_SCALAR > *>::iterator_safe BucketSetIterator
Code alias.
Definition: SVE.h:114