Commit 721ae71d authored by Sébastien Villemot's avatar Sébastien Villemot

Merge branch 'no_print' into 'master'

Fix bugs related to print_info.m and noprint

Closes #1714

See merge request !1721
parents debae9c4 16cbfa7f
Pipeline #3349 passed with stages
in 68 minutes and 47 seconds
......@@ -143,7 +143,7 @@ if ismember('moments', varargin) % Prior simulations (2nd order moments).
end
if info
skipline()
message = get_error_message(info);
message = get_error_message(info,options_);
fprintf('Cannot solve the model on the prior mode (info = %d, %s)\n', info(1), message);
skipline()
return
......
......@@ -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
if info(1)~=0
% there are errors in the solution algorithm
message = get_error_message(info,0,options_);
message = get_error_message(info,options_);
fprintf('-----------\n');
fprintf('The model does not solve for %s (info = %d: %s)\n', parameters, info(1), message);
fprintf('-----------\n');
......
......@@ -59,7 +59,7 @@ function disp_info_error_identification_perturbation(info,j)
% there are errors in the solution algorithm
probl_par = get_the_name(j,varargin{5}.TeX,varargin{3},varargin{2},varargin{5});
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('Cannot solve the model for %s (info = %d, %s)\n', probl_par, info(1), message);
fprintf('Possible solutions:\n')
......
function message = get_error_message(info, noprint, DynareOptions)
function message = get_error_message(info, DynareOptions)
% Returns error messages
%
% INPUTS
% info [double] vector returned by resol.m
% noprint [integer] equal to 0 if the error message has to be printed.
% DynareOptions [structure] --> options_
% OUTPUTS
% message [string] corresponding error message
......@@ -11,7 +10,7 @@ function message = get_error_message(info, noprint, DynareOptions)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2005-2019 Dynare Team
% Copyright (C) 2005-2020 Dynare Team
%
% 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
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~noprint
switch info(1)
case 0
message = '';
case 1
message = 'The model doesn''t determine the current variable uniquely.';
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));
case 3
message = 'Blanchard & Kahn conditions are not satisfied: no stable equilibrium.';
case 4
message = 'Blanchard & Kahn conditions are not satisfied: indeterminacy.';
case 5
message = 'Blanchard & Kahn conditions are not satisfied: indeterminacy due to rank failure.';
case 6
message = 'The Jacobian matrix evaluated at the steady state contains elements that are not real or are infinite.';
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);
case 8
if size(info,2)>=2
global M_;
disp_string = M_.param_names{info(2)};
for ii=1:length(info)-2
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.';
switch info(1)
case 0
message = '';
case 1
message = 'The model doesn''t determine the current variable uniquely.';
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));
case 3
message = 'Blanchard & Kahn conditions are not satisfied: no stable equilibrium.';
case 4
message = 'Blanchard & Kahn conditions are not satisfied: indeterminacy.';
case 5
message = 'Blanchard & Kahn conditions are not satisfied: indeterminacy due to rank failure.';
case 6
message = 'The Jacobian matrix evaluated at the steady state contains elements that are not real or are infinite.';
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);
case 8
if size(info,2)>=2
global M_;
disp_string = M_.param_names{info(2)};
for ii=1:length(info)-2
disp_string = [disp_string, ', ', M_.param_names{info(2+ii)}];
end
case 9
message = 'k_order_pert was unable to compute the solution';
case 10
message = 'The Jacobian of the dynamic model contains Inf. For more information, use options_.debug.';
case 11
message = 'The Hessian of the dynamic model used for second order solutions must not contain Inf';
case 12
message = 'The Hessian of the dynamic model used for second order solutions must not contain NaN';
case 19
message = 'The steadystate file did not compute the steady state';
case 20
if DynareOptions.linear
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));
else
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));
end
case 21
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 22
message = 'The steady state has NaNs or Inf.';
case 23
message = 'Parameters have been updated in the steadystate routine and some have complex values.';
case 24
message = 'Parameters have been updated in the steadystate routine and some are NaNs or Inf.';
case 25
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 26
message = 'The loglinearization of the model cannot be performed, because the steady state is not strictly positive.';
case 30
message = 'Ergodic variance can''t be computed.';
case 41
message = 'one (many) parameter(s) do(es) not satisfy the lower bound';
case 42
message = 'one (many) parameter(s) do(es) not satisfy the upper bound';
case 43
message = 'Covariance matrix of structural shocks is not positive definite';
case 44 %DsgeLikelihood_hh / dsge_likelihood
message = 'The covariance matrix of the measurement errors is not positive definite.';
case 45 %DsgeLikelihood_hh / dsge_likelihood
message = 'Likelihood is not a number (NaN) or a complex number';
case 46 %DsgeLikelihood_hh / dsge_likelihood
message = 'Likelihood is a complex number';
case 47 %DsgeLikelihood_hh / dsge_likelihood
message = 'Prior density is not a number (NaN)';
case 48 %DsgeLikelihood_hh / dsge_likelihood
message = 'Prior density is a complex number';
case 49
message = 'The model violates one (many) endogenous prior restriction(s)';
case 50
message = 'Likelihood is Inf';
case 51
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 52 %dsge_var_likelihood
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 53 %dsge_var_likelihood
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 55
message = 'Fast Kalman filter only works with stationary models [lik_init=1] or stationary observables for non-stationary models [lik_init=3]';
case 61 %Discretionary policy
message = 'Discretionary policy: maximum number of iterations has been reached. Procedure failed.';
case 62
message = 'Discretionary policy: some eigenvalues greater than options_.qz_criterium. Model potentially unstable.';
case 63
message = 'Discretionary policy: NaN elements are present in the solution. Procedure failed.';
case 64
message = 'discretionary_policy: the derivatives of the objective function contain NaN.';
case 65
message = 'discretionary_policy: the model must be written in deviation form and not have constant terms.';
case 66
message = 'discretionary_policy: the objective function must have zero first order derivatives.';
case 71
message = 'Calibrated covariance of the structural errors implies correlation larger than +-1.';
case 72
message = 'Calibrated covariance of the measurement errors implies correlation larger than +-1.';
% Aim Code Conversions by convertAimCodeToInfo.m
case 81
message = ['Ramsey: The solution to the static first order conditions for optimal policy could not be found. 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'];
case 82
message = 'Ramsey: The steady state computation resulted in NaN in the static first order conditions for optimal policy';
case 83
message = 'Ramsey: The steady state computation resulted in NaN in the auxiliary equations for optimal policy';
case 84
message = 'Ramsey: The steady state file computation for the Ramsey problem resulted in NaNs at the initial values of the instruments';
case 85
message = 'Ramsey: The steady state file does not solve the static first order conditions conditional on the instruments.';
case 86
message = 'Ramsey: The steady state file provides complex numbers conditional on the instruments.';
case 87
message = 'Ramsey: The maximum number of iterations has been reached. Try increasing maxit.';
case 102
message = 'Aim: roots not correctly computed by real_schur';
case 103
message = 'Aim: too many explosive roots: no stable equilibrium';
case 135
message = 'Aim: too many explosive roots, and q(:,right) is singular';
case 104
message = 'Aim: too few explosive roots: indeterminacy';
case 145
message = 'Aim: too few explosive roots, and q(:,right) is singular';
case 105
message = 'Aim: q(:,right) is singular';
case 161
message = 'Aim: too many exact shiftrights';
case 162
message = 'Aim: too many numeric shiftrights';
case 163
message = 'Aim: A is NAN or INF.';
case 164
message = 'Aim: Problem in SPEIG.';
otherwise
message = 'This case shouldn''t happen. Contact the authors of Dynare';
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
case 9
message = 'k_order_pert was unable to compute the solution';
case 10
message = 'The Jacobian of the dynamic model contains Inf. For more information, use options_.debug.';
case 11
message = 'The Hessian of the dynamic model used for second order solutions must not contain Inf';
case 12
message = 'The Hessian of the dynamic model used for second order solutions must not contain NaN';
case 19
message = 'The steadystate file did not compute the steady state';
case 20
if DynareOptions.linear
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));
else
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));
end
case 21
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 22
message = 'The steady state has NaNs or Inf.';
case 23
message = 'Parameters have been updated in the steadystate routine and some have complex values.';
case 24
message = 'Parameters have been updated in the steadystate routine and some are NaNs or Inf.';
case 25
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 26
message = 'The loglinearization of the model cannot be performed, because the steady state is not strictly positive.';
case 30
message = 'Ergodic variance can''t be computed.';
case 41
message = 'one (many) parameter(s) do(es) not satisfy the lower bound';
case 42
message = 'one (many) parameter(s) do(es) not satisfy the upper bound';
case 43
message = 'Covariance matrix of structural shocks is not positive definite';
case 44 %DsgeLikelihood_hh / dsge_likelihood
message = 'The covariance matrix of the measurement errors is not positive definite.';
case 45 %DsgeLikelihood_hh / dsge_likelihood
message = 'Likelihood is not a number (NaN) or a complex number';
case 46 %DsgeLikelihood_hh / dsge_likelihood
message = 'Likelihood is a complex number';
case 47 %DsgeLikelihood_hh / dsge_likelihood
message = 'Prior density is not a number (NaN)';
case 48 %DsgeLikelihood_hh / dsge_likelihood
message = 'Prior density is a complex number';
case 49
message = 'The model violates one (many) endogenous prior restriction(s)';
case 50
message = 'Likelihood is Inf';
case 51
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 52 %dsge_var_likelihood
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 53 %dsge_var_likelihood
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 55
message = 'Fast Kalman filter only works with stationary models [lik_init=1] or stationary observables for non-stationary models [lik_init=3]';
case 61 %Discretionary policy
message = 'Discretionary policy: maximum number of iterations has been reached. Procedure failed.';
case 62
message = 'Discretionary policy: some eigenvalues greater than options_.qz_criterium. Model potentially unstable.';
case 63
message = 'Discretionary policy: NaN elements are present in the solution. Procedure failed.';
case 64
message = 'discretionary_policy: the derivatives of the objective function contain NaN.';
case 65
message = 'discretionary_policy: the model must be written in deviation form and not have constant terms.';
case 66
message = 'discretionary_policy: the objective function must have zero first order derivatives.';
case 71
message = 'Calibrated covariance of the structural errors implies correlation larger than +-1.';
case 72
message = 'Calibrated covariance of the measurement errors implies correlation larger than +-1.';
% Aim Code Conversions by convertAimCodeToInfo.m
case 81
message = ['Ramsey: The solution to the static first order conditions for optimal policy could not be found. 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'];
case 82
message = 'Ramsey: The steady state computation resulted in NaN in the static first order conditions for optimal policy';
case 83
message = 'Ramsey: The steady state computation resulted in NaN in the auxiliary equations for optimal policy';
case 84
message = 'Ramsey: The steady state file computation for the Ramsey problem resulted in NaNs at the initial values of the instruments';
case 85
message = 'Ramsey: The steady state file does not solve the static first order conditions conditional on the instruments.';
case 86
message = 'Ramsey: The steady state file provides complex numbers conditional on the instruments.';
case 87
message = 'Ramsey: The maximum number of iterations has been reached. Try increasing maxit.';
case 102
message = 'Aim: roots not correctly computed by real_schur';
case 103
message = 'Aim: too many explosive roots: no stable equilibrium';
case 135
message = 'Aim: too many explosive roots, and q(:,right) is singular';
case 104
message = 'Aim: too few explosive roots: indeterminacy';
case 145
message = 'Aim: too few explosive roots, and q(:,right) is singular';
case 105
message = 'Aim: q(:,right) is singular';
case 161
message = 'Aim: too many exact shiftrights';
case 162
message = 'Aim: too many numeric shiftrights';
case 163
message = 'Aim: A is NAN or INF.';
case 164
message = 'Aim: Problem in SPEIG.';
otherwise
message = 'This case shouldn''t happen. Contact the authors of Dynare';
end
\ No newline at end of file
......@@ -11,7 +11,7 @@ function print_info(info, noprint, DynareOptions)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2005-2019 Dynare Team
% Copyright (C) 2005-2020 Dynare Team
%
% 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
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
message = get_error_message(info, noprint, DynareOptions);
error(message);
if ~noprint
message = get_error_message(info, DynareOptions);
error(message);
end
\ No newline at end of file
......@@ -279,6 +279,7 @@ MODFILES = \
ep/rbcii.mod \
ep/linearmodel0.mod \
ep/linearmodel1.mod \
stochastic_simulations/example1_noprint.mod \
stochastic-backward-models/solow_cd.mod \
stochastic-backward-models/solow_ces.mod \
stochastic-backward-models/solow_cd_with_steadystate.mod \
......
/*
* Example 1 from F. Collard (2001): "Stochastic simulations with DYNARE:
* A practical guide" (see "guide.pdf" in the documentation directory).
*/
/*
* Copyright (C) 2001-2010 Dynare Team
*
* This file is part of Dynare.
*
* Dynare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dynare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/
var y, c, k, a, h, b;
varexo e, u;
parameters beta, rho, alpha, delta, theta, psi, tau;
alpha = -0.36; // changed "0.36" to "-0.36" to generate an error
rho = 0.95;
tau = 0.025;
beta = 0.99;
delta = 0.025;
psi = 0;
theta = 2.95;
phi = 0.1;
model;
c*theta*h^(1+psi)=(1-alpha)*y;
k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
*(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
k = exp(b)*(y-c)+(1-delta)*k(-1);
a = rho*a(-1)+tau*b(-1) + e;
b = tau*a(-1)+rho*b(-1) + u;
end;
initval;
y = 1.08068253095672;
c = 0.80359242014163;
h = 0.29175631001732;
k = 11.08360443260358;
a = 0;
b = 0;
e = 0;
u = 0;
end;
shocks;
var e; stderr 0.009;
var u; stderr 0.009;
var e, u = phi*0.009*0.009;
end;
stoch_simul(noprint); // added "noprint"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment