Change minus_logged_prior_density.m to reflect new treatment of estimated and calibrated covariances

time-shift
Johannes Pfeifer 2014-01-28 18:42:47 +01:00
parent d5446e734a
commit c2345fd23b
1 changed files with 29 additions and 17 deletions

View File

@ -66,34 +66,46 @@ Q = DynareModel.Sigma_e;
H = DynareModel.H; H = DynareModel.H;
% Test if Q is positive definite. % Test if Q is positive definite.
if EstimatedParams.ncx if ~issquare(Q) || EstimatedParams.ncx || isfield(EstimatedParams,'calibrated_covariances')
% Try to compute the cholesky decomposition of Q (possible iff Q is positive definite) % Try to compute the cholesky decomposition of Q (possible iff Q is positive definite)
[CholQ,testQ] = chol(Q); [Q_is_positive_definite, penalty] = ispd(Q);
if testQ if ~Q_is_positive_definite
% 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. % 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.
a = diag(eig(Q)); fval = objective_function_penalty_base+penalty;
k = find(a < 0); exit_flag = 0;
if k > 0 info = 43;
fval = objective_function_penalty_base+sum(-a(k)); return
end
if isfield(EstimatedParams,'calibrated_covariances')
correct_flag=check_consistency_covariances(Q);
if ~correct_flag
penalty = sum(Q(EstimatedParams.calibrated_covariances.position).^2);
fval = objective_function_penalty_base+penalty;
exit_flag = 0; exit_flag = 0;
info = 43; info = 71;
return return
end end
end end
end end
% Test if H is positive definite. % Test if H is positive definite.
if EstimatedParams.ncn if ~issquare(H) || EstimatedParams.ncn || isfield(EstimatedParams,'calibrated_covariances_ME')
% 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
% 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. % 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.
a = diag(eig(H)); fval = objective_function_penalty_base+penalty;
k = find(a < 0); exit_flag = 0;
if k > 0 info = 44;
fval = objective_function_penalty_base+sum(-a(k)); return
end
if isfield(EstimatedParams,'calibrated_covariances_ME')
correct_flag=check_consistency_covariances(H);
if ~correct_flag
penalty = sum(H(EstimatedParams.calibrated_covariances_ME.position).^2);
fval = objective_function_penalty_base+penalty;
exit_flag = 0; exit_flag = 0;
info = 44; info = 72;
return return
end end
end end