load_mh_file: recompute results by default and load on request
Prevents general overwriting of results in oo_ and having stale resultstime-shift
parent
5707b4d965
commit
352786c2b4
|
@ -5478,6 +5478,12 @@ provide the @code{mode_file} used in the previous
|
||||||
run or the same user-defined @code{mcmc_jumping_covariance} when using this option.
|
run or the same user-defined @code{mcmc_jumping_covariance} when using this option.
|
||||||
Shouldn't be used together with @code{mh_recover}.
|
Shouldn't be used together with @code{mh_recover}.
|
||||||
|
|
||||||
|
@item load_results_after_load_mh
|
||||||
|
@anchor{load_results_after_load_mh} This option is available when loading a previous MCMC run without
|
||||||
|
adding additional draws, i.e. when @code{load_mh_file} is specified with @code{mh_replic=0}. It tells Dynare
|
||||||
|
to load the previously computed convergence diagnostics, marginal data density, and posterior statistics from an
|
||||||
|
existing @code{_results}-file instead of recomputing them.
|
||||||
|
|
||||||
@item optim = (@var{NAME}, @var{VALUE}, ...)
|
@item optim = (@var{NAME}, @var{VALUE}, ...)
|
||||||
@anchor{optim}
|
@anchor{optim}
|
||||||
A list of @var{NAME} and @var{VALUE} pairs. Can be used to set options for the optimization routines. The set of available options depends on the selected optimization routine (ie on the value of option @ref{mode_compute}):
|
A list of @var{NAME} and @var{VALUE} pairs. Can be used to set options for the optimization routines. The set of available options depends on the selected optimization routine (ie on the value of option @ref{mode_compute}):
|
||||||
|
|
|
@ -430,12 +430,21 @@ if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ...
|
||||||
options_.qz_criterium=qz_criterium_old;
|
options_.qz_criterium=qz_criterium_old;
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
if ~options_.nodiagnostic && options_.mh_replic>0
|
%get stored results if required
|
||||||
oo_= McMCDiagnostics(options_, estim_params_, M_,oo_);
|
if options_.load_mh_file && options_.load_results_after_load_mh
|
||||||
|
oo_load_mh=load([M_.fname '_results'],'oo_');
|
||||||
|
end
|
||||||
|
if ~options_.nodiagnostic
|
||||||
|
if (options_.mh_replic>0 || (options_.load_mh_file && ~options_.load_results_after_load_mh))
|
||||||
|
oo_= McMCDiagnostics(options_, estim_params_, M_,oo_);
|
||||||
|
elseif options_.load_mh_file && options_.load_results_after_load_mh
|
||||||
|
if isfield(oo_load_mh.oo_,'convergence')
|
||||||
|
oo_.convergence=oo_load_mh.oo_.convergence;
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
%% Estimation of the marginal density from the Mh draws:
|
%% Estimation of the marginal density from the Mh draws:
|
||||||
if options_.mh_replic
|
if options_.mh_replic || (options_.load_mh_file && ~options_.load_results_after_load_mh)
|
||||||
[marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_, bayestopt_);
|
[marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_, bayestopt_);
|
||||||
% Store posterior statistics by parameter name
|
% Store posterior statistics by parameter name
|
||||||
oo_ = GetPosteriorParametersStatistics(estim_params_, M_, options_, bayestopt_, oo_, pnames);
|
oo_ = GetPosteriorParametersStatistics(estim_params_, M_, options_, bayestopt_, oo_, pnames);
|
||||||
|
@ -446,8 +455,25 @@ if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ...
|
||||||
% a matrix
|
% a matrix
|
||||||
[oo_.posterior.metropolis.mean,oo_.posterior.metropolis.Variance] ...
|
[oo_.posterior.metropolis.mean,oo_.posterior.metropolis.Variance] ...
|
||||||
= GetPosteriorMeanVariance(M_,options_.mh_drop);
|
= GetPosteriorMeanVariance(M_,options_.mh_drop);
|
||||||
else
|
elseif options_.load_mh_file && options_.load_results_after_load_mh
|
||||||
load([M_.fname '_results'],'oo_');
|
%% load fields from previous MCMC run stored in results-file
|
||||||
|
field_names={'posterior_mode','posterior_std_at_mode',...% fields set by marginal_density
|
||||||
|
'posterior_mean','posterior_hpdinf','posterior_hpdsup','posterior_median','posterior_variance','posterior_std','posterior_deciles','posterior_density',...% fields set by GetPosteriorParametersStatistics
|
||||||
|
'prior_density',...%fields set by PlotPosteriorDistributions
|
||||||
|
};
|
||||||
|
for field_iter=1:size(field_names,2)
|
||||||
|
if isfield(oo_load_mh.oo_,field_names{1,field_iter})
|
||||||
|
oo_.(field_names{1,field_iter})=oo_load_mh.oo_.(field_names{1,field_iter});
|
||||||
|
end
|
||||||
|
end
|
||||||
|
% field set by marginal_density
|
||||||
|
if isfield(oo_load_mh.oo_,'MarginalDensity') && isfield(oo_load_mh.oo_.MarginalDensity,'ModifiedHarmonicMean')
|
||||||
|
oo_.MarginalDensity.ModifiedHarmonicMean=oo_load_mh.oo_.MarginalDensity.ModifiedHarmonicMean;
|
||||||
|
end
|
||||||
|
% field set by GetPosteriorMeanVariance
|
||||||
|
if isfield(oo_load_mh.oo_,'posterior') && isfield(oo_load_mh.oo_.posterior,'metropolis')
|
||||||
|
oo_.posterior.metropolis=oo_load_mh.oo_.posterior.metropolis;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
[error_flag,junk,options_]= metropolis_draw(1,options_,estim_params_,M_);
|
[error_flag,junk,options_]= metropolis_draw(1,options_,estim_params_,M_);
|
||||||
if options_.bayesian_irf
|
if options_.bayesian_irf
|
||||||
|
|
|
@ -595,6 +595,14 @@ else
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if options_.load_results_after_load_mh
|
||||||
|
if ~exist([M_.fname '_results.mat'],'file')
|
||||||
|
fprintf('\ndynare_estimation_init:: You specified the load_results_after_load_mh, but no _results.mat-file\n')
|
||||||
|
fprintf('dynare_estimation_init:: was found. Results will be recomputed.\n')
|
||||||
|
options_.load_results_after_load_mh=0;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if options_.mh_replic
|
if options_.mh_replic
|
||||||
[current_options, options_] = check_posterior_sampler_options([], options_, bounds);
|
[current_options, options_] = check_posterior_sampler_options([], options_, bounds);
|
||||||
options_.posterior_sampler_options.current_options = current_options;
|
options_.posterior_sampler_options.current_options = current_options;
|
||||||
|
|
|
@ -426,6 +426,7 @@ options_.riccati_tol = 1e-6;
|
||||||
options_.lik_algo = 1;
|
options_.lik_algo = 1;
|
||||||
options_.lik_init = 1;
|
options_.lik_init = 1;
|
||||||
options_.load_mh_file = 0;
|
options_.load_mh_file = 0;
|
||||||
|
options_.load_results_after_load_mh = 0;
|
||||||
options_.logdata = 0;
|
options_.logdata = 0;
|
||||||
options_.loglinear = 0;
|
options_.loglinear = 0;
|
||||||
options_.linear_approximation = 0;
|
options_.linear_approximation = 0;
|
||||||
|
|
|
@ -104,7 +104,7 @@ class ParsingDriver;
|
||||||
%token <string_val> INT_NUMBER
|
%token <string_val> INT_NUMBER
|
||||||
%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS IRF_PLOT_THRESHOLD IRF_CALIBRATION
|
%token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS IRF_PLOT_THRESHOLD IRF_CALIBRATION
|
||||||
%token FAST_KALMAN_FILTER KALMAN_ALGO KALMAN_TOL DIFFUSE_KALMAN_TOL SUBSAMPLES OPTIONS TOLF TOLX
|
%token FAST_KALMAN_FILTER KALMAN_ALGO KALMAN_TOL DIFFUSE_KALMAN_TOL SUBSAMPLES OPTIONS TOLF TOLX
|
||||||
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LOGDATA LYAPUNOV LINEAR_APPROXIMATION
|
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_RESULTS_AFTER_LOAD_MH LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LOGDATA LYAPUNOV LINEAR_APPROXIMATION
|
||||||
%token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT
|
%token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT
|
||||||
%token MFS MH_CONF_SIG MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER POSTERIOR_MAX_SUBSAMPLE_DRAWS MIN MINIMAL_SOLVING_PERIODS
|
%token MFS MH_CONF_SIG MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER POSTERIOR_MAX_SUBSAMPLE_DRAWS MIN MINIMAL_SOLVING_PERIODS
|
||||||
%token MODE_CHECK MODE_CHECK_NEIGHBOURHOOD_SIZE MODE_CHECK_SYMMETRIC_PLOTS MODE_CHECK_NUMBER_OF_POINTS MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN
|
%token MODE_CHECK MODE_CHECK_NEIGHBOURHOOD_SIZE MODE_CHECK_SYMMETRIC_PLOTS MODE_CHECK_NUMBER_OF_POINTS MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN
|
||||||
|
@ -1745,6 +1745,7 @@ estimation_options : o_datafile
|
||||||
| o_mh_mode
|
| o_mh_mode
|
||||||
| o_mh_nblocks
|
| o_mh_nblocks
|
||||||
| o_load_mh_file
|
| o_load_mh_file
|
||||||
|
| o_load_results_after_load_mh
|
||||||
| o_loglinear
|
| o_loglinear
|
||||||
| o_logdata
|
| o_logdata
|
||||||
| o_nodecomposition
|
| o_nodecomposition
|
||||||
|
@ -2864,6 +2865,7 @@ o_prior_trunc : PRIOR_TRUNC EQUAL non_negative_number { driver.option_num("prior
|
||||||
o_mh_mode : MH_MODE EQUAL INT_NUMBER { driver.option_num("mh_mode", $3); };
|
o_mh_mode : MH_MODE EQUAL INT_NUMBER { driver.option_num("mh_mode", $3); };
|
||||||
o_mh_nblocks : MH_NBLOCKS EQUAL INT_NUMBER { driver.option_num("mh_nblck", $3); };
|
o_mh_nblocks : MH_NBLOCKS EQUAL INT_NUMBER { driver.option_num("mh_nblck", $3); };
|
||||||
o_load_mh_file : LOAD_MH_FILE { driver.option_num("load_mh_file", "1"); };
|
o_load_mh_file : LOAD_MH_FILE { driver.option_num("load_mh_file", "1"); };
|
||||||
|
o_load_results_after_load_mh : LOAD_RESULTS_AFTER_LOAD_MH { driver.option_num("load_results_after_load_mh", "1"); };
|
||||||
o_loglinear : LOGLINEAR { driver.option_num("loglinear", "1"); };
|
o_loglinear : LOGLINEAR { driver.option_num("loglinear", "1"); };
|
||||||
o_linear_approximation : LINEAR_APPROXIMATION { driver.option_num("linear_approximation", "1"); };
|
o_linear_approximation : LINEAR_APPROXIMATION { driver.option_num("linear_approximation", "1"); };
|
||||||
o_logdata : LOGDATA { driver.option_num("logdata", "1"); };
|
o_logdata : LOGDATA { driver.option_num("logdata", "1"); };
|
||||||
|
|
|
@ -300,6 +300,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
|
||||||
<DYNARE_STATEMENT>mh_mode {return token::MH_MODE;}
|
<DYNARE_STATEMENT>mh_mode {return token::MH_MODE;}
|
||||||
<DYNARE_STATEMENT>mh_nblocks {return token::MH_NBLOCKS;}
|
<DYNARE_STATEMENT>mh_nblocks {return token::MH_NBLOCKS;}
|
||||||
<DYNARE_STATEMENT>load_mh_file {return token::LOAD_MH_FILE;}
|
<DYNARE_STATEMENT>load_mh_file {return token::LOAD_MH_FILE;}
|
||||||
|
<DYNARE_STATEMENT>load_results_after_load_mh {return token::LOAD_RESULTS_AFTER_LOAD_MH;}
|
||||||
<DYNARE_STATEMENT>loglinear {return token::LOGLINEAR;}
|
<DYNARE_STATEMENT>loglinear {return token::LOGLINEAR;}
|
||||||
<DYNARE_STATEMENT>linear_approximation {return token::LINEAR_APPROXIMATION;}
|
<DYNARE_STATEMENT>linear_approximation {return token::LINEAR_APPROXIMATION;}
|
||||||
<DYNARE_STATEMENT>logdata {return token::LOGDATA;}
|
<DYNARE_STATEMENT>logdata {return token::LOGDATA;}
|
||||||
|
|
|
@ -115,3 +115,6 @@ temp2=load([M_.dname filesep 'metropolis' filesep M_.dname '_mh1_blck1.mat']);
|
||||||
if max(max(abs(temp1.x2-temp2.x2)))>1e-10
|
if max(max(abs(temp1.x2-temp2.x2)))>1e-10
|
||||||
error('Draws of unaffected chain are not the same')
|
error('Draws of unaffected chain are not the same')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
save('fs2000_result.mat','oo_')
|
||||||
|
estimation(mode_compute=0,mode_file=fs2000_mode,order=1, datafile=fsdat_simul, nobs=192, loglinear, mh_replic=0, mh_nblocks=1, mh_jscale=10,load_mh_file,load_results_after_load_mh,smoother) gy_obs gp_obs;
|
||||||
|
|
Loading…
Reference in New Issue