Factorized code using ispd routine.

time-shift
Stéphane Adjemian (Charybdis) 2013-06-20 12:59:01 +02:00
parent 3701707e63
commit 268095276c
2 changed files with 17 additions and 30 deletions

View File

@ -224,10 +224,9 @@ if ~isinf(dsge_prior_weight)% Evaluation of the likelihood of the dsge-var model
tmp1 = dsge_prior_weight*DynareDataset.info.ntobs*GYX + mYX; tmp1 = dsge_prior_weight*DynareDataset.info.ntobs*GYX + mYX;
tmp2 = inv(dsge_prior_weight*DynareDataset.info.ntobs*GXX+mXX); tmp2 = inv(dsge_prior_weight*DynareDataset.info.ntobs*GXX+mXX);
SIGMAu = tmp0 - tmp1*tmp2*tmp1'; clear('tmp0'); SIGMAu = tmp0 - tmp1*tmp2*tmp1'; clear('tmp0');
if ~ispd(SIGMAu) [SIGMAu_is_positive_definite, penalty] = ispd(SIGMAu)
v = diag(SIGMAu); if ~SIGMAu_is_positive_definite
k = find(v<0); fval = objective_function_penalty_base + penalty;
fval = objective_function_penalty_base + sum(v(k).^2);
info = 52; info = 52;
exit_flag = 0; exit_flag = 0;
return; return;

View File

@ -206,36 +206,24 @@ Q = Model.Sigma_e;
H = Model.H; H = Model.H;
% Test if Q is positive definite. % Test if Q is positive definite.
if EstimatedParameters.ncx if ~issquare(Q) && EstimatedParameters.ncx
% Try to compute the cholesky decomposition of Q (possible iff Q is positive definite) [Q_is_positive_definite, penalty] = ispd(Q);
[CholQ,testQ] = chol(Q); if ~Q_is_positive_definite
if testQ fval = objective_function_penalty_base+penalty;
% The variance-covariance matrix of the structural innovations is not definite positive. We have to compute the eigenvalues of this matrix in order to build the endogenous penalty. exit_flag = 0;
a = diag(eig(Q)); info = 43;
k = find(a < 0); return
if k > 0
fval = objective_function_penalty_base+sum(-a(k));
exit_flag = 0;
info = 43;
return
end
end end
end end
% Test if H is positive definite. % Test if H is positive definite.
if EstimatedParameters.ncn if ~issquare(H) && EstimatedParameters.ncn
% Try to compute the cholesky decomposition of H (possible iff H is positive definite) [H_is_positive_definite, penalty] = ispd(H);
[CholH,testH] = chol(H); if ~H_is_positive_definite
if testH fval = objective_function_penalty_base+penalty;
% The variance-covariance matrix of the measurement errors is not definite positive. We have to compute the eigenvalues of this matrix in order to build the endogenous penalty. exit_flag = 0;
a = diag(eig(H)); info = 44;
k = find(a < 0); return
if k > 0
fval = objective_function_penalty_base+sum(-a(k));
exit_flag = 0;
info = 44;
return
end
end end
end end