优化不等式约束-不等式的哪一边被考虑?

2024-09-29 00:18:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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

谢谢你。


Tags: 模块类型return定义deftypescipy例子
1条回答
网友
1楼 · 发布于 2024-09-29 00:18:44

如果你引用https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/optimize.html并向下搜索多变量标量函数的约束最小化(minimize),你会发现

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

enter image description here

其中不等式的形式是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

相关问题 更多 >