You are right. I didn't think of the case where start would happen after than the filter has reached stationary state. If it is what happens in your example, then it must explain the difference between the C++ and the Matlab version of the filter.
One more reason to clarify the Matlab code.
Best
Michel
G. Perendia wrote:
- In my experience, the filter cov. determinants dF becomes
stationary after several steps (5-10), e.g. 7 and number of periods the filter is stationary is reste=smpl-7 whilst, if start =41 (presample=40) than reste is then larger than smpl -start+1=smpl-40.
- it is not problematic to add all the determinants at once in the
last period of the stationary filter as long as we subtract from the total sum
start-1-(smpl-reste) = 41 -1 -(smpl-smpl+7)=33 determinants, or, add only min(reste,(smpl-start+1)) Best regards
George
----- Original Message ----- *From:* Stéphane Adjemian <mailto:stephane.adjemian@gmail.com> *To:* List for Dynare developers <mailto:dev@dynare.org> *Cc:* G. Perendia <mailto:george@perendia.orangehome.co.uk> *Sent:* Wednesday, May 27, 2009 11:04 AM *Subject:* Re: [DynareDev] Kalman Filter Hi all, I agree, the matlab code is very unclear (even if I had fun writting it this way ;-) and prone to errors if one uses the vector lik (Marco is using it). I would rather prefer to add the constants outside of the loop with a (sub)vector operation, this should be more efficient. I will do it today or tomorrow. Best, Stéphane. 2009/5/27 Michel Juillard <michel.juillard@ens.fr <mailto:michel.juillard@ens.fr>> On closer inspection, I don't think that the expression pointed by George in kalman_filter.m is wrong: 1. reste = smpl-t or the number of periods during which the filter is stationary. This shouldn't be larger than T-start+1 2. it is problematic (see below) but not wrong to add all the determinants at once in the last period of the stationary filter 3. I don't think this explains the difference with the C++ version of the filter and we still have to look for it. 4. it remains that the current code is very unclear and that if LIK is correct the vector lik doesn't have the correct constants on each elements. 5. I would like to simplify the code and add the correct constant to each element of the lik vector. It would be a little bit less efficient in Matlab than the current code, but I doubt it would be noticeable. Stephane, what do you think? Best Michel G. Perendia wrote: Dear Michel I think I found an error in Dynare Matlab kalman_filter. suite of utilities which affects the likelihood LIK results with start>1 (i.e. presampling>0): the calculation speed-up construct which relies on converged covariance matrix lik(t) = lik(t) + reste*log(dF); adds reste * log(dF) to the last-1 (i.e. the smpl) member of lik (the last, the lik(smpl+1) one contains smpl*pp*log(2*pi)) but reste is usually larger than T-start+1 so that LIK = .5*(sum(lik(start:end))-(start-1)*lik(smpl+1)/smpl) has much more log(dF)s added than required since they are all concentrated in the last-1 (the T) member For example, if I change the above construct to lik(t) = lik(t) + min(reste,(smpl-start+1))*log(dF); the reported likelihood for presample=40 from Matlab KF is 1640935.5855267849 which is nearly the same as that from C++ KF below: 1640935.5854489324 Shall I make changes to kalman/likelihood/ KFs and upload the .m files? This problem affects also the older versions of DiffuseLikelihood**.m too. Best regards George artilogica@btconnect.com <mailto:artilogica@btconnect.com> ----- Original Message ----- From: "Michel Juillard" <michel.juillard@ens.fr <mailto:michel.juillard@ens.fr>> To: "G. Perendia" <george@perendia.orangehome.co.uk <mailto:george@perendia.orangehome.co.uk>> Sent: Tuesday, May 26, 2009 10:32 AM Subject: Re: Kalman Filter+PS Hi George, Re 1) below: I modified C++ KF so that it reports log-likelihood for given start/preampling in same/similar manner as the Matlab KFs do and I am getting approximately close results, e.g. ll= -1640935.5854489324 for C++ and (-) 1640482.4179242959 for Matlab KF (for start=41, i.e. presample=40). whilst they appear same for presample=0 (e.g.2.5906e+006), i.e. -2590556.989730841 vs 2590556.989778722 Are those results acceptably close or should I investigate further where the above difference may come form? This indicates a problem . The difference should be the same with and without presample. It may come from the computation of the likelihood constant. This is done in a very obscure manner in Dynare Matlab. _______________________________________________ Dev mailing list Dev@dynare.org <mailto:Dev@dynare.org> http://www.dynare.org/cgi-bin/mailman/listinfo/dev -- Stéphane Adjemian CEPREMAP & Université du Maine Tel: (33)1-43-13-62-39 ------------------------------------------------------------------------ _______________________________________________ Dev mailing list Dev@dynare.org http://www.dynare.org/cgi-bin/mailman/listinfo/dev
Dev mailing list Dev@dynare.org http://www.dynare.org/cgi-bin/mailman/listinfo/dev