various bugs

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@666 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
adjemian 2006-03-10 13:04:50 +00:00
parent 5f4511ef16
commit 3a4db43a83
4 changed files with 36 additions and 18 deletions

View File

@ -1,4 +1,4 @@
function PosteriorIRF() function PosteriorIRF(type)
% stephane.adjemian@ens.fr [09-25-2005] % stephane.adjemian@ens.fr [09-25-2005]
global options_ estim_params_ oo_ M_ global options_ estim_params_ oo_ M_
nvx = estim_params_.nvx; nvx = estim_params_.nvx;
@ -11,16 +11,32 @@ offset = npar-np;
%% %%
MaxNumberOfPlotPerFigure = 9;% The square root must be an integer! MaxNumberOfPlotPerFigure = 9;% The square root must be an integer!
nn = sqrt(MaxNumberOfPlotPerFigure); nn = sqrt(MaxNumberOfPlotPerFigure);
%%
MhDirectoryName = CheckPath('Output');
DirectoryName = CheckPath('Output'); DirectoryName = CheckPath('Output');
if strcmpi(type,'posterior')
MhDirectoryName = CheckPath('metropolis');
else
MhDirectoryName = CheckPath('prior');
end
MAX_nirfs = ceil(options_.MaxNumberOfBytes/(options_.irf*length(oo_.steady_state)*M_.exo_nbr)/8)+50; MAX_nirfs = ceil(options_.MaxNumberOfBytes/(options_.irf*length(oo_.steady_state)*M_.exo_nbr)/8)+50;
%%
if strcmpi(type,'posterior')
load([ MhDirectoryName '/' M_.fname '_mh_history'])
TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
else% type = 'prior'
NumberOfDraws = 500;
end
B = min([round(.5*NumberOfDraws),500]); B = min([round(.5*NumberOfDraws),500]);
%%
irun = 0; irun = 0;
ifil = 1; ifil = 1;
h = waitbar(0,'Bayesian IRFs...'); if strcmpi(type,'posterior')
h = waitbar(0,'Bayesian (posterior) IRFs...');
else
h = waitbar(0,'Bayesian (prior) IRFs...');
end
if B >= MAX_nirfs if B >= MAX_nirfs
stock_irf = zeros(options_.irf,M_.endo_nbr,M_.exo_nbr,MAX_nirfs); stock_irf = zeros(options_.irf,M_.endo_nbr,M_.exo_nbr,MAX_nirfs);
else else
@ -28,7 +44,7 @@ else
end end
for b=1:B for b=1:B
irun = irun+1; irun = irun+1;
deep = GetOneDraw('posterior'); deep = GetOneDraw(type);
set_parameters(deep); set_parameters(deep);
dr = resol(oo_.steady_state,0); dr = resol(oo_.steady_state,0);
SS(M_.exo_names_orig_ord,M_.exo_names_orig_ord) = M_.Sigma_e+1e-14*eye(M_.exo_nbr); SS(M_.exo_names_orig_ord,M_.exo_names_orig_ord) = M_.Sigma_e+1e-14*eye(M_.exo_nbr);

View File

@ -665,8 +665,9 @@ if (any(bayestopt_.pshape >0 ) & options_.mh_replic) | ...
%% %%
GetPosteriorParametersStatistics; GetPosteriorParametersStatistics;
PlotPosteriorDistributions; PlotPosteriorDistributions;
metropolis_draw(1);% Initialization.
if options_.bayesian_irf if options_.bayesian_irf
PosteriorIRF; PosteriorIRF('posterior');
end end
return return

View File

@ -1,6 +1,6 @@
function xparam=metropolis_draw(init) function xparams=metropolis_draw(init)
global options_ estim_params_ global options_ estim_params_ M_
persistent mh_nblck NumberofDraws fname FirstLine FirstMhFile MAX_nruns persistent mh_nblck NumberOfDraws fname FirstLine FirstMhFile MAX_nruns
if init if init
nvx = estim_params_.nvx; nvx = estim_params_.nvx;
@ -14,12 +14,12 @@ function xparam=metropolis_draw(init)
load([ fname '_mh_history']); load([ fname '_mh_history']);
FirstMhFile = record.KeepedDraws.FirstMhFile; FirstMhFile = record.KeepedDraws.FirstMhFile;
FirstLine = record.KeepedDraws.FirstLine; FirstLine = record.KeepedDraws.FirstLine;
TotalNumberOfMhFiles = sum(record.MhDraws(:,2)); LastMhFile = TotalNumberOfMhFiles; TotalNumberOfMhFiles = sum(record.MhDraws(:,2));
LastMhFile = TotalNumberOfMhFiles;
TotalNumberOfMhDraws = sum(record.MhDraws(:,1)); TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop* ... NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
TotalNumberOfMhDraws);
MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8); MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8);
mh_nblck = options_.nblck; mh_nblck = options_.mh_nblck;
return return
end end

View File

@ -7,6 +7,7 @@ function set_parameters(xparam1)
Sigma_e = M_.Sigma_e; Sigma_e = M_.Sigma_e;
if nvx if nvx
offset = nvx;
var_exo = estim_params_.var_exo; var_exo = estim_params_.var_exo;
for i=1:nvx for i=1:nvx
k = var_exo(i,1); k = var_exo(i,1);
@ -27,7 +28,7 @@ function set_parameters(xparam1)
if np if np
offset = offset+estim_params_.ncx+estim_params_.ncn; offset = offset+estim_params_.ncx+estim_params_.ncn;
M_.params(estim_params_.param_vals(:,1)) = deep(offset+1:end); M_.params(estim_params_.param_vals(:,1)) = xparam1(offset+1:end);
end end
M_.Sigma_e = Sigma_e; M_.Sigma_e = Sigma_e;