models.hpp

Go to the documentation of this file.
00001 #ifndef _BAYES_FILTER__MODELS
00002 #define _BAYES_FILTER__MODELS
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: models.hpp 562 2006-04-05 20:46:23 +0200 (Wed, 05 Apr 2006) mistevens $
00010  */
00011 
00012 /*
00013  * Predict and Observe models
00014  *  These models extend, adapt and simpilify the fundamental Bayesian filter models
00015  *  Simple : Simplify model construction and use
00016  *  General: Generalise a model so it include properties of more then one model
00017  *  Adapted: Adapt one model type into another
00018  */
00019 #include <boost/function.hpp>
00020 
00021 /* Filter namespace */
00022 namespace Bayesian_filter
00023 {
00024 
00025 typedef boost::function1<const FM::Vec&, const FM::Vec&> State_function;
00026 // A generalised function of state. Compatible with predict and observe models
00027 
00028 
00029 class Simple_addative_predict_model : public Addative_predict_model
00030 // Addative predict model initialised from function and model matricies
00031 {
00032     State_function ff;
00033 public:
00034     Simple_addative_predict_model (State_function f_init, const FM::Matrix& G_init, const FM::Vec& q_init);
00035     // Precondition: G, q are conformantly dimensioned (not checked)
00036 
00037     // No default assignment operator
00038 
00039     virtual const FM::Vec& f(const FM::Vec& x) const
00040     {   return ff(x);
00041     }
00042 };
00043 
00044 class Simple_linrz_predict_model : public Linrz_predict_model
00045 // Linrz predict model initialised from function and model matricies
00046 {
00047     State_function ff;
00048 public:
00049     Simple_linrz_predict_model (State_function f_init, const FM::Matrix& Fx_init, const FM::Matrix& G_init, const FM::Vec& q_init);
00050     // Precondition: Fx, G, q are conformantly dimensioned (not checked)
00051 
00052     // No default assignment operator
00053 
00054     virtual const FM::Vec& f(const FM::Vec& x) const
00055     {   return ff(x);
00056     }
00057 };
00058 
00059 class Simple_linear_predict_model : public Linear_predict_model
00060 // Linear predict model initialised from model matricies
00061 {
00062 public:
00063     Simple_linear_predict_model (const FM::Matrix& Fx_init, const FM::Matrix& G_init, const FM::Vec& q_init);
00064     // Precondition: Fx, q and G are conformantly dimensioned (not checked)
00065 };
00066 
00067 
00068 class Simple_linrz_correlated_observe_model : public Linrz_correlated_observe_model
00069 // Linrz observe model initialised from function and model matricies
00070 {
00071     State_function ff;
00072 public:
00073     Simple_linrz_correlated_observe_model (State_function f_init, const FM::Matrix& Hx_init, const FM::SymMatrix& Z_init);
00074     // Precondition: Hx, Z are conformantly dimensioned (not checked)
00075     // No default assignment operator
00076 
00077     virtual const FM::Vec& h(const FM::Vec& x) const
00078     {   return ff(x);
00079     }
00080 };
00081 
00082 class Simple_linrz_uncorrelated_observe_model : public Linrz_uncorrelated_observe_model
00083 // Linrz observe model initialised from function and model matricies
00084 {
00085     State_function ff;
00086 public:
00087     Simple_linrz_uncorrelated_observe_model (State_function f_init, const FM::Matrix& Hx_init, const FM::Vec& Zv_init);
00088     // Precondition: Hx, Zv are conformantly dimensioned (not checked)
00089     // No default assignment operator
00090 
00091     virtual const FM::Vec& h(const FM::Vec& x) const
00092     {   return ff(x);
00093     }
00094 };
00095 
00096 class Simple_linear_correlated_observe_model : public Linear_correlated_observe_model
00097 // Linear observe model initialised from model matricies
00098 {
00099 public:
00100     Simple_linear_correlated_observe_model (const FM::Matrix& Hx_init, const FM::SymMatrix& Z_init);
00101     // Precondition: Hx, Z are conformantly dimensioned (not checked)
00102 };
00103 
00104 class Simple_linear_uncorrelated_observe_model : public Linear_uncorrelated_observe_model
00105 // Linear observe model initialised from model matricies
00106 {
00107 public:
00108     Simple_linear_uncorrelated_observe_model (const FM::Matrix& Hx_init, const FM::Vec& Zv_init);
00109     // Precondition: Hx, Zv are conformantly dimensioned (not checked)
00110 };
00111 
00112 
00113 
00114 /*
00115  * Model Adaptors: Constructed with a reference to another model
00116  */
00117 
00118 
00119 class Adapted_Correlated_addative_observe_model : public Correlated_addative_observe_model
00120 /*
00121  * Adapt Uncorrelated_addative_observe_model to an equivilent
00122  * Correlated_addative_observe_model_adaptor
00123  */
00124 {
00125 public:
00126     Adapted_Correlated_addative_observe_model (Uncorrelated_addative_observe_model& adapt);
00127     const FM::Vec& h(const FM::Vec& x) const
00128     {
00129         return unc.h(x);
00130     }
00131     inline void normalise (FM::Vec& z_denorm, const FM::Vec& z_from) const
00132     {
00133         unc.normalise (z_denorm, z_from);
00134     };
00135 private:
00136     Uncorrelated_addative_observe_model& unc;
00137 };
00138 
00139 class Adapted_Linrz_correlated_observe_model : public Linrz_correlated_observe_model
00140 /*
00141  * Adapt Linrz_uncorrelated_observe_model to an equivilent
00142  * Linrz_correlated_observe_model
00143  */
00144 {
00145 public:
00146     Adapted_Linrz_correlated_observe_model (Linrz_uncorrelated_observe_model& adapt);
00147     const FM::Vec& h(const FM::Vec& x) const
00148     {
00149         return unc.h(x);
00150     }
00151     inline void normalise (FM::Vec& z_denorm, const FM::Vec& z_from) const
00152     {
00153         unc.normalise (z_denorm, z_from);
00154     };
00155 protected:
00156     Linrz_uncorrelated_observe_model& unc;
00157 };
00158 
00159 
00160 /*
00161  * Generalised Models: generalise a model so it include properties of more then one model.
00162  */
00163 
00164 // General Linearised Uncorrelated Addative and Likelihood observe model
00165 class General_LzUnAd_observe_model : public Linrz_uncorrelated_observe_model, public Likelihood_observe_model
00166 {
00167 public:
00168     General_LzUnAd_observe_model (std::size_t x_size, std::size_t z_size) :
00169         Linrz_uncorrelated_observe_model(x_size, z_size),
00170         Likelihood_observe_model(z_size),
00171         li(z_size)
00172     {}
00173     virtual Float L(const FM::Vec& x) const
00174     // Definition of likelihood for addative noise model given zz
00175     {   return li.L(*this, z, h(x));
00176     }
00177     virtual void Lz (const FM::Vec& zz)
00178     // Fix the observation zz about which to evaluate the Likelihood function
00179     // Zv is also fixed
00180     {   Likelihood_observe_model::z = zz;
00181         li.Lz(*this);
00182     }
00183 private:
00184     friend class General_LiUnAd_observe_model;
00185     struct Likelihood_uncorrelated
00186     {
00187         Likelihood_uncorrelated(std::size_t z_size) :
00188             zInnov(z_size), Zv_inv(z_size)
00189         {   zset = false;
00190         }
00191         mutable FM::Vec zInnov; // Normailised innovation, temporary for L(x)
00192         FM::Vec Zv_inv;         // Inverse Noise Covariance given zz
00193         Float logdetZ;          // log(det(Z))
00194         bool zset;
00195         Float L(const Uncorrelated_addative_observe_model& model, const FM::Vec& z, const FM::Vec& zp) const;
00196         // Definition of likelihood for addative noise model given zz
00197         void Lz(const Uncorrelated_addative_observe_model& model);
00198     };
00199     Likelihood_uncorrelated li;
00200 };
00201 
00202 // General Linear Uncorrelated Addative and Likelihood observe model
00203 class General_LiUnAd_observe_model : public Linear_uncorrelated_observe_model, public Likelihood_observe_model
00204 {
00205 public:
00206     General_LiUnAd_observe_model (std::size_t x_size, std::size_t z_size) :
00207         Linear_uncorrelated_observe_model(x_size, z_size),
00208         Likelihood_observe_model(z_size),
00209         li(z_size)
00210     {}
00211     virtual Float L(const FM::Vec& x) const
00212     // Definition of likelihood for addative noise model given zz
00213     {   return li.L(*this, z, h(x));
00214     }
00215     virtual void Lz (const FM::Vec& zz)
00216     // Fix the observation zz about which to evaluate the Likelihood function
00217     // Zv is also fixed
00218     {   Likelihood_observe_model::z = zz;
00219         li.Lz(*this);
00220     }
00221 
00222 private:
00223     General_LzUnAd_observe_model::Likelihood_uncorrelated li;
00224 };
00225 
00226 // General Linearised Correlated Addative and Likelihood observe model
00227 class General_LzCoAd_observe_model : public Linrz_correlated_observe_model, public Likelihood_observe_model
00228 {
00229 public:
00230     General_LzCoAd_observe_model (std::size_t x_size, std::size_t z_size) :
00231         Linrz_correlated_observe_model(x_size, z_size),
00232         Likelihood_observe_model(z_size),
00233         li(z_size)
00234     {}
00235     virtual Float L(const FM::Vec& x) const
00236     // Definition of likelihood for addative noise model given zz
00237     {   return li.L(*this, z, h(x));
00238     }
00239     virtual void Lz (const FM::Vec& zz)
00240     // Fix the observation zz about which to evaluate the Likelihood function
00241     // Zv is also fixed
00242     {   Likelihood_observe_model::z = zz;
00243         li.Lz(*this);
00244     }
00245 
00246 private:
00247     friend class General_LiCoAd_observe_model;
00248     struct Likelihood_correlated
00249     {
00250         Likelihood_correlated(std::size_t z_size) :
00251             zInnov(z_size), Z_inv(z_size,z_size)
00252         {   zset = false;
00253         }
00254         mutable FM::Vec zInnov; // Normailised innovation, temporary for L(x)
00255         FM::SymMatrix Z_inv;    // Inverse Noise Covariance
00256         Float logdetZ;          // log(det(Z)
00257         bool zset;  
00258         static Float scaled_vector_square(const FM::Vec& v, const FM::SymMatrix& V);
00259         Float L(const Correlated_addative_observe_model& model, const FM::Vec& z, const FM::Vec& zp) const;
00260         // Definition of likelihood for addative noise model given zz
00261         void Lz(const Correlated_addative_observe_model& model);
00262     };
00263     Likelihood_correlated li;
00264 };
00265 
00266 // General Linear Correlated Addative and Likelihood observe model
00267 class General_LiCoAd_observe_model : public Linear_correlated_observe_model, public Likelihood_observe_model
00268 {
00269 public:
00270     General_LiCoAd_observe_model (std::size_t x_size, std::size_t z_size) :
00271         Linear_correlated_observe_model(x_size, z_size),
00272         Likelihood_observe_model(z_size),
00273         li(z_size)
00274     {}
00275     virtual Float L(const FM::Vec& x) const
00276     // Definition of likelihood for addative noise model given zz
00277     {   return li.L(*this, z, h(x));
00278     }
00279     virtual void Lz (const FM::Vec& zz)
00280     // Fix the observation zz about which to evaluate the Likelihood function
00281     // Zv is also fixed
00282     {   Likelihood_observe_model::z = zz;
00283         li.Lz(*this);
00284     }
00285 
00286 private:
00287     General_LzCoAd_observe_model::Likelihood_correlated li;
00288 };
00289 
00290 
00291 }// namespace
00292 
00293 #endif

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