在scipy中指定fmin_cobyla的约束 [英] Specifying constraints for fmin_cobyla in scipy
问题描述
我使用Python 2.5。
从numpy import导入numpy
asarray
Initial = numpy.asarray [2,4,5,3]#以
$ b开始的初始值$ b#绑定限制(lower,upper) - 用于可视化
#bounds = [(1,5000),(1,6000),(2,100000),(1,50000)]
#实际传递边界
b1 = lambda x:5000 - x [0]#lambda x:bounds [0] [1] - 初始[0]
b2 = lambda x:x [0] - 2.0#lambda x:Initial [0] - bounds [0] [0]
b3 = lambda x:6000 - x [1] #同上
b4 =拉姆达x:x [1] - 4.0
b5 =拉姆达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]#我的问题非常重要!
opt = optimize.fmin_cobyla(func,Initial,cons = [b1,b2,b3,b4,b5,b6,b7,b8,b9,b10],maxfun = 1500000)
根据初始值初始值
和as每个/在边界内 b1
到 b10
这些值传递给 opt() code>。但是这些值是有偏差的,特别是
b9
。这是我的问题非常重要的边界条件! $ b 传递给我的 x [2]
的值函数 opt()
在每次迭代中必须总是大于 x [3]
- 怎么可能实现这一点?
在我的界限( 还是有更好的方法来定义我的边界吗? 请帮助我。 关于你将要需要解决的是, 我不确定如何以 I use Python 2.5. I am passing bounds to the cobyla optimisation: Based on the initial values "The value of Is there anything wrong in my bounds ( Or is there a better way of defining of my bounds? Please help me. On thing that you will need to fix is that I'm not sure how to implement 这篇关于在scipy中指定fmin_cobyla的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! b1
到 b9 <
fmin_cobyla()
不是内部点方法。也就是说,它会在优化运行过程中将超出界限的点(不可行点)传递给函数。
b9
和 b10
不是 fmin_cobyla()
期望。绑定函数需要返回一个正数,如果它们在边界内,则返回0.0;如果边界正好在边界上,则返回负数;如果超出边界,则返回负数。理想情况下,这些功能应该平稳。 fmin_cobyla()
将尝试取这些函数的数值导数,以便让它知道如何返回到可行区域。
b9 = lambda x:x [2] - x [3]
fmin_cobyla()
的方式实现 b10
但是可以使用。 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
and as per/within the bounds b1
to b10
the values are passed to opt()
. But the values are deviating, especially with b9
. This is a very important bounding condition for my problem!x[2]
passed to my function opt()
at every iteration must be always greater than x[3]
" -- How is it possible to achieve this?b1
to b9
) definition ?fmin_cobyla()
is not an interior point method. That is, it will pass points that are outside of the bounds ("infeasible points") to the function during the course of the optmization run.b9
and b10
are not in the form that fmin_cobyla()
expects. The bound functions need to return a positive number if they are within the bound, 0.0 if they are exactly on the bound, and a negative number if they are out of bounds. Ideally, these functions should be smooth. fmin_cobyla()
will try to take numerical derivatives of these functions in order to let it know how to get back to the feasible region.b9 = lambda x: x[2] - x[3]
b10
in a way that fmin_cobyla()
will be able to use, though.