Scipy Differential Evolution With Integers
Solution 1:
As noted in the comments there isn't direct support for a "integer constraint".
You could however minimize a modified objective function, e.g.:
deffunc1(x):
return func(x) + K * (x[3] - round(x[3]))**2
and this will force x[3]
towards an integer value (unfortunately you have to tune the K
parameter).
An alternative is to round (some of) the real-valued parameters before evaluating the objective function:
deffunc1(x):
z = x;
z[3] = round(z[3])
return func(z)
Both are common techniques to approach a discrete optimization problem using Differential Evolution and they work quite well.
Solution 2:
Differential evolution can support integer constraint but the current scipy implementation would need to be changed.
From the scipy source code it appears that their DE is based Storn, R and Price, K, Differential Evolution - a Simple and Efficient Heuristic for Global Optimization over Continuous Spaces, Journal of Global Optimization, 1997
However there has been progress in this field as pointed out by this review paper Recent advances in differential evolution – An updated survey
There are a few papers which introduce changes to the algorithm so that it can handle ints. I have not had time to look at all the options but perhaps this paper could help.
An Improved Differential Evolution Algorithm for Mixed Integer Programming Problems
Solution 3:
What do I replace the ???'s with to force those variables to be ints in a given range?
wrapdisc
is a package that is a thin wrapper which will let you optimize bounded integer variables alongside floats with various scipy.optimize
optimizers. There is a usage example in its readme. With it, you don't have to adapt your objective function at all. It internally uses rounding in order to support integers, although this detail is hidden from the user.
Post a Comment for "Scipy Differential Evolution With Integers"