Skip to content
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

RFC: more generic convergence assessment #530

Merged
merged 3 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 9 additions & 10 deletions src/multivariate/optimize/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ update_h!(d, state, method::SecondOrderOptimizer) = hessian!(d, state.x)

after_while!(d, state, method, options) = nothing

initial_convergence(d, state, method, initial_x, options) = false
initial_convergence(d, state, method::ZerothOrderOptimizer, initial_x, options) = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?


function initial_convergence(d, state, method::AbstractOptimizer, initial_x, options)
gradient!(d, initial_x)
vecnorm(gradient(d), Inf) < options.g_tol
end

function optimize(d::D, initial_x::AbstractArray{Tx, N}, method::M,
options::Options = Options(;default_options(method)...),
state = initial_state(method, options, d, complex_to_real(d, initial_x))) where {D<:AbstractObjective, M<:AbstractOptimizer, Tx, N}
Expand All @@ -31,16 +39,7 @@ function optimize(d::D, initial_x::AbstractArray{Tx, N}, method::M,
f_limit_reached, g_limit_reached, h_limit_reached = false, false, false
x_converged, f_converged, f_increased = false, false, false

g_converged = if typeof(method) <: NelderMead
nmobjective(state.f_simplex, state.m, n) < options.g_tol
elseif typeof(method) <: ParticleSwarm || typeof(method) <: SimulatedAnnealing
# TODO: remove KrylovTrustRegion when TwiceDifferentiableHV is in NLSolversBase
false
else
gradient!(d, initial_x)
vecnorm(gradient(d), Inf) < options.g_tol
end

g_converged = initial_convergence(d, state, method, initial_x, options)
converged = g_converged

# prepare iteration counter (used to make "initial state" trace entry)
Expand Down
4 changes: 4 additions & 0 deletions src/multivariate/solvers/zeroth_order/nelder_mead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ function assess_convergence(state::NelderMeadState, d, options)
return false, false, g_converged, g_converged, false
end

function initial_convergence(d, state::NelderMeadState, method::NelderMead, initial_x, options)
nmobjective(state.f_simplex, state.m, length(initial_x)) < options.g_tol
end

function trace!(tr, d, state, iteration, method::NelderMead, options)
dt = Dict()
if options.extended_trace
Expand Down
10 changes: 6 additions & 4 deletions src/utilities/assess_convergence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ function default_convergence_assessment(state::AbstractOptimizerState, d, option
f_increased = true
end

if g_residual(gradient(d)) ≤ options.g_tol
g_converged = true
end

g_converged = gradient_convergence_assessment(state,d,options)

converged = x_converged || f_converged || g_converged

return x_converged, f_converged, g_converged, converged, f_increased
end

gradient_convergence_assessment(state::AbstractOptimizerState, d, options) = g_residual(gradient(d)) ≤ options.g_tol
gradient_convergence_assessment(state::ZerothOrderState, d, options) = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in Jonathan's solver outside of Julia :) He wants to make some ZerothOrderSolver's outside of Optim but hook into everything else in Optim