Commit 567c5bcb authored by Stéphane Adjemian (Karaba)'s avatar Stéphane Adjemian (Karaba)
Browse files

Fixed bug in the initialization of the metropolis when mode_compute=6 was...

Fixed bug in the initialization of the metropolis when mode_compute=6 was previously used (so that we have an optimal mh scale factor)
and option load_mh_file is used. After the (stochastic) optimization, the optimal value of the scale parameter is saved in a mat file.
parent 4881b8c3
......@@ -389,6 +389,12 @@ if options_.mode_compute == 0 && length(options_.mode_file) == 0 && options_.mh_
return;
end
if options_.mode_compute>0 || options_.mode_compute==6
% Erase previously computed optimal mh scale parameter.
delete([M_.fname '_optimal_mh_scale_parameter.mat'])
end
%% Estimation of the posterior mode or likelihood mode
if options_.mode_compute > 0 && ~options_.mh_posterior_mode_estimation
if ~options_.dsge_var
......@@ -550,6 +556,7 @@ if options_.mode_compute > 0 && ~options_.mh_posterior_mode_estimation
end
hh = inv(PostVar);
save([M_.fname '_mode.mat'],'xparam1','hh');
save([M_.fname '_optimal_mh_scale_parameter.mat'],'Scale');
bayestopt_.jscale = ones(length(xparam1),1)*Scale;%??!
end
case 7
......
......@@ -94,6 +94,9 @@ else
if (options_.load_mh_file~=0) & any(fline>1) ,
NamFileInput(length(NamFileInput)+1,:)={[M_.dname '/metropolis/'],[ModelName '_mh' int2str(NewFile(1)) '_blck*.mat']};
end
if exist([ModelName '_optimal_mh_scale_parameter.mat'])
NamFileInput(length(NamFileInput)+1,:)={'',[ModelName '_optimal_mh_scale_parameter.mat']};
end
% from where to get back results
% NamFileOutput(1,:) = {[M_.dname,'/metropolis/'],'*.*'};
......
......@@ -88,7 +88,16 @@ end
%%%% NOW i run the (nblck-fblck+1) metropolis-hastings chains
%%%%
proposal_covariance = d * diag(bayestopt_.jscale);
if any(isnan(bayestopt_.jscale))
if exist([ModelName '_optimal_mh_scale_parameter.mat'])% This file is created by mode_compute=6.
load([ModelName '_optimal_mh_scale_parameter'])
proposal_covariance = d*Scale;
else
error('mh:: Something is wrong. I can''t figure out the value of the scale parameter.')
end
else
proposal_covariance = d*diag(bayestopt_.jscale);
end
jloop=0;
......
......@@ -113,6 +113,9 @@ else
if (options_.load_mh_file~=0) & any(fline>1) ,
NamFileInput(length(NamFileInput)+1,:)={[M_.dname '/metropolis/'],[ModelName '_mh' int2str(NewFile(1)) '_blck*.mat']};
end
if exist([ModelName '_optimal_mh_scale_parameter.mat'])
NamFileInput(length(NamFileInput)+1,:)={'',[ModelName '_optimal_mh_scale_parameter.mat']};
end
% from where to get back results
% NamFileOutput(1,:) = {[M_.dname,'/metropolis/'],'*.*'};
......
......@@ -119,7 +119,18 @@ end
%%%% NOW i run the (nblck-fblck+1) metropolis-hastings chains
%%%%
proposal_covariance = d*diag(bayestopt_.jscale);
if any(isnan(bayestopt_.jscale))
if exist([ModelName '_optimal_mh_scale_parameter.mat'])% This file is created by mode_compute=6.
load([ModelName '_optimal_mh_scale_parameter'])
proposal_covariance = d*Scale;
else
error('mh:: Something is wrong. I can''t figure out the value of the scale parameter.')
end
else
proposal_covariance = d*diag(bayestopt_.jscale);
end
jloop=0;
......
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