[SciPy-Dev] API to control iteration in differential evolution #6923

Denis Laxalde denis at laxalde.org
Wed Jan 11 04:38:30 EST 2017


Hi,

Recently there have been discussions about possible extensions of
scipy.optimize.differential_evolution() :

* https://github.com/scipy/scipy/issues/6878 is about having the
callback function receive the function value

* https://github.com/scipy/scipy/issues/6879 is about customizing of
population initialization

The differential_evolution function being already quite complex, we
thought it would be better to expose a "lower level" API to control the
iteration in the algorithm. This would be done by making the
DifferentialEvolutionSolver class (in
scipy/optimize/_differentialevolution.py) public and cleaning it a bit.

I submitted a pull request for this : 
https://github.com/scipy/scipy/pull/6923
One noticeable thing is that it also makes the class a context manager
to encapsulate the population initialization (in enter step) and final
polishing (in exit step). Ultimately, usage of this class (renamed as
DifferentialEvolution) would be:

   with DifferentialEvolution(func, bounds) as solver:
     # iterate until maxiter/maxfev is reached or the algorithm converged
     for step in solver:
       if mycallback(step.x, step.fun):
         break
   result = solver.result

I might look a bit fancy, but I think it makes sense to regard a
computation as a kind of context. Feedback welcome!

Cheers,
Denis.



More information about the SciPy-Dev mailing list