Make sure non_linear_dsge_likelihood.m and dsge_var_likelihood.m return correct error codes if prior or likelihood are Inf or NaN

Closes #284
time-shift
Johannes Pfeifer 2015-05-09 08:03:12 +02:00
parent 3bcb89bd72
commit 481c470ac9
2 changed files with 45 additions and 1 deletions

View File

@ -239,10 +239,38 @@ else% Evaluation of the likelihood of the dsge-var model when the dsge prior wei
lik = .5*lik;% Minus likelihood
end
if isnan(lik)
info = 45;
fval = objective_function_penalty_base + 100;
exit_flag = 0;
return
end
if imag(lik)~=0
info = 46;
fval = objective_function_penalty_base + 100;
exit_flag = 0;
return
end
% Add the (logged) prior density for the dsge-parameters.
lnprior = priordens(xparam1,BayesInfo.pshape,BayesInfo.p6,BayesInfo.p7,BayesInfo.p3,BayesInfo.p4);
fval = (lik-lnprior);
if isnan(fval)
info = 47;
fval = objective_function_penalty_base + 100;
exit_flag = 0;
return
end
if imag(fval)~=0
info = 48;
fval = objective_function_penalty_base + 100;
exit_flag = 0;
return
end
if (nargout == 8)
if isinf(dsge_prior_weight)
iXX = iGXX;

View File

@ -319,9 +319,11 @@ DynareOptions.warning_for_steadystate = 0;
LIK = feval(DynareOptions.particle.algorithm,ReducedForm,Y,start,DynareOptions);
set_dynare_random_generator_state(s1,s2);
if imag(LIK)
info = 46;
likelihood = objective_function_penalty_base;
exit_flag = 0;
elseif isnan(LIK)
info = 45;
likelihood = objective_function_penalty_base;
exit_flag = 0;
else
@ -332,4 +334,18 @@ DynareOptions.warning_for_steadystate = 1;
% Adds prior if necessary
% ------------------------------------------------------------------------------
lnprior = priordens(xparam1(:),BayesInfo.pshape,BayesInfo.p6,BayesInfo.p7,BayesInfo.p3,BayesInfo.p4);
fval = (likelihood-lnprior);
fval = (likelihood-lnprior);
if isnan(fval)
info = 47;
fval = objective_function_penalty_base + 100;
exit_flag = 0;
return
end
if imag(fval)~=0
info = 48;
fval = objective_function_penalty_base + 100;
exit_flag = 0;
return
end