If you want to enable the equality constraint, you cannot really use the nnls procedure, since it does not satisfy the equalities. If you are limited to what is offered in scipy, you can use this:
import numpy as np from scipy.optimize import minimize
Output:
status: 0 success: True njev: 2 nfev: 10 fun: 6608.620222860367 x: array([ 0., 0., 1.]) message: 'Optimization terminated successfully.' jac: array([ -62.50927734, -100.675354 , -127.78314209, 0. ]) nit: 2
This minimizes the objective function directly, and also creates a limit on the equality that interests you.
If speed is important, you can add information about jacobian and hessian or, even better, use the correct QP solver provided by cvxopt .
source share