Bayes++ Bayesian Filtering Classes  Release 2014.5 - Copyright (c) 2003,2004,2005,2006,2011,2012,2014 Michael Stevens
models.hpp
Go to the documentation of this file.
1 #ifndef _BAYES_FILTER__MODELS
2 #define _BAYES_FILTER__MODELS
3 
4 /*
5  * Bayes++ the Bayesian Filtering Library
6  * Copyright (c) 2002 Michael Stevens
7  * See accompanying Bayes++.htm for terms and conditions of use.
8  *
9  * $Id$
10  */
11 
12 /*
13  * Predict and Observe models
14  * These models extend, adapt and simplify the fundamental Bayesian filter models
15  * Simple : Simplify model construction and use
16  * General: Generalise a model so it include properties of more then one model
17  * Adapted: Adapt one model type into another
18  */
19 #include <boost/function.hpp>
20 
21 /* Filter namespace */
22 namespace Bayesian_filter
23 {
24 
25 typedef boost::function1<const FM::Vec&, const FM::Vec&> State_function;
26 // A generalised function of state. Compatible with predict and observe models
27 
28 
30 // Additive predict model initialised from function and model matricies
31 {
32  State_function ff;
33 public:
34  Simple_additive_predict_model (State_function f_init, const FM::Matrix& G_init, const FM::Vec& q_init);
35  // Precondition: G, q are conformantly dimensioned (not checked)
36 
37  // No default assignment operator
38 
39  virtual const FM::Vec& f(const FM::Vec& x) const
40  { return ff(x);
41  }
42 };
43 
45 // Linrz predict model initialised from function and model matrices
46 {
47  State_function ff;
48 public:
49  Simple_linrz_predict_model (State_function f_init, const FM::Matrix& Fx_init, const FM::Matrix& G_init, const FM::Vec& q_init);
50  // Precondition: Fx, G, q are conformantly dimensioned (not checked)
51 
52  // No default assignment operator
53 
54  virtual const FM::Vec& f(const FM::Vec& x) const
55  { return ff(x);
56  }
57 };
58 
60 // Linear predict model initialised from model matricies
61 {
62 public:
63  Simple_linear_predict_model (const FM::Matrix& Fx_init, const FM::Matrix& G_init, const FM::Vec& q_init);
64  // Precondition: Fx, q and G are conformantly dimensioned (not checked)
65 };
66 
67 
69 // Linrz observe model initialised from function and model matrices
70 {
71  State_function ff;
72 public:
73  Simple_linrz_correlated_observe_model (State_function f_init, const FM::Matrix& Hx_init, const FM::SymMatrix& Z_init);
74  // Precondition: Hx, Z are conformantly dimensioned (not checked)
75  // No default assignment operator
76 
77  virtual const FM::Vec& h(const FM::Vec& x) const
78  { return ff(x);
79  }
80 };
81 
83 // Linrz observe model initialised from function and model matrices
84 {
85  State_function ff;
86 public:
87  Simple_linrz_uncorrelated_observe_model (State_function f_init, const FM::Matrix& Hx_init, const FM::Vec& Zv_init);
88  // Precondition: Hx, Zv are conformantly dimensioned (not checked)
89  // No default assignment operator
90 
91  virtual const FM::Vec& h(const FM::Vec& x) const
92  { return ff(x);
93  }
94 };
95 
97 // Linear observe model initialised from model matrices
98 {
99 public:
100  Simple_linear_correlated_observe_model (const FM::Matrix& Hx_init, const FM::SymMatrix& Z_init);
101  // Precondition: Hx, Z are conformantly dimensioned (not checked)
102 };
103 
105 // Linear observe model initialised from model matrices
106 {
107 public:
108  Simple_linear_uncorrelated_observe_model (const FM::Matrix& Hx_init, const FM::Vec& Zv_init);
109  // Precondition: Hx, Zv are conformantly dimensioned (not checked)
110 };
111 
112 
113 
114 /*
115  * Model Adaptors: Constructed with a reference to another model
116  */
117 
118 
120 /*
121  * Adapt Uncorrelated_additive_observe_model to an equivalent
122  * Correlated_additive_observe_model_adaptor
123  */
124 {
125 public:
127  const FM::Vec& h(const FM::Vec& x) const
128  {
129  return unc.h(x);
130  }
131  inline void normalise (FM::Vec& z_denorm, const FM::Vec& z_from) const
132  {
133  unc.normalise (z_denorm, z_from);
134  };
135 private:
137 };
138 
140 /*
141  * Adapt Linrz_uncorrelated_observe_model to an equivalent
142  * Linrz_correlated_observe_model
143  */
144 {
145 public:
147  const FM::Vec& h(const FM::Vec& x) const
148  {
149  return unc.h(x);
150  }
151  inline void normalise (FM::Vec& z_denorm, const FM::Vec& z_from) const
152  {
153  unc.normalise (z_denorm, z_from);
154  };
155 protected:
157 };
158 
159 
160 /*
161  * Generalised Models: generalise a model so it include properties of more then one model.
162  */
163 
164 // General Linearised Uncorrelated Additive and Likelihood observe model
166 {
167 public:
168  General_LzUnAd_observe_model (std::size_t x_size, std::size_t z_size) :
169  Linrz_uncorrelated_observe_model(x_size, z_size),
170  Likelihood_observe_model(z_size),
171  li(z_size)
172  {}
173  virtual Float L(const FM::Vec& x) const
174  // Definition of likelihood for additive noise model given zz
175  { return li.L(*this, z, h(x));
176  }
177  virtual void Lz (const FM::Vec& zz)
178  // Fix the observation zz about which to evaluate the Likelihood function
179  // Zv is also fixed
181  li.Lz(*this);
182  }
183 private:
185  struct Likelihood_uncorrelated
186  {
187  Likelihood_uncorrelated(std::size_t z_size) :
188  zInnov(z_size), Zv_inv(z_size)
189  { zset = false;
190  }
191  mutable FM::Vec zInnov; // Normailised innovation, temporary for L(x)
192  FM::Vec Zv_inv; // Inverse Noise Covariance given zz
193  Float logdetZ; // log(det(Z))
194  bool zset;
195  Float L(const Uncorrelated_additive_observe_model& model, const FM::Vec& z, const FM::Vec& zp) const;
196  // Definition of likelihood for additive noise model given zz
197  void Lz(const Uncorrelated_additive_observe_model& model);
198  };
199  Likelihood_uncorrelated li;
200 };
201 
202 // General Linear Uncorrelated Additive and Likelihood observe model
204 {
205 public:
206  General_LiUnAd_observe_model (std::size_t x_size, std::size_t z_size) :
207  Linear_uncorrelated_observe_model(x_size, z_size),
208  Likelihood_observe_model(z_size),
209  li(z_size)
210  {}
211  virtual Float L(const FM::Vec& x) const
212  // Definition of likelihood for additive noise model given zz
213  { return li.L(*this, z, h(x));
214  }
215  virtual void Lz (const FM::Vec& zz)
216  // Fix the observation zz about which to evaluate the Likelihood function
217  // Zv is also fixed
219  li.Lz(*this);
220  }
221 
222 private:
223  General_LzUnAd_observe_model::Likelihood_uncorrelated li;
224 };
225 
226 // General Linearised Correlated Additive and Likelihood observe model
228 {
229 public:
230  General_LzCoAd_observe_model (std::size_t x_size, std::size_t z_size) :
231  Linrz_correlated_observe_model(x_size, z_size),
232  Likelihood_observe_model(z_size),
233  li(z_size)
234  {}
235  virtual Float L(const FM::Vec& x) const
236  // Definition of likelihood for additive noise model given zz
237  { return li.L(*this, z, h(x));
238  }
239  virtual void Lz (const FM::Vec& zz)
240  // Fix the observation zz about which to evaluate the Likelihood function
241  // Zv is also fixed
243  li.Lz(*this);
244  }
245 
246 private:
248  struct Likelihood_correlated
249  {
250  Likelihood_correlated(std::size_t z_size) :
251  zInnov(z_size), Z_inv(z_size,z_size)
252  { zset = false;
253  }
254  mutable FM::Vec zInnov; // Normalised innovation, temporary for L(x)
255  FM::SymMatrix Z_inv; // Inverse Noise Covariance
256  Float logdetZ; // log(det(Z)
257  bool zset;
258  static Float scaled_vector_square(const FM::Vec& v, const FM::SymMatrix& V);
259  Float L(const Correlated_additive_observe_model& model, const FM::Vec& z, const FM::Vec& zp) const;
260  // Definition of likelihood for additive noise model given zz
261  void Lz(const Correlated_additive_observe_model& model);
262  };
263  Likelihood_correlated li;
264 };
265 
266 // General Linear Correlated Additive and Likelihood observe model
268 {
269 public:
270  General_LiCoAd_observe_model (std::size_t x_size, std::size_t z_size) :
271  Linear_correlated_observe_model(x_size, z_size),
272  Likelihood_observe_model(z_size),
273  li(z_size)
274  {}
275  virtual Float L(const FM::Vec& x) const
276  // Definition of likelihood for additive noise model given zz
277  { return li.L(*this, z, h(x));
278  }
279  virtual void Lz (const FM::Vec& zz)
280  // Fix the observation zz about which to evaluate the Likelihood function
281  // Zv is also fixed
283  li.Lz(*this);
284  }
285 
286 private:
287  General_LzCoAd_observe_model::Likelihood_correlated li;
288 };
289 
290 
291 }// namespace
292 
293 #endif
void normalise(FM::Vec &z_denorm, const FM::Vec &z_from) const
Definition: models.hpp:131
boost::function1< const FM::Vec &, const FM::Vec & > State_function
Definition: models.hpp:25
const FM::Vec & h(const FM::Vec &x) const
Definition: models.hpp:147
Linrz_uncorrelated_observe_model & unc
Definition: models.hpp:154
virtual const FM::Vec & h(const FM::Vec &x) const
Definition: models.hpp:91
General_LiUnAd_observe_model(std::size_t x_size, std::size_t z_size)
Definition: models.hpp:206
General_LzCoAd_observe_model(std::size_t x_size, std::size_t z_size)
Definition: models.hpp:230
General_LiCoAd_observe_model(std::size_t x_size, std::size_t z_size)
Definition: models.hpp:270
Definition: bayesFlt.hpp:154
virtual void Lz(const FM::Vec &zz)
Definition: models.hpp:177
General_LzUnAd_observe_model(std::size_t x_size, std::size_t z_size)
Definition: models.hpp:168
virtual Float L(const FM::Vec &x) const
Definition: models.hpp:173
virtual const FM::Vec & h(const FM::Vec &x) const
Definition: models.hpp:77
Definition: bayesException.hpp:20
virtual const FM::Vec & f(const FM::Vec &x) const
Definition: models.hpp:54
void normalise(FM::Vec &z_denorm, const FM::Vec &z_from) const
Definition: models.hpp:151
virtual Float L(const FM::Vec &x) const
Definition: models.hpp:275
FMVec< detail::BaseVector > Vec
Definition: uBLASmatrix.hpp:323
Simple_additive_predict_model(State_function f_init, const FM::Matrix &G_init, const FM::Vec &q_init)
Definition: bayesFltAlg.cpp:32
virtual Float L(const FM::Vec &x) const
Definition: models.hpp:235
RowMatrix Matrix
Definition: uBLASmatrix.hpp:325
FM::Vec z
Definition: bayesFlt.hpp:258
virtual const FM::Vec & f(const FM::Vec &x) const
Definition: models.hpp:39
Bayesian_filter_matrix::Float Float
Definition: bayesFlt.hpp:39
FMMatrix< detail::SymMatrixWrapper< detail::BaseRowMatrix > > SymMatrix
Definition: uBLASmatrix.hpp:327
Definition: bayesFlt.hpp:240
const FM::Vec & h(const FM::Vec &x) const
Definition: models.hpp:127
Definition: bayesFlt.hpp:177
virtual Float L(const FM::Vec &x) const
Definition: models.hpp:211
virtual void Lz(const FM::Vec &zz)
Definition: models.hpp:215
Definition: bayesFlt.hpp:189
virtual void Lz(const FM::Vec &zz)
Definition: models.hpp:239
virtual void Lz(const FM::Vec &zz)
Definition: models.hpp:279