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

后端 未结 1 976
借酒劲吻你
借酒劲吻你 2020-12-09 11:03

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 equ

1条回答
  •  暖寄归人
    2020-12-09 11:24

    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

    0 讨论(0)
提交回复
热议问题