diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index b4ff3a045ad9a412d7fbacbf1c6af06956c2781f..79087715a052b2e4b4104b02d5bc1f38c46b3e9e 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -352,6 +352,7 @@ end oo_.posterior.optimization.mode = xparam1; oo_.posterior.optimization.Variance = []; +invhess=[]; if ~options_.mh_posterior_mode_estimation if options_.cova_compute invhess = inv(hh); @@ -417,15 +418,17 @@ if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ... end % runs MCMC if options_.mh_replic - if options_.load_mh_file && options_.use_mh_covariance_matrix - invhess = compute_mh_covariance_matrix; - end ana_deriv_old = options_.analytic_derivation; options_.analytic_derivation = 0; - if options_.cova_compute + posterior_sampler_options = options_.posterior_sampler_options; + posterior_sampler_options.bounds = bounds; + posterior_sampler_options.invhess = invhess; + [posterior_sampler_options, options_] = check_posterior_sampler_options(posterior_sampler_options, options_); + if strcmpi(options_.posterior_sampling_method,'adaptive_metropolis_hastings'), % keep old form only for this ... + invhess = posterior_sampler_options.invhess; feval(options_.posterior_sampling_method,objective_function,options_.proposal_distribution,xparam1,invhess,bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_); else - error('I Cannot start the MCMC because the Hessian of the posterior kernel at the mode was not computed.') + posterior_sampler(objective_function,options_.proposal_distribution,xparam1,posterior_sampler_options,bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_); end options_.analytic_derivation = ana_deriv_old; end diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index c7d32065c468b56f47f0c1a2c0f302c55c68fb5a..b3ce3af9e2320dffadb766df2ae171595f111190 100644 --- a/matlab/dynare_estimation_init.m +++ b/matlab/dynare_estimation_init.m @@ -590,3 +590,29 @@ else estim_params_.Sigma_e_entries_to_check_for_positive_definiteness=Sigma_e_non_zero_rows; end + +% slice posterior sampler does not require mode or hessian to run +if strcmp(options_.posterior_sampling_method,'slice') + options_.mh_posterior_mode_estimation=1; + options_.posterior_sampler_options = set_default_option(options_.posterior_sampler_options,'slice_initialize_with_mode',0); + + if options_.posterior_sampler_options.slice_initialize_with_mode + if (isequal(options_.mode_compute,0) && isempty(options_.mode_file) ) + skipline() + disp('You have specified the option "slice_initialize_with_mode"') + disp('to initialize the slice sampler using mode information') + disp('but no mode file nor posterior maximization is selected,') + error('The option "slice_initialize_with_mode" is inconsistent with mode_compute=0 or empty mode_file.') + else + options_.mh_posterior_mode_estimation=0; + end + end + + if any(isinf(bounds.lb)) || any(isinf(bounds.ub)), + skipline() + disp('some priors are unbounded and prior_trunc is set to zero') + error('The option "slice" is inconsistent with prior_trunc=0.') + end + +end +