Commit 6d03f78e authored by Marco Ratto's avatar Marco Ratto
Browse files

New option to slice that runs optimiser steps instead of slice draws: with...

New option to slice that runs optimiser steps instead of slice draws: with this one can run optimisers in parallel, starting from different random locations.
parent 463516c8
......@@ -299,6 +299,12 @@ if init
case 'save_tmp_file'
posterior_sampler_options.save_tmp_file = options_list{i,2};
case 'maximize'
posterior_sampler_options.maximize = options_list{i,2};
case 'mode_compute'
posterior_sampler_options.mode_compute = options_list{i,2};
otherwise
warning(['slice_sampler: Unknown option (' options_list{i,1} ')!'])
end
......
......@@ -450,6 +450,8 @@ options_.posterior_sampler_options.slice.use_mh_covariance_matrix=0;
options_.posterior_sampler_options.slice.WR=[];
options_.posterior_sampler_options.slice.mode_files=[];
options_.posterior_sampler_options.slice.mode=[];
options_.posterior_sampler_options.slice.maximize=0;
options_.posterior_sampler_options.slice.mode_compute=5;
options_.posterior_sampler_options.slice.initial_step_size=0.8;
options_.posterior_sampler_options.slice.save_tmp_file=1;
% Independent Metropolis-Hastings
......
......@@ -50,8 +50,51 @@ mh_bounds = sampler_options.bounds;
switch posterior_sampling_method
case 'slice'
if ~sampler_options.maximize
[par, logpost, neval] = slice_sampler(TargetFun,last_draw, [mh_bounds.lb mh_bounds.ub], sampler_options,varargin{:});
accepted = 1;
else
options_=varargin{3};
bayestopt_=varargin{6};
options_.mode_compute = sampler_options.mode_compute;
if options_.mode_compute==5
%get whether outer product Hessian is requested
newratflag=[];
if ~isempty(options_.optim_opt)
options_list = read_key_value_string(options_.optim_opt);
for i=1:rows(options_list)
if strcmp(options_list{i,1},'Hessian')
newratflag=options_list{i,2};
end
end
end
if options_.analytic_derivation
options_analytic_derivation_old = options_.analytic_derivation;
options_.analytic_derivation = -1;
if ~isempty(newratflag) && newratflag~=0 %numerical hessian explicitly specified
error('newrat: analytic_derivation is incompatible with numerical Hessian.')
else %use default
newratflag=0; %exclude DYNARE numerical hessian
end
elseif ~options_.analytic_derivation
if isempty(newratflag)
newratflag=options_.newrat.hess; %use default numerical dynare hessian
end
end
end
options_.newrat.Save_files = sampler_options.curr_block;
[par, fval, exitflag, hess_mat_optimizer, options_, Scale, new_rat_hess_info] = ...
dynare_minimize_objective(TargetFun,last_draw(:),options_.mode_compute,options_,[mh_bounds.lb mh_bounds.ub],bayestopt_.name,bayestopt_,[], ...
varargin{:}); %inputs for objective
logpost = -fval;
accepted = 1;
neval = 1;
end
case 'random_walk_metropolis_hastings'
neval = 1;
ProposalFun = sampler_options.proposal_distribution;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment