Als: Difference between revisions
imported>Jeremy (Importing text file) |
|||
(32 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
===Purpose=== | ===Purpose=== | ||
Alternating Least Squares computational engine for multivariate curve resolution (MCR). | Alternating Least Squares computational engine for multivariate curve resolution (MCR). | ||
===Synopsis=== | ===Synopsis=== | ||
:[c,s] = als(x,c0,options); | :[c,s] = als(x,c0,options); | ||
===Description=== | ===Description=== | ||
ALS decomposes a matrix X as CS such that X = CS + E where E is minimized in a least squares sense. | |||
Inputs are the matrix to be decomposed x ( | ALS decomposes a matrix '''X''' as '''CS''' such that '''X''' = '''CS''' + '''E''' where '''E''' is minimized in a least squares sense. | ||
An optional input options is described below. | |||
The outputs are the estimated | Inputs are the matrix to be decomposed (x) (''M'' by ''N''), and an initial guess parameter (c0). If (c0) is a matrix of size ''M'' by ''K'', where ''K'' is the number of factors, then it is assumed to be the initial guess for '''C'''. If (c0) is size ''K'' by ''N'' then it is assumed to be the initial guess for '''S'''. If ''M'' = ''K'' then, (c0) is assumed to be the initial guess for '''C'''. The parameter (c0) can also be a scalar or a cell array. If it is a scalar then it represents the number of factors and will use the algorithm identified by the ''initialguessmethod'' option to choose the given number of items. If (c0) is a two-element cell array {k mode} then k is the number of factors and mode indicates which mode of the data (1=rows, 2=columns) to select. | ||
An optional input (options) is described below. | |||
The outputs are the estimated matrices '''C''', (c), (''M'' by ''K'') and '''S''', (s), (''K'' by ''N''). For a typical decomposition, (c) is a matrix of contributions and (s) is a matrix of spectra. The function | |||
:[c,s] = als(x,c0) | :[c,s] = als(x,c0) | ||
will decompose x using an non-negatively constrained alternating least squares | |||
will decompose (x) using an non-negatively constrained alternating least squares. To include other constraints, use the (options) input described below. | |||
Note that if no non-zero equality constraints are imposed on a factor the spectra are normalized to unit length. This can lead to significant scaling differences between factors that have non-zero equality constraints and those that do not. | Note that if no non-zero equality constraints are imposed on a factor the spectra are normalized to unit length. This can lead to significant scaling differences between factors that have non-zero equality constraints and those that do not. | ||
===Options=== | ===Options=== | ||
* | |||
* plots: [ 'none' | {'final'} ] governs level of plotting, | ====Display and Plotting==== | ||
* | * '''display''': [ 'off' | {'on'} ] governs level of display to command window. | ||
* | |||
* | * '''plots''': [ 'none' | {'final'} ] governs level of plotting. | ||
* | |||
* | * '''waitbar''': [ 'off' | 'on' | {'auto'} ] governs use of waitbar, | ||
* | |||
* | ====Non-Negativity Constraints==== | ||
* | |||
* | * '''ccon''': [ 'none' | 'reset' | 'baseline' | 'fastnnls' | {'fasternnls'}] non-negativity on contributions. (fasternnls = fast true non-negative least-squares solution, 'reset' = fast approximate method where negatives are forced to zero after least squares, 'baseline' = reset with polynomial baseline fitting before reset. | ||
* | |||
* | * '''cconind''': [ ] For use with ccon='fastnnls' and 'fasternnls' only; optionally indicates which factors or elements should be nonegatively controlled. Can be either a vector indicating which factors should be required to give non-negative concentration results or a logical matrix (same size as c) which indicates which elements should be non-negative. Default (empty) indicates that all elements and factors should be non-negative. | ||
* | |||
* | * '''scon''': [ 'none' | 'reset' | 'baseline' | 'fastnnls' | {'fasternnls'}] See ccon above | ||
* | |||
* | * '''sconind''': [ ] Same as cconind above except an indication of which factors or elements of s should be non-negatively controlled. If a logical matrix, must be the same size as s. Used only if scon='fastnnls' or 'fasternnls' | ||
* | |||
* | The following two options are only used when ccon or scon = 'baseline'. | ||
* | |||
* | * '''cblorder''': [ ] Order of polynomial to use on concentrations when 'baseline' ccon option is being used. Empty = no baseline (same as 'reset' ccon option). | ||
* '''sblorder''': [ ] Order of polynomial to use on spectra when 'baseline' scon option is being used. Empty = no baseline (same as 'reset' scon option). | |||
====Equality Constraints==== | |||
* '''cc''': [ ] contribution equality constraints, must be a matrix with M rows and up to K columns with NaN where equality constraints are not applied and real value of the constraint where they are applied. If fewer than K columns are supplied, the missing columns will be filled in as unconstrained. | |||
* '''ccwts''': [inf] a scalar value or a 1xK vector with elements corresponding to weightings on constraints (0, no constraint, 0<wt<inf imposes constraint "softly", and inf is hard constrained). If a scalar value is passed for ccwts, that value is applied for all K factors. | |||
:'''NOTE:''' Soft constraints are imposed by augmenting an additional column onto '''X''' and a weight of 1 weights a given equality constraint so that it has an equal influence as the average single variable in '''X'''. For additional information see P.J. Gemperline and E. Cash, “Advantages of Soft versus Hard Constraints in Self–Modeling Curve Resolution Problems. Alternating Least Squares with Penalty Functions”, ''Anal. Chem.,'' '''75'''(16), 4236–4243 (2003). | |||
* '''sc''': [ ] spectra equality constraints, must be a matrix with N columns and up to K rows with NaN where equality contraints are not applied and real value of the constraint where they are applied. If fewer than K rows are supplied, the missing rows will be filled in as unconstrained. | |||
* '''scwts''': [inf] weighting for spectral equality constraints (see ccwts) | |||
* '''contrast''': [ 'contributions' | 'spectra' | 'automatic'| { ' ' } ] introduces a constraint to obtain contrast in spectra of contributions/images. See also [[MCR Contrast Constraint]]. This constraint biases the answer towards maximal contrast in spectra ('spectra') or contributions / concentrations ('contributions') within the feasible bounds of the data. When the assumption of pure variables is appropriate, high contrast in spectra is expected and ('spectra') should be chosen. When samples have distinct layers, such as with a polymer laminate, high contrast in the contributions is expected and ('contributions') should be chosen. The option ('automatic') depends on the initial estimate c0, which is given by the user or by the use of initmode in the function MCR. This option results in: | |||
:('contributions') when (c0) is size (K by N) and MCR initmode==1 | |||
:('spectra') when (c0) is size (M by K) and MCR initmode==2 | |||
:An empty string imposes no constraint. | |||
* '''contrastweight''': [{0.05}]weighting used for contrast constraint. The algorithm makes angles between vectors (spectra or contributions) smaller by adding a portion (contrastweight) to the vectors. For example, for one of the vectora (v1) it would calculate: | |||
:(1-contrastweight)*v1 + contrastweight*mean(v) | |||
====Closure Constraints==== | |||
* '''closure''': [ ] indicates which factors should be constrained to sum to unit concentration (closure is a constraint where the sum of the columns of C must = 1). This option can be a scalar "true" value to indicate that all components should be constrained by closure, or a logical row vector indicating with a "1" for each component that should be constrained. | |||
::e.g. [ 0 1 1 0 0 ] = constrain components 2 and 3 of a five factor model with closure. | |||
:Additional rows can be added to constrain different sets of components. | |||
::e.g. [ 0 1 1 0 0 ; 0 0 0 1 1 ] = constrain components 2 and 3 with closure and also components 4 and 5 (separately). | |||
:Note that no checking is done to verify that these sets are not in conflict. | |||
* '''closurewts''': [ inf ] weighting for closure option. "inf" indicates hard closure constraint. Value of 1 gives closure constraint equal weight as one variable. | |||
====Convergence and Conditions==== | |||
* '''normorder''': [ {2} ] order of normalization applied to spectra (required to assure convergence). Typical settings are: | |||
::1 = normalize to unit area (1-norm) | |||
::2 = normalize to unit length (2-norm) {default} | |||
::inf = normalize to unit maximum (inf-norm) | |||
:This normalization is only applied to non-equality constrained components as these are the ones with a multiplicative ambiguity. | |||
* '''condition''': [{'none'}| 'norm' ] type of conditioning to perform on S and C before each regression step. 'norm' conditions each spectrum or contribution to its own norm. Conditioning can help stabilize the regression whenfactors are significantly different in magnitude. | |||
* '''tolc''': [ {1e-5} ] tolerance on non-negativity for contributions, | |||
* '''tols''': [ {1e-5} ] tolerance on non-negativity for spectra, | |||
* '''ittol''': [ {1e-8} ] convergence tolerance, | |||
* '''itmax''': [ {100} ] maximum number of iterations, | |||
* '''timemax''': [ {3600} ] maximum time for iterations, | |||
* '''rankfail''': [ 'drop' |{'reset'}| 'random' | 'fail' ] how are rank deficiencies handled: | |||
:* '''drop''' - drop deficient components from model | |||
:* '''reset''' - reset deficient components to initial guess | |||
:* '''random''' - replace deficient components with random vector | |||
:* '''fail''' - stop analysis, give error | |||
====Automatic Initial Guess==== | |||
* '''initialguessmethod''': [ 'distslct' | {'exteriorpts'} ] method used to find initial guess for '''C''' or '''S''': | |||
:* '''distslct''' - Selects samples on outside of data space based on Euclidian distance, | |||
:* '''exteriorpts''' - Selects samples on outside of data space based after normalizing the samples. | |||
* '''initialguessminnorm''': [ 0.03 ] value passed to exteriorpts option 'minnorm'. Approximate noise level, points with unit area smaller than this (as a fraction of the maximum value in x) are ignored during selection.. | |||
====Other==== | |||
* '''sclc''': [ ] contributions scale axis, vector with ''M'' elements otherwise 1:M is used. | |||
* '''scls''': [ ] spectra scale axis, vector with ''N'' elements otherwise 1:N is used. | |||
===Examples=== | ===Examples=== | ||
To decompose a matrix x without non-negativity constraints use: | |||
To decompose a matrix (x) without non-negativity constraints use: | |||
:options = als('options'); | :options = als('options'); | ||
:options.ccon = 'none'; | :options.ccon = 'none'; | ||
:options.scon = 'none'; | :options.scon = 'none'; | ||
:[c,s] = als(x,c0,options); | :[c,s] = als(x,c0,options); | ||
The following shows an example of using soft-constraints on the second spectral component of a three-component solution assuming that the variable softs contains the spectrum to which component two should be constrained. | The following shows an example of using soft-constraints on the second spectral component of a three-component solution assuming that the variable softs contains the spectrum to which component two should be constrained. | ||
:[m,n] = size(x); | :[m,n] = size(x); | ||
:options = als('options'); | :options = als('options'); | ||
:options.sc = NaN\*ones(3,n); %all 3 unconstrained | :options.sc = NaN\*ones(3,n); %all 3 unconstrained | ||
:options.sc(2,:) = softs; %constrain component 2 | :options.sc(2,:) = softs; %constrain component 2 | ||
:options.scwts = 0.5; %consider as 1/2 of total signal in X | :options.scwts = 0.5; %consider as 1/2 of total signal in X | ||
:[c,s] = als(x,c0,options); | :[c,s] = als(x,c0,options); | ||
===See Also=== | ===See Also=== | ||
[[mcr]], [[parafac]], [[pca]] | |||
[[als_sit]], [[fasternnls]], [[mcr]], [[parafac]], [[pca]], [[distslct]], [[exteriorpts]] |
Latest revision as of 11:39, 11 December 2023
Purpose
Alternating Least Squares computational engine for multivariate curve resolution (MCR).
Synopsis
- [c,s] = als(x,c0,options);
Description
ALS decomposes a matrix X as CS such that X = CS + E where E is minimized in a least squares sense.
Inputs are the matrix to be decomposed (x) (M by N), and an initial guess parameter (c0). If (c0) is a matrix of size M by K, where K is the number of factors, then it is assumed to be the initial guess for C. If (c0) is size K by N then it is assumed to be the initial guess for S. If M = K then, (c0) is assumed to be the initial guess for C. The parameter (c0) can also be a scalar or a cell array. If it is a scalar then it represents the number of factors and will use the algorithm identified by the initialguessmethod option to choose the given number of items. If (c0) is a two-element cell array {k mode} then k is the number of factors and mode indicates which mode of the data (1=rows, 2=columns) to select.
An optional input (options) is described below.
The outputs are the estimated matrices C, (c), (M by K) and S, (s), (K by N). For a typical decomposition, (c) is a matrix of contributions and (s) is a matrix of spectra. The function
- [c,s] = als(x,c0)
will decompose (x) using an non-negatively constrained alternating least squares. To include other constraints, use the (options) input described below.
Note that if no non-zero equality constraints are imposed on a factor the spectra are normalized to unit length. This can lead to significant scaling differences between factors that have non-zero equality constraints and those that do not.
Options
Display and Plotting
- display: [ 'off' | {'on'} ] governs level of display to command window.
- plots: [ 'none' | {'final'} ] governs level of plotting.
- waitbar: [ 'off' | 'on' | {'auto'} ] governs use of waitbar,
Non-Negativity Constraints
- ccon: [ 'none' | 'reset' | 'baseline' | 'fastnnls' | {'fasternnls'}] non-negativity on contributions. (fasternnls = fast true non-negative least-squares solution, 'reset' = fast approximate method where negatives are forced to zero after least squares, 'baseline' = reset with polynomial baseline fitting before reset.
- cconind: [ ] For use with ccon='fastnnls' and 'fasternnls' only; optionally indicates which factors or elements should be nonegatively controlled. Can be either a vector indicating which factors should be required to give non-negative concentration results or a logical matrix (same size as c) which indicates which elements should be non-negative. Default (empty) indicates that all elements and factors should be non-negative.
- scon: [ 'none' | 'reset' | 'baseline' | 'fastnnls' | {'fasternnls'}] See ccon above
- sconind: [ ] Same as cconind above except an indication of which factors or elements of s should be non-negatively controlled. If a logical matrix, must be the same size as s. Used only if scon='fastnnls' or 'fasternnls'
The following two options are only used when ccon or scon = 'baseline'.
- cblorder: [ ] Order of polynomial to use on concentrations when 'baseline' ccon option is being used. Empty = no baseline (same as 'reset' ccon option).
- sblorder: [ ] Order of polynomial to use on spectra when 'baseline' scon option is being used. Empty = no baseline (same as 'reset' scon option).
Equality Constraints
- cc: [ ] contribution equality constraints, must be a matrix with M rows and up to K columns with NaN where equality constraints are not applied and real value of the constraint where they are applied. If fewer than K columns are supplied, the missing columns will be filled in as unconstrained.
- ccwts: [inf] a scalar value or a 1xK vector with elements corresponding to weightings on constraints (0, no constraint, 0<wt<inf imposes constraint "softly", and inf is hard constrained). If a scalar value is passed for ccwts, that value is applied for all K factors.
- NOTE: Soft constraints are imposed by augmenting an additional column onto X and a weight of 1 weights a given equality constraint so that it has an equal influence as the average single variable in X. For additional information see P.J. Gemperline and E. Cash, “Advantages of Soft versus Hard Constraints in Self–Modeling Curve Resolution Problems. Alternating Least Squares with Penalty Functions”, Anal. Chem., 75(16), 4236–4243 (2003).
- sc: [ ] spectra equality constraints, must be a matrix with N columns and up to K rows with NaN where equality contraints are not applied and real value of the constraint where they are applied. If fewer than K rows are supplied, the missing rows will be filled in as unconstrained.
- scwts: [inf] weighting for spectral equality constraints (see ccwts)
- contrast: [ 'contributions' | 'spectra' | 'automatic'| { ' ' } ] introduces a constraint to obtain contrast in spectra of contributions/images. See also MCR Contrast Constraint. This constraint biases the answer towards maximal contrast in spectra ('spectra') or contributions / concentrations ('contributions') within the feasible bounds of the data. When the assumption of pure variables is appropriate, high contrast in spectra is expected and ('spectra') should be chosen. When samples have distinct layers, such as with a polymer laminate, high contrast in the contributions is expected and ('contributions') should be chosen. The option ('automatic') depends on the initial estimate c0, which is given by the user or by the use of initmode in the function MCR. This option results in:
- ('contributions') when (c0) is size (K by N) and MCR initmode==1
- ('spectra') when (c0) is size (M by K) and MCR initmode==2
- An empty string imposes no constraint.
- contrastweight: [{0.05}]weighting used for contrast constraint. The algorithm makes angles between vectors (spectra or contributions) smaller by adding a portion (contrastweight) to the vectors. For example, for one of the vectora (v1) it would calculate:
- (1-contrastweight)*v1 + contrastweight*mean(v)
Closure Constraints
- closure: [ ] indicates which factors should be constrained to sum to unit concentration (closure is a constraint where the sum of the columns of C must = 1). This option can be a scalar "true" value to indicate that all components should be constrained by closure, or a logical row vector indicating with a "1" for each component that should be constrained.
- e.g. [ 0 1 1 0 0 ] = constrain components 2 and 3 of a five factor model with closure.
- Additional rows can be added to constrain different sets of components.
- e.g. [ 0 1 1 0 0 ; 0 0 0 1 1 ] = constrain components 2 and 3 with closure and also components 4 and 5 (separately).
- Note that no checking is done to verify that these sets are not in conflict.
- closurewts: [ inf ] weighting for closure option. "inf" indicates hard closure constraint. Value of 1 gives closure constraint equal weight as one variable.
Convergence and Conditions
- normorder: [ {2} ] order of normalization applied to spectra (required to assure convergence). Typical settings are:
- 1 = normalize to unit area (1-norm)
- 2 = normalize to unit length (2-norm) {default}
- inf = normalize to unit maximum (inf-norm)
- This normalization is only applied to non-equality constrained components as these are the ones with a multiplicative ambiguity.
- condition: [{'none'}| 'norm' ] type of conditioning to perform on S and C before each regression step. 'norm' conditions each spectrum or contribution to its own norm. Conditioning can help stabilize the regression whenfactors are significantly different in magnitude.
- tolc: [ {1e-5} ] tolerance on non-negativity for contributions,
- tols: [ {1e-5} ] tolerance on non-negativity for spectra,
- ittol: [ {1e-8} ] convergence tolerance,
- itmax: [ {100} ] maximum number of iterations,
- timemax: [ {3600} ] maximum time for iterations,
- rankfail: [ 'drop' |{'reset'}| 'random' | 'fail' ] how are rank deficiencies handled:
- drop - drop deficient components from model
- reset - reset deficient components to initial guess
- random - replace deficient components with random vector
- fail - stop analysis, give error
Automatic Initial Guess
- initialguessmethod: [ 'distslct' | {'exteriorpts'} ] method used to find initial guess for C or S:
- distslct - Selects samples on outside of data space based on Euclidian distance,
- exteriorpts - Selects samples on outside of data space based after normalizing the samples.
- initialguessminnorm: [ 0.03 ] value passed to exteriorpts option 'minnorm'. Approximate noise level, points with unit area smaller than this (as a fraction of the maximum value in x) are ignored during selection..
Other
- sclc: [ ] contributions scale axis, vector with M elements otherwise 1:M is used.
- scls: [ ] spectra scale axis, vector with N elements otherwise 1:N is used.
Examples
To decompose a matrix (x) without non-negativity constraints use:
- options = als('options');
- options.ccon = 'none';
- options.scon = 'none';
- [c,s] = als(x,c0,options);
The following shows an example of using soft-constraints on the second spectral component of a three-component solution assuming that the variable softs contains the spectrum to which component two should be constrained.
- [m,n] = size(x);
- options = als('options');
- options.sc = NaN\*ones(3,n); %all 3 unconstrained
- options.sc(2,:) = softs; %constrain component 2
- options.scwts = 0.5; %consider as 1/2 of total signal in X
- [c,s] = als(x,c0,options);
See Also
als_sit, fasternnls, mcr, parafac, pca, distslct, exteriorpts