model_diagnostics.m: allow setting tolerance for singularity checks starting with Matlab 2022a

mr#2067
Johannes Pfeifer 2022-07-26 15:32:25 +02:00
parent f21577bf39
commit 253c87b894
2 changed files with 16 additions and 5 deletions

View File

@ -42,6 +42,7 @@ options_.timing = 0;
options_.gstep = ones(2,1); options_.gstep = ones(2,1);
options_.gstep(1) = 1e-2; options_.gstep(1) = 1e-2;
options_.gstep(2) = 1.0; options_.gstep(2) = 1.0;
options_.jacobian_tolerance = []; %tolerance for rank of Jacobian in model_diagnostics
options_.scalv = 1; options_.scalv = 1;
options_.debug = false; options_.debug = false;
options_.initval_file = false; options_.initval_file = false;

View File

@ -33,8 +33,6 @@ function model_diagnostics(M,options,oo)
% 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 <https://www.gnu.org/licenses/>. % along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global jacob
endo_nbr = M.endo_nbr; endo_nbr = M.endo_nbr;
endo_names = M.endo_names; endo_names = M.endo_names;
lead_lag_incidence = M.lead_lag_incidence; lead_lag_incidence = M.lead_lag_incidence;
@ -174,7 +172,11 @@ for b=1:nb
display_problematic_vars_Jacobian(imagrow,imagcol,M,dr.ys,'static','MODEL_DIAGNOSTICS: ') display_problematic_vars_Jacobian(imagrow,imagcol,M,dr.ys,'static','MODEL_DIAGNOSTICS: ')
end end
try try
rank_jacob = rank(jacob); %can sometimes fail if isoctave || matlab_ver_less_than('9.12') || isempty(options_.jacobian_tolerance)
rank_jacob = rank(jacob); %can sometimes fail
else
rank_jacob = rank(jacob,options_.jacobian_tolerance); %can sometimes fail
end
catch catch
rank_jacob=size(jacob,1); rank_jacob=size(jacob,1);
end end
@ -185,7 +187,11 @@ for b=1:nb
'singular']) 'singular'])
disp(['MODEL_DIAGNOSTICS: there is ' num2str(endo_nbr-rank_jacob) ... disp(['MODEL_DIAGNOSTICS: there is ' num2str(endo_nbr-rank_jacob) ...
' colinear relationships between the variables and the equations']) ' colinear relationships between the variables and the equations'])
ncol = null(jacob); if isoctave || matlab_ver_less_than('9.12') || isempty(options_.jacobian_tolerance)
ncol = null(jacob);
else
ncol = null(jacob,options_.jacobian_tolerance); %can sometimes fail
end
n_rel = size(ncol,2); n_rel = size(ncol,2);
for i = 1:n_rel for i = 1:n_rel
if n_rel > 1 if n_rel > 1
@ -200,7 +206,11 @@ for b=1:nb
end end
fprintf('%s\n',endo_names{k}) fprintf('%s\n',endo_names{k})
end end
neq = null(jacob'); if isoctave || matlab_ver_less_than('9.12') || isempty(options_.jacobian_tolerance)
neq = null(jacob'); %can sometimes fail
else
neq = null(jacob',options_.jacobian_tolerance); %can sometimes fail
end
n_rel = size(neq,2); n_rel = size(neq,2);
for i = 1:n_rel for i = 1:n_rel
if n_rel > 1 if n_rel > 1