diff --git a/src/multivariate/solvers/zeroth_order/nelder_mead.jl b/src/multivariate/solvers/zeroth_order/nelder_mead.jl index 3c98ce87..2d9c4428 100644 --- a/src/multivariate/solvers/zeroth_order/nelder_mead.jl +++ b/src/multivariate/solvers/zeroth_order/nelder_mead.jl @@ -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, diff --git a/test/general/optimize.jl b/test/general/optimize.jl index 7f0b3061..9281f23f 100644 --- a/test/general/optimize.jl +++ b/test/general/optimize.jl @@ -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 \ No newline at end of file