print_info.m: Fix bug in error handling

get_error_message.m needs to always provide the error string, only throwing out the error message needs to depend on noprint

Closes https://git.dynare.org/Dynare/dynare/issues/1714
time-shift
Johannes Pfeifer 2020-03-07 18:34:42 +01:00
parent debae9c46f
commit b7ef2181f9
4 changed files with 149 additions and 151 deletions

View File

@ -461,7 +461,7 @@ if iload <=0
identification_analysis(params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end implies initialization of persistent variables identification_analysis(params, indpmodel, indpstderr, indpcorr, options_ident, dataset_info, prior_exist, 1); %the 1 at the end implies initialization of persistent variables
if info(1)~=0 if info(1)~=0
% there are errors in the solution algorithm % there are errors in the solution algorithm
message = get_error_message(info,0,options_); message = get_error_message(info,options_);
fprintf('-----------\n'); fprintf('-----------\n');
fprintf('The model does not solve for %s (info = %d: %s)\n', parameters, info(1), message); fprintf('The model does not solve for %s (info = %d: %s)\n', parameters, info(1), message);
fprintf('-----------\n'); fprintf('-----------\n');

View File

@ -59,7 +59,7 @@ function disp_info_error_identification_perturbation(info,j)
% there are errors in the solution algorithm % there are errors in the solution algorithm
probl_par = get_the_name(j,varargin{5}.TeX,varargin{3},varargin{2},varargin{5}); probl_par = get_the_name(j,varargin{5}.TeX,varargin{3},varargin{2},varargin{5});
skipline() skipline()
message = get_error_message(info,0,varargin{5}); message = get_error_message(info,varargin{5});
fprintf('Parameter error in numerical two-sided difference method:\n') fprintf('Parameter error in numerical two-sided difference method:\n')
fprintf('Cannot solve the model for %s (info = %d, %s)\n', probl_par, info(1), message); fprintf('Cannot solve the model for %s (info = %d, %s)\n', probl_par, info(1), message);
fprintf('Possible solutions:\n') fprintf('Possible solutions:\n')

View File

@ -1,9 +1,8 @@
function message = get_error_message(info, noprint, DynareOptions) function message = get_error_message(info, DynareOptions)
% Returns error messages % Returns error messages
% %
% INPUTS % INPUTS
% info [double] vector returned by resol.m % info [double] vector returned by resol.m
% noprint [integer] equal to 0 if the error message has to be printed.
% DynareOptions [structure] --> options_ % DynareOptions [structure] --> options_
% OUTPUTS % OUTPUTS
% message [string] corresponding error message % message [string] corresponding error message
@ -11,7 +10,7 @@ function message = get_error_message(info, noprint, DynareOptions)
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2005-2019 Dynare Team % Copyright (C) 2005-2020 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -28,147 +27,145 @@ function message = get_error_message(info, noprint, DynareOptions)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~noprint switch info(1)
switch info(1) case 0
case 0 message = '';
message = ''; case 1
case 1 message = 'The model doesn''t determine the current variable uniquely.';
message = 'The model doesn''t determine the current variable uniquely.'; case 2
case 2 message = sprintf('The generalized Schur (QZ) decomposition failed. For more information, see the documentation for Lapack function dgges: info=%d, n=%d. You can also run model_diagnostics to get more information on what may cause this problem.', info(2), info(3));
message = sprintf('The generalized Schur (QZ) decomposition failed. For more information, see the documentation for Lapack function dgges: info=%d, n=%d. You can also run model_diagnostics to get more information on what may cause this problem.', info(2), info(3)); case 3
case 3 message = 'Blanchard & Kahn conditions are not satisfied: no stable equilibrium.';
message = 'Blanchard & Kahn conditions are not satisfied: no stable equilibrium.'; case 4
case 4 message = 'Blanchard & Kahn conditions are not satisfied: indeterminacy.';
message = 'Blanchard & Kahn conditions are not satisfied: indeterminacy.'; case 5
case 5 message = 'Blanchard & Kahn conditions are not satisfied: indeterminacy due to rank failure.';
message = 'Blanchard & Kahn conditions are not satisfied: indeterminacy due to rank failure.'; case 6
case 6 message = 'The Jacobian matrix evaluated at the steady state contains elements that are not real or are infinite.';
message = 'The Jacobian matrix evaluated at the steady state contains elements that are not real or are infinite.'; case 7
case 7 message = sprintf('One of the eigenvalues is close to 0/0 (the absolute value of numerator and denominator is smaller than %5.4f!\n If you believe that the model has a unique solution you can try to reduce the value of qz_zero_threshold.',DynareOptions.qz_zero_threshold);
message = sprintf('One of the eigenvalues is close to 0/0 (the absolute value of numerator and denominator is smaller than %5.4f!\n If you believe that the model has a unique solution you can try to reduce the value of qz_zero_threshold.',DynareOptions.qz_zero_threshold); case 8
case 8 if size(info,2)>=2
if size(info,2)>=2 global M_;
global M_; disp_string = M_.param_names{info(2)};
disp_string = M_.param_names{info(2)}; for ii=1:length(info)-2
for ii=1:length(info)-2 disp_string = [disp_string, ', ', M_.param_names{info(2+ii)}];
disp_string = [disp_string, ', ', M_.param_names{info(2+ii)}];
end
message = ['The Jacobian contains NaNs because the following parameters are NaN: ' disp_string];
else
message = 'The Jacobian contains NaNs. For more information, use options_.debug.';
end end
case 9 message = ['The Jacobian contains NaNs because the following parameters are NaN: ' disp_string];
message = 'k_order_pert was unable to compute the solution'; else
case 10 message = 'The Jacobian contains NaNs. For more information, use options_.debug.';
message = 'The Jacobian of the dynamic model contains Inf. For more information, use options_.debug.'; end
case 11 case 9
message = 'The Hessian of the dynamic model used for second order solutions must not contain Inf'; message = 'k_order_pert was unable to compute the solution';
case 12 case 10
message = 'The Hessian of the dynamic model used for second order solutions must not contain NaN'; message = 'The Jacobian of the dynamic model contains Inf. For more information, use options_.debug.';
case 19 case 11
message = 'The steadystate file did not compute the steady state'; message = 'The Hessian of the dynamic model used for second order solutions must not contain Inf';
case 20 case 12
if DynareOptions.linear message = 'The Hessian of the dynamic model used for second order solutions must not contain NaN';
message = sprintf('Impossible to find the steady state (the sum of square residuals of the static equations is %5.4f). Either the model doesn''t have a steady state or there are an infinity of steady states Check whether your model is truly linear or whether there is a mistake in linearization.', info(2)); case 19
else message = 'The steadystate file did not compute the steady state';
message = sprintf('Impossible to find the steady state (the sum of square residuals of the static equations is %5.4f). Either the model doesn''t have a steady state, there are an infinity of steady states, or the guess values are too far from the solution', info(2)); case 20
end if DynareOptions.linear
case 21 message = sprintf('Impossible to find the steady state (the sum of square residuals of the static equations is %5.4f). Either the model doesn''t have a steady state or there are an infinity of steady states Check whether your model is truly linear or whether there is a mistake in linearization.', info(2));
message = sprintf('The steady state is complex (the sum of square residuals of imaginary parts of the steady state is %5.4f)', info(2)); else
case 22 message = sprintf('Impossible to find the steady state (the sum of square residuals of the static equations is %5.4f). Either the model doesn''t have a steady state, there are an infinity of steady states, or the guess values are too far from the solution', info(2));
message = 'The steady state has NaNs or Inf.'; end
case 23 case 21
message = 'Parameters have been updated in the steadystate routine and some have complex values.'; message = sprintf('The steady state is complex (the sum of square residuals of imaginary parts of the steady state is %5.4f)', info(2));
case 24 case 22
message = 'Parameters have been updated in the steadystate routine and some are NaNs or Inf.'; message = 'The steady state has NaNs or Inf.';
case 25 case 23
message = 'The solution to the static equations is not a steady state of the dynamic model: verify that the equations tagged by [static] and [dynamic] are consistent'; message = 'Parameters have been updated in the steadystate routine and some have complex values.';
case 26 case 24
message = 'The loglinearization of the model cannot be performed, because the steady state is not strictly positive.'; message = 'Parameters have been updated in the steadystate routine and some are NaNs or Inf.';
case 30 case 25
message = 'Ergodic variance can''t be computed.'; message = 'The solution to the static equations is not a steady state of the dynamic model: verify that the equations tagged by [static] and [dynamic] are consistent';
case 41 case 26
message = 'one (many) parameter(s) do(es) not satisfy the lower bound'; message = 'The loglinearization of the model cannot be performed, because the steady state is not strictly positive.';
case 42 case 30
message = 'one (many) parameter(s) do(es) not satisfy the upper bound'; message = 'Ergodic variance can''t be computed.';
case 43 case 41
message = 'Covariance matrix of structural shocks is not positive definite'; message = 'one (many) parameter(s) do(es) not satisfy the lower bound';
case 44 %DsgeLikelihood_hh / dsge_likelihood case 42
message = 'The covariance matrix of the measurement errors is not positive definite.'; message = 'one (many) parameter(s) do(es) not satisfy the upper bound';
case 45 %DsgeLikelihood_hh / dsge_likelihood case 43
message = 'Likelihood is not a number (NaN) or a complex number'; message = 'Covariance matrix of structural shocks is not positive definite';
case 46 %DsgeLikelihood_hh / dsge_likelihood case 44 %DsgeLikelihood_hh / dsge_likelihood
message = 'Likelihood is a complex number'; message = 'The covariance matrix of the measurement errors is not positive definite.';
case 47 %DsgeLikelihood_hh / dsge_likelihood case 45 %DsgeLikelihood_hh / dsge_likelihood
message = 'Prior density is not a number (NaN)'; message = 'Likelihood is not a number (NaN) or a complex number';
case 48 %DsgeLikelihood_hh / dsge_likelihood case 46 %DsgeLikelihood_hh / dsge_likelihood
message = 'Prior density is a complex number'; message = 'Likelihood is a complex number';
case 49 case 47 %DsgeLikelihood_hh / dsge_likelihood
message = 'The model violates one (many) endogenous prior restriction(s)'; message = 'Prior density is not a number (NaN)';
case 50 case 48 %DsgeLikelihood_hh / dsge_likelihood
message = 'Likelihood is Inf'; message = 'Prior density is a complex number';
case 51 case 49
message = sprintf('\n The dsge_prior_weight is dsge_var=%5.4f, but must be at least %5.4f for the prior to be proper.\n You are estimating a DSGE-VAR model, but the value of the dsge prior weight is too low!', info(2), info(3)); message = 'The model violates one (many) endogenous prior restriction(s)';
case 52 %dsge_var_likelihood case 50
message = 'You are estimating a DSGE-VAR model, but the implied covariance matrix of the VAR''s innovations, based on artificial and actual sample is not positive definite!'; message = 'Likelihood is Inf';
case 53 %dsge_var_likelihood case 51
message = 'You are estimating a DSGE-VAR model, but the implied covariance matrix of the VAR''s innovations, based on the artificial sample, is not positive definite!'; message = sprintf('\n The dsge_prior_weight is dsge_var=%5.4f, but must be at least %5.4f for the prior to be proper.\n You are estimating a DSGE-VAR model, but the value of the dsge prior weight is too low!', info(2), info(3));
case 55 case 52 %dsge_var_likelihood
message = 'Fast Kalman filter only works with stationary models [lik_init=1] or stationary observables for non-stationary models [lik_init=3]'; message = 'You are estimating a DSGE-VAR model, but the implied covariance matrix of the VAR''s innovations, based on artificial and actual sample is not positive definite!';
case 61 %Discretionary policy case 53 %dsge_var_likelihood
message = 'Discretionary policy: maximum number of iterations has been reached. Procedure failed.'; message = 'You are estimating a DSGE-VAR model, but the implied covariance matrix of the VAR''s innovations, based on the artificial sample, is not positive definite!';
case 62 case 55
message = 'Discretionary policy: some eigenvalues greater than options_.qz_criterium. Model potentially unstable.'; message = 'Fast Kalman filter only works with stationary models [lik_init=1] or stationary observables for non-stationary models [lik_init=3]';
case 63 case 61 %Discretionary policy
message = 'Discretionary policy: NaN elements are present in the solution. Procedure failed.'; message = 'Discretionary policy: maximum number of iterations has been reached. Procedure failed.';
case 64 case 62
message = 'discretionary_policy: the derivatives of the objective function contain NaN.'; message = 'Discretionary policy: some eigenvalues greater than options_.qz_criterium. Model potentially unstable.';
case 65 case 63
message = 'discretionary_policy: the model must be written in deviation form and not have constant terms.'; message = 'Discretionary policy: NaN elements are present in the solution. Procedure failed.';
case 66 case 64
message = 'discretionary_policy: the objective function must have zero first order derivatives.'; message = 'discretionary_policy: the derivatives of the objective function contain NaN.';
case 71 case 65
message = 'Calibrated covariance of the structural errors implies correlation larger than +-1.'; message = 'discretionary_policy: the model must be written in deviation form and not have constant terms.';
case 72 case 66
message = 'Calibrated covariance of the measurement errors implies correlation larger than +-1.'; message = 'discretionary_policy: the objective function must have zero first order derivatives.';
% Aim Code Conversions by convertAimCodeToInfo.m case 71
case 81 message = 'Calibrated covariance of the structural errors implies correlation larger than +-1.';
message = ['Ramsey: The solution to the static first order conditions for optimal policy could not be found. Either the model' ... case 72
' doesn''t have a steady state, there are an infinity of steady states, ' ... message = 'Calibrated covariance of the measurement errors implies correlation larger than +-1.';
' or the guess values are too far from the solution']; % Aim Code Conversions by convertAimCodeToInfo.m
case 82 case 81
message = 'Ramsey: The steady state computation resulted in NaN in the static first order conditions for optimal policy'; message = ['Ramsey: The solution to the static first order conditions for optimal policy could not be found. Either the model' ...
case 83 ' doesn''t have a steady state, there are an infinity of steady states, ' ...
message = 'Ramsey: The steady state computation resulted in NaN in the auxiliary equations for optimal policy'; ' or the guess values are too far from the solution'];
case 84 case 82
message = 'Ramsey: The steady state file computation for the Ramsey problem resulted in NaNs at the initial values of the instruments'; message = 'Ramsey: The steady state computation resulted in NaN in the static first order conditions for optimal policy';
case 85 case 83
message = 'Ramsey: The steady state file does not solve the static first order conditions conditional on the instruments.'; message = 'Ramsey: The steady state computation resulted in NaN in the auxiliary equations for optimal policy';
case 86 case 84
message = 'Ramsey: The steady state file provides complex numbers conditional on the instruments.'; message = 'Ramsey: The steady state file computation for the Ramsey problem resulted in NaNs at the initial values of the instruments';
case 87 case 85
message = 'Ramsey: The maximum number of iterations has been reached. Try increasing maxit.'; message = 'Ramsey: The steady state file does not solve the static first order conditions conditional on the instruments.';
case 102 case 86
message = 'Aim: roots not correctly computed by real_schur'; message = 'Ramsey: The steady state file provides complex numbers conditional on the instruments.';
case 103 case 87
message = 'Aim: too many explosive roots: no stable equilibrium'; message = 'Ramsey: The maximum number of iterations has been reached. Try increasing maxit.';
case 135 case 102
message = 'Aim: too many explosive roots, and q(:,right) is singular'; message = 'Aim: roots not correctly computed by real_schur';
case 104 case 103
message = 'Aim: too few explosive roots: indeterminacy'; message = 'Aim: too many explosive roots: no stable equilibrium';
case 145 case 135
message = 'Aim: too few explosive roots, and q(:,right) is singular'; message = 'Aim: too many explosive roots, and q(:,right) is singular';
case 105 case 104
message = 'Aim: q(:,right) is singular'; message = 'Aim: too few explosive roots: indeterminacy';
case 161 case 145
message = 'Aim: too many exact shiftrights'; message = 'Aim: too few explosive roots, and q(:,right) is singular';
case 162 case 105
message = 'Aim: too many numeric shiftrights'; message = 'Aim: q(:,right) is singular';
case 163 case 161
message = 'Aim: A is NAN or INF.'; message = 'Aim: too many exact shiftrights';
case 164 case 162
message = 'Aim: Problem in SPEIG.'; message = 'Aim: too many numeric shiftrights';
otherwise case 163
message = 'This case shouldn''t happen. Contact the authors of Dynare'; message = 'Aim: A is NAN or INF.';
end case 164
message = 'Aim: Problem in SPEIG.';
otherwise
message = 'This case shouldn''t happen. Contact the authors of Dynare';
end end

View File

@ -11,7 +11,7 @@ function print_info(info, noprint, DynareOptions)
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2005-2019 Dynare Team % Copyright (C) 2005-2020 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -27,6 +27,7 @@ function print_info(info, noprint, DynareOptions)
% %
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~noprint
message = get_error_message(info, noprint, DynareOptions); message = get_error_message(info, DynareOptions);
error(message); error(message);
end