Standard linear Kalman Filter. More...
#include <shark/Models/KalmanFilter.h>
Inheritance diagram for shark::KalmanFilter:
Collaboration diagram for shark::KalmanFilter:Public Member Functions | |
| KalmanFilter (size_t modelSize) | |
| Constructor. More... | |
| std::string | name () const |
| From INameable: return the class name. More... | |
| RealVector | parameterVector () const |
| Return the parameter vector. More... | |
| void | setParameterVector (RealVector const &newParameters) |
| Set the parameter vector. More... | |
| void | eval (const RealVector &pattern, RealVector &output) |
| RealMatrix & | stateDynamics () |
| returns the state transition matrix 'F' More... | |
| const RealMatrix & | stateDynamics () const |
| RealMatrix & | stateNoise () |
| returns the state noise covariance matrix 'Q' More... | |
| const RealMatrix & | stateNoise () const |
| RealMatrix & | observationModel () |
| sets the observation matrix 'H' More... | |
| const RealMatrix & | observationModel () const |
| RealMatrix & | observationNoise () |
| sets the observation noise covriance matrix 'R' More... | |
| const RealMatrix & | observationNoise () const |
| void | setStateVector (const RealVector &stateVec) |
| sets the initial state vector More... | |
| void | setStateErrorCov (const RealMatrix &stateVec) |
| sets the initial covariance matrix of state estimation error More... | |
| void | predict () |
| next time step / forward propgation (calculation of a-priori estimates) More... | |
| void | updateEstimate (const RealVector &z) |
| update state vector; parameter z: measurent vector More... | |
| RealVector & | statePrediction () |
| returs a-priori (predicted) state estimate (updated in 'propagate()') More... | |
| const RealVector & | statePrediction () const |
| RealMatrix & | predictedCovariance () |
| returns a-priori (predicted) covariance of state estimation error More... | |
| const RealMatrix & | predictedCovariance () const |
| RealMatrix & | observedCovariance () |
| returns a-posteriori covariance of state estimation error (after z(t) has been observed) More... | |
| const RealVector & | predictionError () const |
| returns error in predicted measurements More... | |
Public Member Functions inherited from shark::AbstractModel< RealVector, RealVector > | |
| AbstractModel () | |
| virtual | ~AbstractModel () |
| const Features & | features () const |
| virtual void | updateFeatures () |
| bool | hasFirstParameterDerivative () const |
| Returns true when the first parameter derivative is implemented. More... | |
| bool | hasSecondParameterDerivative () const |
| Returns true when the second parameter derivative is implemented. More... | |
| bool | hasFirstInputDerivative () const |
| Returns true when the first input derivative is implemented. More... | |
| bool | hasSecondInputDerivative () const |
| Returns true when the second parameter derivative is implemented. More... | |
| bool | isSequential () const |
| virtual boost::shared_ptr< State > | createState () const |
| Creates an internal state of the model. More... | |
| virtual void | read (InArchive &archive) |
| From ISerializable, reads a model from an archive. More... | |
| virtual void | write (OutArchive &archive) const |
| writes a model to an archive More... | |
| virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs) const |
| Standard interface for evaluating the response of the model to a batch of patterns. More... | |
| virtual void | eval (BatchInputType const &patterns, BatchOutputType &outputs, State &state) const =0 |
| Standard interface for evaluating the response of the model to a batch of patterns. More... | |
| virtual void | eval (InputType const &pattern, OutputType &output) const |
| Standard interface for evaluating the response of the model to a single pattern. More... | |
| Data< OutputType > | operator() (Data< InputType > const &patterns) const |
| Model evaluation as an operator for a whole dataset. This is a convenience function. More... | |
| OutputType | operator() (InputType const &pattern) const |
| Model evaluation as an operator for a single pattern. This is a convenience function. More... | |
| BatchOutputType | operator() (BatchInputType const &patterns) const |
| Model evaluation as an operator for a single pattern. This is a convenience function. More... | |
| virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, RealVector &derivative) const |
| calculates the weighted sum of derivatives w.r.t the parameters. More... | |
| virtual void | weightedParameterDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, Batch< RealMatrix >::type const &errorHessian, State const &state, RealVector &derivative, RealMatrix &hessian) const |
| calculates the weighted sum of derivatives w.r.t the parameters More... | |
| virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, State const &state, BatchInputType &derivative) const |
| calculates the weighted sum of derivatives w.r.t the inputs More... | |
| virtual void | weightedInputDerivative (BatchInputType const &pattern, BatchOutputType const &coefficients, typename Batch< RealMatrix >::type const &errorHessian, State const &state, RealMatrix &derivative, Batch< RealMatrix >::type &hessian) const |
| calculates the weighted sum of derivatives w.r.t the inputs More... | |
| virtual void | weightedDerivatives (BatchInputType const &patterns, BatchOutputType const &coefficients, State const &state, RealVector ¶meterDerivative, BatchInputType &inputDerivative) const |
| calculates weighted input and parameter derivative at the same time More... | |
Public Member Functions inherited from shark::IParameterizable | |
| virtual | ~IParameterizable () |
| virtual std::size_t | numberOfParameters () const |
| Return the number of parameters. More... | |
Public Member Functions inherited from shark::IConfigurable | |
| virtual | ~IConfigurable () |
| Virtual d'tor. More... | |
| virtual void | configure (const PropertyTree &node) |
| Configures the component given a property tree. More... | |
Public Member Functions inherited from shark::INameable | |
| virtual | ~INameable () |
Public Member Functions inherited from shark::ISerializable | |
| virtual | ~ISerializable () |
| Virtual d'tor. More... | |
| void | load (InArchive &archive, unsigned int version) |
| Versioned loading of components, calls read(...). More... | |
| void | save (OutArchive &archive, unsigned int version) const |
| Versioned storing of components, calls write(...). More... | |
| BOOST_SERIALIZATION_SPLIT_MEMBER () | |
Protected Attributes | |
| RealMatrix | m_stateTransition |
| state transition matrix More... | |
| RealMatrix | m_stateNoiseCov |
| state noise covariance matrix More... | |
| RealMatrix | m_observationModel |
| observation matrix More... | |
| RealMatrix | m_observationNoise |
| observation noise covariance matrix More... | |
| RealVector | m_predictedState |
| a-priori (predicted) state estimate at time t (before z(t) has been observed) More... | |
| RealVector | m_state |
| a-posteriori state at timte t (after observation of z(t)) More... | |
| RealMatrix | m_predictedCovariance |
| a-priori (predicted) covariance of state estimation error More... | |
| RealMatrix | m_observedCovariance |
| a-posteriori covariance of state estimation error (after z(t) has been observed) More... | |
| RealVector | m_predictionError |
| error in predicted measurements More... | |
| size_t | m_inputSize |
Protected Attributes inherited from shark::AbstractModel< RealVector, RealVector > | |
| Features | m_features |
Additional Inherited Members | |
Public Types inherited from shark::AbstractModel< RealVector, RealVector > | |
| enum | Feature |
| typedef RealVector | InputType |
| Defines the input type of the model. More... | |
| typedef RealVector | OutputType |
| Defines the output type of the model. More... | |
| typedef Batch< InputType >::type | BatchInputType |
| defines the batch type of the input type. More... | |
| typedef Batch< OutputType >::type | BatchOutputType |
| defines the batch type of the output type More... | |
| typedef TypedFlags< Feature > | Features |
| typedef TypedFeatureNotAvailableException < Feature > | FeatureNotAvailableException |
Standard linear Kalman Filter.
The implementation aims at providing flexibility w.r.t. process and measurement model; no restrictive assumptions concerning specific properties of the matrices are made (although in practical applications often noise covariances have diagonal form). The implementation is not optimized at all for computational efficiency.
For making the algorithm robust against numerical inaccuraries, the update equation for the state error covariance matrix 'P' given in "Applied Optimal Estimation; The Analytic Sciences Corporation; The M.I.T. Press, pp. 305" is used. For very complex modells a square root form (e.g. Cholesky) based implementation might be more appropriate due to its increased numerical robustness.
Process Modell:
------------—
State Dynamics: \( x_t = F*x_{t-1} + n_x; n_x ~ N(0,Q) \)
Observation : \( z_t = H*x_t + n_z; n_z ~ N(0,R) \)
Before filtering the model matrices F,Q,H,R must be set. Furthermore the initial filter states, i.e. the initial state vector x(0) and the initial covariance matrix of state estimation error P(0) must be set.
As a Model subclass the KalmanFilter holds its current a-posteriori state estimate at time t (after z(t) has been observed) in the Model::parameter vector.
Definition at line 38 of file KalmanFilter.h.
| KalmanFilter::KalmanFilter | ( | size_t | modelSize | ) |
| void KalmanFilter::eval | ( | const RealVector & | pattern, |
| RealVector & | output | ||
| ) |
The model first runs the predict phase. Then it updates its internal estimates using the input. Finally the a-posteriori state estimate, that is, the model parameter vector is returned as output.
Definition at line 46 of file KalmanFilter.cpp.
References m_state, predict(), and updateEstimate().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 45 of file KalmanFilter.h.
|
inline |
sets the observation matrix 'H'
Definition at line 90 of file KalmanFilter.h.
References m_observationModel.
|
inline |
Definition at line 93 of file KalmanFilter.h.
References m_observationModel.
|
inline |
sets the observation noise covriance matrix 'R'
Definition at line 99 of file KalmanFilter.h.
References m_observationNoise.
|
inline |
Definition at line 102 of file KalmanFilter.h.
References m_observationNoise.
|
inline |
returns a-posteriori covariance of state estimation error (after z(t) has been observed)
Definition at line 152 of file KalmanFilter.h.
References m_observedCovariance.
|
inlinevirtual |
Return the parameter vector.
Reimplemented from shark::IParameterizable.
Definition at line 48 of file KalmanFilter.h.
| void KalmanFilter::predict | ( | ) |
next time step / forward propgation (calculation of a-priori estimates)
Definition at line 61 of file KalmanFilter.cpp.
References m_observedCovariance, m_predictedCovariance, m_predictedState, m_state, m_stateNoiseCov, m_stateTransition, shark::blas::prod(), and shark::blas::trans().
Referenced by eval().
|
inline |
returns a-priori (predicted) covariance of state estimation error
Definition at line 144 of file KalmanFilter.h.
References m_predictedCovariance.
|
inline |
Definition at line 147 of file KalmanFilter.h.
References m_predictedCovariance.
|
inline |
returns error in predicted measurements
Definition at line 158 of file KalmanFilter.h.
References m_predictionError.
|
inlinevirtual |
Set the parameter vector.
Reimplemented from shark::IParameterizable.
Definition at line 51 of file KalmanFilter.h.
| void KalmanFilter::setStateErrorCov | ( | const RealMatrix & | stateVec | ) |
sets the initial covariance matrix of state estimation error
Definition at line 56 of file KalmanFilter.cpp.
References m_observedCovariance, and m_predictedCovariance.
| void KalmanFilter::setStateVector | ( | const RealVector & | stateVec | ) |
sets the initial state vector
Definition at line 51 of file KalmanFilter.cpp.
References m_predictedState, and m_state.
|
inline |
returns the state transition matrix 'F'
Definition at line 69 of file KalmanFilter.h.
References m_stateTransition.
|
inline |
Definition at line 72 of file KalmanFilter.h.
References m_stateTransition.
|
inline |
returns the state noise covariance matrix 'Q'
Definition at line 77 of file KalmanFilter.h.
References m_stateNoiseCov.
|
inline |
Definition at line 80 of file KalmanFilter.h.
References m_stateNoiseCov.
|
inline |
returs a-priori (predicted) state estimate (updated in 'propagate()')
Definition at line 136 of file KalmanFilter.h.
References m_predictedState.
|
inline |
Definition at line 139 of file KalmanFilter.h.
References m_predictedState.
| void KalmanFilter::updateEstimate | ( | const RealVector & | z | ) |
update state vector; parameter z: measurent vector
Definition at line 72 of file KalmanFilter.cpp.
References shark::invert(), m_inputSize, m_observationModel, m_observationNoise, m_observedCovariance, m_predictedCovariance, m_predictedState, m_predictionError, m_state, shark::blas::prod(), and shark::blas::trans().
Referenced by eval().
|
protected |
Definition at line 190 of file KalmanFilter.h.
Referenced by KalmanFilter(), and updateEstimate().
|
protected |
observation matrix
Definition at line 171 of file KalmanFilter.h.
Referenced by observationModel(), and updateEstimate().
|
protected |
observation noise covariance matrix
Definition at line 174 of file KalmanFilter.h.
Referenced by observationNoise(), and updateEstimate().
|
protected |
a-posteriori covariance of state estimation error (after z(t) has been observed)
Definition at line 185 of file KalmanFilter.h.
Referenced by observedCovariance(), predict(), setStateErrorCov(), and updateEstimate().
|
protected |
a-priori (predicted) covariance of state estimation error
Definition at line 182 of file KalmanFilter.h.
Referenced by predict(), predictedCovariance(), setStateErrorCov(), and updateEstimate().
|
protected |
a-priori (predicted) state estimate at time t (before z(t) has been observed)
Definition at line 177 of file KalmanFilter.h.
Referenced by predict(), setStateVector(), statePrediction(), and updateEstimate().
|
protected |
error in predicted measurements
Definition at line 188 of file KalmanFilter.h.
Referenced by predictionError(), and updateEstimate().
|
protected |
a-posteriori state at timte t (after observation of z(t))
Definition at line 179 of file KalmanFilter.h.
Referenced by eval(), predict(), setStateVector(), and updateEstimate().
|
protected |
state noise covariance matrix
Definition at line 168 of file KalmanFilter.h.
Referenced by predict(), and stateNoise().
|
protected |
state transition matrix
Definition at line 165 of file KalmanFilter.h.
Referenced by predict(), and stateDynamics().