Merge branch 'identification_bug_fixes' into 'master'
Identification bug fixes Closes #1733 See merge request Dynare/dynare!1733time-shift
commit
3dd0b0e110
|
@ -142,9 +142,9 @@ for jide = 1:4
|
|||
disp([upper(strTest), ':'])
|
||||
disp(' !!!WARNING!!!');
|
||||
if SampleSize>1
|
||||
disp([' The rank of ', strJacobian, ' (', strMeaning, ') is deficient for ', num2str(length(find(ide.ino))),' out of ',int2str(SampleSize),' MC runs (with tol = ', num2str(tol_rank), ')!' ]),
|
||||
disp([' The rank of ', strJacobian, ' (', strMeaning, ') is deficient for ', num2str(length(find(ide.ino))),' out of ',int2str(SampleSize),' MC runs!' ]),
|
||||
else
|
||||
disp([' The rank of ', strJacobian, ' (', strMeaning, ') is deficient by ', num2str(size(Jacob,2)-ide.rank), ' (rank(', strJacobian, ') = ', num2str(ide.rank), ' < ', num2str(size(Jacob,2)), ' with tol = ', num2str(tol_rank), ')!']),
|
||||
disp([' The rank of ', strJacobian, ' (', strMeaning, ') is deficient!']),
|
||||
end
|
||||
skipline()
|
||||
for j=1:totparam_nbr
|
||||
|
@ -192,9 +192,9 @@ for jide = 1:4
|
|||
disp([upper(strTest), ':'])
|
||||
disp(' !!!WARNING!!!');
|
||||
if SampleSize>1
|
||||
disp([' The rank of ', strJacobian, ' (', strMeaning, ') is deficient for ', num2str(length(find(ide.ino))),' out of ',int2str(SampleSize),' MC runs (with tol = ', num2str(tol_rank), ')!' ]),
|
||||
disp([' The rank of ', strJacobian, ' (', strMeaning, ') is deficient for ', num2str(length(find(ide.ino))),' out of ',int2str(SampleSize),' MC runs!' ]),
|
||||
else
|
||||
disp([' The rank of ', strJacobian, ' (', strMeaning, ') is deficient by ', num2str(size(Jacob,2)-ide.rank), ' (rank(', strJacobian, ') = ', num2str(ide.rank), ' < ', num2str(size(Jacob,2)), ' with tol = ', num2str(tol_rank), ')!']),
|
||||
disp([' The rank of ', strJacobian, ' (', strMeaning, ') is deficient!']),
|
||||
end
|
||||
if all(cellfun(@isempty,ide.problpars))
|
||||
disp([' No problematic parameter combinations with maximum dimension ', num2str(size(ide.problpars,2)), ' were found. Increase max_dim_subsets_groups.']);
|
||||
|
|
|
@ -501,11 +501,15 @@ if options_.analytic_derivation
|
|||
error('analytic derivation is incompatible with diffuse filter')
|
||||
end
|
||||
options_.analytic_derivation = 1;
|
||||
if estim_params_.np
|
||||
if estim_params_.np || isfield(options_,'identification_check_endogenous_params_with_no_prior')
|
||||
% check if steady state changes param values
|
||||
M=M_;
|
||||
M.params(estim_params_.param_vals(:,1)) = xparam1(estim_params_.nvx+estim_params_.ncx+estim_params_.nvn+estim_params_.ncn+1:end); %set parameters
|
||||
M.params(estim_params_.param_vals(:,1)) = M.params(estim_params_.param_vals(:,1))*1.01; %vary parameters
|
||||
if isfield(options_,'identification_check_endogenous_params_with_no_prior')
|
||||
M.params = M.params*1.01; %vary parameters
|
||||
else
|
||||
M.params(estim_params_.param_vals(:,1)) = xparam1(estim_params_.nvx+estim_params_.ncx+estim_params_.nvn+estim_params_.ncn+1:end); %set parameters
|
||||
M.params(estim_params_.param_vals(:,1)) = M.params(estim_params_.param_vals(:,1))*1.01; %vary parameters
|
||||
end
|
||||
if options_.diffuse_filter || options_.steadystate.nocheck
|
||||
steadystate_check_flag = 0;
|
||||
else
|
||||
|
|
|
@ -270,6 +270,7 @@ if isempty(estim_params_)
|
|||
%reset some options
|
||||
options_ident.prior_mc = 1;
|
||||
options_ident.prior_range = 0;
|
||||
options_.identification_check_endogenous_params_with_no_prior = true; %needed to trigger endogenous steady state parameter check in dynare_estimation_init
|
||||
else
|
||||
prior_exist = 1;
|
||||
parameters = options_ident.parameter_set;
|
||||
|
|
|
@ -241,12 +241,11 @@ if order == 1
|
|||
end
|
||||
|
||||
%% Compute dMOMENTS
|
||||
if ~no_identification_moments
|
||||
if useautocorr
|
||||
E_yy = pruned.Corr_y; dE_yy = pruned.dCorr_y;
|
||||
if ~no_identification_moments
|
||||
E_yy = pruned.Var_y; dE_yy = pruned.dVar_y;
|
||||
if useautocorr
|
||||
E_yyi = pruned.Corr_yi; dE_yyi = pruned.dCorr_yi;
|
||||
else
|
||||
E_yy = pruned.Var_y; dE_yy = pruned.dVar_y;
|
||||
else
|
||||
E_yyi = pruned.Var_yi; dE_yyi = pruned.dVar_yi;
|
||||
end
|
||||
MOMENTS = [MEAN; dyn_vech(E_yy)];
|
||||
|
|
|
@ -205,10 +205,13 @@ if info(1) == 0 %no errors in solution
|
|||
warning_MOMENTS = [warning_MOMENTS ' The number of moments with non-zero derivative is smaller than the number of parameters up to 10 lags.\n'];
|
||||
warning_MOMENTS = [warning_MOMENTS ' Either reduce the list of parameters, or further increase ar, or increase number of observables.\n'];
|
||||
warning_MOMENTS = [warning_MOMENTS ' Skip identification analysis based on moments.\n'];
|
||||
warning_MOMENTS = [warning_MOMENTS ' Skip identification strenght analysis.\n'];
|
||||
fprintf(warning_MOMENTS);
|
||||
%reset options to neither display nor plot dMOMENTS anymore
|
||||
no_identification_moments = 1;
|
||||
options_ident.no_identification_moments = 1;
|
||||
no_identification_strength = 1;
|
||||
options_ident.no_identification_strength = 1;
|
||||
end
|
||||
end
|
||||
if ~no_identification_minimal
|
||||
|
|
|
@ -82,11 +82,7 @@ pruned = pruned_state_space_system(M, options, oo.dr, indvar, nlags, useautocorr
|
|||
|
||||
%% out = [vech(cov(Y_t,Y_t)); vec(cov(Y_t,Y_{t-1}); ...; vec(cov(Y_t,Y_{t-nlags})] of indvar variables, in DR order. This is Iskrev (2010)'s J matrix.
|
||||
if outputflag == 1
|
||||
if useautocorr
|
||||
out = dyn_vech(pruned.Corr_y);
|
||||
else
|
||||
out = dyn_vech(pruned.Var_y);
|
||||
end
|
||||
out = dyn_vech(pruned.Var_y);
|
||||
for i = 1:nlags
|
||||
if useautocorr
|
||||
out = [out;vec(pruned.Corr_yi(:,:,i))];
|
||||
|
|
|
@ -1032,9 +1032,9 @@ end
|
|||
indzeros = find(abs(Var_y) < 1e-12); %find values that are numerical zero
|
||||
Var_y(indzeros) = 0;
|
||||
if useautocorr
|
||||
sy = sqrt(diag(Var_y)); %theoretical standard deviation
|
||||
sy = sy(stationary_vars);
|
||||
sy = sy*sy'; %cross products of standard deviations
|
||||
sdy = sqrt(diag(Var_y)); %theoretical standard deviation
|
||||
sdy = sdy(stationary_vars);
|
||||
sy = sdy*sdy'; %cross products of standard deviations
|
||||
Corr_y = NaN*ones(y_nbr,y_nbr);
|
||||
Corr_y(stationary_vars,stationary_vars) = Var_y(stationary_vars,stationary_vars)./sy;
|
||||
Corr_yi = NaN*ones(y_nbr,y_nbr,nlags);
|
||||
|
@ -1048,21 +1048,21 @@ if compute_derivs
|
|||
end
|
||||
for jpV=1:totparam_nbr
|
||||
if order < 3
|
||||
dVar_y(stationary_vars,stationary_vars,jpV) = dC(stationary_vars,:,jpV)*Var_z*C(stationary_vars,:)' + C(stationary_vars,:)*dVar_z(:,:,jpV)*C(stationary_vars,:)' + C(stationary_vars,:)*Var_z*dC(stationary_vars,:,jpV)'...
|
||||
dVar_y_tmp = dC(stationary_vars,:,jpV)*Var_z*C(stationary_vars,:)' + C(stationary_vars,:)*dVar_z(:,:,jpV)*C(stationary_vars,:)' + C(stationary_vars,:)*Var_z*dC(stationary_vars,:,jpV)'...
|
||||
+ dD(stationary_vars,:,jpV)*Varinov*D(stationary_vars,:)' + D(stationary_vars,:)*dVarinov(:,:,jpV)*D(stationary_vars,:)' + D(stationary_vars,:)*Varinov*dD(stationary_vars,:,jpV)';
|
||||
else
|
||||
dVar_y(stationary_vars,stationary_vars,jpV) = dC(stationary_vars,:,jpV)*Var_z*C(stationary_vars,:)' + C(stationary_vars,:)*dVar_z(:,:,jpV)*C(stationary_vars,:)' + C(stationary_vars,:)*Var_z*dC(stationary_vars,:,jpV)'...
|
||||
dVar_y_tmp = dC(stationary_vars,:,jpV)*Var_z*C(stationary_vars,:)' + C(stationary_vars,:)*dVar_z(:,:,jpV)*C(stationary_vars,:)' + C(stationary_vars,:)*Var_z*dC(stationary_vars,:,jpV)'...
|
||||
+ dD(stationary_vars,:,jpV)*E_inovzlag1*C(stationary_vars,:)' + D(stationary_vars,:)*dE_inovzlag1(:,:,jpV)*C(stationary_vars,:)' + D(stationary_vars,:)*E_inovzlag1*dC(stationary_vars,:,jpV)'...
|
||||
+ dC(stationary_vars,:,jpV)*transpose(E_inovzlag1)*D(stationary_vars,:)' + C(stationary_vars,:)*transpose(dE_inovzlag1(:,:,jpV))*D(stationary_vars,:)' + C(stationary_vars,:)*transpose(E_inovzlag1)*dD(stationary_vars,:,jpV)'...
|
||||
+ dD(stationary_vars,:,jpV)*Varinov*D(stationary_vars,:)' + D(stationary_vars,:)*dVarinov(:,:,jpV)*D(stationary_vars,:)' + D(stationary_vars,:)*Varinov*dD(stationary_vars,:,jpV)';
|
||||
end
|
||||
[indzerosrow,indzeroscol] = find(abs(dVar_y(:,:,jpV)) < 1e-12); %find values that are numerical zero
|
||||
dVar_y(indzerosrow,indzeroscol,jpV) = 0;
|
||||
indzeros = find(abs(dVar_y_tmp) < 1e-12); %find values that are numerical zero
|
||||
dVar_y_tmp(indzeros) = 0;
|
||||
dVar_y(stationary_vars,stationary_vars,jpV) = dVar_y_tmp;
|
||||
if useautocorr
|
||||
%is this correct?[@wmutschl]
|
||||
dsy = 1/2./sy.*diag(dVar_y(:,:,jpV));
|
||||
dsy = 1/2./sdy.*diag(dVar_y(:,:,jpV));
|
||||
dsy = dsy(stationary_vars);
|
||||
dsy = dsy*sy'+sy*dsy';
|
||||
dsy = dsy*sdy'+sdy*dsy';
|
||||
dCorr_y(stationary_vars,stationary_vars,jpV) = (dVar_y(stationary_vars,stationary_vars,jpV).*sy-dsy.*Var_y(stationary_vars,stationary_vars))./(sy.*sy);
|
||||
dCorr_y(stationary_vars,stationary_vars,jpV) = dCorr_y(stationary_vars,stationary_vars,jpV)-diag(diag(dCorr_y(stationary_vars,stationary_vars,jpV)))+diag(diag(dVar_y(stationary_vars,stationary_vars,jpV)));
|
||||
end
|
||||
|
@ -1137,6 +1137,9 @@ if compute_derivs
|
|||
+ dD(stationary_vars,:,jpVi)*E_inovzlagi*C(stationary_vars,:)' + D(stationary_vars,:)*dE_inovzlagi_jpVi*C(stationary_vars,:)' + D(stationary_vars,:)*E_inovzlagi*dC(stationary_vars,:,jpVi)';
|
||||
end
|
||||
if useautocorr
|
||||
dsy = 1/2./sdy.*diag(dVar_y(:,:,jpVi));
|
||||
dsy = dsy(stationary_vars);
|
||||
dsy = dsy*sdy'+sdy*dsy';
|
||||
dCorr_yi(stationary_vars,stationary_vars,i,jpVi) = (dVar_yi(stationary_vars,stationary_vars,i,jpVi).*sy-dsy.*Var_yi(stationary_vars,stationary_vars,i))./(sy.*sy);
|
||||
end
|
||||
dAi_jpVi = dAi_jpVi*A + Ai*dA(:,:,jpVi);
|
||||
|
|
|
@ -65,8 +65,42 @@ steady; % compute steady state given the starting values
|
|||
resid; % check the starting values for the steady state
|
||||
check; % check Blanchard & Khan rank condition
|
||||
|
||||
@#define CORRFLAG = 1
|
||||
|
||||
@#ifdef kronflag
|
||||
identification(ar=3, useautocorr=1, nodisplay, nograph, parameter_set=calibration, analytic_derivation_mode=@{kronflag});
|
||||
identification(ar=3, useautocorr=@{CORRFLAG}, nodisplay, nograph, parameter_set=calibration, analytic_derivation_mode=@{kronflag},tol_rank=1e-8);
|
||||
@#else
|
||||
identification(ar=3, useautocorr=1, nodisplay, nograph, parameter_set=calibration, analytic_derivation_mode=0);
|
||||
identification(ar=3, useautocorr=@{CORRFLAG}, nodisplay, nograph, parameter_set=calibration, analytic_derivation_mode=0, tol_rank=1e-8);
|
||||
@#endif
|
||||
|
||||
% Unit test for correct identification results
|
||||
load('BrockMirman/identification/BrockMirman_Current_params_identif.mat','ide_moments_point', 'ide_spectrum_point', 'ide_minimal_point', 'ide_reducedform_point')
|
||||
pause(1);
|
||||
chk.ind0 = [1 1 1 1 1];
|
||||
chk.indno = [1 0 0 0 1];
|
||||
chk.jweak = [1 0 0 0 1];
|
||||
chk.jweak_pair = [0 0 0 0 0 0 0 0 0 0 1 0 0 0 0];
|
||||
for strVars = {'ind0' 'indno' 'jweak' 'jweak_pair'}
|
||||
if ~isequal(ide_moments_point.(strVars{:}) , chk.(strVars{:}))
|
||||
disp('dMoments:')
|
||||
disp(ide_moments_point.dMOMENTS);
|
||||
disp(strVars{:})
|
||||
disp(ide_moments_point.(strVars{:}));
|
||||
error('identification based on moments is wrong for %s',strVars{:})
|
||||
end
|
||||
if ~isequal(ide_spectrum_point.(strVars{:}) , chk.(strVars{:}))
|
||||
disp('dSPECTRUM');
|
||||
disp(ide_spectrum_point.dSPECTRUM);
|
||||
disp(strVars{:})
|
||||
disp(ide_spectrum_point.(strVars{:}));
|
||||
error('identification based on spectrum is wrong for %s',strVars{:})
|
||||
end
|
||||
if ~isequal(ide_minimal_point.(strVars{:}) , chk.(strVars{:}))
|
||||
disp('dMINIMAL')
|
||||
disp(ide_minimal_point.dMINIMAL);
|
||||
disp(strVars{:})
|
||||
disp(ide_minimal_point.(strVars{:}));
|
||||
error('identification based on minimal system is wrong for %s',strVars{:})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -81,11 +81,48 @@ end;
|
|||
|
||||
varobs c i;
|
||||
|
||||
identification(advanced=1,max_dim_cova_group=3);
|
||||
identification(advanced=1,max_dim_cova_group=3,tol_rank=1e-8);
|
||||
//varobs c i lam; //to check if observing lam identifies phi and theta
|
||||
//identification(ar=1,advanced=1,max_dim_cova_group=3,prior_mc=250);
|
||||
//identification(prior_mc=100);
|
||||
|
||||
% Unit test for analytic_derivation_mode
|
||||
load('kim2/identification/kim2_prior_mean_identif.mat','store_options_ident')
|
||||
if store_options_ident.analytic_derivation~=1 && store_options_ident.analytic_derivation_mode~=-2
|
||||
error('the steady state file changed parameters and we should switch to numerical derivatives for the steady state, i.e. analytic_derivation_mode=-2')
|
||||
end
|
||||
|
||||
% Unit test for correct identification results
|
||||
load('kim2/identification/kim2_prior_mean_identif.mat','ide_moments_point', 'ide_spectrum_point', 'ide_minimal_point', 'ide_reducedform_point')
|
||||
pause(1);
|
||||
chk.ind0 = [1 1 1 0];
|
||||
chk.indno = [0 0 0 1; 0 1 1 0];
|
||||
chk.jweak = [0 1 1 0];
|
||||
chk.jweak_pair = [0 0 0 0 1 0 0 0 0 0];
|
||||
for strVars = {'ind0' 'indno' 'jweak' 'jweak_pair'}
|
||||
if ~isequal(ide_moments_point.(strVars{:}) , chk.(strVars{:}))
|
||||
disp('dMoments:')
|
||||
disp(ide_moments_point.dMOMENTS);
|
||||
disp(strVars{:})
|
||||
disp(ide_moments_point.(strVars{:}));
|
||||
error('identification based on moments is wrong for %s',strVars{:})
|
||||
end
|
||||
if ~isequal(ide_spectrum_point.(strVars{:}) , chk.(strVars{:}))
|
||||
disp('dSPECTRUM');
|
||||
disp(ide_spectrum_point.dSPECTRUM);
|
||||
disp(strVars{:})
|
||||
disp(ide_spectrum_point.(strVars{:}));
|
||||
error('identification based on spectrum is wrong for %s',strVars{:})
|
||||
end
|
||||
if ~isequal(ide_minimal_point.(strVars{:}) , chk.(strVars{:}))
|
||||
disp('dMINIMAL')
|
||||
disp(ide_minimal_point.dMINIMAL);
|
||||
disp(strVars{:})
|
||||
disp(ide_minimal_point.(strVars{:}));
|
||||
error('identification based on minimal system is wrong for %s',strVars{:})
|
||||
end
|
||||
end
|
||||
|
||||
% Integration test if identification works without priors
|
||||
estim_params_=[];
|
||||
identification(advanced=1,max_dim_cova_group=3);
|
||||
|
|
Loading…
Reference in New Issue