Skip to content

Add Never <: ConvergenceMetric #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/convergence.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ calculations.
Evolutionary.AbsDiff
Evolutionary.RelDiff
Evolutionary.GD
Evolutionary.Never
```

## Auxiliary Functions
Expand Down
2 changes: 1 addition & 1 deletion src/api/results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function show(io::IO, r::EvolutionaryOptimizationResults)
sgn = converged(cm) ? "≤" : "≰"
dsc = description(cm)
lpd = " "^(maxdsclen + 1 - length(dsc))
print(io, "$rpd$dsc$lpd= $(diff(cm)) $sgn $(tolerance(cm))\n" )
!isa(cm, Never) && print(io, "$rpd$dsc$lpd= $(diff(cm)) $sgn $(tolerance(cm))\n" )
end
print(io, "\n")
end
Expand Down
12 changes: 11 additions & 1 deletion src/api/termination.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end
GD(tol::T, inv=false) where {T<:AbstractFloat} = GD(tol, Inf, zeros(T,0,0), inv)
GD(inv=false) = GD(1e-5, inv)
function description(m::GD)
prefix = m.inverted ? "I" : ""
prefix = m.inverted ? "I" : ""
"|$(prefix)GD(P) - $(prefix)GD(P')|"
end
function assess!(m::GD, state::AbstractOptimizerState)
Expand All @@ -131,6 +131,16 @@ function assess!(m::GD, state::AbstractOptimizerState)
converged(m)
end

"""
"Never converges" metric for single objective optimization.

This allows one to force the optimization algorithm to run for a given number of iterations.
"""
mutable struct Never <: ConvergenceMetric
end
description(m::Never) = "never converges (fixed number of iterations)"
assess!(m::Never, state::AbstractOptimizerState) = false
converged(m::Never) = false

"""
spread(S,R)
Expand Down
Loading