Bayes++ Library入门学习之熟悉class-Bayesian_filter_base(2)
前面我们已经熟悉了Bayesian_filter::Bayes_filter_base和其子类的击继承关系,接下来我们开始学习该类的实现。
bayesFlt.hpp文件为其实现主体,首先是两个常规的头文件,一个是异常处理类型相关的,另一个是支持矩阵的头文件。
#include "bayesException.hpp" // exception types #include "matSupSub.hpp" // matrix support subsystem
接着,所有的声明和定义全部都在namespace Bayseian_filter内部。在Bayes++库中,一般将Bayesian_filter_matrix以别名的形式使用
namespace FM = Bayesian_filter_matrix;
接着定义了一个抽象预测模型,该预测模型用来参数化滤波器中的预测函数
class Predict_model_base : public Bayes_base { // Empty };
高斯预测模型,x(k|k-1) = x(k-1|k-1)) + G(k)w(k),其中q(k)是状态噪声协方差,即w(k)的协方差,G(k)表示状态噪声耦合
class Gaussian_predict_model : virtual public Predict_model_base { public: Gaussian_predict_model (std::size_t x_size, std::size_t q_size); FM::Vec q; // Noise variance (always dense, use coupling to represent sparseness) FM::Matrix G; // Noise Coupling Numerical_rcond rclimit; // Reciprocal condition number limit of linear components when factorised or inverted };
线性化预测模型,x(k|k-1) = f(x(k-1|k-1),Fx(x(k-1|k-1)表示函数fx相对于状态x的雅各比矩阵
class Linrz_predict_model : public Additive_predict_model { public: Linrz_predict_model (std::size_t x_size, std::size_t q_size); FM::Matrix Fx; // Model };
抽象量测模型,量测模型被用来参数化滤波器的量测函数
class Observe_model_base : public Bayes_base { // Empty };
Kalman状态滤波器,线性滤波器被表示成均值和协方差两个元素;概率性分布用状态向量x和协方差矩阵X表示。一般状态x的size假设为常量,
class Kalman_state_filter : public State_filter { public: FM::SymMatrix X; // state covariance Kalman_state_filter (std::size_t x_size); /* Initialise filter and set constant sizes */ /* Virtual functions for filter algorithm */ virtual void init () = 0; /* Initialise from current state and state covariance Requires x(k|k), X(k|k) */ void init_kalman (const FM::Vec& x, const FM::SymMatrix& X); /* Initialise from a state and state covariance Parameters that reference the instance's x and X members are valid */ virtual void update () = 0; /* Update filters state and state covariance Updates x(k|k), X(k|k) */ // Minimum allowable reciprocal condition number for PD Matrix factorisations Numerical_rcond rclimit; };
线性化滤波器模型,其中滤波器预测步骤使用了Linrz_predict_model来获取一个雅各比矩阵Fx和添加的噪声
class Linrz_filter : virtual public Bayes_filter_base { public: /* Virtual functions for filter algorithm */ virtual Float predict (Linrz_predict_model& f) = 0; /* Predict state using a Linrz model Requires x(k|k), X(k|k) or internal equivilent Returns: Reciprocal condition number of primary matrix used in predict computation (1. if none) */ virtual Float observe (Linrz_uncorrelated_observe_model& h, const FM::Vec& z) = 0; virtual Float observe (Linrz_correlated_observe_model& h, const FM::Vec& z) = 0; /* Observation z(k) and with (Un)correlated observation noise model Requires x(k|k), X(k|k) or internal equivalent Returns: Reciprocal condition number of primary matrix used in observe computation (1. if none) */ };
EKF的量测的实现使用了量测模型的非线性部分和线性化量测模型的线性部分得到
class Extended_kalman_filter : public Linrz_kalman_filter { protected: Extended_kalman_filter() : Kalman_state_filter(0) // define a default constructor {} public: virtual Float observe (Linrz_uncorrelated_observe_model& h, const FM::Vec& z); virtual Float observe (Linrz_correlated_observe_model& h, const FM::Vec& z); /* Observation z(k) and with (Un)correlated observation noise model Requires x(k|k), X(k|k) or internal equivalent Returns: Reciprocal condition number of primary matrix used in observe computation (1. if none) Default implementation simple computes innovation for observe_innovation */ virtual Float observe_innovation (Linrz_uncorrelated_observe_model& h, const FM::Vec& s) = 0; virtual Float observe_innovation (Linrz_correlated_observe_model& h, const FM::Vec& s) = 0; /* Observation innovation s(k) and with (Un)correlated observation noise model Requires x(k|k), X(k|k) or internal equivalent Returns: Reciprocal condition number of primary matrix used in observe computation (1. if none) */ };
至此,我们将常用的几个模型基类进行了简单的说明。