Skip to content
Snippets Groups Projects
Commit 996ab961 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Merge branch 'block_model_diagnostics' into 'master'

model_diagnostics.m: adapt logic of using block information

See merge request Dynare/dynare!2121
parents 6dbc7c2a c8045e2c
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,6 @@ function model_diagnostics(M,options,oo) ...@@ -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 ...@@ -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);
...@@ -156,9 +155,20 @@ for b=1:nb ...@@ -156,9 +155,20 @@ for b=1:nb
'evaluate', 'static', 'block_decomposed', ['block=' ... 'evaluate', 'static', 'block_decomposed', ['block=' ...
int2str(b)]); int2str(b)]);
end end
else
if options.block
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 else
[res, T_order, T] = feval([M.fname '.sparse.static_resid'], dr.ys, exo, M.params); [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); 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 ...@@ -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,8 +215,12 @@ for b=1:nb ...@@ -205,8 +215,12 @@ for b=1:nb
break break
end end
end end
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}) 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
else else
...@@ -224,10 +238,14 @@ for b=1:nb ...@@ -224,10 +238,14 @@ for b=1:nb
break break
end end
end end
if options.block && ~options.bytecode
disp(M.block_structure_stat.block(b).equation(k))
else
disp(k') disp(k')
end end
end end
end end
end
if singularity_problem if singularity_problem
try try
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment