Merge branch 'block_model_diagnostics' into 'master'

model_diagnostics.m: adapt logic of using block information

See merge request Dynare/dynare!2121
silicon
Sébastien Villemot 2023-03-16 09:24:17 +00:00
commit 996ab9613c
1 changed files with 26 additions and 8 deletions

View File

@ -33,7 +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/>.
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;
maximum_endo_lag = M.maximum_endo_lag; maximum_endo_lag = M.maximum_endo_lag;
@ -139,7 +138,7 @@ end
% singular Jacobian of static model % singular Jacobian of static model
% %
singularity_problem = 0; singularity_problem = 0;
if ~isfield(M,'block_structure_stat') if ~options.block
nb = 1; nb = 1;
else else
nb = length(M.block_structure_stat.block); nb = length(M.block_structure_stat.block);
@ -157,8 +156,19 @@ for b=1:nb
int2str(b)]); int2str(b)]);
end end
else else
[res, T_order, T] = feval([M.fname '.sparse.static_resid'], dr.ys, exo, M.params); if options.block
jacob = feval([M.fname '.sparse.static_g1'], dr.ys, exo, M.params, M.static_g1_sparse_rowval, M.static_g1_sparse_colval, M.static_g1_sparse_colptr, T_order, T); T = NaN(M.block_structure_stat.tmp_nbr, 1);
fh_static = str2func(sprintf('%s.sparse.block.static_%d', M.fname, b));
[~, ~,~, jacob] = fh_static(dr.ys, exo, M.params, M.block_structure_stat.block(b).g1_sparse_rowval, ...
M.block_structure_stat.block(b).g1_sparse_colval, ...
M.block_structure_stat.block(b).g1_sparse_colptr, T);
n_vars_jacob=size(jacob,2);
else
[res, T_order, T] = feval([M.fname '.sparse.static_resid'], dr.ys, exo, M.params);
jacob = feval([M.fname '.sparse.static_g1'], dr.ys, exo, M.params, M.static_g1_sparse_rowval, M.static_g1_sparse_colval, M.static_g1_sparse_colptr, T_order, T);
n_vars_jacob=M.endo_nbr;
end
jacob=full(jacob);
end end
if any(any(isinf(jacob) | isnan(jacob))) if any(any(isinf(jacob) | isnan(jacob)))
problem_dummy=1; problem_dummy=1;
@ -186,8 +196,8 @@ for b=1:nb
singularity_problem = 1; singularity_problem = 1;
disp(['MODEL_DIAGNOSTICS: The Jacobian of the static model is ' ... disp(['MODEL_DIAGNOSTICS: The Jacobian of the static model is ' ...
'singular']) 'singular'])
disp(['MODEL_DIAGNOSTICS: there is ' num2str(endo_nbr-rank_jacob) ... disp(['MODEL_DIAGNOSTICS: there is ' num2str(n_vars_jacob-rank_jacob) ...
' colinear relationships between the variables and the equations']) ' collinear relationships between the variables and the equations'])
if isoctave || matlab_ver_less_than('9.12') || isempty(options.jacobian_tolerance) if isoctave || matlab_ver_less_than('9.12') || isempty(options.jacobian_tolerance)
ncol = null(jacob); ncol = null(jacob);
else else
@ -205,7 +215,11 @@ for b=1:nb
break break
end end
end end
fprintf('%s\n',endo_names{k}) if options.block && ~options.bytecode
fprintf('%s\n',endo_names{M.block_structure_stat.block(b).variable(k)})
else
fprintf('%s\n',endo_names{k})
end
end end
if isoctave || matlab_ver_less_than('9.12') || isempty(options.jacobian_tolerance) if isoctave || matlab_ver_less_than('9.12') || isempty(options.jacobian_tolerance)
neq = null(jacob'); %can sometimes fail neq = null(jacob'); %can sometimes fail
@ -224,7 +238,11 @@ for b=1:nb
break break
end end
end end
disp(k') if options.block && ~options.bytecode
disp(M.block_structure_stat.block(b).equation(k))
else
disp(k')
end
end end
end end
end end