From 4b1e815728ede32aced69185d065ad68d1c4804e Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 31 Oct 2014 11:58:17 +0100 Subject: [PATCH] Always display value of posterior/likelihood at the mode Also clarifies that minus the posterior/likelihood is displayed --- matlab/dynare_estimation_1.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index c30529e9c..d278ce421 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -256,6 +256,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation end [xparam1,fval,exitflag,output,lamdba,grad,hessian_fmincon] = ... fmincon(objective_function,xparam1,[],[],[],[],bounds.lb,bounds.ub,[],optim_options,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); case 2 error('ESTIMATION: mode_compute=2 option (Lester Ingber''s Adaptive Simulated Annealing) is no longer available') case 3 @@ -279,6 +280,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation func = @(x) objective_function(x, dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); [xparam1,fval,exitflag] = fminunc(func,xparam1,optim_options); end + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); case 4 % Set default options. H0 = 1e-4*eye(nx); @@ -316,7 +318,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation [fval,xparam1,grad,hessian_csminwel,itct,fcount,retcodehat] = ... csminwel1(objective_function, xparam1, H0, analytic_grad, crit, nit, numgrad, epsilon, dataset_, dataset_info, options_, M_, estim_params_, bayestopt_,bounds, oo_); % Disp value at the mode. - disp(sprintf('Objective function at mode: %f',fval)) + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); case 5 if isfield(options_,'hess') flag = options_.hess; @@ -361,6 +363,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation end parameter_names = bayestopt_.name; save([M_.fname '_mode.mat'],'xparam1','hh','parameter_names'); + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); case 6 % Set default options gmhmaxlikOptions = options_.gmhmaxlik; @@ -479,7 +482,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation skipline() disp(['Optimal value of the scale parameter = ' num2str(Scale)]) skipline() - disp(['Final value of the log posterior (or likelihood): ' num2str(fval)]) + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); skipline() parameter_names = bayestopt_.name; save([M_.fname '_mode.mat'],'xparam1','hh','parameter_names'); @@ -495,6 +498,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); end [xparam1,fval,exitflag] = fminsearch(objective_function,xparam1,optim_options,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); case 8 % Dynare implementation of the simplex algorithm. simplexOptions = options_.simplex; @@ -520,6 +524,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation end end [xparam1,fval,exitflag] = simplex_optimization_routine(objective_function,xparam1,simplexOptions,bayestopt_.name,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); case 9 % Set defaults H0 = 1e-4*ones(nx,1); @@ -546,7 +551,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation warning('off','CMAES:InitialSigma'); [x, fval, COUNTEVAL, STOPFLAG, OUT, BESTEVER] = cmaes(func2str(objective_function),xparam1,H0,cmaesOptions,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); xparam1=BESTEVER.x; - disp(sprintf('\n Objective function at mode: %f',fval)) + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', BESTEVER.f); case 10 simpsaOptions = options_.simpsa; if isfield(options_,'optim_opt') @@ -576,6 +581,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation simpsaOptionsList = options2cell(simpsaOptions); simpsaOptions = simpsaset(simpsaOptionsList{:}); [xparam1, fval, exitflag] = simpsa(func2str(objective_function),xparam1,bounds.lb,bounds.ub,simpsaOptions,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); case 11 options_.cova_compute = 0 ; [xparam1,stdh,lb_95,ub_95,med_param] = online_auxiliary_filter(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_) ; @@ -585,6 +591,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation myoptions(3)=1e-6; %accuracy of function (see Solvopt p.29) myoptions(5)= 1.0; [xparam1,fval]=solvopt(xparam1,objective_function,[],myoptions,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); case 102 %simulating annealing % LB=zeros(size(xparam1))-20; @@ -622,9 +629,11 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation [xparam1, fval, nacc, nfcnev, nobds, ier, t, vm] = sa(objective_function,xparam1,maxy,rt_,epsilon,ns,nt ... ,neps,maxevl,LB,UB,c,idisp ,t,vm,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); otherwise if ischar(options_.mode_compute) [xparam1, fval, retcode ] = feval(options_.mode_compute,objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); else error(['dynare_estimation:: mode_compute = ' int2str(options_.mode_compute) ' option is unknown!']) end