View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
nnls - Non negative least squares

4.0 | 1 rating Rate this file 18 Downloads (last 30 days) File Size: 6.27 KB File ID: #38003 Version: 1.1

nnls - Non negative least squares



04 Sep 2012 (Updated )

nnls - Alternative to lsqnonneg: faster on large problems, improved convergence, optional restart

| Watch this File

File Information

nnls - Alternative to lsqnonneg: can be faster on large problems,
 improved convergence control, optional restart vector

Solves non negative least squares:
    min wrt x: (d-Cx)'*(d-Cx) subject to: x>=0

This version of nnls aims to solve convergance problems that can occur
with the 2011-2012 version of lsqnonneg, and provides a fast solution of
large problems. Includes an option to give initial positive terms for x
for faster solution of iterative problems using nnls.

For some large problems nnls can be faster than lsqnonneg,
see test file (nnlstest.m).

Simple usage: x=nnls(C,d)

 C Coefficient matrix
 d Rhs vector
 opts Struct containing options: (optional)
       .Accy 0 fast version, 1 refines final value (default),
                2 uses accurate steps but very slow on large cases,
                faster on small cases, result usually identical to 1
       .Order True or [], or order to initially include positive terms
                if included will supply info.Order, if x0 available use
                find(x0>0), but best saved from previous run of nnls
       .Tol Tolerance test value, default zero, use multiple of eps
       .Iter Maximum number of iterations, should not be needed.

 x Positive solution vector x>=0
 w Lagrange multiplier vector w(x==0)<= approx zero
 info Struct with extra information:
       .iter Number of iterations used
       .wsc0 Estimated size of errors in w
       .wsc Maximum of test values for w
       .Order Order variables used, use to restart nnls with opts.Order

Examples in nnlstest.m


Nlcontrol inspired this file.

This file inspired Nlsq & Nnnlsq Least Squares and Zero Sr1.

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
12 Oct 2016 Bill Whiten

nnls may fail to conserve on singular cases.
to regularise the problem by removing the singularity.
Can try different values for reg.

Comment only
22 Sep 2016 Gang Wu

nnls Failed to converge in 965 iterations

24 Aug 2015 Bill Whiten

See nnnlsq Non negative non linear least squares for non linear case.

Comment only
01 Mar 2013 Peter Näsholm

Thank you Bill for providing this function. For my particular problem, it turns out that your function can find an appropriate solution, while on the other hand the Matlab function lsqnonneg can not.

It's just a pity that i fiddeled and almost re-wrote lsqnonneg before I searched and found your implementation.

Once more: thank you!

Comment only
04 Sep 2012 Bill Whiten

Actual acknowledgement should be:
Lawson & Hanson, Solving Least Squares Problems, Ch 23.

Comment only
23 Apr 2013 1.1

Correction for case of all zero solution.

Contact us