lsqsn
|
Contents: Description, Arguments, Usage, Examples, Sub-Functions, Related Functions, Source Supported Under Version: >1.00
Description Constrained least squares fitting, where some components are allowed to be negative and others are not
Arguments and Return Values Arguments: A two-dimensional matrix, a column vector, a scalar specifying the number of forced components, and an optional fourth 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: lsqsn(library_matrix, vector_to_be_fitted, n_unc[, mode]) library_matrix - A two-dimensional matrix (dimensions [n, m, 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, m, 1]) with the sample to be fitted. The first two inputs must have the same y-dimension.
This function basically sets up and runs calls to lsqnn, using binbyte to iterate through all combinations of positive and negative for the unconstrained components. Therefore increasing n_unc by one doubles the required number of computations. In order to limit computational time, n_unc must be less than or equal to 30, and values close to this limit will probably take too long to be feasible.
The fitted coefficients calculated by this function must be positive or zero for the first (n - nunc) samples; the coefficients for samples (n - nunc + 1) through n are unconstrained. This is for applications such as spectral deconvolution where it does not make physical sense to have negative coefficients for most samples, but a few, such as the blackbody term or the atmospheric components, might be negative. For cases where any of the coefficients are allowed to be negative, use lsq. For cases where none of the coefficients are allowed to be negative, use lsqnn.
If $4=0, lsqsn 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.
Examples dv> lsqsn()
Constrained least squares, where some elements are allowed to be
negative and others are not
lsqsn(X,y,n) returns A such that X*A best approximates y,
where the last n elements are allowed to be negative but
the first elements must be positive (or zero)
n must be less than or equal to 30
In essence, this function just sets up a bunch of calls to lsqnn,
which effectively means that each additional unconstrained
term effectively doubles the number of computations.
Optional fourth input controls output mode
If $4 is 1 (or omitted), will print summary and return structure
with errors and fitted spectrum, in addition to calculated
coefficients.
If $4 is 0, will only return structure with coefficients
This means that the format of the output depends on $4.
S.Marshall 11-09-2010
dv> Xb = cat(X, clone(1., 1,923,1), axis=x) # Adding blackbody
74x923x1 array of float, bsq format [273,208 bytes]
dv> y
1x923x1 array of float, bsq format [3,692 bytes]
dv> A = lsqsn(Xb, y, 1, 0)
1x74x1 array of double, bsq format [592 bytes]
dv> A = lsqsn(Xb, y, 1, 1)
Errors in fitted spectrum:
Mean absolute error: 0.011729
RMS error: 0.019572
Maximum absolute error: 0.182021
struct, 5 elements
A: 1x74x1 array of double, bsq format [592 bytes]
Yfit: 1x923x1 array of double, bsq format [7,384 bytes]
MAE: 0.0117294792933117
RMSE: 0.0195723106839733
maxE: 0.182020887732506
dv> A = lsqsn(Xb, y, 1)
Errors in fitted spectrum:
Mean absolute error: 0.011729
RMS error: 0.019572
Maximum absolute error: 0.182021
struct, 5 elements
A: 1x74x1 array of double, bsq format [592 bytes]
Yfit: 1x923x1 array of double, bsq format [7,384 bytes]
MAE: 0.0117294792933117
RMSE: 0.0195723106839733
maxE: 0.182020887732506
|
DavinciWiki Mini-Nav Bar Contents
Contact Developers
All other topics
Recent Library Changes Created On: 12-02-2010 |