问题描述
我正在使用 scipy.optimize 模块来寻找可以最小化我的输出的最佳输入权重.从我看到的例子中,我们用单边方程定义了约束;然后我们创建一个不等式"类型的变量.我的问题是优化包如何知道我的约束中变量的总和需要小于 1 还是大于 1?
...
def 约束 1(x):返回 x[0]+x[1]+x[2]+x[3]-1
....
con1 = {'type':'ineq','fun':constraint1}
链接到我在示例中使用的完整解决方案:
其中不等式的形式为 C_j(x) >= 0
.
所以当你将约束定义为
def 约束 1(x):返回 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
I am using the scipy.optimize module to find optimal input weights that would minimize my output. From the examples I've seen, we define the constraint with a one-sided equation; then we create a variable that's of the type 'inequality'. My question is how does the optimization package know whether the sum of the variables in my constraint need to be smaller than 1 or larger than 1?
...
def constraint1(x):
return x[0]+x[1]+x[2]+x[3]-1
....
con1 = {'type': 'ineq', 'fun': constraint1}
link to full solution I'm using in my example:http://apmonitor.com/che263/index.php/Main/PythonOptimization
Thank you.
If you refer to https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/optimize.html and scrool down to Constrained minimization of multivariate scalar functions (minimize), you can find that
where the inequalities are of the form C_j(x) >= 0
.
So when you define the constraint as
def constraint1(x):
return x[0]+x[1]+x[2]+x[3]-1
and specify the type of the constraint as
con1 = {'type': 'ineq', 'fun': constraint1}
it automatically assumes that the constraint is in the standard form x[0]+x[1]+x[2]+x[3]-1>=0
i.e., x[0]+x[1]+x[2]+x[3]>=1
这篇关于Scipy.optimize 不等式约束 - 考虑不等式的哪一侧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!