Scipy.optimize Inequality Constraint - Which side of the inequality is considered?

折月煮酒 提交于 2019-11-30 16:55:56

问题


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.


回答1:


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

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

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



来源:https://stackoverflow.com/questions/42303470/scipy-optimize-inequality-constraint-which-side-of-the-inequality-is-considere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!