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 */
38namespace 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{
50public:
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.
63private:
64 friend class Unscented_filter; // Filter implementation need to know noise size
65 std::size_t q_unscented;
66};
67
68
70{
71private:
72 std::size_t q_max; // Maximum size allocated for noise model, constructed before XX
73public:
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);
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
87 // Efficient Unscented prediction
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
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
109public: // Exposed Numerical Results
110 FM::Vec s; // Innovation
111 FM::SymMatrix S, SI; // Innovation Covariance and Inverse
112
113protected:
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
120protected: // 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
124private:
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
130protected: // Permanently allocated temps
132};
133
134
135}//namespace
136#endif
Definition bayesFlt.hpp:162
Definition bayesFlt.hpp:437
FM::SymMatrix X
Definition bayesFlt.hpp:491
Definition bayesFlt.hpp:589
Definition bayesFlt.hpp:183
Definition bayesFlt.hpp:96
FM::Vec x
Definition bayesFlt.hpp:461
virtual const FM::SymMatrix & Q(const FM::Vec &x) const =0
virtual const FM::Vec & f(const FM::Vec &x) const =0
Unscented_predict_model(std::size_t q_size)
Definition unsFlt.hpp:51
friend class Unscented_filter
Definition unsFlt.hpp:64
Definition unsFlt.hpp:70
FM::SymMatrix SI
Definition unsFlt.hpp:111
std::size_t last_z_size
Definition unsFlt.hpp:121
FM::ColMatrix fXX
Definition unsFlt.hpp:131
void init_XX()
Definition unsFlt.cpp:96
virtual Float observe_Kappa(std::size_t size) const
Definition unsFlt.cpp:78
Float observe(Uncorrelated_additive_observe_model &h, const FM::Vec &z)
Definition unsFlt.cpp:256
Float kappa
Definition unsFlt.hpp:75
void update()
Definition unsFlt.cpp:128
virtual Float predict_Kappa(std::size_t size) const
Definition unsFlt.cpp:71
Float predict(Linrz_predict_model &f)
Definition unsFlt.hpp:90
FM::ColMatrix XX
Definition unsFlt.hpp:74
Float observe(Linrz_correlated_observe_model &h, const FM::Vec &z)
Definition unsFlt.hpp:104
void predict(Unscented_predict_model &f)
Definition unsFlt.cpp:216
FM::SymMatrix S
Definition unsFlt.hpp:111
FM::Vec s
Definition unsFlt.hpp:110
Float observe(Linrz_uncorrelated_observe_model &h, const FM::Vec &z)
Definition unsFlt.hpp:100
void observe_size(std::size_t z_size)
Definition unsFlt.cpp:242
void update_XX(Float kappa)
Definition unsFlt.cpp:136
void init()
Definition unsFlt.cpp:85
Unscented_scheme & operator=(const Unscented_scheme &)
Definition unsFlt.cpp:38
FMMatrix< detail::BaseColMatrix > ColMatrix
Definition uBLASmatrix.hpp:326
FMMatrix< detail::SymMatrixWrapper< detail::BaseRowMatrix > > SymMatrix
Definition uBLASmatrix.hpp:327
FMVec< detail::BaseVector > Vec
Definition uBLASmatrix.hpp:323
double Float
Definition matSupSub.hpp:55
Definition bayesException.hpp:21