Skip to content

Commit

Permalink
Minor improvements and bugfixes related to NelderMead (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkofod authored Apr 29, 2024
1 parent 6f3b372 commit 658c39a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/src/user/minimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ Defined for multivariate optimization:
* `g_converged(res)`
* `initial_state(res)`

Defined for `NelderMead` with the option `trace_simplex=true`:

* `centroid_trace(res)` (with `extended_trace=true`)
* `simplex_trace(res)`
* `simplex_values_trace(res)`

## Input types
Most users will input `Vector`'s as their `initial_x`'s, and get an `Optim.minimizer(res)` out that is also a vector. For zeroth and first order methods, it is also possible to pass in matrices, or even higher dimensional arrays. The only restriction imposed by leaving the `Vector` case is, that it is no longer possible to use finite difference approximations or automatic differentiation. Second order methods (variants of Newton's method) do not support this more general input type.

Expand Down
1 change: 1 addition & 0 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function simplex_trace(r::MultivariateOptimizationResults)
[ state.metadata["simplex"] for state in tr ]
end
function simplex_value_trace(r::MultivariateOptimizationResults)
tr = trace(r)
if !isa(r.method, NelderMead)
throw(ArgumentError("There are no simplex values involved in optimization using $(r.method). Please use f_trace(...) to grab the objective values from the trace."))
end
Expand Down
12 changes: 12 additions & 0 deletions test/general/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
Optim.optimize(d2, initial_x, LBFGS())

Optim.optimize(f, initial_x, NelderMead())
ne_res = Optim.optimize(f, initial_x, NelderMead(), Optim.Options(store_trace=true,))
@test_throws ErrorException Optim.simplex_trace(ne_res)
@test_throws ErrorException Optim.simplex_value_trace(ne_res)
@test_throws ErrorException Optim.centroid_trace(ne_res)
ne_res2 = Optim.optimize(f, initial_x, NelderMead(), Optim.Options(store_trace=true,trace_simplex=true))
Optim.simplex_trace(ne_res2)
Optim.simplex_value_trace(ne_res2)
@test_throws ErrorException Optim.centroid_trace(ne_res2)
ne_res3 = Optim.optimize(f, initial_x, NelderMead(), Optim.Options(store_trace=true,extended_trace=true,trace_simplex=true))
Optim.simplex_trace(ne_res3)
Optim.simplex_value_trace(ne_res3)
Optim.centroid_trace(ne_res3)

Optim.optimize(d3, initial_x, Newton())

Expand Down

0 comments on commit 658c39a

Please sign in to comment.