I declared a function, I want to find its minimum by the method of differential evolution.

import math def f(x): return math.sin(x/5.0)*math.exp(x/10.0)+5*math.exp(-x/2.0) from scipy import optimize bounds = [1, 30] result = optimize.differential_evolution(f, bounds) 

But after running the script, I get the following error:

 # population is scaled to between [0, 1]. IndexError: tuple index out of range 

What is the problem?

    2 answers 2

    bounds is not just a pair (min, max), but a list of such pairs. The bounds = [(1, 30)] fix should fix this.

    Description and example in the official documentation .

      Note that the boundaries of the function's arguments are a list of tuples (a list in which objects of the tuple type are placed). Even if you have a function of one argument, put the boundaries of its values ​​in square brackets to pass in this parameter a list from one tuple, since In the implementation of scipy.optimize.differential_evolution, the length of this list is used to determine the number of function arguments.