NLopt :FORCED_STOP

Hello,

I am trying to get NLopt to work but it just stops immediately and gives :FORCED_STOP. I tried the following but it looks like the algorithm isn’t even going into _ff. Any thoughts? Thank you!

function ff(x)
    return sum(x.^2)
    #return sum(abs.(SSresid(mod_pars,x[1],x[2],x[3])));
end
function _ff(x)
    try ff(x)
    catch 
        println("error")
    end
end
opt = Opt(:LN_SBPLX, 3);
opt.xtol_rel = 1e-1;
opt.min_objective = _ff;
(minf,minx,ret) = NLopt.optimize(opt, [1,25,0.1])

Read the tutorial: https://github.com/JuliaOpt/NLopt.jl#tutorial. You need to provide the gradient:

using ForwardDiff
using NLopt

opt = NLopt.Opt(:LN_SBPLX, 3);
f(x) = sum(x.^2)
function my_obj(x, g)
    if length(g) > 0
        ForwardDiff.gradient!(g, f, x)
    end
    return f(x)
end
opt.min_objective = my_obj
sol = NLopt.optimize(opt, [1.0, 25.0, 0.1])

You may be interested in https://github.com/JuliaNLSolvers/Optim.jl

2 Likes