shark::KalmanFilter Class Reference

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 Featuresfeatures () 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< StatecreateState () 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< OutputTypeoperator() (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 &parameterDerivative, 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< FeatureFeatures
 
typedef
TypedFeatureNotAvailableException
< Feature
FeatureNotAvailableException
 

Detailed Description

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.

Constructor & Destructor Documentation

KalmanFilter::KalmanFilter ( size_t  modelSize)

Constructor.

Definition at line 42 of file KalmanFilter.cpp.

References m_inputSize.

Member Function Documentation

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().

std::string shark::KalmanFilter::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 45 of file KalmanFilter.h.

RealMatrix& shark::KalmanFilter::observationModel ( )
inline

sets the observation matrix 'H'

Definition at line 90 of file KalmanFilter.h.

References m_observationModel.

const RealMatrix& shark::KalmanFilter::observationModel ( ) const
inline

Definition at line 93 of file KalmanFilter.h.

References m_observationModel.

RealMatrix& shark::KalmanFilter::observationNoise ( )
inline

sets the observation noise covriance matrix 'R'

Definition at line 99 of file KalmanFilter.h.

References m_observationNoise.

const RealMatrix& shark::KalmanFilter::observationNoise ( ) const
inline

Definition at line 102 of file KalmanFilter.h.

References m_observationNoise.

RealMatrix& shark::KalmanFilter::observedCovariance ( )
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.

RealVector shark::KalmanFilter::parameterVector ( ) const
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().

RealMatrix& shark::KalmanFilter::predictedCovariance ( )
inline

returns a-priori (predicted) covariance of state estimation error

Definition at line 144 of file KalmanFilter.h.

References m_predictedCovariance.

const RealMatrix& shark::KalmanFilter::predictedCovariance ( ) const
inline

Definition at line 147 of file KalmanFilter.h.

References m_predictedCovariance.

const RealVector& shark::KalmanFilter::predictionError ( ) const
inline

returns error in predicted measurements

Definition at line 158 of file KalmanFilter.h.

References m_predictionError.

void shark::KalmanFilter::setParameterVector ( RealVector const &  newParameters)
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.

RealMatrix& shark::KalmanFilter::stateDynamics ( )
inline

returns the state transition matrix 'F'

Definition at line 69 of file KalmanFilter.h.

References m_stateTransition.

const RealMatrix& shark::KalmanFilter::stateDynamics ( ) const
inline

Definition at line 72 of file KalmanFilter.h.

References m_stateTransition.

RealMatrix& shark::KalmanFilter::stateNoise ( )
inline

returns the state noise covariance matrix 'Q'

Definition at line 77 of file KalmanFilter.h.

References m_stateNoiseCov.

const RealMatrix& shark::KalmanFilter::stateNoise ( ) const
inline

Definition at line 80 of file KalmanFilter.h.

References m_stateNoiseCov.

RealVector& shark::KalmanFilter::statePrediction ( )
inline

returs a-priori (predicted) state estimate (updated in 'propagate()')

Definition at line 136 of file KalmanFilter.h.

References m_predictedState.

const RealVector& shark::KalmanFilter::statePrediction ( ) const
inline

Definition at line 139 of file KalmanFilter.h.

References m_predictedState.

void KalmanFilter::updateEstimate ( const RealVector &  z)

Member Data Documentation

size_t shark::KalmanFilter::m_inputSize
protected

Definition at line 190 of file KalmanFilter.h.

Referenced by KalmanFilter(), and updateEstimate().

RealMatrix shark::KalmanFilter::m_observationModel
protected

observation matrix

Definition at line 171 of file KalmanFilter.h.

Referenced by observationModel(), and updateEstimate().

RealMatrix shark::KalmanFilter::m_observationNoise
protected

observation noise covariance matrix

Definition at line 174 of file KalmanFilter.h.

Referenced by observationNoise(), and updateEstimate().

RealMatrix shark::KalmanFilter::m_observedCovariance
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().

RealMatrix shark::KalmanFilter::m_predictedCovariance
protected

a-priori (predicted) covariance of state estimation error

Definition at line 182 of file KalmanFilter.h.

Referenced by predict(), predictedCovariance(), setStateErrorCov(), and updateEstimate().

RealVector shark::KalmanFilter::m_predictedState
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().

RealVector shark::KalmanFilter::m_predictionError
protected

error in predicted measurements

Definition at line 188 of file KalmanFilter.h.

Referenced by predictionError(), and updateEstimate().

RealVector shark::KalmanFilter::m_state
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().

RealMatrix shark::KalmanFilter::m_stateNoiseCov
protected

state noise covariance matrix

Definition at line 168 of file KalmanFilter.h.

Referenced by predict(), and stateNoise().

RealMatrix shark::KalmanFilter::m_stateTransition
protected

state transition matrix

Definition at line 165 of file KalmanFilter.h.

Referenced by predict(), and stateDynamics().


The documentation for this class was generated from the following files: