Public Member Functions | Public Attributes | Friends

MatrixKalmanFilter Class Reference
[Auxilliary Tools]

Auxilliary Tool: A Kalman Filter for estimating the values of a matrix, which is like doing online linear regression from a probability theory perspective. More...

#include <MatrixKalmanFilter.h>

List of all members.

Public Member Functions

MatrixKalmanFilteroperator= (const MatrixKalmanFilter &rhs)
 Assignment Operator. Perform a deep copy of another MatrixKalmanFilter.
 MatrixKalmanFilter (const MatrixKalmanFilter &copy)
 Copy Constructor. Perform a deep copy of another MatrixKalmanFilter.
 MatrixKalmanFilter ()
 Default Constructor. Initializes a trivial Matrix Kalman Filter with one state and one observation (i.e. it would estimate a scalar value).
 MatrixKalmanFilter (size_t numStates, size_t numObs=1)
 Main Constructor. Initialize with numStates (size of the input vector x) and numObs (size of the output vector y in xC=y).
virtual ~MatrixKalmanFilter ()
 Destructor.
void setMuPrior (double val=0.0)
 Set the mean of the estimate of C to have each element with identical value.
void setSigmaPrior (double diagval=1.0)
 Set the uncertainty in the estimate of C to a diagonal matrix with identical values along the diagonal.
void setR (double diagval=0.0)
 Set R, the drift in the estimate of C, to a diagonal matrix with identical values along the diagonal.
void setQ (double diagval=1.0)
 Set Q, the noise in observations y, to a diagonal matrix with identical values along the diagonal.
void setMuPrior (const cv::Mat &muPrior)
 Set the mean of the estimate of C to a specific matrix.
void setSigmaPrior (const cv::Mat &sigmaPrior)
 Set the uncertainty in the estimate of C to a specific matrix.
void setR (const cv::Mat &rVal)
 Set R, the drift in the estimate of C, to a specific matrix.
void setQ (const cv::Mat &qVal)
 Set Q, the noise in observations y, to a specific matrix.
void setQDiag (const cv::Mat &qVal)
 Set Q, the noise in observations y, to be a diagonal matrix with values given by the vector qVal. qVal must have numObsx1 elements.
void setNumStatesAndObs (size_t numStates=1, size_t numObs=1)
 Reinitialize this MatrixKalmanFilter to have a new number of states and observations. This resets all default values for Mu, Sigma, Q, and R.
void getObsMean (const cv::Mat &x, cv::Mat &y)
 Compute the expected value of y given x and the current estimate of C, i.e. Cx = y.
double obsLogLikelihood (const cv::Mat &x, const cv::Mat &y)
 Compute log likelihood of y given x, based on the current mean and variance in the estimate of C.
likelihood modelLogLikelihood (const cv::Mat &x, const cv::Mat &y)
 Compute log likelihood of y given x, based on the current mean and variance in the estimate of C.
void updateModel (const cv::Mat &x, const cv::Mat &y)
 Update the current mean and variance in the estimate of C based on a newly observed input (x) and output (y)
void rectify ()
 Rectify the estimate of C so that no elements are less than 0. Calling this after updateModel will approximate non-negative matrix factorization.

Public Attributes

cv::Mat mu
 The vectorized mean of the current C estimate, row major. This vector has size (numStates * numObs) x 1. This is the actual underlying estimate data. It is exposed for convenient inspection. Don't modify it.
cv::Mat Sigma
 The covariance matrix for the current C estimate. This vector has size (numStates * numObs) x (numStates * numObs) . This is the actual underlying estimate data. It is exposed for convenient inspection. Don't modify it.

Friends

std::ostream & operator<< (std::ostream &ofs, const MatrixKalmanFilter &feat)
 Write to a file.
std::istream & operator>> (std::istream &ifs, MatrixKalmanFilter &feat)
 Read from a file.

Detailed Description

Auxilliary Tool: A Kalman Filter for estimating the values of a matrix, which is like doing online linear regression from a probability theory perspective.

Linear Regression problems take the form Cx = y. x and y are observed, and C must be inferred from data. The Kalman Filter gives a Mean estimate of the values of C's elements, and maintains a covariance matrix Sigma of uncertainties on those estimates.

There are many parameters to a Kalman Filter that may be set:

It is useful to think of there being a stochastic relation between Cx and y, specifically y is drawn from a normal distribution with mean Cx and Covariance Q.

It is also useful to think of there being a drift in C, i.e. its values may change over time. This drift is 0 mean, and has covariance R. If R is 0, you are making a strong assertion that the elements of C will never change.

Finally, you may set a prior mean estimate Mu of C, and a prior uncertainty, Sigma.

Author:
Nicholas Butko
Date:
2010 version 0.4

Constructor & Destructor Documentation

MatrixKalmanFilter::MatrixKalmanFilter ( size_t  numStates,
size_t  numObs = 1 
)

Main Constructor. Initialize with numStates (size of the input vector x) and numObs (size of the output vector y in xC=y).

MuPrior, SigmaPrior, R, and Q are set to default values. Use setter functions to modify them.

Parameters:
numStatesThe number of inputs, i.e. the length of the vector x in Cx=y, when we are trying to estimate C. The matrix C has size numStates x numObs.
numObsThe number of outputs, i.e. the length of the vector y in Cx=y.The matrix C has size numStates x numObs.

Member Function Documentation

void MatrixKalmanFilter::getObsMean ( const cv::Mat &  x,
cv::Mat &  y 
)

Compute the expected value of y given x and the current estimate of C, i.e. Cx = y.

Parameters:
xInput vector
yOutput vector: computation is passed back out by y.

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