python中的离散优化 [英] Discrete optimzation in python
问题描述
我正在尝试使用scipy.optimize
包来优化离散优化问题(全局优化).根据文档,在scipy.optimize.anneal
中实现的模拟退火应该是一个不错的选择.但是我不确定如何强制优化器仅搜索搜索空间的整数值.有人可以帮忙吗?
I am trying to use the scipy.optimize
package to optimize a discrete optimization problem (global optimization). Acc to the doc, simulated annealing implemented in scipy.optimize.anneal
should be a good choice for the same. But I am not sure how to force the optimizer to search only integer values of the search space. Can someone help?
一个示例:
f(x1,x2) = (1-0.4*x1)^2 + 100*(0.6*x2 -0.4*x1^2)^2
where, $x1, x2 \in I$
推荐答案
我检查了scipy.optimize.anneal,但看不到使用离散值的方法.自己实现该方法的方法是创建一个自定义的移动"功能,但是必须(通过字符串)指定计划的方法使您无法这样做.
I've checked scipy.optimize.anneal, and I can't see a way to use discrete values. The way to implement it yourself, is to create a custom "move" function, but the way you have to specify the schedule (by a string) prevents you from doing so.
我认为这是一个很大的错误,如果您可以将自定义计划类作为参数传递,则可以使用离散变量和更多内容对其进行自定义.
I think it is a big mistake, if you could just pass a custom schedule class as the parameter, you could customize it for using discrete variables and many more things.
我找到的解决方案是改用其他实现: https://github.com/perrygeo/python-simulated-annealing
The solution I found is to use this other implementation instead: https://github.com/perrygeo/python-simulated-annealing
因为必须提供修改状态的功能,所以可以控制它可以具有的值,或者它们是离散的还是连续的.
Because you have to provide the function which modifies the state, you have control on what values it can have, or if they are discrete or continuous.
希望有帮助.
这篇关于python中的离散优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!