indii/ml/filter/KalmanFilter.hpp

00001 #ifndef INDII_ML_ESTIMATOR_KALMANFILTER_HPP
00002 #define INDII_ML_ESTIMATOR_KALMANFILTER_HPP
00003 
00004 #include "../aux/vector.hpp"
00005 #include "../aux/GaussianPdf.hpp"
00006 
00007 #include "Filter.hpp"
00008 #include "KalmanFilterModel.hpp"
00009 
00010 namespace indii {
00011   namespace ml {
00012     namespace filter {
00013 
00014 /**
00015  * Kalman %filter.
00016  *
00017  * @author Lawrence Murray <lawrence@indii.org>
00018  * @version $Rev: 544 $
00019  * @date $Date: 2008-09-01 15:04:39 +0100 (Mon, 01 Sep 2008) $
00020  *
00021  * @param T The type of time.
00022  * 
00023  * KalmanFilter is suitable for models with linear transition and
00024  * measurement functions, approximating state and noise with
00025  * indii::ml::aux::GaussianPdf distributions.
00026  *
00027  * @see indii::ml::filter for general usage guidelines.
00028  * @see LinearModel for more detail on linear filters.
00029  */
00030 template <class T = unsigned int>
00031 class KalmanFilter : public Filter<T> {
00032 public:
00033   /**
00034    * Create new Kalman %filter.
00035    *
00036    * @param model Model to estimate.
00037    * @param p_x0 \f$p(\mathbf{x}_0)\f$; prior over the
00038    * initial state \f$\mathbf{x}_0\f$.
00039    */
00040   KalmanFilter(KalmanFilterModel<T>* model,
00041       const indii::ml::aux::GaussianPdf& p_x0);
00042 
00043   /**
00044    * Destructor.
00045    */
00046   virtual ~KalmanFilter();
00047 
00048   virtual void filter(const T tnp1, const indii::ml::aux::vector& ytnp1);
00049 
00050   virtual indii::ml::aux::GaussianPdf measure();
00051 
00052 private:
00053   /**
00054    * Model to estimate.
00055    */
00056   KalmanFilterModel<T>* model;
00057 
00058 };
00059 
00060     }
00061   }
00062 }
00063 
00064 namespace aux = indii::ml::aux;
00065 
00066 using namespace indii::ml::filter;
00067 
00068 template <class T>
00069 KalmanFilter<T>::KalmanFilter(KalmanFilterModel<T>* model,
00070     const aux::GaussianPdf& p_x0) : Filter<T>(p_x0),
00071     model(model) {
00072   //
00073 }
00074 
00075 template <class T>
00076 KalmanFilter<T>::~KalmanFilter() {
00077   //
00078 }
00079 
00080 template <class T>
00081 void KalmanFilter<T>::filter(T tnp1, const aux::vector& ytnp1) {
00082   /* pre-condition */
00083   assert (tnp1 > Filter<T>::tn);
00084 
00085   /* update time */
00086   T delta = tnp1 - Filter<T>::tn;
00087   Filter<T>::tn = tnp1;
00088 
00089   /* system update */
00090   aux::GaussianPdf p_xtnp1_ytn(model->p_xtnp1_ytn(Filter<T>::p_xtn_ytn,delta));
00091 
00092   /* measurement update */
00093   Filter<T>::p_xtn_ytn = model->p_xtnp1_ytnp1(p_xtnp1_ytn, ytnp1, delta);
00094 
00095   /* post-condition */
00096   assert (Filter<T>::tn == tnp1);
00097 }
00098 
00099 template <class T>
00100 aux::GaussianPdf KalmanFilter<T>::measure() {
00101   return model->p_y_x(Filter<T>::p_xtn_ytn);
00102 }
00103 
00104 #endif

Generated on Wed Dec 17 15:11:57 2008 for dysii Dynamical Systems Library by  doxygen 1.5.3