Scipy.optimize 不等式约束 - 考虑不等式的哪一边?
Scipy.optimize Inequality Constraint - Which side of the inequality is considered?
我正在使用 scipy.optimize 模块来寻找可以最小化输出的最佳输入权重。从我看过的例子中,我们用单边方程定义约束;然后我们创建一个 'inequality' 类型的变量。我的问题是优化包如何知道我的约束中的变量之和需要小于1还是大于1?
...
def constraint1(x):
return x[0]+x[1]+x[2]+x[3]-1
.....
con1 = {'type': 'ineq', 'fun': constraint1}
link 到我在示例中使用的完整解决方案:
http://apmonitor.com/che263/index.php/Main/PythonOptimization
参考https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/optimize.html,向下滚动到Constrained minimization of multivariate scalar functions (minimize),可以发现
This algorithm allows to deal with constrained minimization problems
of the form:
[![在此处输入图片描述][1]][1]
其中不等式的形式为 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
[1]: https://i.stack.imgur.com/E3LPs.png
我正在使用 scipy.optimize 模块来寻找可以最小化输出的最佳输入权重。从我看过的例子中,我们用单边方程定义约束;然后我们创建一个 'inequality' 类型的变量。我的问题是优化包如何知道我的约束中的变量之和需要小于1还是大于1?
...
def constraint1(x):
return x[0]+x[1]+x[2]+x[3]-1
.....
con1 = {'type': 'ineq', 'fun': constraint1}
link 到我在示例中使用的完整解决方案: http://apmonitor.com/che263/index.php/Main/PythonOptimization
参考https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/optimize.html,向下滚动到Constrained minimization of multivariate scalar functions (minimize),可以发现
This algorithm allows to deal with constrained minimization problems of the form:
[![在此处输入图片描述][1]][1]
其中不等式的形式为 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
[1]: https://i.stack.imgur.com/E3LPs.png