diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 432db043b1a45bfdf7579d83f6d707f26f71fcde..91ad49231db74e496b3ee1be137dfe786512b43f 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; diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index cde28a7007723875ddb92cb3b35b22139c596f6b..3b3fba2a24c53b400ed5652f3bf1b0f818cda7fb 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/matlab/missing_DiffuseKalmanSmootherH3_Z.m b/matlab/missing_DiffuseKalmanSmootherH3_Z.m index 6ba116349471c14480f39fe4375d9a36e07bfd53..8f100f5286e1730b9b3a0674345fd334ea83cccf 100644 --- a/matlab/missing_DiffuseKalmanSmootherH3_Z.m +++ b/matlab/missing_DiffuseKalmanSmootherH3_Z.m @@ -341,6 +341,9 @@ while notsteady && t<smpl varargout{2} = []; varargout{3} = []; varargout{4} = []; + varargout{5} = []; + varargout{6} = []; + varargout{7} = []; return end @@ -363,6 +366,7 @@ while notsteady && t<smpl P(:,:,t) = Px(:,:,1); P1(:,:,t) = P1x(:,:,2); P(:,:,t+1) = Px(:,:,2); + aK(1,:,t+1) = a1(:,t+1); for jnk=1:nk PK(jnk,:,:,t+jnk) = Px(:,:,1+jnk); aK(jnk,:,t+jnk) = ax(:,1+jnk); @@ -455,14 +459,16 @@ while notsteady && t<smpl end PK(jnk,:,:,t+jnk) = Pf; end - 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))'; + 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 diff --git a/matlab/store_smoother_results.m b/matlab/store_smoother_results.m index 850832603c29bad363bdca68a438933569b4100e..534f7ba7288514a6d82c1cc8300fdb7e9fbe8140 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 <https://www.gnu.org/licenses/>. +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; diff --git a/tests/occbin/filter/NKM.mod b/tests/occbin/filter/NKM.mod index c8b17848ec38170ffc093a0e3d5c21abf1e3e6af..cd871d250a839b3071884e5fd2f4048f2f00ab19 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,