python – Scipy.optimize Inequality Constraint – 不平等的哪一方被考虑?

我正在使用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并且scrool到约束最小化多变量标量函数(最小化),你会发现

This algorithm allows to deal with constrained minimization problems
of the form:

其中不等式的形式为C_j(x)> = 0.

因此,当您将约束定义为

def constraint1(x):
    return x[0]+x[1]+x[2]+x[3]-1

并将约束的类型指定为

con1 = {'type': 'ineq','fun': constraint1}

它自动假设约束是标准形式x [0] x [1] x [2] x [3] -1> = 0即x [0] x [1] x [2] x [3] > = 1

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。