Allow sampler specific options via optim;

bug fixes on options logic
time-shift
Marco Ratto 2016-04-20 12:45:09 +02:00 committed by Johannes Pfeifer
parent 6aa65e2a6a
commit 0c01565298
1 changed files with 28 additions and 7 deletions

View File

@ -41,7 +41,7 @@ if ~strcmp(posterior_sampler_options.posterior_sampling_method,'slice')
error('I Cannot start the MCMC because the Hessian of the posterior kernel at the mode was not computed.') error('I Cannot start the MCMC because the Hessian of the posterior kernel at the mode was not computed.')
end end
if options_.load_mh_file && options_.use_mh_covariance_matrix, if options_.load_mh_file && options_.use_mh_covariance_matrix,
invhess = compute_mh_covariance_matrix; [junk, invhess] = compute_mh_covariance_matrix;
posterior_sampler_options.invhess = invhess; posterior_sampler_options.invhess = invhess;
end end
posterior_sampler_options.parallel_bar_refresh_rate=50; posterior_sampler_options.parallel_bar_refresh_rate=50;
@ -61,7 +61,7 @@ if strcmp(options_.posterior_sampling_method,'slice')
posterior_sampler_options.save_tmp_file=1; posterior_sampler_options.save_tmp_file=1;
posterior_sampler_options = set_default_option(posterior_sampler_options,'rotated',0); posterior_sampler_options = set_default_option(posterior_sampler_options,'rotated',0);
posterior_sampler_options = set_default_option(posterior_sampler_options,'slice_initialize_with_mode',0); posterior_sampler_options = set_default_option(posterior_sampler_options,'slice_initialize_with_mode',0);
posterior_sampler_options = set_default_option(posterior_sampler_options,'use_slice_covariance_matrix',0); posterior_sampler_options = set_default_option(posterior_sampler_options,'use_mh_covariance_matrix',0);
posterior_sampler_options = set_default_option(posterior_sampler_options,'WR',[]); posterior_sampler_options = set_default_option(posterior_sampler_options,'WR',[]);
if ~isfield(posterior_sampler_options,'mode'), if ~isfield(posterior_sampler_options,'mode'),
posterior_sampler_options.mode = []; posterior_sampler_options.mode = [];
@ -70,7 +70,28 @@ if strcmp(options_.posterior_sampling_method,'slice')
end end
posterior_sampler_options = set_default_option(posterior_sampler_options,'mode_files',[]); posterior_sampler_options = set_default_option(posterior_sampler_options,'mode_files',[]);
posterior_sampler_options = set_default_option(posterior_sampler_options,'W1',0.8*(bounds.ub-bounds.lb)); posterior_sampler_options = set_default_option(posterior_sampler_options,'W1',0.8*(bounds.ub-bounds.lb));
if ~isempty(options_.optim_opt)
options_list = read_key_value_string(options_.optim_opt);
for i=1:rows(options_list)
switch options_list{i,1}
case 'rotated'
posterior_sampler_options.rotated = options_list{i,2};
case 'mode'
posterior_sampler_options.mode = options_list{i,2};
case 'mode_files'
posterior_sampler_options.mode_files = options_list{i,2};
case 'slice_initialize_with_mode'
posterior_sampler_options.slice_initialize_with_mode = options_list{i,2};
case 'initial_step_size'
posterior_sampler_options.W1 = options_list{i,2}*(bounds.ub-bounds.lb);
case 'use_mh_covariance_matrix'
posterior_sampler_options.use_mh_covariance_matrix = options_list{i,2};
otherwise
warning(['slice_sampler: Unknown option (' options_list{i,1} ')!'])
end
end
end
if options_.load_mh_file, if options_.load_mh_file,
posterior_sampler_options.slice_initialize_with_mode = 0; posterior_sampler_options.slice_initialize_with_mode = 0;
else else
@ -80,9 +101,9 @@ if strcmp(options_.posterior_sampling_method,'slice')
end end
if posterior_sampler_options.rotated, if posterior_sampler_options.rotated,
if isempty(posterior_sampler_options.mode_files) && ~isfield(posterior_sampler_options,'mode'), % rotated unimodal if isempty(posterior_sampler_options.mode_files) && isempty(posterior_sampler_options.mode), % rotated unimodal
if ~options_.cova_compute && ~(options_.load_mh_file && options_.use_mh_covariance_matrix) if ~options_.cova_compute && ~(options_.load_mh_file && posterior_sampler_options.use_mh_covariance_matrix)
skipline() skipline()
disp('I cannot start rotated slice sampler because') disp('I cannot start rotated slice sampler because')
disp('there is no previous MCMC to load ') disp('there is no previous MCMC to load ')
@ -92,8 +113,8 @@ if strcmp(options_.posterior_sampling_method,'slice')
if isempty(invhess) if isempty(invhess)
error('oops! This error should not occur, please contact developers.') error('oops! This error should not occur, please contact developers.')
end end
if options_.load_mh_file && posterior_sampler_options.use_slice_covariance_matrix, if options_.load_mh_file && posterior_sampler_options.use_mh_covariance_matrix,
invhess = compute_mh_covariance_matrix; [junk, invhess] = compute_mh_covariance_matrix;
posterior_sampler_options.invhess = invhess; posterior_sampler_options.invhess = invhess;
end end
[V1 D]=eig(invhess); [V1 D]=eig(invhess);