Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nelder-Mead termination #86

Closed
mzaffalon opened this issue Aug 31, 2017 · 1 comment
Closed

Nelder-Mead termination #86

mzaffalon opened this issue Aug 31, 2017 · 1 comment

Comments

@mzaffalon
Copy link
Contributor

Nelder-Mead fails in the following two test cases: in too_many_iterations(), it reaches the correct minimum, (0,0) but it takes a few hundreds iteration before stopping: in wrong_minimum() it fails to find the minimum despite the tolerances on x and f being zero.

function obj_func(x, grad)
    r = sum(abs2, x)
    println(x, " -> ", r)
    r
end

function too_many_iterations()
    N = 2
    opt = Opt(:LN_NELDERMEAD, N)
    lower_bounds!(opt, -0.3 * ones(Float64, N))
    initial_step!(opt, 0.2 * ones(N))
    min_objective!(opt, obj_func)
    optimize(opt, ones(N))
end


function wrong_minimum()
    N = 2
    opt = Opt(:LN_NELDERMEAD, N)
    #println(stopval(opt), " ", ftol_rel(opt), " ", ftol_abs(opt), " ", xtol_abs(opt))
    lower_bounds!(opt, -0.3 * ones(Float64, N))
    initial_step!(opt, 0.7 * ones(N))
    min_objective!(opt, obj_func)
    optimize(opt, ones(N))
end

@odow
Copy link
Member

odow commented Mar 3, 2022

These are both correct given the tolerances. For example:

julia> function too_many_iterations()
           N = 2
           opt = Opt(:LN_NELDERMEAD, N)
           opt.ftol_abs = 1e-2
           lower_bounds!(opt, -0.3 * ones(Float64, N))
           initial_step!(opt, 0.2 * ones(N))
           min_objective!(opt, obj_func)
           optimize(opt, ones(N))
       end
too_many_iterations (generic function with 1 method)

julia> too_many_iterations()
[1.0, 1.0] -> 2.0
[1.2, 1.0] -> 2.44
[1.0, 1.2] -> 2.44
[1.2000000000000002, 0.8] -> 2.0800000000000005
[1.0000000000000002, 0.8] -> 1.6400000000000006
[0.9000000000000004, 0.7000000000000001] -> 1.3000000000000007
[0.7000000000000002, 0.9000000000000001] -> 1.3000000000000005
[0.4500000000000002, 0.9500000000000002] -> 1.1050000000000004
[0.35000000000000053, 0.6500000000000004] -> 0.5450000000000008
[0.0250000000000008, 0.47500000000000053] -> 0.22625000000000056
[-0.3, 0.7250000000000006] -> 0.6156250000000009
[-0.3, 0.2500000000000009] -> 0.15250000000000044
[-0.3, -0.09999999999999876] -> 0.09999999999999976
[0.0250000000000008, -0.3] -> 0.09062500000000004
[0.1875000000000012, -0.3] -> 0.12515625000000044
[-0.3, -0.3] -> 0.18
[-0.21874999999999978, -0.3] -> 0.1378515624999999
[-0.05624999999999941, -0.09999999999999876] -> 0.013164062499999686
[0.02500000000000077, 1.8596235662471372e-15] -> 0.0006250000000000386
[0.3500000000000016, -0.1999999999999994] -> 0.16250000000000087
[-0.13749999999999962, -0.12499999999999892] -> 0.034531249999999625
[-0.13749999999999965, 0.17500000000000293] -> 0.04953125000000093
[-0.09687499999999954, 0.0562500000000022] -> 0.012548828125000158
[0.06562500000000085, 0.181250000000003] -> 0.03715820312500119
[-0.08671874999999951, -0.04843749999999845] -> 0.009866333007812264
[0.035156250000000805, -0.10468749999999878] -> 0.012195434570312302
[0.0021484375000007175, -0.06445312499999854] -> 0.004158821105956846
(0.0006250000000000386, [0.02500000000000077, 1.8596235662471372e-15], :FTOL_REACHED)

@odow odow closed this as completed Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants