Home > manopt > core > stoppingcriterion.m

stoppingcriterion

PURPOSE ^

Checks for standard stopping criteria, as a helper to solvers.

SYNOPSIS ^

function [stop, reason] = stoppingcriterion(problem, x, options, info, last)

DESCRIPTION ^

 Checks for standard stopping criteria, as a helper to solvers.

 function [stop, reason] = stoppingcriterion(problem, x, options, info, last)

 Executes standard stopping criterion checks, based on what is defined in
 the info(last) stats structure and in the options structure.

 The returned number 'stop' is 0 if none of the stopping criteria
 triggered, and a (strictly) positive integer otherwise. The integer
 identifies which criterion triggered:
  0 : Nothing triggered;
  1 : Cost tolerance reached;
  2 : Gradient norm tolerance reached;
  3 : Max time exceeded;
  4 : Max iteration count reached;
  5 : Maximum number of cost evaluations reached;
  6 : User defined stopfun criterion triggered.

 The output 'reason' is a string describing the triggered event.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [stop, reason] = stoppingcriterion(problem, x, options, info, last)
0002 % Checks for standard stopping criteria, as a helper to solvers.
0003 %
0004 % function [stop, reason] = stoppingcriterion(problem, x, options, info, last)
0005 %
0006 % Executes standard stopping criterion checks, based on what is defined in
0007 % the info(last) stats structure and in the options structure.
0008 %
0009 % The returned number 'stop' is 0 if none of the stopping criteria
0010 % triggered, and a (strictly) positive integer otherwise. The integer
0011 % identifies which criterion triggered:
0012 %  0 : Nothing triggered;
0013 %  1 : Cost tolerance reached;
0014 %  2 : Gradient norm tolerance reached;
0015 %  3 : Max time exceeded;
0016 %  4 : Max iteration count reached;
0017 %  5 : Maximum number of cost evaluations reached;
0018 %  6 : User defined stopfun criterion triggered.
0019 %
0020 % The output 'reason' is a string describing the triggered event.
0021 
0022 % This file is part of Manopt: www.manopt.org.
0023 % Original author: Nicolas Boumal, Dec. 30, 2012.
0024 % Contributors:
0025 % Change log:
0026 %
0027 %   April 2, 2015 (NB):
0028 %       'reason' now contains the option (name and value) that triggered.
0029 
0030 
0031     stop = 0;
0032     reason = '';
0033     
0034     stats = info(last);
0035 
0036     % Target cost attained
0037     if isfield(stats, 'cost') && isfield(options, 'tolcost') && ...
0038        stats.cost <= options.tolcost
0039         reason = sprintf('Cost tolerance reached; options.tolcost = %g.', options.tolcost);
0040         stop = 1;
0041         return;
0042     end
0043 
0044     % Target gradient norm attained
0045     if isfield(stats, 'gradnorm') && isfield(options, 'tolgradnorm') && ...
0046        stats.gradnorm < options.tolgradnorm
0047         reason = sprintf('Gradient norm tolerance reached; options.tolgradnorm = %g.', options.tolgradnorm);
0048         stop = 2;
0049         return;
0050     end
0051 
0052     % Allotted time exceeded
0053     if isfield(stats, 'time') && isfield(options, 'maxtime') && ...
0054        stats.time >= options.maxtime
0055         reason = sprintf('Max time exceeded; options.maxtime = %g.', options.maxtime);
0056         stop = 3;
0057         return;
0058     end
0059 
0060     % Allotted iteration count exceeded
0061     if isfield(stats, 'iter') && isfield(options, 'maxiter') && ...
0062        stats.iter >= options.maxiter
0063         reason = sprintf('Max iteration count reached; options.maxiter = %g.', options.maxiter);
0064         stop = 4;
0065         return;
0066     end
0067     
0068     % Allotted function evaluation count exceeded
0069     if isfield(stats, 'costevals') && isfield(options, 'maxcostevals') && ...
0070        stats.costevals >= options.maxcostevals
0071         reason = sprintf('Maximum number of cost evaluations reached; options.maxcostevals = %g.', options.maxcostevals);
0072         stop = 5;
0073     end
0074 
0075     % Check whether the possibly user defined stopping criterion
0076     % triggers or not.
0077     if isfield(options, 'stopfun')
0078         userstop = options.stopfun(problem, x, info, last);
0079         if userstop
0080             reason = 'User defined stopfun criterion triggered; see options.stopfun.';
0081             stop = 6;
0082             return;
0083         end
0084     end
0085 
0086 end

Generated on Fri 08-Sep-2017 12:43:19 by m2html © 2005