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
----- Original Message ----- From: "Michel Juillard" michel.juillard@ens.fr To: "G. Perendia" 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.
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
On closer inspection, I don't think that the expression pointed by George in kalman_filter.m is wrong:
- reste = smpl-t or the number of periods during which the filter is
stationary. This shouldn't be larger than T-start+1
- it is problematic (see below) but not wrong to add all the determinants
at once in the last period of the stationary filter
- I don't think this explains the difference with the C++ version of the
filter and we still have to look for it.
- 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.
- 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
----- Original Message ----- From: "Michel Juillard" < michel.juillard@ens.fr> To: "G. Perendia" 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 http://www.dynare.org/cgi-bin/mailman/listinfo/dev
1. 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.
2. 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 To: List for Dynare developers Cc: G. Perendia 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
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
----- Original Message ----- From: "Michel Juillard" michel.juillard@ens.fr To: "G. Perendia" 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 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
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
George, Can you share your example. In my experience (with medium scaled models) it takes much more iterations to get to the steady state kalman filter...
I didn't look at the cc codes, but one possible source of discrepancy between matlab and cc may be the steady state KF criterion. I test for the stationarity of KF considering the changes in the biggest elements of the Kalman Gain matrix, not the changes in the determinant of the forecast errors covariance matrix...
Best, Stéphane.
2009/5/27 G. Perendia george@perendia.orangehome.co.uk
- 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 stephane.adjemian@gmail.com *To:* List for Dynare developers dev@dynare.org *Cc:* G. Perendia 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
On closer inspection, I don't think that the expression pointed by George in kalman_filter.m is wrong:
- reste = smpl-t or the number of periods during which the filter is
stationary. This shouldn't be larger than T-start+1
- it is problematic (see below) but not wrong to add all the determinants
at once in the last period of the stationary filter
- I don't think this explains the difference with the C++ version of the
filter and we still have to look for it.
- 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.
- 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
----- Original Message ----- From: "Michel Juillard" < michel.juillard@ens.fr> To: "G. Perendia" 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 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
A (rather simplified) example enclosed
Best regards
George Perendia ----- Original Message ----- From: Stéphane Adjemian To: List for Dynare developers ; G. Perendia Sent: Wednesday, May 27, 2009 11:56 AM Subject: Re: [DynareDev] Kalman Filter
George, Can you share your example. In my experience (with medium scaled models) it takes much more iterations to get to the steady state kalman filter...
I didn't look at the cc codes, but one possible source of discrepancy between matlab and cc may be the steady state KF criterion. I test for the stationarity of KF considering the changes in the biggest elements of the Kalman Gain matrix, not the changes in the determinant of the forecast errors covariance matrix...
Best, Stéphane.
2009/5/27 G. Perendia george@perendia.orangehome.co.uk
1. 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.
2. 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 To: List for Dynare developers Cc: G. Perendia 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
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
----- Original Message ----- From: "Michel Juillard" michel.juillard@ens.fr To: "G. Perendia" 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 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
-- 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
Thanks George, S.
2009/5/27 G. Perendia george@perendia.orangehome.co.uk
A (rather simplified) example enclosed
Best regards
George Perendia ----- Original Message -----
*From:* Stéphane Adjemian stephane.adjemian@gmail.com *To:* List for Dynare developers dev@dynare.org ; G. Perendiageorge@perendia.orangehome.co.uk *Sent:* Wednesday, May 27, 2009 11:56 AM *Subject:* Re: [DynareDev] Kalman Filter
George, Can you share your example. In my experience (with medium scaled models) it takes much more iterations to get to the steady state kalman filter...
I didn't look at the cc codes, but one possible source of discrepancy between matlab and cc may be the steady state KF criterion. I test for the stationarity of KF considering the changes in the biggest elements of the Kalman Gain matrix, not the changes in the determinant of the forecast errors covariance matrix...
Best, Stéphane.
2009/5/27 G. Perendia george@perendia.orangehome.co.uk
- 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 stephane.adjemian@gmail.com *To:* List for Dynare developers dev@dynare.org *Cc:* G. Perendia 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
On closer inspection, I don't think that the expression pointed by George in kalman_filter.m is wrong:
- reste = smpl-t or the number of periods during which the filter is
stationary. This shouldn't be larger than T-start+1
- it is problematic (see below) but not wrong to add all the
determinants at once in the last period of the stationary filter
- I don't think this explains the difference with the C++ version of the
filter and we still have to look for it.
- 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.
- 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
----- Original Message ----- From: "Michel Juillard" < michel.juillard@ens.fr> To: "G. Perendia" 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 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
-- 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
In fact the discrepancy found by George occurs only for start ~= 1 So it is clearly related to the handling of the constants.
Best
Michel
Stéphane Adjemian wrote:
George, Can you share your example. In my experience (with medium scaled models) it takes much more iterations to get to the steady state kalman filter...
I didn't look at the cc codes, but one possible source of discrepancy between matlab and cc may be the steady state KF criterion. I test for the stationarity of KF considering the changes in the biggest elements of the Kalman Gain matrix, not the changes in the determinant of the forecast errors covariance matrix...
Best, Stéphane.
2009/5/27 G. Perendia <george@perendia.orangehome.co.uk mailto:george@perendia.orangehome.co.uk>
1. 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. 2. 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 <mailto:Dev@dynare.org> http://www.dynare.org/cgi-bin/mailman/listinfo/dev _______________________________________________ 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
Thanks Stephane,
I just uploaded a new version of kalman_filter.m Tell me what you think
Best
Michel
Stéphane Adjemian wrote:
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
Thanks Michel. Your commit is ok for me. I do not yet understand the problem raised by George. I need to go through his example...
Stéphane.
2009/5/27 Michel Juillard michel.juillard@ens.fr
Thanks Stephane,
I just uploaded a new version of kalman_filter.m Tell me what you think
Best
Michel
Stéphane Adjemian wrote:
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:
- reste = smpl-t or the number of periods during which the filter
is stationary. This shouldn't be larger than T-start+1
- it is problematic (see below) but not wrong to add all the
determinants at once in the last period of the stationary filter
- I don't think this explains the difference with the C++ version
of the filter and we still have to look for it.
- 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.
- 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
Si le filtre converge a l'etat stationnaire a une date avant start (la date a partir de laquelle on cumule la vraisemblance), alors additionner tous les determinants des iterations dans le filtre stationnaire a la derniere periode fausse le calcul de la constante.
amicalement
Michel
Stéphane Adjemian wrote:
Thanks Michel. Your commit is ok for me. I do not yet understand the problem raised by George. I need to go through his example...
Stéphane.
2009/5/27 Michel Juillard <michel.juillard@ens.fr mailto:michel.juillard@ens.fr>
Thanks Stephane, I just uploaded a new version of kalman_filter.m Tell me what you think Best Michel Stéphane Adjemian wrote: 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> <mailto: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> <mailto:artilogica@btconnect.com <mailto:artilogica@btconnect.com>> ----- Original Message ----- From: "Michel Juillard" <michel.juillard@ens.fr <mailto:michel.juillard@ens.fr> <mailto:michel.juillard@ens.fr <mailto:michel.juillard@ens.fr>>> To: "G. Perendia" <george@perendia.orangehome.co.uk <mailto:george@perendia.orangehome.co.uk> <mailto: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> <mailto: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 <mailto:Dev@dynare.org> http://www.dynare.org/cgi-bin/mailman/listinfo/dev _______________________________________________ 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
Oui, oui... I never use the presampling option... And with all the examples I have ever considered it takes much more than 10 iterations to get to the steady state kalman filter.
By the way, is there somewhere linux a Makefile for the cc kalman routines? Also, why do we need Atlas (if we also use matlab's lapack/blas libraries)?
Stéphane.
2009/5/27 Michel Juillard michel.juillard@ens.fr
Si le filtre converge a l'etat stationnaire a une date avant start (la date a partir de laquelle on cumule la vraisemblance), alors additionner tous les determinants des iterations dans le filtre stationnaire a la derniere periode fausse le calcul de la constante.
amicalement
Michel
Stéphane Adjemian wrote:
Thanks Michel. Your commit is ok for me. I do not yet understand the problem raised by George. I need to go through his example...
Stéphane.
2009/5/27 Michel Juillard <michel.juillard@ens.fr mailto: michel.juillard@ens.fr>
Thanks Stephane,
I just uploaded a new version of kalman_filter.m Tell me what you think
Best
Michel
Stéphane Adjemian wrote:
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> <mailto: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> <mailto:artilogica@btconnect.com <mailto:artilogica@btconnect.com>> ----- Original Message ----- From: "Michel Juillard" <michel.juillard@ens.fr <mailto:michel.juillard@ens.fr> <mailto:michel.juillard@ens.fr <mailto:michel.juillard@ens.fr>>> To: "G. Perendia" <george@perendia.orangehome.co.uk <mailto:george@perendia.orangehome.co.uk> <mailto: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> <mailto: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 <mailto:Dev@dynare.org> http://www.dynare.org/cgi-bin/mailman/listinfo/dev
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
Currently we should link against blas/lapack from Matlab. I asked Andrea to get inspiration from Atlas to specialize the matrix multiplications that involve quasi-triangular T matrices.
Michel
Stéphane Adjemian wrote:
Oui, oui... I never use the presampling option... And with all the examples I have ever considered it takes much more than 10 iterations to get to the steady state kalman filter.
By the way, is there somewhere linux a Makefile for the cc kalman routines? Also, why do we need Atlas (if we also use matlab's lapack/blas libraries)?
Stéphane.
2009/5/27 Michel Juillard <michel.juillard@ens.fr mailto:michel.juillard@ens.fr>
Si le filtre converge a l'etat stationnaire a une date avant start (la date a partir de laquelle on cumule la vraisemblance), alors additionner tous les determinants des iterations dans le filtre stationnaire a la derniere periode fausse le calcul de la constante. amicalement Michel Stéphane Adjemian wrote: Thanks Michel. Your commit is ok for me. I do not yet understand the problem raised by George. I need to go through his example... Stéphane. 2009/5/27 Michel Juillard <michel.juillard@ens.fr <mailto:michel.juillard@ens.fr> <mailto:michel.juillard@ens.fr <mailto:michel.juillard@ens.fr>>> Thanks Stephane, I just uploaded a new version of kalman_filter.m Tell me what you think Best Michel Stéphane Adjemian wrote: 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> <mailto:michel.juillard@ens.fr <mailto:michel.juillard@ens.fr>> <mailto:michel.juillard@ens.fr <mailto:michel.juillard@ens.fr> <mailto: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> <mailto:artilogica@btconnect.com <mailto:artilogica@btconnect.com>> <mailto:artilogica@btconnect.com <mailto:artilogica@btconnect.com> <mailto:artilogica@btconnect.com <mailto:artilogica@btconnect.com>>> ----- Original Message ----- From: "Michel Juillard" <michel.juillard@ens.fr <mailto:michel.juillard@ens.fr> <mailto:michel.juillard@ens.fr <mailto:michel.juillard@ens.fr>> <mailto:michel.juillard@ens.fr <mailto:michel.juillard@ens.fr> <mailto:michel.juillard@ens.fr <mailto:michel.juillard@ens.fr>>>> To: "G. Perendia" <george@perendia.orangehome.co.uk <mailto:george@perendia.orangehome.co.uk> <mailto:george@perendia.orangehome.co.uk <mailto:george@perendia.orangehome.co.uk>> <mailto:george@perendia.orangehome.co.uk <mailto:george@perendia.orangehome.co.uk> <mailto: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> <mailto:Dev@dynare.org <mailto:Dev@dynare.org>> <mailto:Dev@dynare.org <mailto:Dev@dynare.org> <mailto: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 <mailto:Dev@dynare.org> <mailto:Dev@dynare.org <mailto:Dev@dynare.org>> http://www.dynare.org/cgi-bin/mailman/listinfo/dev _______________________________________________ Dev mailing list Dev@dynare.org <mailto:Dev@dynare.org> <mailto: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 <mailto:Dev@dynare.org> http://www.dynare.org/cgi-bin/mailman/listinfo/dev _______________________________________________ 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
Dear All,
I have added a test folder for parallel routines in trunk. In principle they should be test-able under linux. For linux I assume:
1) matlab is in the path of the machine, e.g. in the etc/environment file the matlab bin folder is in the PATH variable; 2) ssh is properly installed and working; 3) for a grid of unix machines, sshfs also needs to be installed and working;
So far, mixed platform grids (linux and win) are not working: only homogeneous grids (unix or win) are tested.
best wishes Marco
Many thanks Marco. We are going to try it.
Could you please write a Wiki page for it on https://www.dynare.org/DynareWiki with an entry under NewFeatures ?
Best
Michel
Marco Ratto wrote:
Dear All,
I have added a test folder for parallel routines in trunk. In principle they should be test-able under linux. For linux I assume:
- matlab is in the path of the machine, e.g. in the etc/environment
file the matlab bin folder is in the PATH variable; 2) ssh is properly installed and working; 3) for a grid of unix machines, sshfs also needs to be installed and working;
So far, mixed platform grids (linux and win) are not working: only homogeneous grids (unix or win) are tested.
best wishes Marco
Sure, I will do that,
all the best Marco
Many thanks Marco. We are going to try it.
Could you please write a Wiki page for it on https://www.dynare.org/DynareWiki with an entry under NewFeatures ?
Best
Michel
Marco Ratto wrote:
Dear All,
I have added a test folder for parallel routines in trunk. In principle they should be test-able under linux. For linux I assume:
- matlab is in the path of the machine, e.g. in the etc/environment
file the matlab bin folder is in the PATH variable; 2) ssh is properly installed and working; 3) for a grid of unix machines, sshfs also needs to be installed and working;
So far, mixed platform grids (linux and win) are not working: only homogeneous grids (unix or win) are tested.
best wishes Marco
Dev mailing list Dev@dynare.org http://www.dynare.org/cgi-bin/mailman/listinfo/dev
Hi
The C++ Kalman dll driver routines in /mex/kalman/matlab are still in development and the code there is still subject to developer testing and the Makefile there is not yet complete but it should use blas/lapack from Matlab libraries.
Best regards
George Perendia Tel.: 02072815392 Mob: 07951415480 ----- Original Message ----- From: Stéphane Adjemian To: List for Dynare developers Sent: Wednesday, May 27, 2009 2:18 PM Subject: Re: [DynareDev] Kalman Filter
Oui, oui... I never use the presampling option... And with all the examples I have ever considered it takes much more than 10 iterations to get to the steady state kalman filter.
By the way, is there somewhere linux a Makefile for the cc kalman routines? Also, why do we need Atlas (if we also use matlab's lapack/blas libraries)?
Stéphane.
2009/5/27 Michel Juillard michel.juillard@ens.fr
Si le filtre converge a l'etat stationnaire a une date avant start (la date a partir de laquelle on cumule la vraisemblance), alors additionner tous les determinants des iterations dans le filtre stationnaire a la derniere periode fausse le calcul de la constante.
amicalement
Michel
Stéphane Adjemian wrote:
Thanks Michel. Your commit is ok for me. I do not yet understand the problem raised by George. I need to go through his example...
Stéphane.
2009/5/27 Michel Juillard <michel.juillard@ens.fr mailto:michel.juillard@ens.fr>
Thanks Stephane,
I just uploaded a new version of kalman_filter.m Tell me what you think
Best
Michel
Stéphane Adjemian wrote:
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 <mailto: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
<mailto:artilogica@btconnect.com
mailto:artilogica@btconnect.com>
----- Original Message ----- From: "Michel Juillard" <michel.juillard@ens.fr mailto:michel.juillard@ens.fr
<mailto:michel.juillard@ens.fr mailto:michel.juillard@ens.fr>>
To: "G. Perendia" <george@perendia.orangehome.co.uk mailto:george@perendia.orangehome.co.uk <mailto: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
<mailto: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 mailto:Dev@dynare.org http://www.dynare.org/cgi-bin/mailman/listinfo/dev
_______________________________________________ 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
-- 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
*Hi George*
2009/5/27 G. Perendia george@perendia.orangehome.co.uk
Hi
The C++ Kalman dll driver routines in /mex/kalman/matlab are still in development
*Sure... *
and the code there is still subject to developer testing
*... But I'd like to play with it.*
and the Makefile there is not yet complete but it should use blas/lapack from Matlab libraries.
*Ok. I will adapt your Makefile for my platform.**
Best, Stéphane.*
Best regards
George Perendia Tel.: 02072815392 Mob: 07951415480
----- Original Message ----- *From:* Stéphane Adjemian stephane.adjemian@gmail.com *To:* List for Dynare developers dev@dynare.org *Sent:* Wednesday, May 27, 2009 2:18 PM *Subject:* Re: [DynareDev] Kalman Filter
Oui, oui... I never use the presampling option... And with all the examples I have ever considered it takes much more than 10 iterations to get to the steady state kalman filter.
By the way, is there somewhere linux a Makefile for the cc kalman routines? Also, why do we need Atlas (if we also use matlab's lapack/blas libraries)?
Stéphane.
2009/5/27 Michel Juillard michel.juillard@ens.fr
Si le filtre converge a l'etat stationnaire a une date avant start (la date a partir de laquelle on cumule la vraisemblance), alors additionner tous les determinants des iterations dans le filtre stationnaire a la derniere periode fausse le calcul de la constante.
amicalement
Michel
Stéphane Adjemian wrote:
Thanks Michel. Your commit is ok for me. I do not yet understand the problem raised by George. I need to go through his example...
Stéphane.
2009/5/27 Michel Juillard <michel.juillard@ens.fr mailto: michel.juillard@ens.fr>
Thanks Stephane,
I just uploaded a new version of kalman_filter.m Tell me what you think
Best
Michel
Stéphane Adjemian wrote:
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> <mailto: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> <mailto:artilogica@btconnect.com <mailto:artilogica@btconnect.com>> ----- Original Message ----- From: "Michel Juillard" <michel.juillard@ens.fr <mailto:michel.juillard@ens.fr> <mailto:michel.juillard@ens.fr <mailto:michel.juillard@ens.fr>>> To: "G. Perendia" <george@perendia.orangehome.co.uk <mailto:george@perendia.orangehome.co.uk> <mailto: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> <mailto: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 <mailto:Dev@dynare.org> http://www.dynare.org/cgi-bin/mailman/listinfo/dev
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
-- 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
The filter routines there have names and should follow calling rules for the par matlab/kalman/likelihood ones but they do not yet take mf and still expect Z matrix of 1s to map system to observables instead and Pinf must not be empty but at least be initialised to a zeros matrix of Pstar size.
The smoother is generic as it was, not suitable for running at all
Best regards
George
----- Original Message ----- From: Stéphane Adjemian To: List for Dynare developers Sent: Wednesday, May 27, 2009 2:46 PM Subject: Re: [DynareDev] Kalman Filter
Hi George
2009/5/27 G. Perendia george@perendia.orangehome.co.uk
Hi
The C++ Kalman dll driver routines in /mex/kalman/matlab are still in development
Sure...
and the code there is still subject to developer testing
... But I'd like to play with it.
and the Makefile there is not yet complete but it should use blas/lapack from Matlab libraries.
Ok. I will adapt your Makefile for my platform.
Best, Stéphane.
Best regards
George Perendia Tel.: 02072815392 Mob: 07951415480 ----- Original Message ----- From: Stéphane Adjemian To: List for Dynare developers Sent: Wednesday, May 27, 2009 2:18 PM Subject: Re: [DynareDev] Kalman Filter
Oui, oui... I never use the presampling option... And with all the examples I have ever considered it takes much more than 10 iterations to get to the steady state kalman filter.
By the way, is there somewhere linux a Makefile for the cc kalman routines? Also, why do we need Atlas (if we also use matlab's lapack/blas libraries)?
Stéphane.
2009/5/27 Michel Juillard michel.juillard@ens.fr
Si le filtre converge a l'etat stationnaire a une date avant start (la date a partir de laquelle on cumule la vraisemblance), alors additionner tous les determinants des iterations dans le filtre stationnaire a la derniere periode fausse le calcul de la constante.
amicalement
Michel
Stéphane Adjemian wrote:
Thanks Michel. Your commit is ok for me. I do not yet understand the problem raised by George. I need to go through his example...
Stéphane.
2009/5/27 Michel Juillard <michel.juillard@ens.fr mailto:michel.juillard@ens.fr>
Thanks Stephane,
I just uploaded a new version of kalman_filter.m Tell me what you think
Best
Michel
Stéphane Adjemian wrote:
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 <mailto: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
<mailto:artilogica@btconnect.com
mailto:artilogica@btconnect.com>
----- Original Message ----- From: "Michel Juillard" <michel.juillard@ens.fr mailto:michel.juillard@ens.fr
<mailto:michel.juillard@ens.fr mailto:michel.juillard@ens.fr>>
To: "G. Perendia" <george@perendia.orangehome.co.uk mailto:george@perendia.orangehome.co.uk <mailto: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
<mailto: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 mailto:Dev@dynare.org http://www.dynare.org/cgi-bin/mailman/listinfo/dev
_______________________________________________ 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
-- 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
-- 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