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.time-shift
parent
4881b8c3f9
commit
567c5bcb1f
|
@ -389,6 +389,12 @@ if options_.mode_compute == 0 && length(options_.mode_file) == 0 && options_.mh_
|
||||||
return;
|
return;
|
||||||
end
|
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
|
%% Estimation of the posterior mode or likelihood mode
|
||||||
if options_.mode_compute > 0 && ~options_.mh_posterior_mode_estimation
|
if options_.mode_compute > 0 && ~options_.mh_posterior_mode_estimation
|
||||||
if ~options_.dsge_var
|
if ~options_.dsge_var
|
||||||
|
@ -550,6 +556,7 @@ if options_.mode_compute > 0 && ~options_.mh_posterior_mode_estimation
|
||||||
end
|
end
|
||||||
hh = inv(PostVar);
|
hh = inv(PostVar);
|
||||||
save([M_.fname '_mode.mat'],'xparam1','hh');
|
save([M_.fname '_mode.mat'],'xparam1','hh');
|
||||||
|
save([M_.fname '_optimal_mh_scale_parameter.mat'],'Scale');
|
||||||
bayestopt_.jscale = ones(length(xparam1),1)*Scale;%??!
|
bayestopt_.jscale = ones(length(xparam1),1)*Scale;%??!
|
||||||
end
|
end
|
||||||
case 7
|
case 7
|
||||||
|
|
|
@ -94,6 +94,9 @@ else
|
||||||
if (options_.load_mh_file~=0) & any(fline>1) ,
|
if (options_.load_mh_file~=0) & any(fline>1) ,
|
||||||
NamFileInput(length(NamFileInput)+1,:)={[M_.dname '/metropolis/'],[ModelName '_mh' int2str(NewFile(1)) '_blck*.mat']};
|
NamFileInput(length(NamFileInput)+1,:)={[M_.dname '/metropolis/'],[ModelName '_mh' int2str(NewFile(1)) '_blck*.mat']};
|
||||||
end
|
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
|
% from where to get back results
|
||||||
% NamFileOutput(1,:) = {[M_.dname,'/metropolis/'],'*.*'};
|
% NamFileOutput(1,:) = {[M_.dname,'/metropolis/'],'*.*'};
|
||||||
|
|
|
@ -88,7 +88,16 @@ end
|
||||||
%%%% NOW i run the (nblck-fblck+1) metropolis-hastings chains
|
%%%% NOW i run the (nblck-fblck+1) metropolis-hastings chains
|
||||||
%%%%
|
%%%%
|
||||||
|
|
||||||
|
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);
|
proposal_covariance = d*diag(bayestopt_.jscale);
|
||||||
|
end
|
||||||
|
|
||||||
jloop=0;
|
jloop=0;
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,9 @@ else
|
||||||
if (options_.load_mh_file~=0) & any(fline>1) ,
|
if (options_.load_mh_file~=0) & any(fline>1) ,
|
||||||
NamFileInput(length(NamFileInput)+1,:)={[M_.dname '/metropolis/'],[ModelName '_mh' int2str(NewFile(1)) '_blck*.mat']};
|
NamFileInput(length(NamFileInput)+1,:)={[M_.dname '/metropolis/'],[ModelName '_mh' int2str(NewFile(1)) '_blck*.mat']};
|
||||||
end
|
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
|
% from where to get back results
|
||||||
% NamFileOutput(1,:) = {[M_.dname,'/metropolis/'],'*.*'};
|
% NamFileOutput(1,:) = {[M_.dname,'/metropolis/'],'*.*'};
|
||||||
|
|
|
@ -119,7 +119,18 @@ end
|
||||||
%%%% NOW i run the (nblck-fblck+1) metropolis-hastings chains
|
%%%% NOW i run the (nblck-fblck+1) metropolis-hastings chains
|
||||||
%%%%
|
%%%%
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
proposal_covariance = d*diag(bayestopt_.jscale);
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
jloop=0;
|
jloop=0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue