Python 多约束Scipy极小化
我想使用scipy模块scipy.optimize最小化一个函数,我正在努力理解如何实现我的约束。我的解的极值点必须正好是0和1,所以现在我要Python 多约束Scipy极小化,python,optimization,scipy,constraints,Python,Optimization,Scipy,Constraints,我想使用scipy模块scipy.optimize最小化一个函数,我正在努力理解如何实现我的约束。我的解的极值点必须正好是0和1,所以现在我要 cons = ({'type': 'eq', 'fun' : lambda x: x[0]}, #the initial point is 0 {'type': 'eq', 'fun' : lambda x: x[-1]-1.}) #the final point is 1 但我还需要每隔一点严格
cons = ({'type': 'eq',
'fun' : lambda x: x[0]}, #the initial point is 0
{'type': 'eq',
'fun' : lambda x: x[-1]-1.}) #the final point is 1
但我还需要每隔一点严格地大于0小于1。如何为数组的所有其他点显式添加此进一步约束 如果
x[0]
必须为0且x[-1]
必须为1,则您没有对其进行优化,因此您可以在函数中将其设置为这些值,无需添加约束。对于其他点,使用边界设置0和1之间的边界:
bounds=[(0,1),(0,1),…]
谢谢,这正是我想要的。