Merge branch 'smoother' into 'master'

Various fixes to smoother output

See merge request Dynare/dynare!2057
mr#2067
Sébastien Villemot 2022-07-26 14:33:42 +00:00
commit f7ea4313b5
5 changed files with 42 additions and 13 deletions

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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,