Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/src/user/minimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ julia> Optim.minimizer(res)
-0.3333
-1.49994

julia> minimum(res)
julia> Optim.minimum(res)
-2.8333333205768865
```

Expand Down
2 changes: 1 addition & 1 deletion ext/OptimMOIExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ MOI.get(::Optimizer, ::MOI.DualStatus) = MOI.NO_SOLUTION

function MOI.get(model::Optimizer, attr::MOI.ObjectiveValue)
MOI.check_result_index_bounds(model, attr)
val = minimum(model.results)
val = Optim.minimum(model.results)
if model.sense == MOI.MAX_SENSE
val = -val
end
Expand Down
1 change: 0 additions & 1 deletion src/Optim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import StatsBase: var
using LinearAlgebra:
LinearAlgebra,
Diagonal,
diag,
Hermitian,
Symmetric,
rmul!,
Expand Down
2 changes: 1 addition & 1 deletion src/api.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Base.summary(io::IO, r::OptimizationResults) = summary(io, r.method) # might want to do more here than just return summary of the method used
minimizer(r::OptimizationResults) = r.minimizer
Base.minimum(r::OptimizationResults) = r.minimum
minimum(r::OptimizationResults) = r.minimum
iterations(r::OptimizationResults) = r.iterations
iteration_limit_reached(r::OptimizationResults) = r.stopped_by.iterations
trace(r::OptimizationResults) =
Expand Down
2 changes: 1 addition & 1 deletion src/maximize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function maximize(
end

maximizer(r::MaximizationWrapper) = minimizer(res(r))
Base.maximum(r::MaximizationWrapper) = -minimum(res(r))
maximum(r::MaximizationWrapper) = -minimum(res(r))
Base.summary(io::IO, r::MaximizationWrapper) = summary(io, res(r))

for api_method in (
Expand Down
2 changes: 1 addition & 1 deletion src/multivariate/solvers/constrained/fminbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ function optimize(
dfbox.obj.h_calls[1] = 0
end
copyto!(x, minimizer(results))
boxdist = min(minimum(x - l), minimum(u - x))
boxdist = Base.minimum(((xi, li, ui),) -> min(xi - li, ui - xi), zip(x, l, u)) # Base.minimum !== minimum
if show_trace > 0
println()
println("Exiting inner optimizer with x = ", x)
Expand Down
2 changes: 1 addition & 1 deletion src/multivariate/solvers/constrained/samin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function optimize(
else
converge = 1
x_converged = true
x_absΔ = maximum(bounds)
x_absΔ = Base.maximum(bounds) # maximum !== Base.maximum
end
else
f_converged = false
Expand Down
3 changes: 2 additions & 1 deletion src/multivariate/solvers/first_order/ngmres.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ function update_state!(
Aview = view(state.A, 1:curw, 1:curw)
bview = view(state.b, 1:curw)
# The outer max is to avoid δ=0, which may occur if A=0, e.g. at numerical convergence
δ = method.ϵ0 * max(maximum(diag(Aview)), method.ϵ0)
# Note that Base.maximum !== maximum
δ = method.ϵ0 * max(Base.maximum(@view(Aview[diagind(Aview)])), method.ϵ0)
try
α .= (Aview + δ * I) \ bview
catch e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ work well without these safeguards when the Hessian is not positive definite.
function initial_safeguards(H, gr, delta, lambda)
# equations are on p. 560 of [MORESORENSEN]
T = eltype(gr)
λS = maximum(-diag(H))
λS = -Base.minimum(@view(H[diagind(H)])) # Base.minimum !== minimum
# they state on the first page that ||⋅|| is the Euclidean norm
gr_norm = norm(gr)
Hnorm = opnorm(H, 1)
Expand Down
4 changes: 2 additions & 2 deletions src/multivariate/solvers/zeroth_order/particle_swarm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function initial_state(
end
else
# user did not define number of particles
n_particles = maximum([3, length(initial_x)])
n_particles = max(3, length(initial_x))
end
c1 = T(2)
c2 = T(2)
Expand Down Expand Up @@ -193,7 +193,7 @@ function update_state!(f, state::ParticleSwarmState{T}, method::ParticleSwarm) w

if state.iteration == 0
copyto!(state.best_score, state.score)
f.F = minimum(state.score)
f.F = Base.minimum(state.score) # Base.minimum !== minimum
end
f.F = housekeeping!(
state.score,
Expand Down
6 changes: 3 additions & 3 deletions src/utilities/assess_convergence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ f_relchange(f_x::T, f_x_previous) where {T} = abs(f_x - f_x_previous) / abs(f_x)
x_abschange(state) = x_abschange(state.x, state.x_previous)
x_abschange(x, x_previous) = maxdiff(x, x_previous)
x_relchange(state) = x_relchange(state.x, state.x_previous)
x_relchange(x, x_previous) = maxdiff(x, x_previous) / maximum(abs, x)
x_relchange(x, x_previous) = maxdiff(x, x_previous) / Base.maximum(abs, x) # Base.maximum !== maximum

g_residual(d, state) = g_residual(d)
g_residual(d, state::NelderMeadState) = state.nm_x
g_residual(d::AbstractObjective) = g_residual(gradient(d))
g_residual(d::NonDifferentiable) = convert(typeof(value(d)), NaN)
g_residual(g) = maximum(abs, g)
g_residual(g) = Base.maximum(abs, g) # Base.maximum !== maximum
gradient_convergence_assessment(state::AbstractOptimizerState, d, options) =
g_residual(gradient(d)) ≤ options.g_abstol
gradient_convergence_assessment(state::ZerothOrderState, d, options) = false
Expand Down Expand Up @@ -52,7 +52,7 @@ function assess_convergence(
if x_abschange(x, x_previous) ≤ x_abstol
x_converged = true
end
if x_abschange(x, x_previous) ≤ x_reltol * maximum(abs, x)
if x_abschange(x, x_previous) ≤ x_reltol * Base.maximum(abs, x) # Base.maximum !== maximum
x_converged = true
end

Expand Down
2 changes: 1 addition & 1 deletion src/utilities/trace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function common_trace!(
dt["g(x)"] = copy(gradient(d))
dt["Current step size"] = state.alpha
end
g_norm = maximum(abs, gradient(d))
g_norm = Base.maximum(abs, gradient(d)) # Base.maximum !== maximum
update!(
tr,
iteration,
Expand Down
4 changes: 4 additions & 0 deletions test/general/api.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Test multivariate optimization
@testset "Multivariate API" begin
# We do not overload `Base.minimum` and `Base.maximum`
@test Optim.minimum !== minimum
@test Optim.maximum !== maximum

rosenbrock = MultivariateProblems.UnconstrainedProblems.examples["Rosenbrock"]
f = MVP.objective(rosenbrock)
g! = MVP.gradient(rosenbrock)
Expand Down
Loading