Skip to content

Nelder-Mead stops prematurely if function returns Inf #1231

@MaximilianWollner

Description

@MaximilianWollner

Issue
Optimizing a function which returns Inf at one of the vertices causes the Nelder-Mead solver to stop prematurely without giving a proper reason for its termination. I did not encounter this issue in previous versions of Optim, where Inf was a valid function output.

Example

using Optim, LinearAlgebra

function test(x)
    if norm(x) > 1
        return Inf
    else
        return sum(x)
    end
end

res = optimize(x -> begin; y = test(x); println(y); y; end, [0.7, 0.3], NelderMead(), Optim.Options(show_trace=true))

foreach((key, value) -> println("$key: $value"), keys(res.stopped_by), values(res.stopped_by))
println("Termination code: $(res.termination_code)")

Versions
Julia v1.12.4
Optim v2.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions