bundles / scipy latest / scipy / optimize / _nnls / nnls
function
scipy.optimize._nnls:nnls
source: /scipy/optimize/_nnls.py :9
Signature
def nnls ( A , b , * , maxiter = None , atol = <object object at 0x0000> ) Summary
Solve argmin_x || Ax - b ||_2^2 for x>=0.
Extended Summary
This problem, often called as NonNegative Least Squares, is a convex optimization problem with convex constraints. It typically arises when the x models quantities for which only nonnegative values are attainable; weight of ingredients, component costs and so on.
Parameters
A: (m, n) ndarrayCoefficient array
b: (m,) ndarray, floatRight-hand side vector.
maxiter: int, optionalMaximum number of iterations, optional. Default value is
3 * n.atol: float, optional
Returns
x: ndarraySolution vector.
rnorm: floatThe 2-norm of the residual,
|| Ax-b ||_2.
Notes
The code is based on the classical algorithm of [1]. It utilizes an active set method and solves the KKT (Karush-Kuhn-Tucker) conditions for the non-negative least squares problem.
Examples
import numpy as np from scipy.optimize import nnls A = np.array([[1, 0], [1, 0], [0, 1]]) b = np.array([2, 1, 1])✓
nnls(A, b)
✗b = np.array([-1, -1, -1]) nnls(A, b)✓
See also
- lsq_linear
Linear least squares with bounds on the variables
Aliases
-
scipy.optimize.nnls