Bug in kalman_filter.m

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Bug in kalman_filter.m

Postby jpfeifer » Thu Jun 03, 2010 7:40 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Bug in kalman_filter.m

Postby StephaneAdjemian » Wed Jun 09, 2010 9:04 am

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.
Stéphane Adjemian
Université du Maine, GAINS and DynareTeam
https://stepan.adjemian.eu
StephaneAdjemian
 
Posts: 429
Joined: Wed Jan 05, 2005 4:24 pm
Location: Paris, France.


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 9 guests