-1
$\begingroup$

I'm using Nevergrad by Facebook in Python and am observing some strange behaviour relating to bounds.

Let's find the minimum of a standard simple function:

def ackley( x, a=20, b=0.2, c=2*pi ):
    x = np.asarray_chkfinite(x)  # ValueError if any NaN or Inf
    n = len(x)
    s1 = sum( x**2 )
    s2 = sum( cos( c * x ))
    return -a*exp( -b*sqrt( s1 / n )) - exp( s2 / n ) + a + exp(1)

I'd like to use Nevergrad to optimise this. The true minimum value is at

minimum = np.zeros(n)

which gives a calculated value of

4.440892098500626e-16.

I'm using Nevergrad as follows:

from nevergrad import instrumentation as inst
from nevergrad.optimization import optimizerlib

n = 5

# Define the variable ranges...
instrum = inst.Instrumentation(*[inst.var.Array(1).asfloat().bounded(-10, 10) for _ in range(5)])

# Optimise the function...
optimizer = optimizerlib.TwoPointsDE(instrumentation=instrum, budget=10000)
recommendation = optimizer.optimize(lambda *args: ackley(np.array(args)))
print(recommendation)

This rightly returns:

>>> Candidate(args=(-1.4223567512956928e-11, 1.161667735276156e-11, 1.5909965473446878e-11, 3.142964723880178e-11, 2.1667036390793597e-12), kwargs={})

I.e., roughly zero. However, if I change the bounds to [-10, k], with k<0 I get:

k=-2
>>> Candidate(args=(-2.97922395034131, -2.979223956777669, -2.9792239575180597, -2.979223949490683, -2.979223956813635), kwargs={})

k=-4
>>> Candidate(args=(-4.986180458441733, -4.9861804545723105, -4.986180452383419, -4.986180455508544, -4.986180459693069), kwargs={})

...the minimum value is always claimed to be k-1*np.ones(n), however in all cases it should be at k*np.ones(n).

My question is: what's going on here? Why is Nevergrad getting these answers so consistently wrong? Have I done something wrong with the bounds? I can't see any documentation on the bounds so it's largely guess work here. Any help would be appreciated!

Thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.