lsq
Contents: Description, Arguments, Usage, Examples, Sub-Functions, Related Functions, Source Supported Under Version: >1.00
Description Unconstrained 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: lsq(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.
The fitted coefficients calculated by this function may be positive, negative, or zero. In some cases, such as spectral deconvolution, 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 none of the coefficients are allowed to be negative, use lsqnn. For cases where some but not all of the coefficients are allowed to be negative, use lsqsn.
If $3=0, lsq 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> lsq() Unconstrained least squares fitting lsq(X,y) returns A such that X*A best approximates y by minimizing the sum of squares of the residuals. That is, A for which sum((y_i - A_i*X_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. Will also display summary of errors, unless given a third input equal to zero S.Marshall 09-09-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 = lsq(X, y, 0) 1x73x1 array of double, bsq format [584 bytes] dv> A = lsq(X, y, 1) Errors in fitted spectrum: MAD error: 0.007514 RMS error: 0.009874 Maximum absolute error: 0.040065 struct, 5 elements A: 1x73x1 array of double, bsq format [584 bytes] Yfit: 1x923x1 array of double, bsq format [7,384 bytes] MADE: 0.00751428542362132 RMSE: 0.00987431262035916 maxE: 0.0400653928518295 dv> A = lsq(X, y) Errors in fitted spectrum: MAD error: 0.007514 RMS error: 0.009874 Maximum absolute error: 0.040065 struct, 5 elements A: 1x73x1 array of double, bsq format [584 bytes] Yfit: 1x923x1 array of double, bsq format [7,384 bytes] MADE: 0.00751428542362132 RMSE: 0.00987431262035916 maxE: 0.0400653928518295 |
DavinciWiki Mini-Nav Bar Contents
Contact Developers
All other topics
Recent Library Changes Created On: 12-02-2010 |