00001 #ifndef _BAYES_FILTER 00002 #define _BAYES_FILTER 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: bayesFlt.hpp 562 2006-04-05 20:46:23 +0200 (Wed, 05 Apr 2006) mistevens $ 00010 */ 00011 00012 /* 00013 * Bayesian filtering reresented as Dual heirarchy of: 00014 * Prediction and Observation models 00015 * Filtering Schemes 00016 */ 00017 00018 // Common headers required for declerations 00019 #include "bayesException.hpp" // exception types 00020 #include "matSupSub.hpp" // matrix support subsystem 00021 00022 /* Filter namespace */ 00023 namespace Bayesian_filter 00024 { 00025 // Allow use of a short name for matrix namespace 00026 namespace FM = Bayesian_filter_matrix; 00027 00028 00029 /* 00030 * Abstraction support classes, at the base of the heirarchy 00031 */ 00032 00033 class Bayes_base { 00034 /* 00035 * A very abstract Polymorphic base representation! 00036 * Interface provides: type, internal error handing, and destruction 00037 */ 00038 public: 00039 typedef Bayesian_filter_matrix::Float Float; 00040 // Type used thoughout as a number representation for state etc 00041 00042 virtual ~Bayes_base() = 0; 00043 // Polymorphic 00044 00045 static void error (const Numeric_exception& a); 00046 static void error (const Logic_exception& a); 00047 // Report a filter, throw a Filter_exception 00048 // No exception saftey rules are specified, assume the object is invalid 00049 // May have side effects for debuging 00050 }; 00051 00052 00053 class Numerical_rcond 00054 /* 00055 * Numerical comparison of reciprocal condition numbers 00056 * Required for all linear algebra in models and filters 00057 * Implements minimum allowable reciprocal condition number for PD Matrix factorisations 00058 */ 00059 { 00060 public: 00061 Numerical_rcond() 00062 { limit_PD = limit_PD_init; 00063 } 00064 void set_limit_PD(Bayes_base::Float nl) 00065 { limit_PD = nl; 00066 } 00067 inline void check_PSD (Bayes_base::Float rcond, const char* error_description) const 00068 /* Checks a the reciprocal condition number 00069 * Generates a Bayes_filter_exception if value represents a NON PSD matrix 00070 * Inverting condition provides a test for IEC 559 NaN values 00071 */ 00072 { if (!(rcond >= 0)) 00073 Bayes_base::error (Numeric_exception (error_description)); 00074 } 00075 00076 inline void check_PD (Bayes_base::Float rcond, const char* error_description) const 00077 /* Checks a reciprocal condition number 00078 * Generates a Bayes_filter_exception if value represents a NON PD matrix 00079 * I.e. rcond is bellow given conditioning limit 00080 * Inverting condition provides a test for IEC 559 NaN values 00081 */ 00082 { if (!(rcond >= limit_PD)) 00083 Bayes_base::error (Numeric_exception (error_description)); 00084 } 00085 private: 00086 Bayes_base::Float limit_PD; 00087 const static Bayes_base::Float limit_PD_init; // Initial common value for limit_PD 00088 }; 00089 00090 00091 /* 00092 * Abstract Prediction models 00093 * Predict models are used to parameterise predict functions of filters 00094 */ 00095 class Predict_model_base : public Bayes_base 00096 { 00097 // Empty 00098 }; 00099 00100 00101 class Sampled_predict_model : virtual public Predict_model_base 00102 /* Sampled stochastic predict model 00103 x*(k) = fw(x(k-1), w(k)) 00104 fw should generate samples from the stochastic variable w(k) 00105 This fundamental model is used instead of the predict likelihood function L(x*|x) 00106 Since drawing samples from an arbitary L is non-trivial (see MCMC theory) 00107 the burden is place on the model to generate these samples. 00108 Defines an Interface without data members 00109 */ 00110 { 00111 public: 00112 virtual const FM::Vec& fw(const FM::Vec& x) const = 0; 00113 // Note: Reference return value as a speed optimisation, MUST be copied by caller. 00114 }; 00115 00116 class Functional_predict_model :virtual public Predict_model_base 00117 /* Functional (non-stochastic) predict model f 00118 x*(k) = fx(x(k-1)) 00119 This fundamental model is used instead of the predict likelihood function L(x*|x) 00120 Since L is a delta function which isn't much use for numerical systems. 00121 Defines an Interface without data members 00122 */ 00123 { 00124 public: 00125 virtual const FM::Vec& fx(const FM::Vec& x) const = 0; 00126 // Functional model 00127 // Note: Reference return value as a speed optimisation, MUST be copied by caller. 00128 00129 const FM::Vec& operator()(const FM::Vec& x) const 00130 { // Operator form of functional model 00131 return fx(x); 00132 } 00133 }; 00134 00135 class Gaussian_predict_model : virtual public Predict_model_base 00136 /* Gaussian noise predict model 00137 This fundamental noise model for linear/linearised filtering 00138 x(k|k-1) = x(k-1|k-1)) + G(k)w(k) 00139 G(k)w(k) 00140 q(k) = state noise covariance, q(k) is covariance of w(k) 00141 G(k) = state noise coupling 00142 */ 00143 { 00144 public: 00145 Gaussian_predict_model (std::size_t x_size, std::size_t q_size); 00146 00147 FM::Vec q; // Noise variance (always dense, use coupling to represent sparseness) 00148 FM::Matrix G; // Noise Coupling 00149 00150 Numerical_rcond rclimit; 00151 // Reciprocal condition number limit of linear components when factorised or inverted 00152 }; 00153 00154 class Addative_predict_model : virtual public Predict_model_base 00155 /* Addative Gaussian noise predict model 00156 This fundamental model for non-linear filtering with addative noise 00157 x(k|k-1) = f(x(k-1|k-1)) + G(k)w(k) 00158 q(k) = state noise covariance, q(k) is covariance of w(k) 00159 G(k) = state noise coupling 00160 ISSUE Should be privately derived from Gaussian_predict_model but access control in GCC is broken 00161 */ 00162 { 00163 public: 00164 Addative_predict_model (std::size_t x_size, std::size_t q_size); 00165 00166 virtual const FM::Vec& f(const FM::Vec& x) const = 0; 00167 // Functional part of addative model 00168 // Note: Reference return value as a speed optimisation, MUST be copied by caller. 00169 00170 FM::Vec q; // Noise variance (always dense, use coupling to represent sparseness) 00171 FM::Matrix G; // Noise Coupling 00172 00173 Numerical_rcond rclimit; 00174 // Reciprocal condition number limit of linear components when factorised or inverted 00175 }; 00176 00177 class Linrz_predict_model : public Addative_predict_model 00178 /* Linrz predict model 00179 This fundamental model for linear/linearised filtering 00180 x(k|k-1) = f(x(k-1|k-1) 00181 Fx(x(k-1|k-1) = Jacobian of of functional part fx with respect to state x 00182 */ 00183 { 00184 public: 00185 Linrz_predict_model (std::size_t x_size, std::size_t q_size); 00186 FM::Matrix Fx; // Model 00187 }; 00188 00189 class Linear_predict_model : public Linrz_predict_model 00190 /* Linear predict model 00191 Enforces linearity on f 00192 x(k|k-1) = Fx(k-1|k-1) * x(k-1|k-1) 00193 */ 00194 { 00195 public: 00196 Linear_predict_model (std::size_t x_size, std::size_t q_size); 00197 const FM::Vec& f(const FM::Vec& x) const 00198 { // Provide the linear implementation of functional f 00199 xp.assign (FM::prod(Fx,x)); 00200 return xp; 00201 } 00202 private: 00203 mutable FM::Vec xp; 00204 }; 00205 00206 class Linear_invertable_predict_model : public Linear_predict_model 00207 /* Linear invertable predict model 00208 Fx has an inverse 00209 x(k-1|k-1) = inv.Fx(k-1|k-1) * x(k|k-1) 00210 */ 00211 { 00212 public: 00213 Linear_invertable_predict_model (std::size_t x_size, std::size_t q_size); 00214 struct inverse_model { 00215 inverse_model (std::size_t x_size); 00216 FM::ColMatrix Fx; // Model inverse (ColMatrix as usually transposed) 00217 } inv; 00218 }; 00219 00220 00221 00222 /* 00223 * Abstract Observation models 00224 * Observe models are used to parameterise the observe functions of filters 00225 */ 00226 class Observe_model_base : public Bayes_base 00227 { 00228 // Empty 00229 }; 00230 00231 class Observe_function : public Bayes_base 00232 // Function object for predict of observations 00233 { 00234 public: 00235 virtual const FM::Vec& h(const FM::Vec& x) const = 0; 00236 // Note: Reference return value as a speed optimisation, MUST be copied by caller. 00237 }; 00238 00239 00240 class Likelihood_observe_model : virtual public Observe_model_base 00241 /* Likelihood observe model L(z |x) 00242 * The most fundamental Bayesian definition of an observation 00243 * Defines an Interface without data members 00244 */ 00245 { 00246 public: 00247 Likelihood_observe_model(std::size_t z_size) : z(z_size) 00248 {} 00249 virtual Float L(const FM::Vec& x) const = 0; 00250 // Likelihood L(z | x) 00251 00252 virtual void Lz (const FM::Vec& zz) 00253 // Set the observation zz about which to evaluate the Likelihood function 00254 { 00255 z = zz; 00256 } 00257 protected: 00258 FM::Vec z; // z set by Lz 00259 }; 00260 00261 class Functional_observe_model : virtual public Observe_model_base, public Observe_function 00262 /* Functional (non-stochastic) observe model h 00263 * zp(k) = hx(x(k|k-1)) 00264 * This is a seperate fundamental model and not derived from likelihood because: 00265 * L is a delta function which isn't much use for numerical systems 00266 * Defines an Interface without data members 00267 */ 00268 { 00269 public: 00270 Functional_observe_model(std::size_t /*z_size*/) 00271 {} 00272 const FM::Vec& operator()(const FM::Vec& x) const 00273 { return h(x); 00274 } 00275 00276 }; 00277 00278 class Parametised_observe_model : virtual public Observe_model_base, public Observe_function 00279 /* Observation model parametised with a fixed z size 00280 * Includes the functional part of a noise model 00281 * Model is assume to have linear and non-linear components 00282 * Linear components need to be checked for conditioning 00283 * Non-linear components may be discontinous and need normalisation 00284 */ 00285 { 00286 public: 00287 Parametised_observe_model(std::size_t /*z_size*/) 00288 {} 00289 virtual const FM::Vec& h(const FM::Vec& x) const = 0; 00290 // Functional part of addative model 00291 virtual void normalise (FM::Vec& /*z_denorm*/, const FM::Vec& /*z_from*/) const 00292 // Discontinous h. Normalise one observation (z_denorm) from another 00293 {} // Default normalistion, z_denorm unchanged 00294 00295 Numerical_rcond rclimit; 00296 // Reciprocal condition number limit of linear components when factorised or inverted 00297 }; 00298 00299 class Uncorrelated_addative_observe_model : public Parametised_observe_model 00300 /* Observation model, uncorrelated addative observation noise 00301 Z(k) = I * Zv(k) observe noise variance vector Zv 00302 */ 00303 { 00304 public: 00305 Uncorrelated_addative_observe_model (std::size_t z_size) : 00306 Parametised_observe_model(z_size), Zv(z_size) 00307 {} 00308 FM::Vec Zv; // Noise Variance 00309 }; 00310 00311 class Correlated_addative_observe_model : public Parametised_observe_model 00312 /* Observation model, correlated addative observation noise 00313 Z(k) = observe noise covariance 00314 */ 00315 { 00316 public: 00317 Correlated_addative_observe_model (std::size_t z_size) : 00318 Parametised_observe_model(z_size), Z(z_size,z_size) 00319 {} 00320 FM::SymMatrix Z; // Noise Covariance (not necessarly dense) 00321 }; 00322 00323 class Jacobian_observe_model : virtual public Observe_model_base 00324 /* Linrz observation model Hx, h about state x (fixed size) 00325 Hx(x(k|k-1) = Jacobian of h with respect to state x 00326 Normalisation consistency Hx: Assume normalise will be from h(x(k|k-1)) so result is consistent with Hx 00327 */ 00328 { 00329 public: 00330 FM::Matrix Hx; // Model 00331 protected: // Jacobian model is not sufficient, it is used to build Linrz observe model's 00332 Jacobian_observe_model (std::size_t x_size, std::size_t z_size) : 00333 Hx(z_size, x_size) 00334 {} 00335 }; 00336 00337 class Linrz_correlated_observe_model : public Correlated_addative_observe_model, public Jacobian_observe_model 00338 /* Linrz observation model Hx, h with repespect to state x (fixed size) 00339 correlated observation noise 00340 zp(k) = h(x(k-1|k-1) 00341 Hx(x(k|k-1) = Jacobian of f with respect to state x 00342 Z(k) = observe noise covariance 00343 */ 00344 { 00345 public: 00346 Linrz_correlated_observe_model (std::size_t x_size, std::size_t z_size) : 00347 Correlated_addative_observe_model(z_size), Jacobian_observe_model(x_size, z_size) 00348 {} 00349 }; 00350 00351 class Linrz_uncorrelated_observe_model : public Uncorrelated_addative_observe_model, public Jacobian_observe_model 00352 /* Linrz observation model Hx, h with repespect to state x (fixed size) 00353 uncorrelated observation noise 00354 zp(k) = h(x(k-1|k-1) 00355 Hx(x(k|k-1) = Jacobian of f with respect to state x 00356 Zv(k) = observe noise covariance 00357 */ 00358 { 00359 public: 00360 Linrz_uncorrelated_observe_model (std::size_t x_size, std::size_t z_size) : 00361 Uncorrelated_addative_observe_model(z_size), Jacobian_observe_model(x_size, z_size) 00362 {} 00363 }; 00364 00365 class Linear_correlated_observe_model : public Linrz_correlated_observe_model 00366 /* Linear observation model, correlated observation noise 00367 zp(k) = Hx(k) * x(k|k-1) 00368 Enforces linear model invariant. Careful when deriving to to change this invariant! 00369 */ 00370 { 00371 public: 00372 Linear_correlated_observe_model (std::size_t x_size, std::size_t z_size) : 00373 Linrz_correlated_observe_model(x_size, z_size), hx(z_size) 00374 {} 00375 const FM::Vec& h(const FM::Vec& x) const 00376 { // Provide a linear implementation of functional h assumes model is already Linrz for Hx 00377 hx.assign (FM::prod(Hx,x)); 00378 return hx; 00379 } 00380 private: 00381 mutable FM::Vec hx; 00382 }; 00383 00384 class Linear_uncorrelated_observe_model : public Linrz_uncorrelated_observe_model 00385 /* Linear observation model, uncorrelated observation noise 00386 zp(k) = Hx(k) * x(k|k-1) 00387 Enforces linear model invariant. Careful when deriving to to change this invariant! 00388 */ 00389 { 00390 public: 00391 Linear_uncorrelated_observe_model (std::size_t x_size, std::size_t z_size) : 00392 Linrz_uncorrelated_observe_model(x_size, z_size), hx(z_size) 00393 {} 00394 const FM::Vec& h(const FM::Vec& x) const 00395 { // Provide a linear implementation of functional h assumes model is already Linrz for Hx 00396 hx.assign (FM::prod(Hx,x)); 00397 return hx; 00398 } 00399 private: 00400 mutable FM::Vec hx; 00401 }; 00402 00403 00404 /* 00405 * Bayesian Filter 00406 * 00407 * A Bayesian Filter uses Bayes rule to fuse the state probabilities 00408 * of a prior and a likelhood function 00409 */ 00410 class Bayes_filter_base : public Bayes_base 00411 { 00412 // Empty 00413 }; 00414 00415 /* 00416 * Likelihood Filter - Abstract filtering property 00417 * Represents only the Bayesian Likelihood of a state observation 00418 */ 00419 class Likelihood_filter : virtual public Bayes_filter_base 00420 { 00421 public: 00422 /* Virtual functions for filter algorithm */ 00423 00424 virtual void observe (Likelihood_observe_model& h, const FM::Vec& z) = 0; 00425 /* Observation state posterior using likelihood model h at z 00426 */ 00427 }; 00428 00429 /* 00430 * Functional Filter - Abstract filtering property 00431 * Represents only filter predict by a simple functional 00432 * (non-stochastic) model 00433 * 00434 * A similar functional observe is not generally useful. The inverse of h is needed for observe! 00435 */ 00436 class Functional_filter : virtual public Bayes_filter_base 00437 { 00438 public: 00439 /* Virtual functions for filter algorithm */ 00440 00441 virtual void predict (Functional_predict_model& f) = 0; 00442 /* Predict state with functional no noise model 00443 Requires x(k|k), X(k|k) or internal equivilent 00444 Predicts x(k+1|k), X(k+1|k), using predict model 00445 */ 00446 }; 00447 00448 /* 00449 * State Filter - Abstract filtering property 00450 * Represents only filter state and an update on that state 00451 */ 00452 class State_filter : virtual public Bayes_filter_base 00453 { 00454 public: 00455 State_filter (std::size_t x_size); 00456 /* Set constant sizes, state must not be empty (must be >=1) 00457 Exceptions: 00458 bayes_filter_exception is x_size < 1 00459 */ 00460 00461 FM::Vec x; // expected state 00462 00463 /* Virtual functions for filter algorithm */ 00464 00465 virtual void update () = 0; 00466 /* Update filters state 00467 Updates x(k|k) 00468 */ 00469 }; 00470 00471 00472 /* 00473 * Kalman State Filter - Abstract filtering property 00474 * Linear filter representation for 1st (mean) and 2nd (covariance) moments of a distribution 00475 * 00476 * Probability distributions are represted by state vector (x) and a covariance matix.(X) 00477 * 00478 * State (x) sizes is assumed to remain constant. 00479 * The state and state covariance are public so they can be directly manipulated. 00480 * init: Should be called if x or X are altered 00481 * update: Guarantees that any internal changes made filter are reflected in x,X. 00482 * This allows considerable flexibility so filter implemtations can use different numerical representations 00483 * 00484 * Derived filters supply definititions for the abstract functions and determine the algorithm used 00485 * to implement the filter. 00486 */ 00487 00488 class Kalman_state_filter : public State_filter 00489 { 00490 public: 00491 FM::SymMatrix X; // state covariance 00492 00493 Kalman_state_filter (std::size_t x_size); 00494 /* Initialise filter and set constant sizes 00495 */ 00496 00497 /* Virtual functions for filter algorithm */ 00498 00499 virtual void init () = 0; 00500 /* Initialise from current state and state covariance 00501 Requires x(k|k), X(k|k) 00502 */ 00503 void init_kalman (const FM::Vec& x, const FM::SymMatrix& X); 00504 /* Initialise from a state and state covariance 00505 Parameters that reference the instance's x and X members are valid 00506 */ 00507 virtual void update () = 0; 00508 /* Update filters state and state covariance 00509 Updates x(k|k), X(k|k) 00510 */ 00511 00512 // Minimum allowable reciprocal condition number for PD Matrix factorisations 00513 Numerical_rcond rclimit; 00514 }; 00515 00516 00517 /* 00518 * Information State Filter - Abstract filtering property 00519 * Linear filter information space representation for 1st (mean) and 2nd (covariance) moments of a distribution 00520 * Y = inv(X) Information 00521 * y = Y*x Information state 00522 */ 00523 00524 class Information_state_filter : virtual public Bayes_filter_base 00525 { 00526 public: 00527 Information_state_filter (std::size_t x_size); 00528 FM::Vec y; // Information state 00529 FM::SymMatrix Y; // Information 00530 00531 virtual void init_yY () = 0; 00532 /* Initialise from a information state and information 00533 Requires y(k|k), Y(k|k) 00534 Parameters that reference the instance's y and Y members are valid 00535 */ 00536 void init_information (const FM::Vec& y, const FM::SymMatrix& Y); 00537 /* Initialise from a information state and information 00538 Parameters that reference the instance's y and Y members are valid 00539 */ 00540 00541 virtual void update_yY () = 0; 00542 /* Update filters information state and information 00543 Updates y(k|k), Y(k|k) 00544 */ 00545 }; 00546 00547 00548 /* 00549 * Linearizable filter models - Abstract filtering property 00550 * Linrz == A linear, or gradient Linearized filter 00551 * 00552 * Predict uses a Linrz_predict_model that maintains a Jacobian matrix Fx and addative noise 00553 * NOTE: Functional (non-stochastic) predict is NOT possible as predict requires Fx. 00554 * 00555 * Observe uses a Linrz_observe_model and a variable size observation (z) 00556 * There are two variants for correlated and uncorrelated observation noise 00557 * Derived filters supply the init,predict,observe,update functions and determine 00558 * the algorithm used to implement the filter. 00559 */ 00560 00561 class Linrz_filter : virtual public Bayes_filter_base 00562 { 00563 public: 00564 /* Virtual functions for filter algorithm */ 00565 00566 virtual Float predict (Linrz_predict_model& f) = 0; 00567 /* Predict state using a Linrz model 00568 Requires x(k|k), X(k|k) or internal equivilent 00569 Returns: Reciprocal condition number of primary matrix used in predict computation (1. if none) 00570 */ 00571 00572 virtual Float observe (Linrz_uncorrelated_observe_model& h, const FM::Vec& z) = 0; 00573 virtual Float observe (Linrz_correlated_observe_model& h, const FM::Vec& z) = 0; 00574 /* Observation z(k) and with (Un)correlated observation noise model 00575 Requires x(k|k), X(k|k) or internal equivilent 00576 Returns: Reciprocal condition number of primary matrix used in observe computation (1. if none) 00577 */ 00578 }; 00579 00580 00581 /* 00582 * Linearizable Kalman Filter 00583 * Kalman state representation and linearizable models 00584 * 00585 * Common abstration for many linear filters 00586 * Has a virtual base to represent the common state 00587 */ 00588 class Linrz_kalman_filter : public Linrz_filter, virtual public Kalman_state_filter 00589 { 00590 protected: 00591 Linrz_kalman_filter() : Kalman_state_filter(0) // define a default constructor 00592 {} 00593 }; 00594 00595 00596 /* 00597 * Extended Kalman Filter 00598 * Kalman state representation and linearizable models 00599 * 00600 * Observe is implemented using an innovation computed from the non-linear part of the 00601 * obseve model and linear part of the Linrz_observe_model 00602 * 00603 * Common abstration for many linear filters 00604 * Has a virtual base to represent the common state 00605 */ 00606 class Extended_kalman_filter : public Linrz_kalman_filter 00607 { 00608 protected: 00609 Extended_kalman_filter() : Kalman_state_filter(0) // define a default constructor 00610 {} 00611 public: 00612 virtual Float observe (Linrz_uncorrelated_observe_model& h, const FM::Vec& z); 00613 virtual Float observe (Linrz_correlated_observe_model& h, const FM::Vec& z); 00614 /* Observation z(k) and with (Un)correlated observation noise model 00615 Requires x(k|k), X(k|k) or internal equivilent 00616 Returns: Reciprocal condition number of primary matrix used in observe computation (1. if none) 00617 Default implementation simple computes innovation for observe_innovation 00618 */ 00619 00620 virtual Float observe_innovation (Linrz_uncorrelated_observe_model& h, const FM::Vec& s) = 0; 00621 virtual Float observe_innovation (Linrz_correlated_observe_model& h, const FM::Vec& s) = 0; 00622 /* Observation innovation s(k) and with (Un)correlated observation noise model 00623 Requires x(k|k), X(k|k) or internal equivilent 00624 Returns: Reciprocal condition number of primary matrix used in observe computation (1. if none) 00625 */ 00626 }; 00627 00628 00629 /* 00630 * Sample State Filter - Abstract filtering property 00631 * 00632 * Probability distributions are represted by a finite sampling 00633 * 00634 * State (x_size) size and its sampling (s_size) are assumed to remain constant. 00635 * The state sampling public so they can be directly manipulated. 00636 * init: Should be used if they to be altered 00637 * update: Guarantees that any internal changes made filter are reflected in sampling S. 00638 */ 00639 00640 class Sample_state_filter : virtual public Bayes_filter_base 00641 { 00642 public: 00643 FM::ColMatrix S; // state sampleing (x_size,s_size) 00644 00645 Sample_state_filter (std::size_t x_size, std::size_t s_size); 00646 /* Initialise filter and set constant sizes for 00647 x_size of the state vector 00648 s_size sample size 00649 Exceptions: 00650 bayes_filter_exception is s_size < 1 00651 */ 00652 ~Sample_state_filter() = 0; // ISSUE Provide unambigues distructor incase S is not distructable 00653 00654 /* Virtual functions for filter algorithm */ 00655 00656 virtual void init_S () = 0; 00657 /* Initialise from current sampleing 00658 */ 00659 00660 void init_sample (const FM::ColMatrix& initS); 00661 /* Initialise from a sampling 00662 */ 00663 00664 virtual Float update_resample () = 0; 00665 /* Resampling update 00666 Returns lcond, Smallest normalised likelihood weight, represents conditioning of resampling solution 00667 lcond == 1. if no resampling performed 00668 This should by multipled by the number of samples to get the Likelihood function conditioning 00669 */ 00670 00671 std::size_t unique_samples () const; 00672 /* Count number of unique (unequal value) samples in S 00673 Implementation requires std::sort on sample column references 00674 */ 00675 }; 00676 00677 00678 /* 00679 * Sample Filter: Bayes filter using 00680 * 00681 * Probability distributions are represted by a finite sampling 00682 * 00683 * The filter is operated by performing a 00684 * predict, observe 00685 * cycle derived from the bayes_filter. observe Likelihoods are merged into a single combined weight. 00686 * update: MUST be used to complete a explict resampling of the particles using merged weights 00687 * 00688 * Derived filters supply definititions for the abstract functions and determine the algorithm used 00689 * to implement the filter. 00690 */ 00691 00692 class Sample_filter : public Likelihood_filter, public Functional_filter, virtual public Sample_state_filter 00693 { 00694 public: 00695 Sample_filter (std::size_t x_size, std::size_t s_size); 00696 /* Initialise filter and set constant sizes for 00697 x_size of the state vector 00698 s_size sample size 00699 Exceptions: 00700 bayes_filter_exception is s_size < 1 00701 */ 00702 00703 /* Virtual functions for filter algorithm */ 00704 00705 virtual void predict (Functional_predict_model& f); 00706 /* Predict state posterior with functional no noise model 00707 */ 00708 00709 virtual void predict (Sampled_predict_model& f) = 0; 00710 /* Predict state posterior with sampled noise model 00711 */ 00712 00713 virtual void observe (Likelihood_observe_model& h, const FM::Vec& z) = 0; 00714 /* Observation state posterior using likelihood model h at z 00715 */ 00716 00717 virtual void observe_likelihood (const FM::Vec& lw) = 0; 00718 /* Observation fusion directly from likelihood weights 00719 lw may be smaller then the state sampling. Weights for additional particles are assumed to be 1 00720 */ 00721 }; 00722 00723 00724 }//namespace 00725 #endif
1.4.6