Skip to content

Commit

Permalink
Merge branch 'master' into kn/adam-gen-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore-nori committed Oct 30, 2024
2 parents b848abf + 77501f4 commit 9d2a5f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/src/user/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ In addition to the solver, you can alter the behavior of the Optim package by us
* `show_warnings`: Should warnings due to NaNs or Inf be shown? Defaults to `true`.
* `trace_simplex`: Include the full simplex in the trace for `NelderMead`. Defaults to `false`.
* `show_every`: Trace output is printed every `show_every`th iteration.
* `callback`: A function to be called during tracing. A return value of `true` stops the `optimize` call. The callback function is called every `show_every`th iteration. If `store_trace` is false, the argument to the callback is of the type [`OptimizationState`](https://github.com/JuliaNLSolvers/Optim.jl/blob/a1035134ca1f3ebe855f1cde034e32683178225a/src/types.jl#L155), describing the state of the current iteration. If `store_trace` is true, the argument is a list of all the states from the first iteration to the current.
* `callback`: A function to be called during tracing. The return value should be a boolean, where `true` will stop the `optimize` call early. The callback function is called every `show_every`th iteration. If `store_trace` is false, the argument to the callback is of the type [`OptimizationState`](https://github.com/JuliaNLSolvers/Optim.jl/blob/a1035134ca1f3ebe855f1cde034e32683178225a/src/types.jl#L155), describing the state of the current iteration. If `store_trace` is true, the argument is a list of all the states from the first iteration to the current.
* `time_limit`: A soft upper limit on the total run time. Defaults to `NaN` (unlimited).

Box constrained optimization has additional keywords to alter the behavior of the outer solver:
Expand Down
4 changes: 2 additions & 2 deletions src/multivariate/solvers/zeroth_order/nelder_mead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ function trace!(tr, d, state, iteration, method::NelderMead, options::Options, c
dt["step_type"] = state.step_type
end
if options.trace_simplex
dt["simplex"] = state.simplex
dt["simplex_values"] = state.f_simplex
dt["simplex"] = deepcopy(state.simplex) # vector of arrays
dt["simplex_values"] = copy(state.f_simplex)
end
update!(tr,
iteration,
Expand Down
18 changes: 18 additions & 0 deletions test/general/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,21 @@
results = optimize(cos, 0.0, 2pi, method = Brent())
@test norm(Optim.minimizer(results) - pi) < 0.01
end


@testset "nm trace" begin
# https://github.com/JuliaNLSolvers/Optim.jl/issues/1112
f(x) = (x[1]^2 + x[2] - 11)^2 + (x[1] + x[2]^2 - 7)^2

x0 = [0.0, 0.0]
opt = Optim.Options(store_trace = true,
trace_simplex = true,
extended_trace = true)
res = optimize(f, x0, NelderMead(), opt)
tr = Optim.simplex_trace(res)
trval = Optim.simplex_value_trace(res)
trcent = Optim.centroid_trace(res)
@test tr[end] != tr[end-1]
@test trval[end] != trval[end-1]
@test trcent[end] != trcent[end-1]
end

0 comments on commit 9d2a5f2

Please sign in to comment.