Page 1 of 1

Bug in kalman_filter.m

PostPosted: Thu Jun 03, 2010 7:40 am
by jpfeifer
Hi,

there is obviously a bug in the file kalman_filter.m used in Dynare. The respective part is

Code: Select all
while notsteady & t<smpl
    t  = t+1;
    v  = Y(:,t)-a(mf);
    F  = P(mf,mf) + H;
    if rcond(F) < kalman_tol
        if ~all(abs(F(:))<kalman_tol)
            return
        else
            a = T*a;
            P = T*P*transpose(T)+QQ;
        end
    else
        F_singular = 0;
        dF     = det(F);
        iF     = inv(F);
        lik(t) = log(dF)+transpose(v)*iF*v;
        K      = P(:,mf)*iF;
        a      = T*(a+K*v);
        P      = T*(P-K*P(mf,:))*transpose(T)+QQ;
    end
    notsteady = max(max(abs(K-oldK))) > riccati_tol;
    oldK = K;
end


If
Code: Select all
rcond(F) < kalman_tol

and
Code: Select all
~all(abs(F(:))<kalman_tol)

Dynare only sets the variables a and P. However, after the if-clause, K is used in
Code: Select all
max(max(abs(K-oldK)))
But K was never defined, hence Dynare stops with an error.

Re: Bug in kalman_filter.m

PostPosted: Wed Jun 09, 2010 9:04 am
by StephaneAdjemian
Dear Johannes, Thanks for reporting this bug. I have never met this problem. When the condition rcond(F)<kalman_tol is true we cannot update the Kalman gain because the covariance matrix F is not invertible. In this case don't need to check for the steady state of the Kalman filter. We just have to move :

Code: Select all
    notsteady = max(max(abs(K-oldK))) > riccati_tol;
    oldK = K;


before the end keyword. I will commit this correction in couple of minutes. The next release 4.1.2 will contain the fix.

Best, Stéphane.