unsFlt.hpp

Go to the documentation of this file.
00001 #ifndef _BAYES_FILTER_UNSCENTED
00002 #define _BAYES_FILTER_UNSCENTED
00003 
00004 /*
00005  * Bayes++ the Bayesian Filtering Library
00006  * Copyright (c) 2002 Michael Stevens
00007  * See accompanying Bayes++.htm for terms and conditions of use.
00008  *
00009  * $Id: unsFlt.hpp 562 2006-04-05 20:46:23 +0200 (Wed, 05 Apr 2006) mistevens $
00010  */
00011 
00012 /*
00013  * Unscented Filter Scheme.
00014  *  A Julier-Uhlmann Unscented non-linear Kalman filter
00015  *  Uses the classic implementation of Duplex Unscented transform.
00016  * The Unscented transform is used for non-linear state and observation predictions
00017  *
00018  * Observations are fused using innovation gain equations from a Covariance filter
00019  *
00020  * Predictions of state and state covariance (and observation) use
00021  * unscented transformations to interpolate the non-linear predict and observe
00022  * models. unscented transforms can be further optimised by vary the Kappa
00023  * parameter from its usual value of 1.
00024  * Discontinous observe models require that a normailisation function.
00025  *
00026  * The predict model is represtented by the state prediction function and a 
00027  * seperate prediction noise matrix.
00028  * The observe model is represtented by the observation prediction function and
00029  * a function to normalise observeations.
00030  *
00031  * The filter is operated by performing a
00032  *  predict, observe
00033  * cycle defined by the base class
00034  */
00035 #include "bayesFlt.hpp"
00036 
00037 /* Filter namespace */
00038 namespace Bayesian_filter
00039 {
00040 
00041 class Unscented_predict_model : public Predict_model_base
00042 /* Specific Unscented prediction model for Addative noise
00043  *  x(k|k-1) = f(x(k-1|k-1)) + w(x(k))
00044  *
00045  * Unscented filter requires
00046  *  f the function part of the non-linear model
00047  *  Q the covariance of the addative w(x(k)), w is specificly allow to be a function of state
00048  */
00049 {
00050 public:
00051     Unscented_predict_model (std::size_t q_size)
00052     {
00053         q_unscented = q_size;
00054     }
00055 
00056     virtual const FM::Vec& f(const FM::Vec& x) const = 0;
00057     // Functional part of addative model
00058     // Note: Reference return value as a speed optimisation, MUST be copied by caller.
00059 
00060     virtual const FM::SymMatrix& Q(const FM::Vec& x) const = 0;
00061     // Covariance of addative noise
00062     // Note: Reference return value as a speed optimisation, MUST be copied by caller.
00063 private:
00064     friend class Unscented_filter;  // Filter implementation need to know noise size
00065     std::size_t q_unscented;
00066 };
00067 
00068 
00069 class Unscented_scheme : public Linrz_kalman_filter, public Functional_filter
00070 {
00071 private:
00072     std::size_t q_max;          // Maxiumum size allocated for noise model, constructed before XX
00073 public:
00074     FM::ColMatrix XX;       // Unscented form of state, with associated kappa
00075     Float kappa;
00076 
00077     Unscented_scheme (std::size_t x_size, std::size_t z_initialsize = 0);
00078     Unscented_scheme& operator= (const Unscented_scheme&);
00079     // Optimise copy assignment to only copy filter state
00080 
00081     void init ();
00082     void init_XX ();
00083     void update ();
00084     void update_XX (Float kappa);
00085 
00086     void predict (Unscented_predict_model& f);
00087     // Efficient Unscented prediction 
00088     void predict (Functional_predict_model& f);
00089     void predict (Addative_predict_model& f);
00090     Float predict (Linrz_predict_model& f)
00091     {   // Adapt to use the more general addative model
00092         predict(static_cast<Addative_predict_model&>(f));
00093         return 1.;      // Always well condition for addative predict
00094     }
00095     
00096     Float observe (Uncorrelated_addative_observe_model& h, const FM::Vec& z);
00097     Float observe (Correlated_addative_observe_model& h, const FM::Vec& z);
00098     // Unscented filter implements general addative observe models 
00099     
00100     Float observe (Linrz_uncorrelated_observe_model& h, const FM::Vec& z)
00101     {   // Adapt to use the more general addative model
00102         return observe (static_cast<Uncorrelated_addative_observe_model&>(h),z);
00103     }
00104     Float observe (Linrz_correlated_observe_model& h, const FM::Vec& z)
00105     {   // Adapt to use the more general addative model
00106         return observe (static_cast<Correlated_addative_observe_model&>(h),z);
00107     }
00108 
00109 public:                     // Exposed Numerical Results
00110     FM::Vec s;                  // Innovation
00111     FM::SymMatrix S, SI;        // Innovation Covariance and Inverse
00112 
00113 protected:
00114     virtual Float predict_Kappa (std::size_t size) const;
00115     virtual Float observe_Kappa (std::size_t size) const;
00116     /* unscented Kappa values
00117        default uses the rule which minimise mean squared error of 4th order term
00118     */
00119 
00120 protected:                  // allow fast operation if z_size remains constant
00121     std::size_t last_z_size;
00122     void observe_size (std::size_t z_size);
00123 
00124 private:
00125     void unscented (FM::ColMatrix& XX, const FM::Vec& x, const FM::SymMatrix& X, Float scale);
00126     /* Determine Unscented points for a distribution */
00127     std::size_t x_size;
00128     std::size_t XX_size;    // 2*x_size+1
00129 
00130 protected:                  // Permenantly allocated temps
00131     FM::ColMatrix fXX;
00132 };
00133 
00134 
00135 }//namespace
00136 #endif

Generated on Wed Oct 4 22:57:23 2006 for Bayes++ Bayesian Filtering Classes by  doxygen 1.4.6