Bayes++ Bayesian Filtering Classes  Release 2014.5 - Copyright (c) 2003,2004,2005,2006,2011,2012,2014 Michael Stevens
unsFlt.hpp
Go to the documentation of this file.
1 #ifndef _BAYES_FILTER_UNSCENTED
2 #define _BAYES_FILTER_UNSCENTED
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  * Unscented Filter Scheme.
14  * A Julier-Uhlmann Unscented non-linear Kalman filter
15  * Uses the classic implementation of the Duplex Unscented transform.
16  * The Unscented transform is used for non-linear state and observation predictions
17  *
18  * Observations are fused using innovation gain equations from a Covariance filter
19  *
20  * Predictions of state and state covariance (and observation) use
21  * Unscented transformations to interpolate the non-linear predict and observe
22  * models. Unscented transforms can be further optimised by vary the Kappa
23  * parameter from its usual value of 1.
24  * Discontinuous observe models require that a normalisation function.
25  *
26  * The predict model is represented by the state prediction function and a
27  * separate prediction noise matrix.
28  * The observe model is represented by the observation prediction function and
29  * a function to normalise observations.
30  *
31  * The filter is operated by performing a
32  * predict, observe
33  * cycle defined by the base class
34  */
35 #include "bayesFlt.hpp"
36 
37 /* Filter namespace */
38 namespace Bayesian_filter
39 {
40 
42 /* Specific Unscented prediction model for Additive noise
43  * x(k|k-1) = f(x(k-1|k-1)) + w(x(k))
44  *
45  * Unscented filter requires
46  * f the function part of the non-linear model
47  * Q the covariance of the additive w(x(k)), w is specifically allow to be a function of state
48  */
49 {
50 public:
51  Unscented_predict_model (std::size_t q_size)
52  {
53  q_unscented = q_size;
54  }
55 
56  virtual const FM::Vec& f(const FM::Vec& x) const = 0;
57  // Functional part of additive model
58  // Note: Reference return value as a speed optimisation, MUST be copied by caller.
59 
60  virtual const FM::SymMatrix& Q(const FM::Vec& x) const = 0;
61  // Covariance of additive noise
62  // Note: Reference return value as a speed optimisation, MUST be copied by caller.
63 private:
64  friend class Unscented_filter; // Filter implementation need to know noise size
65  std::size_t q_unscented;
66 };
67 
68 
70 {
71 private:
72  std::size_t q_max; // Maximum size allocated for noise model, constructed before XX
73 public:
74  FM::ColMatrix XX; // Unscented form of state, with associated Kappa
76 
77  Unscented_scheme (std::size_t x_size, std::size_t z_initialsize = 0);
78  Unscented_scheme& operator= (const Unscented_scheme&);
79  // Optimise copy assignment to only copy filter state
80 
81  void init ();
82  void init_XX ();
83  void update ();
84  void update_XX (Float kappa);
85 
86  void predict (Unscented_predict_model& f);
87  // Efficient Unscented prediction
88  void predict (Functional_predict_model& f);
89  void predict (Additive_predict_model& f);
91  { // Adapt to use the more general additive model
92  predict(static_cast<Additive_predict_model&>(f));
93  return 1.; // Always well condition for additive predict
94  }
95 
96  Float observe (Uncorrelated_additive_observe_model& h, const FM::Vec& z);
97  Float observe (Correlated_additive_observe_model& h, const FM::Vec& z);
98  // Unscented filter implements general additive observe models
99 
101  { // Adapt to use the more general additive model
102  return observe (static_cast<Uncorrelated_additive_observe_model&>(h),z);
103  }
105  { // Adapt to use the more general additive model
106  return observe (static_cast<Correlated_additive_observe_model&>(h),z);
107  }
108 
109 public: // Exposed Numerical Results
110  FM::Vec s; // Innovation
111  FM::SymMatrix S, SI; // Innovation Covariance and Inverse
112 
113 protected:
114  virtual Float predict_Kappa (std::size_t size) const;
115  virtual Float observe_Kappa (std::size_t size) const;
116  /* Unscented Kappa values
117  default uses the rule which minimise mean squared error of 4th order term
118  */
119 
120 protected: // allow fast operation if z_size remains constant
121  std::size_t last_z_size;
122  void observe_size (std::size_t z_size);
123 
124 private:
125  void unscented (FM::ColMatrix& XX, const FM::Vec& x, const FM::SymMatrix& X, Float scale);
126  /* Determine Unscented points for a distribution */
127  std::size_t x_size;
128  std::size_t XX_size; // 2*x_size+1
129 
130 protected: // Permanently allocated temps
132 };
133 
134 
135 }//namespace
136 #endif
Definition: unsFlt.hpp:69
Definition: bayesFlt.hpp:95
std::size_t last_z_size
Definition: unsFlt.hpp:121
Definition: bayesFlt.hpp:154
Definition: bayesFlt.hpp:588
virtual const FM::SymMatrix & Q(const FM::Vec &x) const =0
Float predict(Linrz_predict_model &f)
Definition: unsFlt.hpp:90
Definition: bayesException.hpp:20
friend class Unscented_filter
Definition: unsFlt.hpp:64
FMVec< detail::BaseVector > Vec
Definition: uBLASmatrix.hpp:323
Float observe(Linrz_uncorrelated_observe_model &h, const FM::Vec &z)
Definition: unsFlt.hpp:100
virtual const FM::Vec & f(const FM::Vec &x) const =0
Unscented_predict_model(std::size_t q_size)
Definition: unsFlt.hpp:51
Definition: bayesFlt.hpp:116
FM::ColMatrix XX
Definition: unsFlt.hpp:74
Bayesian_filter_matrix::Float Float
Definition: bayesFlt.hpp:39
FM::ColMatrix fXX
Definition: unsFlt.hpp:131
FMMatrix< detail::SymMatrixWrapper< detail::BaseRowMatrix > > SymMatrix
Definition: uBLASmatrix.hpp:327
Definition: bayesFlt.hpp:436
Definition: bayesFlt.hpp:177
FMMatrix< detail::BaseColMatrix > ColMatrix
Definition: uBLASmatrix.hpp:326
FM::SymMatrix SI
Definition: unsFlt.hpp:111
FM::Vec s
Definition: unsFlt.hpp:110
Float kappa
Definition: unsFlt.hpp:75
Float observe(Linrz_correlated_observe_model &h, const FM::Vec &z)
Definition: unsFlt.hpp:104