P convergence likelihood bug fix

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2824 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
george 2009-07-08 12:20:21 +00:00
parent 181b268699
commit f4c3482acd
4 changed files with 54 additions and 50 deletions

View File

@ -51,12 +51,10 @@ function [LIK, lik] = DiffuseLikelihood1(T,R,Q,Pinf,Pstar,Y,trend,start)
dF = 1;
QQ = R*Q*transpose(R);
t = 0;
lik = zeros(smpl+1,1);
lik = zeros(smpl,1);
LIK = Inf;
lik(smpl+1) = smpl*pp*log(2*pi);
notsteady = 1;
crit = options_.kalman_tol;
reste = 0;
while rank(Pinf,crit) & t < smpl
t = t+1;
v = Y(:,t)-a(mf)-trend(:,t);
@ -116,14 +114,17 @@ function [LIK, lik] = DiffuseLikelihood1(T,R,Q,Pinf,Pstar,Y,trend,start)
error(['The variance of the forecast error remains singular until the' ...
'end of the sample'])
end
reste = smpl-t;
while t < smpl
t = t+1;
v = Y(:,t)-a(mf)-trend(:,t);
a = T*(a+K*v);
lik(t) = transpose(v)*iF*v;
end
lik(t) = lik(t) + reste*log(dF);
if t < smpl
t0 = t+1;
while t < smpl
t = t+1;
v = Y(:,t)-a(mf)-trend(:,t);
a = T*(a+K*v);
lik(t) = transpose(v)*iF*v;
end
lik(t0:smpl) = lik(t0:smpl) + log(dF);
end
% adding log-likelihhod constants
lik = (lik + pp*log(2*pi))/2;
LIK = .5*(sum(lik(start:end))-(start-1)*lik(smpl+1)/smpl);% Minus the log-likelihood.
LIK = sum(lik(start:end)); % Minus the log-likelihood.

View File

@ -50,12 +50,10 @@ function [LIK, lik] = DiffuseLikelihood1_Z(T,Z,R,Q,Pinf,Pstar,Y,start)
dF = 1;
QQ = R*Q*transpose(R);
t = 0;
lik = zeros(smpl+1,1);
lik = zeros(smpl,1);
LIK = Inf;
lik(smpl+1) = smpl*pp*log(2*pi);
notsteady = 1;
crit = options_.kalman_tol;
reste = 0;
while rank(Pinf,crit) & t < smpl
t = t+1;
v = Y(:,t)-Z*a;
@ -116,14 +114,17 @@ function [LIK, lik] = DiffuseLikelihood1_Z(T,Z,R,Q,Pinf,Pstar,Y,start)
error(['The variance of the forecast error remains singular until the' ...
'end of the sample'])
end
reste = smpl-t;
while t < smpl
t = t+1;
v = Y(:,t)-Z*a;
a = T*(a+K*v);
lik(t) = v'*iF*v;
if t < smpl
t0 = t+1;
while t < smpl
t = t+1;
v = Y(:,t)-Z*a;
a = T*(a+K*v);
lik(t) = v'*iF*v;
end
lik(t0:smpl) = lik(t0:smpl) + log(dF);
end
lik(t) = lik(t) + reste*log(dF);
% adding log-likelihhod constants
lik = (lik + pp*log(2*pi))/2;
LIK = .5*(sum(lik(start:end))-(start-1)*lik(smpl+1)/smpl);% Minus the log-likelihood.
LIK = sum(lik(start:end)); % Minus the log-likelihood.

View File

@ -52,12 +52,10 @@ function [LIK, lik] = DiffuseLikelihoodH1(T,R,Q,H,Pinf,Pstar,Y,trend,start)
dF = 1;
QQ = R*Q*transpose(R);
t = 0;
lik = zeros(smpl+1,1);
lik = zeros(smpl,1);
LIK = Inf;
lik(smpl+1) = smpl*pp*log(2*pi);
notsteady = 1;
crit = options_.kalman_tol;
reste = 0;
while rank(Pinf,crit) & t < smpl
t = t+1;
v = Y(:,t)-a(mf)-trend(:,t);
@ -117,14 +115,17 @@ function [LIK, lik] = DiffuseLikelihoodH1(T,R,Q,H,Pinf,Pstar,Y,trend,start)
error(['The variance of the forecast error remains singular until the' ...
'end of the sample'])
end
reste = smpl-t;
while t < smpl
t = t+1;
v = Y(:,t)-a(mf)-trend(:,t);
a = T*(a+K*v);
lik(t) = transpose(v)*iF*v;
if t < smpl
t0 = t+1;
while t < smpl
t = t+1;
v = Y(:,t)-a(mf)-trend(:,t);
a = T*(a+K*v);
lik(t) = transpose(v)*iF*v;
end
lik(t0:smpl) = lik(t0:smpl) + log(dF);
end
lik(t) = lik(t) + reste*log(dF);
LIK = .5*(sum(lik(start:end))-(start-1)*lik(smpl+1)/smpl);% Minus the
% log-likelihood.
% adding log-likelihhod constants
lik = (lik + pp*log(2*pi))/2;
LIK = sum(lik(start:end)); % Minus the log-likelihood.

View File

@ -52,12 +52,10 @@ function [LIK, lik] = DiffuseLikelihoodH1_Z(T,Z,R,Q,H,Pinf,Pstar,Y,start)
dF = 1;
QQ = R*Q*transpose(R);
t = 0;
lik = zeros(smpl+1,1);
lik = zeros(smpl,1);
LIK = Inf;
lik(smpl+1) = smpl*pp*log(2*pi);
notsteady = 1;
crit = options_.kalman_tol;
reste = 0;
while rank(Pinf,crit) & t < smpl
t = t+1;
v = Y(:,t)-Z*a;
@ -118,14 +116,17 @@ function [LIK, lik] = DiffuseLikelihoodH1_Z(T,Z,R,Q,H,Pinf,Pstar,Y,start)
error(['The variance of the forecast error remains singular until the' ...
'end of the sample'])
end
reste = smpl-t;
while t < smpl
t = t+1;
v = Y(:,t)-Z*a;
a = T*(a+K*v);
lik(t) = v'*iF*v;
if t < smpl
t0 = t+1;
while t < smpl
t = t+1;
v = Y(:,t)-Z*a;
a = T*(a+K*v);
lik(t) = v'*iF*v;
end
lik(t0:smpl) = lik(t0:smpl) + log(dF);
end
lik(t) = lik(t) + reste*log(dF);
% adding log-likelihhod constants
lik = (lik + pp*log(2*pi))/2;
LIK = .5*(sum(lik(start:end))-(start-1)*lik(smpl+1)/smpl);% Minus the log-likelihood.
LIK = sum(lik(start:end)); % Minus the log-likelihood.