indirect.hpp

Go to the documentation of this file.
00001 #ifndef _BAYES_FILTER_INDIRECT
00002 #define _BAYES_FILTER_INDIRECT
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: indirect.hpp 562 2006-04-05 20:46:23 +0200 (Wed, 05 Apr 2006) mistevens $
00010  */
00011  
00012 /*
00013  * Indirect Filter Adaptor
00014  *  Hides the details of the indirect operation of the filter
00015  *  The error filter uses the same linear models as the direct filter,
00016  *  observation error computation (subtraction) is linear!
00017  */
00018 
00019 /* Filter namespace */
00020 namespace Bayesian_filter
00021 {
00022 
00023 
00024 template <typename Error_base>
00025 class Indirect_state_filter : public State_filter {
00026 /*
00027  * Indirect state filter
00028  *  Estimates state using an associated observation error filter
00029  */
00030 public:
00031     Indirect_state_filter (Error_base& error_filter)
00032         : State_filter(error_filter.x.size()), direct(error_filter)
00033     {   // Construct and zero initial error filter
00034         direct.x.clear();
00035     }
00036 
00037     template <typename P_model>
00038     void predict (P_model& f)
00039     {
00040         x = f.f(x);
00041         direct.predict(f);              // May be optimised for linear f as x = 0
00042     };
00043 
00044     template <typename O_model>
00045     void observe (O_model& h, const FM::Vec& z)
00046     {
00047                 // Observe error (explict temporary)
00048         FM::Vec z_error(z.size());
00049         z_error = h.h(x);
00050         z_error -= z;
00051         direct.observe (h, z_error);
00052                 // Update State estimate with error
00053         x -= direct.x;
00054                 // Reset the error
00055         direct.x.clear();
00056     }
00057 
00058     template <typename O_model>
00059     void observe_error (O_model& h, const FM::Vec& z_error)
00060     {
00061         direct.observe (h, z_error);
00062                 // Update State estimate with error
00063         x -= direct.x;
00064                 // Reset the error
00065         direct.x.clear();
00066     }
00067 
00068     void update ()
00069     /* Update filters state
00070          Updates x(k|k)
00071     */
00072     {}
00073 
00074 private:
00075     Error_base& direct;
00076 };
00077 
00078 
00079 template <typename Error_base>
00080 class Indirect_kalman_filter : public Kalman_state_filter {
00081 /*
00082  * Indirect kalman filter
00083  *  Estimates state using an associated observation error filter
00084  */
00085 public:
00086     Indirect_kalman_filter (Error_base& error_filter)
00087         : Kalman_state_filter(error_filter.x.size()), direct(error_filter)
00088     {   
00089     }
00090 
00091     void init ()
00092     /* Initialise from state and state covariance
00093     */
00094     {
00095         direct.x.clear();               // Zero initial error
00096         direct.X = X;
00097         direct.init();
00098     }
00099 
00100     template <typename P_model>
00101     void predict (P_model& f)
00102     {
00103         x = f.f(x);
00104         direct.predict(f);              // May be optimised for linear f as x = 0
00105     };
00106 
00107     template <typename O_model>
00108     void observe (O_model& h, const FM::Vec& z)
00109     {
00110                 // Observe error (explict temporary)
00111         FM::Vec z_error(z.size());
00112         z_error = h.h(x);
00113         z_error -= z;
00114         direct.observe (h, z_error);
00115         direct.update();
00116                 // Update State estimate with error
00117         x -= direct.x;
00118                 // Reset the error
00119         direct.x.clear();
00120         direct.init ();
00121     }
00122 
00123     template <typename O_model>
00124     void observe_error (O_model& h, const FM::Vec& z_error)
00125     {
00126         direct.observe (h, z_error);
00127                 // Update State estimate with error
00128         x -= direct.x;
00129                 // Reset the error
00130         direct.clear();
00131     }
00132 
00133     void update ()
00134     /* Update filters state
00135          Updates x(k|k)
00136     */
00137     {
00138         direct.update();
00139         X = direct.X;
00140     }
00141 
00142 private:
00143     Error_base& direct;
00144 };
00145 
00146 
00147 }//namespace
00148 #endif

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