Factorize estimation: wrapper for tune_mh_jscale

kalman-mex
Willi Mutschler 2023-09-01 23:02:21 +02:00
parent c356db4531
commit 6941bd5516
No known key found for this signature in database
GPG Key ID: 91E724BF17A73F6D
2 changed files with 51 additions and 12 deletions

View File

@ -385,19 +385,10 @@ if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ...
% Tunes the jumping distribution's scale parameter
if options_.mh_tune_jscale.status
if strcmp(options_.posterior_sampler_options.posterior_sampling_method, 'random_walk_metropolis_hastings')
%get invhess in case of use_mh_covariance_matrix
posterior_sampler_options_temp = options_.posterior_sampler_options.current_options;
posterior_sampler_options_temp.invhess = invhess;
posterior_sampler_options_temp = check_posterior_sampler_options(posterior_sampler_options_temp, M_.fname, M_.dname, options_);
options = options_.mh_tune_jscale;
options.rwmh = options_.posterior_sampler_options.rwmh;
options_.mh_jscale = calibrate_mh_scale_parameter(objective_function, ...
posterior_sampler_options_temp.invhess, xparam1, [bounds.lb,bounds.ub], ...
options, dataset_, dataset_info, options_, M_, estim_params_, bayestopt_, bounds, oo_);
clear('posterior_sampler_options_temp','options')
options_.mh_jscale = tune_mcmc_mh_jscale_wrapper(invhess, options_, M_, objective_function, xparam1, bounds,...
dataset_, dataset_info, options_, M_, estim_params_, bayestopt_, bounds, oo_);
bayestopt_.jscale(:) = options_.mh_jscale;
fprintf('mh_jscale has been set equal to %s\n', num2str(options_.mh_jscale))
fprintf('mh_jscale has been set equal to %s\n', num2str(options_.mh_jscale));
else
warning('mh_tune_jscale is only available with Random Walk Metropolis Hastings!')
end

View File

@ -0,0 +1,48 @@
function mh_jscale = tune_mcmc_mh_jscale_wrapper(invhess, options_, M_, objective_function, xparam1, bounds, varargin)
% function mh_jscale = tune_mcmc_mh_jscale_wrapper(invhess, options_, M_, objective_function, xparam1, bounds, varargin)
% -------------------------------------------------------------------------
% Wrapper to call the algorithm to tune the jumping scale parameter for the
% Metropolis-Hastings algorithm; currently only support RW-MH algorithm.
% =========================================================================
% INPUTS
% o invhess: [matrix] jumping covariance matrix
% o options_: [struct] Dynare options
% o M_: [struct] Dynare model structure
% o objective_function: [function handle] objective function
% o xparam1: [vector] vector of estimated parameters at the mode
% o bounds: [struct] structure containing information on bounds
% o varargin: [cell] additional arguments to be passed to the objective function
% -------------------------------------------------------------------------
% OUTPUTS
% o mh_jscale: [double] tuned jumping scale parameter
% -------------------------------------------------------------------------
% This function is called by
% o dynare_estimation_1.m
% -------------------------------------------------------------------------
% Copyright © 2023 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
% =========================================================================
% get invhess in case of use_mh_covariance_matrix
posterior_sampler_options_temp = options_.posterior_sampler_options.current_options;
posterior_sampler_options_temp.invhess = invhess;
posterior_sampler_options_temp = check_posterior_sampler_options(posterior_sampler_options_temp, M_.fname, M_.dname, options_);
opt = options_.mh_tune_jscale;
opt.rwmh = options_.posterior_sampler_options.rwmh;
mh_jscale = calibrate_mh_scale_parameter(objective_function, ...
posterior_sampler_options_temp.invhess, xparam1, [bounds.lb,bounds.ub], ...
opt, varargin{:});