2

I'm writing a code in Python for optimization. I'm using the differential_evolution algorithm available in scipy library. I wrote the following code with the help of internet resources:

from scipy.optimize import differential_evolution
from numpy import exp
from numpy import sqrt
from numpy import cos
from numpy import e
from numpy import pi
import math

def objective(v):
    x, y = v
    return -20.0 * exp(-0.2 * sqrt(0.5 * (x**2 + y**2))) - exp(0.5 * (cos(2 * pi * x) + cos(2 * pi * y))) + e + 20

result = differential_evolution(objective)

and I'm getting the error:

Exception has occurred: TypeError
differential_evolution() missing 1 required positional argument: 'bounds'

When I try the same code with bounds it works:

result = differential_evolution(objective,[[-5.0,5.0],[-5.0,5.0]])

But according to the documentation, the 'bounds' argument is optional. (Also screenshot below)enter image description here And also I really don't see the point of requiring that argument. I really don't want to supply that argument because in most cases I don't really know a bound.

Am I missing something here? Am I doing something wrong?

Asclepius
  • 57,944
  • 17
  • 167
  • 143
PPGoodMan
  • 313
  • 4
  • 15
  • 2
    That looks like a mistake in the documentation. `bounds` is a positional argument with no default value, so it is not optional. – Warren Weckesser Apr 13 '21 at 22:02
  • 2
    FYI: The documentation in the development version has been updated: https://github.com/scipy/scipy/pull/13865 – Warren Weckesser Apr 15 '21 at 17:46
  • @WarrenWeckesser thank you! That possibility DID cross my mind. But usually we don't even know what bounds are in optimization problem. I tried feeding np.inf but it didn't work. Maybe I'd have to compromise and give a bound to the problem. – PPGoodMan Apr 18 '21 at 14:23

0 Answers0