nlopt icon indicating copy to clipboard operation
nlopt copied to clipboard

MMA cycles between two iterates

Open jmlarson1 opened this issue 7 years ago • 4 comments

When running MMA on a 2-dimensional test function, I see that it fails to converge, but rather bounces between two points indefinitely. MMA is at a local solution, but has not identified it as such.

Reproducing code example:

import numpy as np
import nlopt

np.set_printoptions(precision=16)
def six_hump_camel_func(x):
    x1 = x[0]; x2 = x[1]

    term1 = (4-2.1*x1**2+(x1**4)/3) * x1**2;
    term2 = x1*x2;
    term3 = (-4+4*x2**2) * x2**2;

    return  term1 + term2 + term3

def six_hump_camel_grad(x):
    x1 = x[0]; x2 = x[1]; grad = np.zeros(2)

    grad[0] = 2.0*(x1**5 - 4.2*x1**3 + 4.0*x1 + 0.5*x2)
    grad[1] = x1 + 16*x2**3 - 8*x2

    return grad

def objective(x,grad):

    f = six_hump_camel_func(x)
    grad[:] = six_hump_camel_grad(x)
    print(x)
    return f

opt = nlopt.opt(nlopt.LD_MMA, 2)
opt.set_min_objective(objective)
opt.set_lower_bounds(-np.array([3,2]))
opt.set_upper_bounds(np.array([3,2]))

x = opt.optimize([-1.64574396,  0.85195592])

Output:

[-1.64574396  0.85195592]
[-3.                -0.265038270143849]
... after a few dozen iterations ...
[-1.7036067193868951  0.7960835871353801]
[-1.7036067193868951  0.7960835871353804]
[-1.7036067193868951  0.7960835871353801]
[-1.7036067193868951  0.7960835871353804]
... keeps repeating the last two points ...

Scipy/Numpy/Python/NLopt version information:

>>> import scipy, numpy, nlopt; print(scipy.__version__, numpy.__version__, sys.version_info, nlopt.__version__)
1.1.0 1.14.3 sys.version_info(major=3, minor=6, micro=5, releaselevel='final', serial=0) 2.4.2

jmlarson1 avatar Jun 07 '18 21:06 jmlarson1

You haven't set any stopping criteria?

stevengj avatar Jul 26 '18 17:07 stevengj

Is there no default stopping criteria?

jmlarson1 avatar Jul 26 '18 17:07 jmlarson1

Nope. Sometimes it will stop if it can detect that the solution is at the limits of roundoff error, but not all algorithms implement this check.

stevengj avatar Jul 26 '18 17:07 stevengj

Default stopping criteria would be nice to have. I've experienced the same issue.

Maybe this could be reclassified as a feature request?

rsln-s avatar Oct 01 '18 14:10 rsln-s