This week I followed up on the previous week’s meeting about state-space models with a tutorial on Kalman filtering / smoothing. We started with three Gaussian “fun facts” about linear transformations of Gaussian random variables and products of Gaussian densities. Then we derived the Kalman filtering equations, the EM algorithm, and discussed a simple implementation of Kalman smoothing using sparse matrices and the “backslash” operator in matlab.
Here’s how to do Kalman smoothing in one line of matlab:
Xmap = (Qinv + speye(nsamps) / varY) \ (Y / varY + Qinv * muX);
where the latent variable X has prior mean muX and inverse covariance Qinv, and Y | X is Gaussian with mean X and variance varY * I. Note Qinv is tri-diagonal and can be formed with a single call to “spdiags”.