python中的离散优化 [英] Discrete optimization 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屋!