我使用 Python 2.5。
我将界限传递给 cobyla 优化:
import numpy
from numpy import asarray
Initial = numpy.asarray [2, 4, 5, 3] # Initial values to start with
#bounding limits (lower,upper) - for visualizing
#bounds = [(1, 5000), (1, 6000), (2, 100000), (1, 50000)]
# actual passed bounds
b1 = lambda x: 5000 - x[0] # lambda x: bounds[0][1] - Initial[0]
b2 = lambda x: x[0] - 2.0 # lambda x: Initial[0] - bounds[0][0]
b3 = lambda x: 6000 - x[1] # same as above
b4 = lambda x: x[1] - 4.0
b5 = lambda x: 100000 - x[2]
b6 = lambda x: x[2] - 5.0
b7 = lambda x: 50000 - x[3]
b8 = lambda x: x[3] - 3.0
b9 = lambda x: x[2] > x[3] # very important condition for my problem!
opt= optimize.fmin_cobyla(func,Initial,cons=[b1,b2,b3,b4,b5,b6,b7,b8,b9,b10],maxfun=1500000)
基于初始值Initial
并根据/在范围内b1
将b10
值传递给opt()
. 但是这些值是有偏差的,尤其是b9
. 这是我的问题的一个非常重要的边界条件!
“在每次迭代中x[2]
传递给我的函数的值opt()
必须始终大于x[3]
”——如何实现这一点?
我的 bounds ( b1
to b9
) 定义有什么问题吗?
还是有更好的方法来定义我的界限?
请帮我。