MATLAB MEX Function Reference
Fixed-interval Smoothing (kalcvs.m)

Fixed-interval smoothing is concerned with the smoothing of a finite set of data, i.e., with obtaining for fixed T and all t in the interval t = 1, ... , T.

Syntax

[sm, vsm] = kalcvs(data, a, F, b, H, var, pred, vpred)
[sm, vsm] = kalcvs(data, a, F, b, H, var, pred, vpred, un, vun)


Description

KALCVS uses backward recursions to compute the smoothed estimate and its covariance matrix, , where T is the number of observations in the complete data set.

The inputs to the KALCVS function are as follows.

data
is a Ny×T matrix containing data ( y1, ... , yT)'.

a
is an Nz×1 vector for a time-invariant input vector in the transition equation, or a Nz×T vector containing input vectors in the transition equation.

F
is an Nz×Nz matrix for a time-invariant transition matrix in the transition equation, or a Nz×Nz×T matrix containing T transition matrices.

b
is an Ny×1 vector for a time-invariant input vector in the measurement equation, or a Ny×T vector containing input vectors in the measurement equation.

H
is an Ny×Nz matrix for a time-invariant measurement matrix in the measurement equation, or a Ny×Nz×T matrix containing T time variant Ht matrices in the measurement equation.

var
is an (Ny+Nz)×(Ny+Nz) covariance matrix for the errors in the transition and the measurement equations, or a (Ny+Nz)×(Ny + NzT matrix containing covariance matrices in the transition equation and measurement equation noises, that is, .

pred
is a Nz×T matrix containing one-step forecasts .

vpred
is a Nz×Nz×T matrix containing mean square error matrices of predicted state vectors .

un
is an optional Nz×1 vector containing uT. The returned value is u0.

vun
is an optional Nz×Nz matrix containing UT. The returned value is U0.
The KALCVS function returns the following values:
sm
is a Nz×T matrix containing smoothed state vectors .

vsm
is a Nz×Nz×T matrix containing covariance matrices of smoothed state vectors .

Algorithm

When the Kalman filtering is performed using KALCVF function, the KALCVS function computes smoothed state vectors and their covariance matrices. The fixed-interval smoothing state vector at time t is obtained by the conditional expectation given all observations.

The smoothing algorithm uses one-step forecasts and their covariance matrices, which are obtained using KALCVF function. For notation, is the smoothed value of the state vector zt, and the mean square error matrix is denoted . For smoothing,
where t = T, T-1, ... , 1. The initial values are uT = 0 and UT = 0.

When the SSM is specified using the alternative transition equation
the fixed-interval smoothing is performed using the following backward recursions:
where it is assumed that Gt = 0.

You can use the KALCVS function regardless of the specification of the transition equation when Gt = 0. Harvey (1991) gives the following fixed-interval smoothing formula, which produces the same smoothed value:
where
under the shifted transition equation, but
under the alternative transition equation.

The KALCVS function is accompanied by the KALCVF function, as shown in the following code. Note that you do not need to specify UN and VUN.

[logl, pred, vpred] = kalcvf(y, 0, a, F, b, H, var);
[sm, vsm] = kalcvs(y, a, F, b, H, var, pred, vpred);

You can also compute the smoothed estimate and its covariance matrix on an observation-by-observation basis. When the SSM is time invariant, the following example performs smoothing. In this situation, you should initialize UN and VUN as matrices of value 0.
[logl, pred, vpred] = kalcvf(y, 0, a, F, b, H, var);
n = size(y,2);
nz = size(F,1);
un = zeros(nz,1);
vun = zeros(nz,nz);
sm = zeros(nz,n);
vsm = zeros(nz,nz,n);
for i=n:-1:1
y_i = y(:,i);
pred_i  = pred(:,i);
vpred_i = vpred(:,:,i);
[sm_i, vsm_i] = kalcvs(y_i, a, F, b, H, var, pred_i, vpred_i, un, vun);
sm(:,i)  = sm_i;
vsm(:,:,i) = vsm_i;
end


KALCVF performs covariance filtering and prediction

Getting Started with State Space Models

Kalman Filtering Example 1: Likelihood Function Evaluation

Kalman Filtering Example 2: Estimating an SSM Using the EM Algorithm

References

[1]  Harvey, A.C., Forecasting, Structural Time Series Models and the Kalman Filter, Cambridge: Cambridge University Press, 1991.

[2]  Anderson, B.D.O., and J.B. Moore, Optimal Filtering, Englewood Cliffs, NJ: Prentice-Hall, 1979.

[3]  Hamilton, J.D., Time Series Analysis, Princeton, 1994.