Stopping Criteria
Stopping criteria are implemented as a functor
, i.e. inherit from the base type
Manopt.StoppingCriterion
— TypeStoppingCriterion
An abstract type for the functors representing stopping criteria, i.e. they are callable structures. The naming Scheme follows functions, see for example StopAfterIteration
.
Every StoppingCriterion has to provide a constructor and its function has to have the interface (p,o,i)
where a Problem
as well as Options
and the current number of iterations are the arguments and returns a Bool whether to stop or not.
By default each StoppingCriterion
should provide a fields reason
to provide details when a criterion is met (and that is empty otherwise).
They can also be grouped, which is summarized in the type of a set of criteria
Manopt.StoppingCriterionSet
— TypeStoppingCriterionGroup <: StoppingCriterion
An abstract type for a Stopping Criterion that itself consists of a set of Stopping criteria. In total it acts as a stopping criterion itself. Examples are StopWhenAny
and StopWhenAll
that can be used to combine stopping criteria.
Then the stopping criteria s
might have certain internal values to check against, and this is done when calling them as a function s(p::Problem, o::Options)
, where the Problem
and the Options
together represent the current state of the solver. The functor returns either false
when the stopping criterion is not fulfilled or true
otherwise. One field all criteria should have is the s.reason
, a string giving the reason to stop, see get_reason
.
Stopping Criteria
The following generic stopping criteria are available. Some require that, for example, the corresponding Options
have a field gradient
when the criterion should check that.
Further stopping criteria might be available for individual solvers.
Manopt.StopAfter
— TypeStopAfter <: StoppingCriterion
store a threshold when to stop looking at the complete runtime. It uses time_ns()
to measure the time and you provide a Period
as a time limit, i.e. Minute(15)
Constructor
StopAfter(t)
initialize the stopping criterion to a Period t
to stop after.
Manopt.StopAfterIteration
— TypeStopAfterIteration <: StoppingCriterion
A functor for an easy stopping criterion, i.e. to stop after a maximal number of iterations.
Fields
maxIter
– stores the maximal iteration number where to stop atreason
– stores a reason of stopping if the stopping criterion has one be reached, seeget_reason
.
Constructor
StopAfterIteration(maxIter)
initialize the stopafterIteration functor to indicate to stop after maxIter
iterations.
Manopt.StopWhenAll
— TypeStopWhenAll <: StoppingCriterion
store an array of StoppingCriterion
elements and indicates to stop, when all indicate to stop. The reason
is given by the concatenation of all reasons.
Constructor
StopWhenAll(c::NTuple{N,StoppingCriterion} where N)
StopWhenAll(c::StoppingCriterion,...)
Manopt.StopWhenAny
— TypeStopWhenAny <: StoppingCriterion
store an array of StoppingCriterion
elements and indicates to stop, when any single one indicates to stop. The reason
is given by the concatenation of all reasons (assuming that all non-indicating return ""
).
Constructor
StopWhenAny(c::NTuple{N,StoppingCriterion} where N)
StopWhenAny(c::StoppingCriterion...)
Manopt.StopWhenChangeLess
— TypeStopWhenChangeLess <: StoppingCriterion
stores a threshold when to stop looking at the norm of the change of the optimization variable from within a Options
, i.e get_iterate(o)
. For the storage a StoreOptionsAction
is used
Constructor
StopWhenChangeLess(ε[, a])
initialize the stopping criterion to a threshold ε
using the StoreOptionsAction
a
, which is initialized to just store :Iterate
by default.
Manopt.StopWhenCostLess
— TypeStopWhenCostLess <: StoppingCriterion
store a threshold when to stop looking at the cost function of the optimization problem from within a Problem
, i.e get_cost(p,get_iterate(o))
.
Constructor
StopWhenCostLess(ε)
initialize the stopping criterion to a threshold ε
.
Manopt.StopWhenGradientNormLess
— TypeStopWhenGradientNormLess <: StoppingCriterion
stores a threshold when to stop looking at the norm of the gradient from within a GradientProblem
.
Manopt.StopWhenSmallerOrEqual
— TypeStopWhenSmallerOrEqual <: StoppingCriterion
A functor for an stopping criterion, where the algorithm if stopped when a variable is smaller than or equal to its minimum value.
Fields
value
– stores the variable which has to fall under a threshold for the algorithm to stopminValue
– stores the threshold where, if the value is smaller or equal to this threshold, the algorithm stopsreason
– stores a reason of stopping if the stopping criterion has one be reached, seeget_reason
.
Constructor
StopWhenSmallerOrEqual(value, minValue)
initialize the stopifsmallerorequal functor to indicate to stop after value
is smaller than or equal to minValue
.
Manopt.StopWhenStepsizeLess
— TypeStopWhenStepsizeLess <: StoppingCriterion
stores a threshold when to stop looking at the last step size determined or found during the last iteration from within a Options
.
Constructor
StopWhenStepsizeLess(ε)
initialize the stopping criterion to a threshold ε
.
Functions for Stopping Criteria
There are a few functions to update, combine and modify stopping criteria, especially to update internal values even for stopping criteria already being used within an Options
structure.
Base.:&
— Method&(s1,s2)
s1 & s2
Combine two StoppingCriterion
within an StopWhenAll
. If either s1
(or s2
) is already an StopWhenAll
, then s2
(or s1
) is appended to the list of StoppingCriterion
within s1
(or s2
).
Example
a = StopAfterIteration(200) & StopWhenChangeLess(1e-6)
b = a & StopWhenGradientNormLess(1e-6)
Is the same as
a = StopWhenAll(StopAfterIteration(200), StopWhenChangeLess(1e-6))
b = StopWhenAll(StopAfterIteration(200), StopWhenChangeLess(1e-6), StopWhenGradientNormLess(1e-6))
Base.:|
— Method|(s1,s2)
s1 | s2
Combine two StoppingCriterion
within an StopWhenAny
. If either s1
(or s2
) is already an StopWhenAny
, then s2
(or s1
) is appended to the list of StoppingCriterion
within s1
(or s2
)
Example
a = StopAfterIteration(200) | StopWhenChangeLess(1e-6)
b = a | StopWhenGradientNormLess(1e-6)
Is the same as
a = StopWhenAny(StopAfterIteration(200), StopWhenChangeLess(1e-6))
b = StopWhenAny(StopAfterIteration(200), StopWhenChangeLess(1e-6), StopWhenGradientNormLess(1e-6))
Manopt.are_these_stopping_critera_active
— Methodare_these_stopping_critera_active(c::StoppingCriterion, cond)
Return true
if any criterion from the given set is both active and fulfils the given condition cond
(cond(c)
returns true
).
Manopt.get_active_stopping_criteria
— Methodget_active_stopping_criteria(c)
returns all active stopping criteria, if any, that are within a StoppingCriterion
c
, and indicated a stop, i.e. their reason is nonempty. To be precise for a simple stopping criterion, this returns either an empty array if no stop is indicated or the stopping criterion as the only element of an array. For a StoppingCriterionSet
all internal (even nested) criteria that indicate to stop are returned.
Manopt.get_reason
— Methodget_reason(o)
return the current reason stored within the StoppingCriterion
from within the Options
This reason is empty if the criterion has never been met.
Manopt.get_reason
— Methodget_reason(c)
return the current reason stored within a StoppingCriterion
c
. This reason is empty if the criterion has never been met.
Manopt.get_stopping_criteria
— Methodget_stopping_criteria(c)
return the array of internally stored StoppingCriterion
s for a StoppingCriterionSet
c
.
Manopt.update_stopping_criterion!
— Methodupdate_stopping_criterion!(c::Stoppingcriterion, s::Symbol, v::value)
update_stopping_criterion!(o::Options, s::Symbol, v::value)
update_stopping_criterion!(c::Stoppingcriterion, ::Val{Symbol}, v::value)
Update a value within a stopping criterion, specified by the symbol s
, to v
. If a criterion does not have a value assigned that corresponds to s
, the update is ignored.
For the second signature, the stopping criterion within the Options
o
is updated.
To see which symbol updates which value, see the specific stopping criteria. They should use dispatch per symbol value (the third signature).
Manopt.update_stopping_criterion!
— Methodupdate_stopping_criterion!(c::StopAfter, :MaxTime, v::Period)
Update the time period after which an algorithm shall stop.
Manopt.update_stopping_criterion!
— Methodupdate_stopping_criterion!(c::StopAfterIteration, :;MaxIteration, v::Int)
Update the number of iterations after which the algorithm should stop.
Manopt.update_stopping_criterion!
— Methodupdate_stopping_criterion!(c::StopWhenChangeLess, :MinIterateChange, v::Int)
Update the minimal change blow which an algorithm shall stop.
Manopt.update_stopping_criterion!
— Methodupdate_stopping_criterion!(c::StopWhenCostLess, :MinCost, v)
Update the minimal cost below which the slgorithm shall stop
Manopt.update_stopping_criterion!
— Methodupdate_stopping_criterion!(c::StopWhenGradientNormLess, :MinGradNorm, v::Float64)
Update the minimal gradient norm when an algorithm shall stop
Manopt.update_stopping_criterion!
— Methodupdate_stopping_criterion!(c::StopWhenStepsizeLess, :MinStepsize, v)
Update the minimal step size below which the slgorithm shall stop