Skip to content
Snippets Groups Projects
Commit c4e0cd05 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Merge branch 'posterior_smoother' into 'master'

prior_posterior_statistics_core.m: filter out cases where model does not solve

See merge request Dynare/dynare!1860
parents ae574fff 7541b1b1
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ function pdraw = prior_draw(BayesInfo, prior_trunc, uniform) % --*-- Unitary tes ...@@ -21,7 +21,7 @@ function pdraw = prior_draw(BayesInfo, prior_trunc, uniform) % --*-- Unitary tes
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% %
% NOTE 1. Input arguments 1 an 2 are only needed for initialization. % NOTE 1. Input arguments 1 and 2 are only needed for initialization.
% NOTE 2. A given draw from the joint prior distribution does not satisfy BK conditions a priori. % NOTE 2. A given draw from the joint prior distribution does not satisfy BK conditions a priori.
% NOTE 3. This code relies on bayestopt_ as created in the base workspace % NOTE 3. This code relies on bayestopt_ as created in the base workspace
% by the preprocessor (or as updated in subsequent pieces of code and handed to the base workspace) % by the preprocessor (or as updated in subsequent pieces of code and handed to the base workspace)
......
...@@ -108,6 +108,9 @@ if ~strcmpi(type,'prior') ...@@ -108,6 +108,9 @@ if ~strcmpi(type,'prior')
if strcmpi(type,'posterior') if strcmpi(type,'posterior')
logpost=myinputs.logpost; logpost=myinputs.logpost;
end end
else
x=(prior_draw(bayestopt_,options_.prior_trunc))';
options_=select_qz_criterium_value(options_);
end end
if whoiam if whoiam
Parallel=myinputs.Parallel; Parallel=myinputs.Parallel;
...@@ -177,7 +180,7 @@ end ...@@ -177,7 +180,7 @@ end
if naK if naK
stock_filter_step_ahead =NaN(length(options_.filter_step_ahead),endo_nbr,gend+max(options_.filter_step_ahead),MAX_naK); stock_filter_step_ahead =NaN(length(options_.filter_step_ahead),endo_nbr,gend+max(options_.filter_step_ahead),MAX_naK);
end end
stock_param = NaN(MAX_nruns,size(myinputs.x,2)); stock_param = NaN(MAX_nruns,size(x,2));
stock_logpo = NaN(MAX_nruns,1); stock_logpo = NaN(MAX_nruns,1);
stock_ys = NaN(MAX_nruns,endo_nbr); stock_ys = NaN(MAX_nruns,endo_nbr);
if filter_covariance if filter_covariance
...@@ -187,11 +190,18 @@ if smoothed_state_uncertainty ...@@ -187,11 +190,18 @@ if smoothed_state_uncertainty
stock_smoothed_uncert = zeros(endo_nbr,endo_nbr,gend,MAX_n_smoothed_state_uncertainty); stock_smoothed_uncert = zeros(endo_nbr,endo_nbr,gend,MAX_n_smoothed_state_uncertainty);
end end
opts_local = options_;
for b=fpar:B for b=fpar:B
if strcmpi(type,'prior') if strcmpi(type,'prior')
iter=1;
[deep, logpo] = GetOneDraw(type,M_,estim_params_,oo_,options_,bayestopt_); logpo=[];
while (isempty(logpo) || isinf(logpo)) && iter<1000
[deep, logpo] = GetOneDraw(type,M_,estim_params_,oo_,options_,bayestopt_);
iter=iter+1;
end
if iter==1000
fprintf('\nprior_posterior_statistics: unable to get a valid draw in 1000 tries. Giving up.')
end
else else
deep = x(b,:); deep = x(b,:);
if strcmpi(type,'posterior') if strcmpi(type,'posterior')
...@@ -203,9 +213,18 @@ for b=fpar:B ...@@ -203,9 +213,18 @@ for b=fpar:B
M_ = set_all_parameters(deep,estim_params_,M_); M_ = set_all_parameters(deep,estim_params_,M_);
if run_smoother if run_smoother
[dr,info,M_,options_,oo_] =compute_decision_rules(M_,options_,oo_); [dr,info,M_,opts_local,oo_] =compute_decision_rules(M_,opts_local,oo_);
[alphahat,etahat,epsilonhat,alphatilde,SteadyState,trend_coeff,aK,~,~,P,~,~,trend_addition,state_uncertainty,M_,oo_,options_,bayestopt_] = ... if ismember(info(1),[3,4])
DsgeSmoother(deep,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_); opts_local.qz_criterium = 1 + (opts_local.qz_criterium-1)*10; %loosen tolerance, useful for big models where BK conditions were tested on restricted state space
[dr,info,M_,opts_local,oo_] =compute_decision_rules(M_,opts_local,oo_);
end
if info(1)
message=get_error_message(info,opts_local);
fprintf('\nprior_posterior_statistics: One of the draws failed with the error:\n%s\n',message)
fprintf('prior_posterior_statistics: This should not happen. Please contact the developers.\n',message)
end
[alphahat,etahat,epsilonhat,alphatilde,SteadyState,trend_coeff,aK,~,~,P,~,~,trend_addition,state_uncertainty,M_,oo_,opts_local,bayestopt_] = ...
DsgeSmoother(deep,gend,Y,data_index,missing_value,M_,oo_,opts_local,bayestopt_,estim_params_);
stock_trend_coeff(options_.varobs_id,irun(9))=trend_coeff; stock_trend_coeff(options_.varobs_id,irun(9))=trend_coeff;
stock_smoothed_trend(IdObs,:,irun(11))=trend_addition; stock_smoothed_trend(IdObs,:,irun(11))=trend_addition;
......
...@@ -123,3 +123,9 @@ save('fs2000_result.mat','oo_') ...@@ -123,3 +123,9 @@ save('fs2000_result.mat','oo_')
options_.load_results_after_load_mh=1; options_.load_results_after_load_mh=1;
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,smoother) gy_obs gp_obs; 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,smoother) gy_obs gp_obs;
oo_.MarginalDensity.LaplaceApproximation = Laplace; %reset correct Laplace oo_.MarginalDensity.LaplaceApproximation = Laplace; %reset correct Laplace
%test prior sampling
options_.prior_draws=100;
options_.no_graph.posterior=0;
prior_posterior_statistics('prior',dataset_,dataset_info); %get smoothed and filtered objects and forecasts
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment