Wlsbaseline: Difference between revisions

From Eigenvector Research Documentation Wiki
Jump to navigation Jump to search
imported>Jeremy
(Importing text file)
 
imported>Donal
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
===Purpose===
===Purpose===
Weighted least squares baseline function.
Weighted least squares baseline function.
===Synopsis===
===Synopsis===
:[bldata,wts] = wlsbaseline(data,baseline,options)
 
:[bldata,wts] = wlsbaseline(data,order,options)
:[bldata,wts,baseline,vweights] = wlsbaseline(data,baseline,options)
:[bldata,wts,baseline,vweights] = wlsbaseline(data,order,options)
:[bldata] = wlsbaseline(data,lambda,options);  %Whittaker
 
===Description===
===Description===
Subtracts a baseline (or other signal) from a spectrum with the constraint that residuals below zero be weighted more heavily than those above zero. This achieves a robust "non-negaitve" residual fit when residuals of significant amplitude (e.g. signals on a background) are present.
 
Inputs are data the spectral data, baseline the reference spectrum/spectra to use for baseline OR an integer value representing the order of polynomial baselining to use and options an optional options structure.  
Subtracts a baseline (or other signal) from a spectrum (row) using an iterative asymmetric least squares algorithm. Points with residuals <0 are up-weighted at each iteration of the least squares fitting (this corresponds to the default options.trbflag='bottom'). The result is a robust "non-negaitve" residual fit when residuals of significant amplitude are present (i.e., signal is present on a background).
Outputs are the baselined data bldata and the weightings wts indicating the amount of baseline which was removed from each spectrum in data. (i.e. bldata = data - wts\*baseline)
 
Polynomial baseline Option: If a positive scalar value is given instead of the input baseline, then a polynomial baseline of that order will be used. In this mode, any row of the output wts can be used with the polyval function to obtain the baseline removed from the corresponding row of data.
There are several different filters are available, defined using the "filter" option:
:* 'basis' = baseline subtraction using either specified vectors, or a polynomial basis. This algorithms is generally slower but introduces fewer artifacts.
:* 'whittaker' = baseline subtraction using the Eilers' method based on a Whittaker filter. This algorithm is fast and handles more structured baselines, but can introduce peak shape artifacts (Eilers, Paul HC, and Hans FM Boelens. "Baseline correction with asymmetric least squares smoothing." Report ''(Leiden University Medical Centre, 2005)'' (2005). )
 
====Inputs====
* '''data''' = MxN data to be baselined - each ROW is baselined.
* '''baseline''' = 1xN reference spectrum (or KxN spectra) to use for baseline.
: An integer scalar value (order) corresponding to the order of polynomial baseline to use.
: A scalar value (lambda) indicating required smoothness to use with algorithm 'whittaker' when using the Eilers' method of baseline removal.
 
====Outputs====
* '''bldata''' = MxN baselined data.
* '''wts''' = Weights corresponding the amount of baseline removed from each spectrum (i.e. bldata = data - wts*baseline). If (baseline == polynomial order), wts contains the polynomial coefficients. Each row of (wts) can be used with the "baseline" output (see below) to obtain the baseline removed from the corresponding row of data. Note that wts can also be used with the POLYVAL function to reconstruct the baseline, however, a normalization factor of 1./sqrt(n) must be used on each baseline to correct for the number of variables (n).
* '''baseline''' = Baseline used for each spectrum. Note: this is the input (baseline) or polynomial basis.
* '''vweights''' = Variable weights used for each spectrum. Indicates the weighting used on each variable in each spectrum.
 
===Options===
===Options===
*    plots :  [{'none'} | 'debug' | 'intermediate' | 'final'] governs plots
 
*    weightmode :  [ {1} |  2 ] flag indicating which weighting mode to use.
*    '''dim''': [2] Dimension (mode) of data to baseline.
*  Mode 1 = Power method. Negative residuals are weighted up by the power of 10.\^(option.negw). All residuals are then raised to the power of (option.power)
*    '''plots''' :  [{'none'} | 'debug' | 'intermediate' | 'final'] governs plots
*  Mode 2 = T squared method. Negative residuals are weighted up by the extent to which the surpass an estimate of the noise limit and the approximate t-limit defined by (option.tsqlim)
*    '''filter''' : [ 'basis' | 'whittaker' ] governs baseline filter type.
*    trbflag :  [ 'bottom' | 'top' ] baseline to top or bottom of data
** 'basis' uses a set of basis vectors fit to each spectrum. Input (baseline) specifies either a polynomial order or the specific baselines to use.
*    negw :  {1} deweighting scale of negative values (10\^negw) (used only for weightmode = 1),
** 'whittaker' uses the Whittaker piecewise filter. Input (baseline) specifies the lambda smoothness.
*    power :  {2} exponential amplification of residuals (used only for weightmode = 1),
*    '''weightmode''' :  [ {1} |  2 ] flag indicating which weighting mode to use:
* tsqlim :  [0.99] t-test confidence limit for significant negative residuals which need to be up-weighted. (used only for weightmode = 2),
*'''Mode 1''' = Power method. Negative residuals are weighted up by the power of <math>10^{option.negw}</math>. All residuals are then raised to the power of (option.power)
* nonneg :  ['no'|{'yes'}] flag to force non-negative baseline weighting, most often used when "real" spectra are used for baslineing and they should not be "flipped" by a negative weighting. Using nonneg = 'yes', WLSBASELINE an be used as a partial CLS prediction to estimate the concentration of a species when not all species' pure component spectra are known,
*'''Mode 2''' = T squared method. Negative residuals are weighted up by the extent to which the surpass an estimate of the noise limit and the approximate t-limit defined by (option.tsqlim)
*    delta :  [1e-4] change-of-fit convergence criterion,
*    '''trbflag''' :  [ 'bottom' | 'top' ] baseline to top or bottom of data
*    maxiter :  [100] maximum iterations allowed per spectrum,
*    '''negw''' :  {1} deweighting scale of negative values (<math>10^{negw}</math>) (used only for weightmode = 1),
*    maxtime :  [600] maximum time (in seconds) permitted for baselining of all data.
*    '''power''' :  {2} exponential amplification of residuals (used only for weightmode = 1),
===Examples===
*   '''p''' : {0.001} asymmetry (used only with algorithm = 'whittaker'),
To swap 4 BYTES in a 32 bit number:
* '''tsqlim''' :  [0.99] t-test confidence limit for significant negative residuals which need to be up-weighted. (used only for weightmode = 2).
* '''nonneg''' :  ['no'|{'yes'}] flag to force non-negative baseline weighting, most often used when "real" spectra are used for baslineing and they should not be "flipped" by a negative weighting. Using nonneg = 'yes', WLSBASELINE an be used as a partial CLS prediction to estimate the concentration of a species when not all species' pure component spectra are known.
*    '''delta''' :  [1e-4] change-of-fit convergence criterion. Iterations are stopped when the relative change in fit is less than this value.
*    '''maxiter''' :  [100] maximum iterations allowed per spectrum,
*    '''maxtime''' :  [600] maximum time (in seconds) permitted for baselining of all data.
 
===See Also===
===See Also===
[[baseline]], [[baselinew]]
[[baseline]], [[baselinew]]

Latest revision as of 22:23, 10 June 2014

Purpose

Weighted least squares baseline function.

Synopsis

[bldata,wts,baseline,vweights] = wlsbaseline(data,baseline,options)
[bldata,wts,baseline,vweights] = wlsbaseline(data,order,options)
[bldata] = wlsbaseline(data,lambda,options); %Whittaker

Description

Subtracts a baseline (or other signal) from a spectrum (row) using an iterative asymmetric least squares algorithm. Points with residuals <0 are up-weighted at each iteration of the least squares fitting (this corresponds to the default options.trbflag='bottom'). The result is a robust "non-negaitve" residual fit when residuals of significant amplitude are present (i.e., signal is present on a background).

There are several different filters are available, defined using the "filter" option:

  • 'basis' = baseline subtraction using either specified vectors, or a polynomial basis. This algorithms is generally slower but introduces fewer artifacts.
  • 'whittaker' = baseline subtraction using the Eilers' method based on a Whittaker filter. This algorithm is fast and handles more structured baselines, but can introduce peak shape artifacts (Eilers, Paul HC, and Hans FM Boelens. "Baseline correction with asymmetric least squares smoothing." Report (Leiden University Medical Centre, 2005) (2005). )

Inputs

  • data = MxN data to be baselined - each ROW is baselined.
  • baseline = 1xN reference spectrum (or KxN spectra) to use for baseline.
An integer scalar value (order) corresponding to the order of polynomial baseline to use.
A scalar value (lambda) indicating required smoothness to use with algorithm 'whittaker' when using the Eilers' method of baseline removal.

Outputs

  • bldata = MxN baselined data.
  • wts = Weights corresponding the amount of baseline removed from each spectrum (i.e. bldata = data - wts*baseline). If (baseline == polynomial order), wts contains the polynomial coefficients. Each row of (wts) can be used with the "baseline" output (see below) to obtain the baseline removed from the corresponding row of data. Note that wts can also be used with the POLYVAL function to reconstruct the baseline, however, a normalization factor of 1./sqrt(n) must be used on each baseline to correct for the number of variables (n).
  • baseline = Baseline used for each spectrum. Note: this is the input (baseline) or polynomial basis.
  • vweights = Variable weights used for each spectrum. Indicates the weighting used on each variable in each spectrum.

Options

  • dim: [2] Dimension (mode) of data to baseline.
  • plots : [{'none'} | 'debug' | 'intermediate' | 'final'] governs plots
  • filter : [ 'basis' | 'whittaker' ] governs baseline filter type.
    • 'basis' uses a set of basis vectors fit to each spectrum. Input (baseline) specifies either a polynomial order or the specific baselines to use.
    • 'whittaker' uses the Whittaker piecewise filter. Input (baseline) specifies the lambda smoothness.
  • weightmode : [ {1} | 2 ] flag indicating which weighting mode to use:
    • Mode 1 = Power method. Negative residuals are weighted up by the power of . All residuals are then raised to the power of (option.power)
    • Mode 2 = T squared method. Negative residuals are weighted up by the extent to which the surpass an estimate of the noise limit and the approximate t-limit defined by (option.tsqlim)
  • trbflag : [ 'bottom' | 'top' ] baseline to top or bottom of data
  • negw : {1} deweighting scale of negative values () (used only for weightmode = 1),
  • power : {2} exponential amplification of residuals (used only for weightmode = 1),
  • p : {0.001} asymmetry (used only with algorithm = 'whittaker'),
  • tsqlim : [0.99] t-test confidence limit for significant negative residuals which need to be up-weighted. (used only for weightmode = 2).
  • nonneg : ['no'|{'yes'}] flag to force non-negative baseline weighting, most often used when "real" spectra are used for baslineing and they should not be "flipped" by a negative weighting. Using nonneg = 'yes', WLSBASELINE an be used as a partial CLS prediction to estimate the concentration of a species when not all species' pure component spectra are known.
  • delta : [1e-4] change-of-fit convergence criterion. Iterations are stopped when the relative change in fit is less than this value.
  • maxiter : [100] maximum iterations allowed per spectrum,
  • maxtime : [600] maximum time (in seconds) permitted for baselining of all data.

See Also

baseline, baselinew