Is it possible that in a Kalman Filter implementation the 'Predicted estimate covariance', P(k|k-1), (see the wiki here) could be a singular matrix? If not, is something is wrong with my code?
This is the state-space model
% y{t}=Z{t} b{t} + eps{t}, eps{t} ~ N(0,H{t})
% b{t} = Pi{t} b{t-1} + tao{t} tao{t} ~ N(0,Q{t})
% b{1} ~ N(b0,P0)
% t=1,...,T
and this is the backward recursion as the main part of the kalman-filter algorithm:
for t=1:T
v{t} = y{t} - Z{t} * b_tt_1{t};
M{t} = P_tt_1{t} * Z{t}';
F{t} = Z{t} * M{t} + H{t};
F_{t}= inv(F{t});
MF_{t}= M{t} * F_{t};
b_tt{t}=b_tt_1{t} + MF_{t} * v{t};
P_tt{t}=P_tt_1{t} - MF_{t} * M{t}';
b_tt_1{t+1} = Pi{t} * b_tt{t};
P_tt_1{t+1} = Pi{t} * P_tt{t} * Pi{t}' + Q{t};
end
This happened when I used actual data. To see where the problem might be, I wrote some code to generate random state-space models (I can provide the code, if it is needed).
When T is large, After some t0, P_tt_1{t0} is singular and the states (b{t0}) diverge.
Edit: I used "Joseph form" of the covariance update equation (see Wikipedia). It helped, but the result still diverges when the state-space model is Large (in sense of number of equations or states). I think this means the problem is related to numerical stability. Is there a way to solve this?
the problem is with inversion process of inv or pinv functions. the matrices are large, but they are also positive definite. so I used cholesky decomposition for inversion. the function is:
function A_=inversePD(A)
%A:positive definite matrix
M=size(A,1);
[R b] = chol(A);
if b~=0
return
end
R_ = R \ eye(M);
A_ = R_ * R_';
end