Skip to content
Snippets Groups Projects
Commit 78621c03 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Merge pull request #742 from JohannesPfeifer/second_order_hessian_problems

Deal with NaN and Inf in Hessian of dynamic model
parents 42bcd22a b43d5227
No related branches found
No related tags found
No related merge requests found
...@@ -68,6 +68,10 @@ if ~noprint ...@@ -68,6 +68,10 @@ if ~noprint
error(['k_order_pert was unable to compute the solution']) error(['k_order_pert was unable to compute the solution'])
case 10 case 10
error(['The Jacobian of the dynamic model contains Inf. For more information, use options_.debug.']) error(['The Jacobian of the dynamic model contains Inf. For more information, use options_.debug.'])
case 11
error('The Hessian of the dynamic model used for second order solutions must not contain Inf')
case 12
error('The Hessian of the dynamic model used for second order solutions must not contain NaN')
case 19 case 19
error('The steadystate file did not compute the steady state') error('The steadystate file did not compute the steady state')
case 20 case 20
......
...@@ -113,6 +113,30 @@ elseif options_.order == 2 ...@@ -113,6 +113,30 @@ elseif options_.order == 2
hessian1 = sparse(hessian1(:,1), hessian1(:,2), hessian1(:,3), ... hessian1 = sparse(hessian1(:,1), hessian1(:,2), hessian1(:,3), ...
size(jacobia_, 1), size(jacobia_, 2)*size(jacobia_, 2)); size(jacobia_, 1), size(jacobia_, 2)*size(jacobia_, 2));
end end
[infrow,infcol]=find(isinf(hessian1));
if options_.debug
if ~isempty(infrow)
fprintf('\nSTOCHASTIC_SOLVER: The Hessian of the dynamic model contains Inf.\n')
fprintf('STOCHASTIC_SOLVER: Try running model_diagnostics to find the source of the problem.\n')
save([M_.fname '_debug.mat'],'hessian1')
end
end
if ~isempty(infrow)
info(1)=11;
return
end
[nanrow,nancol]=find(isnan(hessian1));
if options_.debug
if ~isempty(nanrow)
fprintf('\nSTOCHASTIC_SOLVER: The Hessian of the dynamic model contains NaN.\n')
fprintf('STOCHASTIC_SOLVER: Try running model_diagnostics to find the source of the problem.\n')
save([M_.fname '_debug.mat'],'hessian1')
end
end
if ~isempty(nanrow)
info(1)=12;
return
end
end end
[infrow,infcol]=find(isinf(jacobia_)); [infrow,infcol]=find(isinf(jacobia_));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment