Adjust verbosity of solvers

time-shift
Johannes Pfeifer 2016-03-25 20:14:25 +01:00
parent 4b83c1bf76
commit 0669ac4c1c
2 changed files with 21 additions and 13 deletions

View File

@ -176,7 +176,7 @@ end
if oo_.deterministic_simulation.status == 1
disp('Perfect foresight solution found.')
else
warning('Failed to solve perfect foresight model')
disp('Failed to solve perfect foresight model')
end
skipline()

View File

@ -163,15 +163,15 @@ for iter = 1:options.simul.maxit
if endogenous_terminal_period && iter>1
dy = ZERO;
if options.simul.robust_lin_solve
dy(1:i_rows(end)) = -lin_solve_robust( A(1:i_rows(end),1:i_rows(end)), res(1:i_rows(end)) );
dy(1:i_rows(end)) = -lin_solve_robust( A(1:i_rows(end),1:i_rows(end)), res(1:i_rows(end)),verbose );
else
dy(1:i_rows(end)) = -lin_solve( A(1:i_rows(end),1:i_rows(end)), res(1:i_rows(end)) );
dy(1:i_rows(end)) = -lin_solve( A(1:i_rows(end),1:i_rows(end)), res(1:i_rows(end)), verbose );
end
else
if options.simul.robust_lin_solve
dy = -lin_solve_robust( A, res );
dy = -lin_solve_robust( A, res, verbose );
else
dy = -lin_solve( A, res );
dy = -lin_solve( A, res, verbose );
end
end
@ -232,7 +232,7 @@ if verbose
skipline();
end
function x = lin_solve( A, b )
function x = lin_solve( A, b,verbose)
if norm( b ) < sqrt( eps ) % then x = 0 is a solution
x = 0;
return
@ -241,11 +241,11 @@ function x = lin_solve( A, b )
x = A\b;
x( ~isfinite( x ) ) = 0;
relres = norm( b - A * x ) / norm( b );
if relres > 1e-6
if relres > 1e-6 && verbose
fprintf( 'WARNING : Failed to find a solution to the linear system.\n' );
end
function [ x, flag, relres ] = lin_solve_robust( A, b )
function [ x, flag, relres ] = lin_solve_robust( A, b , verbose)
if norm( b ) < sqrt( eps ) % then x = 0 is a solution
x = 0;
flag = 0;
@ -262,7 +262,9 @@ function [ x, flag, relres ] = lin_solve_robust( A, b )
disp( relres );
fprintf( 'Initial bicgstab failed, trying alternative start point.\n' );
if verbose
fprintf( 'Initial bicgstab failed, trying alternative start point.\n' );
end
old_x = x;
old_relres = relres;
[ x, flag, relres ] = bicgstab( A, b );
@ -270,7 +272,9 @@ function [ x, flag, relres ] = lin_solve_robust( A, b )
return
end
fprintf( 'Alternative start point also failed with bicgstab, trying gmres.\n' );
if verbose
fprintf( 'Alternative start point also failed with bicgstab, trying gmres.\n' );
end
if old_relres < relres
x = old_x;
end
@ -279,7 +283,9 @@ function [ x, flag, relres ] = lin_solve_robust( A, b )
return
end
fprintf( 'Initial gmres failed, trying alternative start point.\n' );
if verbose
fprintf( 'Initial gmres failed, trying alternative start point.\n' );
end
old_x = x;
old_relres = relres;
[ x, flag, relres ] = gmres( A, b );
@ -287,7 +293,9 @@ function [ x, flag, relres ] = lin_solve_robust( A, b )
return
end
fprintf( 'Alternative start point also failed with gmres, using the (SLOW) Moore-Penrose Pseudo-Inverse.\n' );
if verbose
fprintf( 'Alternative start point also failed with gmres, using the (SLOW) Moore-Penrose Pseudo-Inverse.\n' );
end
if old_relres < relres
x = old_x;
relres = old_relres;
@ -301,6 +309,6 @@ function [ x, flag, relres ] = lin_solve_robust( A, b )
relres = old_relres;
end
flag = relres > 1e-6;
if flag ~= 0
if flag ~= 0 && verbose
fprintf( 'WARNING : Failed to find a solution to the linear system\n' );
end