Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • giovanma/dynare
  • giorgiomas/dynare
  • Vermandel/dynare
  • Dynare/dynare
  • normann/dynare
  • MichelJuillard/dynare
  • wmutschl/dynare
  • FerhatMihoubi/dynare
  • sebastien/dynare
  • lnsongxf/dynare
  • rattoma/dynare
  • CIMERS/dynare
  • FredericKarame/dynare
  • SumuduK/dynare
  • MinjeJeon/dynare
  • camilomrch/dynare
  • DoraK/dynare
  • avtishin/dynare
  • selma/dynare
  • claudio_olguin/dynare
  • jeffjiang07/dynare
  • EthanSystem/dynare
  • stepan-a/dynare
  • wjgatt/dynare
  • JohannesPfeifer/dynare
  • gboehl/dynare
26 results
Show changes
Showing
with 322 additions and 349 deletions
......@@ -55,9 +55,11 @@ skipline(2)
disp('ESTIMATION RESULTS')
skipline()
if ishssmc(options_)
if ishssmc(options_)
dprintf('Log data density is %f.', oo_.MarginalDensity.hssmc);
hpd_draws = round((1-options_.mh_conf_sig)*num_draws);
elseif isonline(options_)
hpd_draws = num_draws;
elseif isdime(options_)
hpd_draws = round((1-options_.mh_conf_sig)*num_draws);
else
......@@ -87,7 +89,7 @@ if np
disp(tit2)
ip = nvx+nvn+ncx+ncn+1;
for i=1:np
if options_.mh_replic || (options_.load_mh_file && ~options_.load_results_after_load_mh) || ishssmc(options_)
if options_.mh_replic || (options_.load_mh_file && ~options_.load_results_after_load_mh) || ishssmc(options_) || isonline(options_)
draws = getalldraws(ip);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(draws, options_.mh_conf_sig);
name = bayestopt_.name{ip};
......
......@@ -45,6 +45,8 @@ if ~issmc(options_)
else
if ishssmc(options_)
[MetropolisFolder, info] = CheckPath('hssmc',M_.dname);
elseif isonline(options_)
[MetropolisFolder, info] = CheckPath('online',M_.dname);
elseif isdime(options_)
[MetropolisFolder, info] = CheckPath('dime',M_.dname);
else
......@@ -76,6 +78,10 @@ else
% Load draws from the posterior distribution
pfiles = dir(sprintf('%s/hssmc/particles-*.mat', M_.dname));
mhdate = get_date_of_a_file(sprintf('%s/hssmc/particles-%u-%u.mat', M_.dname, length(pfiles), length(pfiles)));
elseif isonline(options_)
% Load draws from the posterior distribution
pfiles = dir(sprintf('%s/online/parameters_particles_final.mat', M_.dname));
mhdate = get_date_of_a_file(sprintf('%s/online/parameters_particles_final.mat', M_.dname, length(pfiles), length(pfiles)));
elseif isdime(options_)
mhdate = get_date_of_a_file(sprintf('%s%s%s%schains.mat', M_.dname, filesep(), 'dime', filesep()));
end
......
......@@ -374,125 +374,150 @@ if init
posterior_sampler_options.WR=[];
end
case 'hssmc'
case 'hssmc'
% default options
posterior_sampler_options = add_fields_(posterior_sampler_options, options_.posterior_sampler_options.hssmc);
% default options
posterior_sampler_options = add_fields_(posterior_sampler_options, options_.posterior_sampler_options.hssmc);
% user defined options
if ~isempty(options_.posterior_sampler_options.sampling_opt)
options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt);
for i=1:rows(options_list)
switch options_list{i,1}
% user defined options
if ~isempty(options_.posterior_sampler_options.sampling_opt)
options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt);
for i=1:rows(options_list)
switch options_list{i,1}
case 'target'
posterior_sampler_options.target = options_list{i,2};
posterior_sampler_options.target = options_list{i,2};
case 'steps'
posterior_sampler_options.steps = options_list{i,2};
posterior_sampler_options.steps = options_list{i,2};
case 'scale'
posterior_sampler_options.scale = options_list{i,2};
posterior_sampler_options.scale = options_list{i,2};
case 'particles'
posterior_sampler_options.particles = options_list{i,2};
posterior_sampler_options.particles = options_list{i,2};
case 'lambda'
posterior_sampler_options.lambda = options_list{i,2};
posterior_sampler_options.lambda = options_list{i,2};
otherwise
warning(['hssmc: Unknown option (' options_list{i,1} ')!'])
end
end
end
options_.mode_compute = 0;
options_.cova_compute = 0;
options_.mh_replic = 0;
options_.mh_posterior_mode_estimation = false;
case 'dime_mcmc'
% default options
posterior_sampler_options = add_fields_(posterior_sampler_options, options_.posterior_sampler_options.dime);
% user defined options
if ~isempty(options_.posterior_sampler_options.sampling_opt)
options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt);
for i=1:rows(options_list)
switch options_list{i,1}
warning(['hssmc: Unknown option (' options_list{i,1} ')!'])
end
end
end
options_.mode_compute = 0;
options_.cova_compute = 0;
options_.mh_replic = 0;
options_.mh_posterior_mode_estimation = false;
case 'dime_mcmc'
% default options
posterior_sampler_options = add_fields_(posterior_sampler_options, options_.posterior_sampler_options.dime);
if ~isempty(options_.posterior_sampler_options.sampling_opt)
options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt);
for i=1:rows(options_list)
switch options_list{i,1}
case 'nchain'
posterior_sampler_options.nchain = options_list{i,2};
posterior_sampler_options.nchain = options_list{i,2};
case 'niter'
posterior_sampler_options.niter = options_list{i,2};
posterior_sampler_options.niter = options_list{i,2};
case 'parallel'
posterior_sampler_options.parallel = options_list{i,2};
posterior_sampler_options.parallel = options_list{i,2};
case 'tune'
posterior_sampler_options.tune = options_list{i,2};
posterior_sampler_options.tune = options_list{i,2};
case 'aimh_prob'
posterior_sampler_options.aimh_prob = options_list{i,2};
posterior_sampler_options.aimh_prob = options_list{i,2};
case 'sigma'
posterior_sampler_options.sigma = options_list{i,2};
posterior_sampler_options.sigma = options_list{i,2};
case 'gamma'
posterior_sampler_options.gamma = options_list{i,2};
posterior_sampler_options.gamma = options_list{i,2};
case 'df_proposal_dist'
posterior_sampler_options.df_proposal_dist = options_list{i,2};
posterior_sampler_options.df_proposal_dist = options_list{i,2};
case 'rho'
posterior_sampler_options.rho = options_list{i,2};
posterior_sampler_options.rho = options_list{i,2};
otherwise
warning(['dime: Unknown option (' options_list{i,1} ')!'])
end
end
end
if ~isfield(posterior_sampler_options,'tune')
posterior_sampler_options.tune = ceil(50000 / posterior_sampler_options.nchain);
dprintf('dime: setting number of ensemble iterations to keep (`tune`) to %d.', posterior_sampler_options.tune)
end
options_.mode_compute = 0;
options_.cova_compute = 0;
options_.mh_replic = 0;
options_.mh_posterior_mode_estimation = false;
warning(['dime: Unknown option (' options_list{i,1} ')!'])
end
end
end
if ~isfield(posterior_sampler_options,'tune')
posterior_sampler_options.tune = ceil(50000 / posterior_sampler_options.nchain);
dprintf('dime: setting number of ensemble iterations to keep (`tune`) to %d.', posterior_sampler_options.tune)
end
case 'online'
% default options
posterior_sampler_options = add_fields_(posterior_sampler_options, options_.posterior_sampler_options.online);
% user defined options
if ~isempty(options_.posterior_sampler_options.sampling_opt)
options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt);
for i=1:rows(options_list)
switch options_list{i,1}
case 'particles'
posterior_sampler_options.particles = options_list{i,2};
case 'liu_west_delta'
posterior_sampler_options.liu_west_delta = options_list{i,2};
case 'liu_west_max_resampling_tries'
posterior_sampler_options.liu_west_max_resampling_tries = options_list{i,2};
case 'second_resampling'
posterior_sampler_options.second_resampling = options_list{i,2};
otherwise
warning(['online: Unknown option (' options_list{i,1} ')!'])
end
end
end
options_.mode_compute = 0;
options_.cova_compute = 0;
options_.mh_replic = 0;
options_.mh_posterior_mode_estimation = false;
case 'dsmh'
% default options
posterior_sampler_options = add_fields_(posterior_sampler_options, options_.posterior_sampler_options.dsmh);
% user defined options
if ~isempty(options_.posterior_sampler_options.sampling_opt)
options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt);
for i=1:rows(options_list)
switch options_list{i,1}
case 'proposal_distribution'
if ~(strcmpi(options_list{i,2}, 'rand_multivariate_student') || ...
strcmpi(options_list{i,2}, 'rand_multivariate_normal'))
error(['initial_estimation_checks:: the proposal_distribution option to estimation takes either ' ...
'rand_multivariate_student or rand_multivariate_normal as options']);
else
posterior_sampler_options.proposal_distribution=options_list{i,2};
end
case 'student_degrees_of_freedom'
if options_list{i,2} <= 0
error('initial_estimation_checks:: the student_degrees_of_freedom takes a positive integer argument');
else
posterior_sampler_options.student_degrees_of_freedom=options_list{i,2};
end
case 'save_tmp_file'
posterior_sampler_options.save_tmp_file = options_list{i,2};
case 'number_of_particles'
posterior_sampler_options.particles = options_list{i,2};
otherwise
warning(['rwmh_sampler: Unknown option (' options_list{i,1} ')!'])
end
end
end
options_.mode_compute = 0;
options_.cova_compute = 0;
options_.mh_replic = 0;
options_.mh_posterior_mode_estimation = true;
% default options
posterior_sampler_options = add_fields_(posterior_sampler_options, options_.posterior_sampler_options.dsmh);
% user defined options
if ~isempty(options_.posterior_sampler_options.sampling_opt)
options_list = read_key_value_string(options_.posterior_sampler_options.sampling_opt);
for i=1:rows(options_list)
switch options_list{i,1}
case 'proposal_distribution'
if ~(strcmpi(options_list{i,2}, 'rand_multivariate_student') || ...
strcmpi(options_list{i,2}, 'rand_multivariate_normal'))
error(['initial_estimation_checks:: the proposal_distribution option to estimation takes either ' ...
'rand_multivariate_student or rand_multivariate_normal as options']);
else
posterior_sampler_options.proposal_distribution=options_list{i,2};
end
case 'student_degrees_of_freedom'
if options_list{i,2} <= 0
error('initial_estimation_checks:: the student_degrees_of_freedom takes a positive integer argument');
else
posterior_sampler_options.student_degrees_of_freedom=options_list{i,2};
end
case 'save_tmp_file'
posterior_sampler_options.save_tmp_file = options_list{i,2};
case 'number_of_particles'
posterior_sampler_options.particles = options_list{i,2};
otherwise
warning(['rwmh_sampler: Unknown option (' options_list{i,1} ')!'])
end
end
end
options_.mode_compute = 0;
options_.cova_compute = 0;
options_.mh_replic = 0;
options_.mh_posterior_mode_estimation = true;
otherwise
error('check_posterior_sampler_options:: Unknown posterior_sampling_method option %s ',posterior_sampler_options.posterior_sampling_method);
end
otherwise
error('check_posterior_sampler_options:: Unknown posterior_sampling_method option %s ',posterior_sampler_options.posterior_sampling_method);
end
return
return
end
end % if init
% here are all samplers requiring a proposal distribution
if ~strcmp(posterior_sampler_options.posterior_sampling_method,'slice')
......
......@@ -237,17 +237,24 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation &
optimizer_vec = [options_.mode_compute;num2cell(options_.additional_optimizer_steps)];
for optim_iter = 1:length(optimizer_vec)
current_optimizer = optimizer_vec{optim_iter};
if current_optimizer~=11
[xparam1, fval, ~, hh, options_, Scale, new_rat_hess_info] = dynare_minimize_objective(objective_function,xparam1,current_optimizer,options_,[bounds.lb bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_.dr, oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
else
[xparam1, fval, ~, hh, options_, Scale, new_rat_hess_info] = dynare_minimize_objective(objective_function,xparam1,current_optimizer,options_,[bounds.lb bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
if isnumeric(current_optimizer)
if current_optimizer==5
if options_.analytic_derivation
old_analytic_derivation = options_.analytic_derivation;
options_.analytic_derivation=-1; %force analytic outer product gradient hessian for each iteration
end
end
end
[xparam1, fval, ~, hh, options_, Scale, new_rat_hess_info] = dynare_minimize_objective(objective_function,xparam1,current_optimizer,options_,[bounds.lb bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_.dr, oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
if isnumeric(current_optimizer)
if current_optimizer==5
newratflag = new_rat_hess_info.newratflag;
new_rat_hess_info = new_rat_hess_info.new_rat_hess_info;
if options_.analytic_derivation
options_.analytic_derivation = old_analytic_derivation;
end
elseif current_optimizer==6 %save scaling factor
save([M_.dname filesep 'Output' filesep M_.fname '_optimal_mh_scale_parameter.mat'],'Scale');
options_.mh_jscale = Scale;
......@@ -271,7 +278,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation &
hh = hessian(penalized_objective_function, xparam1, options_.gstep, objective_function, fval, dataset_, dataset_info, options_, M_, estim_params_, bayestopt_, bounds,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
else
hh = hessian(objective_function, xparam1, options_.gstep, dataset_, dataset_info, options_, M_, estim_params_, bayestopt_, bounds,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
end
end
hh = reshape(hh, nx, nx);
elseif isnumeric(current_optimizer) && isequal(current_optimizer,5)
% other numerical hessian options available with optimizer
......@@ -398,7 +405,11 @@ end
% Run SMC sampler.
%
if ishssmc(options_)
if isonline(options_)
[posterior_sampler_options, options_, bayestopt_] = check_posterior_sampler_options([], M_.fname, M_.dname, options_, bounds, bayestopt_);
options_.posterior_sampler_options.current_options = posterior_sampler_options;
online_auxiliary_filter(xparam1, dataset_, options_, M_, estim_params_, bayestopt_, oo_);
elseif ishssmc(options_)
[posterior_sampler_options, options_, bayestopt_] = check_posterior_sampler_options([], M_.fname, M_.dname, options_, bounds, bayestopt_);
options_.posterior_sampler_options.current_options = posterior_sampler_options;
oo_.MarginalDensity.hssmc = hssmc(objective_function, bounds, dataset_, dataset_info, options_, M_, estim_params_, bayestopt_, oo_);
......@@ -471,7 +482,7 @@ if issmc(options_) || (any(bayestopt_.pshape>0) && options_.mh_replic) || (any(
oo_.lprob = trace_plot_dime(options_, M_);
end
% Estimation of the marginal density from the Mh draws:
if ishssmc(options_) || isdime(options_) || options_.mh_replic || (options_.load_mh_file && ~options_.load_results_after_load_mh)
if ishssmc(options_) || isonline(options_) || isdime(options_) || options_.mh_replic || (options_.load_mh_file && ~options_.load_results_after_load_mh)
if ~issmc(options_)
[~, oo_] = marginal_density(M_, options_, estim_params_, oo_, bayestopt_);
end
......@@ -509,7 +520,11 @@ if issmc(options_) || (any(bayestopt_.pshape>0) && options_.mh_replic) || (any(
if error_flag
error('%s: I cannot compute the posterior IRFs!',dispString)
end
oo_=PosteriorIRF('posterior',options_,estim_params_,oo_,M_,bayestopt_,dataset_,dataset_info,dispString);
if options_.occbin.likelihood.status
fprintf('%s: the bayesian_irf option is not compatible with the use of OccBin.',dispString)
else
oo_=PosteriorIRF('posterior',options_,estim_params_,oo_,M_,bayestopt_,dataset_,dataset_info,dispString);
end
end
if options_.moments_varendo
if error_flag
......@@ -538,7 +553,11 @@ if issmc(options_) || (any(bayestopt_.pshape>0) && options_.mh_replic) || (any(
end
end
end
oo_ = compute_moments_varendo('posterior',options_,M_,oo_,estim_params_,var_list_);
if options_.occbin.likelihood.status
fprintf('%s: the moments_varendo option is not compatible with the use of OccBin.',dispString)
else
oo_ = compute_moments_varendo('posterior',options_,M_,oo_,estim_params_,var_list_);
end
end
if options_.smoother || ~isempty(options_.filter_step_ahead) || options_.forecast
if error_flag
......
......@@ -117,16 +117,21 @@ if isequal(options_.diffuse_filter,1) || (options_.kalman_algo>2)
end
end
if strcmp('slice',options_.posterior_sampler_options.posterior_sampling_method)
if options_.prior_trunc==0
fprintf('\ndynare_estimation_init: slice requires bounded support. Setting options_.prior_trunc=1e-10.\n')
options_.prior_trunc=1e-10;
end
end
options_=select_qz_criterium_value(options_);
% Set options related to filtered variables.
if isequal(options_.filtered_vars,0) && ~isempty(options_.filter_step_ahead)
if isequal(options_.filtered_vars,0) && ~isempty(options_.filter_step_ahead) %require filtered var because filter_step_ahead was set
options_.filtered_vars = 1;
end
if ~isequal(options_.filtered_vars,0) && isempty(options_.filter_step_ahead)
options_.filter_step_ahead = 1;
end
if ~isequal(options_.filtered_vars,0) && isequal(options_.filter_step_ahead,0)
if ~isequal(options_.filtered_vars,0) && (isempty(options_.filter_step_ahead) || isequal(options_.filter_step_ahead,0)) %require filter_step_ahead because filtered_vars was requested
options_.filter_step_ahead = 1;
end
if ~isequal(options_.filter_step_ahead,0)
......@@ -533,12 +538,17 @@ if (options_.occbin.likelihood.status && options_.occbin.likelihood.inversion_fi
error('IVF-filter: an observable is mapped to a zero variance shock.')
end
end
if ~isequal(M_.H,0)
error('IVF-filter: Measurement erros are not allowed with the inversion filter.')
end
end
if options_.occbin.smoother.status && options_.occbin.smoother.inversion_filter
if ~isempty(options_.nk)
fprintf('dynare_estimation_init: the inversion filter does not support filter_step_ahead. Disabling the option.\n')
fprintf('dynare_estimation_init: the inversion filter does not support filter_step_ahead and filtered_variables. Disabling the option.\n')
options_.nk=[];
options_.filter_step_ahead=[];
options_.filtered_vars=0;
end
if options_.filter_covariance
fprintf('dynare_estimation_init: the inversion filter does not support filter_covariance. Disabling the option.\n')
......
......@@ -36,6 +36,8 @@ else
folder_name='hssmc';
elseif isdime(options_)
folder_name='dime';
elseif isonline(options_)
folder_name='online';
else
error('get_posterior_folder_name:: case should not happen. Please contact the developers')
end
......
......@@ -7,7 +7,9 @@ function xparam = get_posterior_parameters(type,M_,estim_params_,oo_,options_,fi
% o type [char] = 'mode' or 'mean'.
% o M_: [structure] Dynare structure describing the model.
% o estim_params_: [structure] Dynare structure describing the estimated parameters.
% o field_1 [char] optional field like 'mle_'.
% o oo_: [structure] Dynare results structure
% o options_: [structure] Dynare options structure
% o field_1 [char] optional field like 'mle_'.
%
% OUTPUTS
% o xparam vector of estimated parameters
......@@ -15,7 +17,7 @@ function xparam = get_posterior_parameters(type,M_,estim_params_,oo_,options_,fi
% SPECIAL REQUIREMENTS
% None.
% Copyright © 2006-2018 Dynare Team
% Copyright © 2006-2025 Dynare Team
%
% This file is part of Dynare.
%
......@@ -76,8 +78,6 @@ for i=1:ncn
m = m+1;
end
FirstDeep = m;
for i=1:np
name1 = M_.param_names{estim_params_.param_vals(i,1)};
xparam(m) = oo_.([field1 type]).parameters.(name1);
......
......@@ -86,6 +86,15 @@ if options_.occbin.likelihood.status || options_.occbin.smoother.status
if options_.fast_kalman_filter
error('initial_estimation_checks:: Occbin is incompatible with the fast Kalman filter.')
end
if options_.bayesian_irf
error('initial_estimation_checks:: Occbin is incompatible with the bayesian_irf option.')
end
if options_.moments_varendo
error('initial_estimation_checks:: Occbin is incompatible with the moments_varendo option.')
end
if options_.forecast
error('initial_estimation_checks:: Occbin is incompatible with the forecast option.')
end
end
if (options_.occbin.likelihood.status && options_.occbin.likelihood.inversion_filter) || (options_.occbin.smoother.status && options_.occbin.smoother.inversion_filter)
......@@ -161,6 +170,10 @@ if (any(bayestopt_.pshape >0 ) && options_.mh_replic) && options_.mh_nblck<1
error('initial_estimation_checks:: Bayesian estimation cannot be conducted with mh_nblocks=0.')
end
if options_.mh_drop<0 || options_.mh_drop>=1
error('initial_estimation_checks:: mh_drop must be in [0,1).')
end
% check and display warnings if steady-state solves static model (except if diffuse_filter == 1) and if steady-state changes estimated parameters
[oo_.steady_state] = check_steady_state_changes_parameters(M_,estim_params_,oo_,options_, [options_.diffuse_filter==0 options_.diffuse_filter==0] );
......
......@@ -3,10 +3,11 @@ function [marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_, bay
% Computes the marginal density
%
% INPUTS
% M_ [structure] Dynare model structure
% options_ [structure] Dynare options structure
% estim_params_ [structure] Dynare estimation parameter structure
% M_ [structure] Dynare model structure
% oo_ [structure] Dynare results structure
% bayestopt_ [structure] describing the priors
% outputFolderName [string] name of folder with results
%
% OUTPUTS
......@@ -16,7 +17,7 @@ function [marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_, bay
% SPECIAL REQUIREMENTS
% none
% Copyright © 2005-2023 Dynare Team
% Copyright © 2005-2025 Dynare Team
%
% This file is part of Dynare.
%
......@@ -64,7 +65,7 @@ if ~isfield(oo_,'posterior_mode') || (options_.mh_replic && isequal(options_.pos
end
% save the posterior mean and the inverse of the covariance matrix
% (usefull if the user wants to perform some computations using
% (useful if the user wants to perform some computations using
% the posterior mean instead of the posterior mode ==> ).
parameter_names = bayestopt_.name;
save([M_.dname filesep outputFolderName filesep M_.fname '_mean.mat'],'xparam1','hh','parameter_names','SIGMA');
......
function bool = isonline(options_)
% Copyright © 2024 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
bool = false;
if isfield(options_, 'posterior_sampler_options')
if strcmp(options_.posterior_sampler_options.posterior_sampling_method, 'online')
bool = true;
end
end
......@@ -141,9 +141,9 @@ if options_.filter_covariance
filter_covariance=1;
end
smoothed_state_uncertainty=0;
smoothed_state_uncertainty=false;
if options_.smoothed_state_uncertainty
smoothed_state_uncertainty=1;
smoothed_state_uncertainty=true;
end
% Store the variable mandatory for local/remote parallel computing.
......@@ -327,6 +327,9 @@ if options_.smoother
varlist,'UpdatedVariables',DirectoryName, ...
'_update',dispString);
if smoothed_state_uncertainty
if isfield(oo_,'Smoother') && isfield(oo_.Smoother,'State_uncertainty')
oo_.Smoother=rmfield(oo_.Smoother,'State_uncertainty'); %needs to be removed as classical smoother field has a different format
end
oo_=pm3(M_,options_,oo_,endo_nbr,endo_nbr,ifil(13),B,'State Uncertainty',...
varlist,M_.endo_names_tex,M_.endo_names,...
varlist,'StateUncertainty',DirectoryName,'_state_uncert',dispString);
......
......@@ -76,7 +76,7 @@ naK=myinputs.naK;
horizon=myinputs.horizon;
iendo=myinputs.iendo;
IdObs=myinputs.IdObs; %index of observables
if horizon
if horizon && ~options_.occbin.smoother.status
i_last_obs=myinputs.i_last_obs;
MAX_nforc1=myinputs.MAX_nforc1;
MAX_nforc2=myinputs.MAX_nforc2;
......@@ -168,7 +168,7 @@ if run_smoother
stock_smoothed_constant=NaN(endo_nbr,gend,MAX_n_smoothed_constant);
stock_smoothed_trend=NaN(endo_nbr,gend,MAX_n_smoothed_trend);
stock_trend_coeff = zeros(endo_nbr,MAX_n_trend_coeff);
if horizon
if horizon && ~options_.occbin.smoother.status
stock_forcst_mean= NaN(endo_nbr,horizon,MAX_nforc1);
stock_forcst_point = NaN(endo_nbr,horizon,MAX_nforc2);
if ~isequal(M_.H,0)
......@@ -230,11 +230,28 @@ for b=fpar:B
opts_local.occbin.simul.waitbar=0;
opts_local.occbin.smoother.waitbar = 0;
opts_local.occbin.smoother.linear_smoother=false; % speed-up
[alphahat,etahat,epsilonhat,alphatilde,SteadyState,trend_coeff,aK,~,~,P,~,~,trend_addition,state_uncertainty,oo_,bayestopt_] = ...
occbin.DSGE_smoother(deep,gend,Y,data_index,missing_value,M_,oo_,opts_local,bayestopt_,estim_params_);
if oo_.occbin.smoother.error_flag(1)
message=get_error_message(oo_.occbin.smoother.error_flag,opts_local);
fprintf('\nprior_posterior_statistics: One of the draws failed with the error:\n%s\n',message)
if options_.occbin.smoother.inversion_filter
dataset_.data=Y';
[~, info, ~, ~, ~, ~, ~, ~, ~, ~, oo_.dr, alphahat, etahat] = ...
occbin.IVF_posterior(deep,dataset_,[],options_,M_,estim_params_,bayestopt_,prior_bounds(bayestopt_,options_.prior_trunc),oo_.dr, oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
if info(1)
message=get_error_message(info,opts_local);
fprintf('\nprior_posterior_statistics: IVF smoother failed for one of the draws:\n%s\n',message)
else
alphatilde = alphahat*nan;
SteadyState=oo_.dr.ys;
trend_coeff = zeros(length(options_.varobs_id),1);
trend_addition=zeros(options_.number_of_observed_variables,gend);
end
%epsilonhat not available as no measurement error allowed
else
opts_local.verbosity=0;
[alphahat,etahat,epsilonhat,alphatilde,SteadyState,trend_coeff,aK,~,~,P,~,~,trend_addition,state_uncertainty,oo_,bayestopt_] = ...
occbin.DSGE_smoother(deep,gend,Y,data_index,missing_value,M_,oo_,opts_local,bayestopt_,estim_params_);
if oo_.occbin.smoother.error_flag(1)
message=get_error_message(oo_.occbin.smoother.error_flag,opts_local);
fprintf('\nprior_posterior_statistics: One of the draws failed with the error:\n%s\n',message)
end
end
else
[alphahat,etahat,epsilonhat,alphatilde,SteadyState,trend_coeff,aK,~,~,P,~,~,trend_addition,state_uncertainty,oo_,bayestopt_] = ...
......@@ -311,7 +328,7 @@ for b=fpar:B
end
end
end
if horizon
if horizon && ~options_.occbin.smoother.status
yyyy = alphahat(iendo,i_last_obs);
yf = simulate_posterior_forecasts(yyyy,dr,horizon,false,M_.Sigma_e,1);
if options_.prefilter
......@@ -546,7 +563,7 @@ dyn_waitbar_close(h);
function yf=simulate_posterior_forecasts(y0,dr,horizon,stochastic_indicator,Sigma_e,n)
% function yf=forcst2(y0,horizon,dr,n)
% function yf=simulate_posterior_forecasts(y0,horizon,dr,n)
%
% computes forecasts based on first order model solution, given shocks
% drawn from the shock distribution, but not including measurement error
......
......@@ -57,6 +57,11 @@ else
posterior = load(sprintf('%s/hssmc/particles-%u-%u.mat', M_.dname, length(pfiles), length(pfiles)));
NumberOfDraws = size(posterior.particles,2);
NumberOfDrawsPerChain=NumberOfDraws;
elseif isonline(options_)
% Load draws from the posterior distribution
posterior = load(sprintf('%s/online/parameters_particles_final.mat', M_.dname));
NumberOfDraws = size(posterior.param,2);
NumberOfDrawsPerChain=NumberOfDraws;
elseif isdime(options_)
posterior = load(sprintf('%s%s%s%schains.mat', M_.dname, filesep(), 'dime', filesep()));
tune = posterior.tune;
......
......@@ -17,4 +17,4 @@ function bool = issmc(options_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
bool = ishssmc(options_) || isdsmh(options_) || isdime(options_);
bool = ishssmc(options_) || isonline(options_) || isdsmh(options_) || isdime(options_);
function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,decomp,trend_addition,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0,d] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,varargin)
% [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,decomp,trend_addition,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0,d] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,varargin)
function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,decomp,trend_addition,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0,d,info] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,varargin)
% [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,decomp,trend_addition,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0,d,info] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,varargin)
% Estimation of the smoothed variables and innovations.
%
% INPUTS
......@@ -35,7 +35,14 @@ function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,de
% about the smoothed state (decision-rule order)
% o oo_ [structure] storing the results
% o bayestopt_ [structure] describing the priors
%
% o alphahat0 [double] (m*1) matrix, smoothed endogenous variables
% (a_{0}) for initial period from PKF
% o state_uncertainty0 [double] (K,K) matrix storing the uncertainty about
% the smoothed state for the initial
% period from the PKF
% o d [integer] number of diffuse periods
% o info [1 by 4 double] error code and penalty
% Notes:
% m: number of endogenous variables (M_.endo_nbr)
% T: number of Time periods (options_.nobs)
......@@ -74,9 +81,9 @@ function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,de
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
alphahat = [];
etahat = [];
epsilonhat = [];
alphahat = [];
etahat = [];
epsilonhat = [];
ahat = [];
SteadyState = [];
trend_coeff = [];
......@@ -86,8 +93,11 @@ R = [];
P = [];
PK = [];
decomp = [];
vobs = length(options_.varobs);
vobs = length(options_.varobs);
smpl = size(Y,2);
alphahat0 = [];
state_uncertainty0 =[];
d = 0;
if ~isempty(xparam1) %not calibrated model
M_ = set_all_parameters(xparam1,estim_params_,M_);
......
......@@ -12,7 +12,7 @@ function tf = contains(string, pattern, varargin)
% OUTPUT
% - tf [logical]
%
% Copyright © 2019 Dynare Team
% Copyright © 2019-2024 Dynare Team
%
% This file is part of Dynare.
%
......@@ -62,9 +62,9 @@ end
tf = false(size(string));
for ii = 1:numel(pattern)
idx = regexp(string, pattern{ii});
idx = regexp(string, regexptranslate('escape', pattern{ii}));
for jj = 1:numel(string)
tf(jj) = tf(jj) || ~isempty(idx{jj});
end
end
end
\ No newline at end of file
end
......@@ -160,6 +160,7 @@ for b=1:nb
'evaluate', 'static', 'block_decomposed', ['block=' ...
int2str(b)]);
end
n_vars_jacob=size(jacob,2);
else
if options_.block
T = NaN(M_.block_structure_stat.tmp_nbr, 1);
......
......@@ -279,7 +279,6 @@ function print_line(names,var_index,lead_lag,M_)
end
else
aux_index=find([M_.aux_vars(:).endo_index]==var_index);
aux_type=M_.aux_vars(aux_index).type;
if lead_lag==0
str = subst_auxvar(var_index, [], M_);
else
......
This diff is collapsed.