lsqnn

From DavinciWiki
Jump to: navigation, search

Citation

Nonnegative Least Squares:

  • Lawson, C. L., and R. J. Hanson. Solving Least Squares Problems, pp. 160-161 (Problem NNLS). Prentice-Hall, 1974.

Description

Nonnegative least squares fitting

Arguments and Return Values

Arguments: A two-dimensional matrix, a column vector, and an optional third input specifying the format to return

Return Value: A vector with the fitted coefficients, or a structure containing the fitted coefficients and other fit quantities

Usage

Syntax: lsqnn(library_matrix, vector_to_be_fitted[, mode])

library_matrix - A two-dimensional matrix (dimensions [m, n, 1]) with the library of known samples (e.g. spectra from mineral library), and a column vector with the unknown sample (e.g. spectrum of some rock) to be fitted with the library.

vector_to_be_fitted - A column vector (dimensions [1, n, 1]) with the sample to be fitted.

The first two inputs must have the same y-dimension.


If using this function for spectral deconvolution, the first input should be a matrix where each column corresponds to a different known sample (usually a known mineral) and each row gives the emissivity or reflectivity value of the samples at a certain wavelength or wavenumber. The second input should be a vector with the unknown sample to be analyzed, and the returned coefficients will be the concentration of each known sample.

The fitted coefficients calculated by this function must be positive or zero. This is for applications such as spectral deconvolution where it does not make physical sense to have negative coefficients. (What does it mean to have a sample that is -5% quartz?) For cases where any of the coefficients are allowed to be negative, use lsq. For cases where some but not all of the coefficients are allowed to be negative, use lsqsn.


An optional third input (passed by value) controls the output mode. If $3=0, the function will only return the fitted coefficients. If $3 is nonzero, or if it is omitted, the function will display a summary of the fit errors and will return a structure with the fitted coefficients, the fitted spectrum, the fit errors, and the number of positive endmembers after each iteration (field np).

If $3=0, lsqnn returns a column vector containing the fitted coefficients. Otherwise, it returns a structure with the fields A (fitted coefficients), Yfit (fitted spectrum), and other fields quantifying the errors in the fitted spectrum.


This function returns A such that X*A best approximates y, such that the sum of the squared errors is minimized. The data are fit to y = a1*x1 + a2*x2 + ... + an*xn, subject to the constraint that all ai≥0. Note that no constant offset (e.g. blackbody for emissivity spectra) is automatically included by this function; that must be added elsewhere if needed. Many spectral fitting functions (e.g. sma) have their own option to add the constant term.


If lsqnn() is entered with no arguments, it prints its description, as shown below.

Examples

dv> lsqnn()

Nonnegative least squares fitting
lsqnn(X,y) returns A such that X*A best approximates y
 by minimizing the sum of squares of the residuals,
 subject to the constraint that all elements of A are >= 0.
 That is, A for which sum((y_i - X_i*A_i)^2) is minimized.
The data input X should have m rows, n columns, and 1 plane.
The test input y should have m rows, 1 column, and 1 plane.
Optional third input controls output mode
 If $3 is 1 (or omitted), will print summary and return structure
  with errors and fitted spectrum, in addition to calculated
  coefficients.
 If $3 is 0, will only return structure with coefficients
 This means that the format of the output depends on $3.
This function uses an algorithm outlined in Lawson & Hanson 1974
Note that this function is set to stop after 100 iterations and
 return its best solution if no convergence is reached by then.
S.Marshall 10-31-2010

0
dv> X
73x923x1 array of float, bsq format [269,516 bytes]
dv> y
1x923x1 array of float, bsq format [3,692 bytes]
dv> A = lsqnn(X, y, 0)
1x73x1 array of double, bsq format [584 bytes]
dv> A = lsqnn(X, y, 1)

4 iterations; 1 significant (nonzero) end members
Errors in fitted spectrum:
Mean absolute error: 0.053749
RMS error: 0.081349
Maximum absolute error: 0.249029
struct, 6 elements
    A: 1x73x1 array of double, bsq format [584 bytes]
    Yfit: 1x923x1 array of double, bsq format [7,384 bytes]
    MAE: 0.0537490896174796
    RMSE: 0.0813486861080412
    maxE: 0.249029457569122
    np: 4x1x1 array of short, bsq format [8 bytes]
dv> A = lsqnn(X, y)

4 iterations; 1 significant (nonzero) end members
Errors in fitted spectrum:
Mean absolute error: 0.053749
RMS error: 0.081349
Maximum absolute error: 0.249029
struct, 6 elements
    A: 1x73x1 array of double, bsq format [584 bytes]
    Yfit: 1x923x1 array of double, bsq format [7,384 bytes]
    MAE: 0.0537490896174796
    RMSE: 0.0813486861080412
    maxE: 0.249029457569122
    np: 4x1x1 array of short, bsq format [8 bytes]

DavinciWiki Mini-Nav Bar

Contents


Contact Developers

  • davinci-dev [AT] mars.asu.edu

All other topics

  • See navigation on the left

Related Functions

Recent Library Changes

Created On: 12-02-2010
Modified On: 12-05-2010

Personal tools