From 59882e803bff73adbd2cd107b403119b70338802 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 26 Jul 2022 14:35:36 +0200 Subject: [PATCH 1/4] store_smoother_results.m: correctly set input arguments --- matlab/store_smoother_results.m | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/matlab/store_smoother_results.m b/matlab/store_smoother_results.m index 850832603..534f7ba72 100644 --- a/matlab/store_smoother_results.m +++ b/matlab/store_smoother_results.m @@ -72,6 +72,18 @@ function [oo_, yf]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,da % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . +if nargin<15 + PK=[]; +end +if nargin<16 + decomp=[]; +end +gend=dataset_.nobs; +if nargin<17 + Trend=zeros(options_.number_of_observed_variables,gend); +end + + %make sure there are no stale results field_names={'Smoother','SmoothedVariables','UpdatedVariables','FilteredVariables','FilteredVariablesKStepAhead','FilteredVariablesShockDecomposition','FilteredVariablesKStepAheadVariances','SmoothedShocks','SmoothedMeasurementErrors'}; for field_iter=1:length(field_names) @@ -86,10 +98,6 @@ else oo_.Smoother.occbin = false; end -gend=dataset_.nobs; -if nargin<16 - Trend=zeros(options_.number_of_observed_variables,gend); -end if options_.loglinear oo_.Smoother.loglinear = true; From 9bc71dffdef7c48add482d250a1e95724cf03d0a Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 26 Jul 2022 14:36:25 +0200 Subject: [PATCH 2/4] dynare_estimation_1.m: fix typo --- matlab/dynare_estimation_1.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 432db043b..91ad49231 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -588,7 +588,7 @@ end if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.pshape> 0) && options_.load_mh_file)) ... || ~options_.smoother ) && ~options_.partial_information % to be fixed - %% ML estimation, or posterior mode without Metropolis-Hastings or Metropolis without Bayesian smoothes variables + %% ML estimation, or posterior mode without Metropolis-Hastings or Metropolis without Bayesian smoothed variables if options_.occbin.smoother.status && options_.occbin.smoother.inversion_filter [~, ~, ~, ~, ~, ~, ~, ~, ~, ~, oo_, atT, innov] = occbin.IVF_posterior(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,prior_bounds(bayestopt_,options_.prior_trunc),oo_); updated_variables = atT*nan; From 622f8316255e91d0e2bdefe134bfcfeb06ee5ed0 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 26 Jul 2022 14:43:31 +0200 Subject: [PATCH 3/4] Inversion filter: disable unavailable smoother outputs Related to https://git.dynare.org/Dynare/dynare/-/issues/1861 --- matlab/dynare_estimation_init.m | 15 +++++++++++++++ tests/occbin/filter/NKM.mod | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index cde28a700..3b3fba2a2 100644 --- a/matlab/dynare_estimation_init.m +++ b/matlab/dynare_estimation_init.m @@ -699,4 +699,19 @@ if options_.occbin.likelihood.status && options_.occbin.likelihood.inversion_fil error('IVF-filter: an observable is mapped to a zero variance shock.') end 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') + options_.nk=[]; + end + if options_.filter_covariance + fprintf('dynare_estimation_init: the inversion filter does not support filter_covariance. Disabling the option.\n') + options_.filter_covariance=false; + end + if options_.smoothed_state_uncertainty + fprintf('dynare_estimation_init: the inversion filter does not support smoothed_state_uncertainty. Disabling the option.\n') + options_.smoothed_state_uncertainty=false; + end end \ No newline at end of file diff --git a/tests/occbin/filter/NKM.mod b/tests/occbin/filter/NKM.mod index c8b17848e..cd871d250 100644 --- a/tests/occbin/filter/NKM.mod +++ b/tests/occbin/filter/NKM.mod @@ -317,7 +317,7 @@ varobs yg inom pi; datafile=dataobsfile2, mode_file=NKM_mh_mode_saved, mode_compute=0, nobs=120, first_obs=1, mh_replic=0, plot_priors=0, smoother, - nodisplay,consider_all_endogenous,heteroskedastic_filter); + nodisplay,consider_all_endogenous,heteroskedastic_filter,filter_step_ahead=[1],smoothed_state_uncertainty); oo0=oo_; // use inversion filter (note that IF provides smoother together with likelihood) @@ -327,7 +327,7 @@ varobs yg inom pi; datafile=dataobsfile2, mode_file=NKM_mh_mode_saved, mode_compute=0, nobs=120, first_obs=1, mh_replic=0, plot_priors=0, smoother, - nodisplay, consider_all_endogenous,heteroskedastic_filter); + nodisplay, consider_all_endogenous,heteroskedastic_filter,filter_step_ahead=[1],smoothed_state_uncertainty); // show initial condition effect of IF figure, From 2816550290c29a43c475c80adaf5b349d2e0b883 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 26 Jul 2022 14:44:26 +0200 Subject: [PATCH 4/4] PKF: get required output if nk=1 Related to https://git.dynare.org/Dynare/dynare/-/issues/1861 --- matlab/missing_DiffuseKalmanSmootherH3_Z.m | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/matlab/missing_DiffuseKalmanSmootherH3_Z.m b/matlab/missing_DiffuseKalmanSmootherH3_Z.m index 6ba116349..8f100f528 100644 --- a/matlab/missing_DiffuseKalmanSmootherH3_Z.m +++ b/matlab/missing_DiffuseKalmanSmootherH3_Z.m @@ -341,6 +341,9 @@ while notsteady && t=first_period_occbin_update || isinf(first_period_occbin_update)) - if smoother_redux - aK(jnk,:,t+jnk) = out.piecewise(jnk,oo_.dr.order_var(oo_.dr.restrict_var_list)) - out.ys(oo_.dr.order_var(oo_.dr.restrict_var_list))'; + if jnk>1 + if isoccbin && (t>=first_period_occbin_update || isinf(first_period_occbin_update)) + if smoother_redux + aK(jnk,:,t+jnk) = out.piecewise(jnk,oo_.dr.order_var(oo_.dr.restrict_var_list)) - out.ys(oo_.dr.order_var(oo_.dr.restrict_var_list))'; + else + aK(jnk,oo_.dr.inv_order_var,t+jnk) = out.piecewise(jnk,:) - out.ys'; + end else - aK(jnk,oo_.dr.inv_order_var,t+jnk) = out.piecewise(jnk,:) - out.ys'; + aK(jnk,:,t+jnk) = T*dynare_squeeze(aK(jnk-1,:,t+jnk-1)); end - elseif jnk>1 - aK(jnk,:,t+jnk) = T*dynare_squeeze(aK(jnk-1,:,t+jnk-1)); end end end