我正在使用scipy.optimize模块来找到能够最小化输出的最佳输入权重。从我看到的例子来看,我们用一个单侧方程定义约束,然后我们创建一个类型为“不等式”的变量。我的问题是,优化包如何知道约束中的变量之和需要小于1还是大于1?
。。。
def constraint1(x):
return x[0]+x[1]+x[2]+x[3]-1
。。。。
con1 = {'type': 'ineq', 'fun': constraint1}
链接到我在示例中使用的完整解决方案: http://apmonitor.com/che263/index.php/Main/PythonOptimization
谢谢你。
如果你引用https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/optimize.html并向下搜索多变量标量函数的约束最小化(minimize),你会发现
其中不等式的形式是
C_j(x) >= 0
。所以当你把约束定义为
并将约束的类型指定为
它自动假设约束是标准形式的
x[0]+x[1]+x[2]+x[3]-1>=0
,即x[0]+x[1]+x[2]+x[3]>=1
相关问题 更多 >
编程相关推荐