Preprocess: Difference between revisions

From Eigenvector Research Documentation Wiki
Jump to navigation Jump to search
imported>Jeremy
(Importing text file)
 
(32 intermediate revisions by 7 users not shown)
Line 1: Line 1:
===Purpose===
===Purpose===


Selection and application of preprocessing methods.
Selection and application of standard [[Model_Building:_Preprocessing_Methods|preprocessing methods]].


===Synopsis===
===Synopsis===


:s = preprocess(''s'')                       %GUI preprocessing selection
: s = preprocess;                  %Modal GUI to select preprocessing
 
:[s,changed] = preprocess(s); %Modal GUI to modify preprocessing
:s = preprocess('default','methodname')             %Non-GUI selection
:list = preprocess('initcatalog'); % Gives a list of the available methods
 
:preprocess('keywords'); %Lists valid method names.
:[datap,sp] = preprocess('calibrate',s,data)  %single block calibrate
:s = preprocess('default','methodname');            %Non-GUI interactive preprocessing selection
 
:[datap,sp] = preprocess('calibrate',s,data);   %single block calibration of preprocessing
:[datap,sp] = preprocess('calibrate',s,xblock,yblock)    %multi-block
:[datap,sp] = preprocess('calibrate',s,xblock,yblock);     %multi-block calibration of preprocessing
 
:datap = preprocess('apply',sp,data);               %apply to new data
:datap = preprocess('apply',sp,data)                %apply to new data
:data = preprocess('undo',sp,datap) ;              %undo preprocessing
 
:data = preprocess('undo_silent',sp,datap);    %undo preprocessing (no warnings)
:data = preprocess('undo',sp,datap)               %undo preprocessing
:[datap,s] = preprocess(data);                      %Modal GUI to preprocess selected data
:[datap,s] = preprocess(data,s);                    %Modal GUI to preprocess selected data


===Description===
===Description===


PREPROCESS is a general tool to choose preprocessing steps and to perform these steps on data. See PREPROUSER for a description on how custom preprpocessing can be added to the standard proprocessings listed below. PREPROCESS has four basic command-line forms which include:
PREPROCESS is a general tool to choose preprocessing steps and to perform the steps on data. It can be used as a graphical interface or as a command-line tool. See [[ModelBuilding_PreProcessingMethods|Model Building - PreProcessing Methods]] for a description of the use of the graphical user interface. See [[User Defined Preprocessing]] and [[preprouser]] for a description on how custom preprocessing can be added to the standard preprocessing options listed below.
 
1) SELECTION OF PREPROCESSING.
 
The purpose of the following calls to PREPROCESS is to generate standard structure arrays that contain the desired preprocessing steps.
 
:s = preprocess;
 
generates a GUI and allows the user to select preprocessing steps interactively. The output s is a standard preprocessing structure.


:s = preprocess(s);
From the command line, PREPROCESS can be used to perform four different tasks:
* 1) Specification of Preprocessing (or preprocessing steps),
* 2) Estimate preprocessing parameters (calibrate),
* 3) Apply preprocessing to new data (apply), and
* 4) Remove the preprocessing previously performed on the data (undo).


allows the user to interactively edit a previously identified preprocessing structure s. The output s is the edited preprocessing structure.
====Case 1) Specification of Preprocessing====


:s = preprocess('default','methodname');
The purpose of the following calls to PREPROCESS is to generate standard preprocessing structure arrays that contain the desired preprocessing steps. The commands are listed here.


returns the default structure for method 'methodname'. A list of strings that can be used for 'methodname' can be viewed using the command:
s = preprocess;
creates a GUI that allows the user to select preprocessing steps interactively. The output <tt>s</tt> is a standard preprocessing structure. If multiple preprocessing steps are selected, <tt>s</tt> is a multi-record structure with each record corresponding to a preprocessing step.


:preprocess('keywords')
[s,changed] = preprocess(s);
allows the user to interactively edit a previously-built preprocessing structure <tt>s</tt>. The output <tt>s</tt> is the edited preprocessing structure. The second output <tt>changed</tt> is a flag that indicates whether the user clicked "OK" (==1) or "Cancel" (==0) to close the interface. If the user cancels, the output will be the same as the input (no changes have been made.)


A list of standard methods 'methodname' follow:
s = preprocess('default','methodname');
 
returns the default preprocessing structure for method <tt>methodname</tt>. A list of valid method names, <tt>methodname</tt>, can be obtained using the command:
* ''''abs'''': takes the absolute value of the data (see ABS),
preprocess('keywords')
 
* ''''autoscale'''': centers columns to zero mean and scales to unit variance (see AUTO),
 
* ''''simple''' baseline': baseline (specified points),
 
* ''''baseline'''': baseline (weighted least squares),
 
* ''''derivative'''': derivative (SavGol),
 
* ''''detrend'''': remove a linear trend (see BASELINE),
 
* ''''gls''' weighting': generalized least squares weighting (see GLSW),
 
* ''''groupscale'''': group/block scaling (see GSCALE),


The technical description of the different types of preprocessing can be found on the [[Model_Building:_Preprocessing_Methods|Model Building: Preprocessing Methods]] page. Below is list of standard methods that can be used for 'methodname':
* ''''abs'''': takes the absolute value of the data (see [[Advanced_Preprocessing:_Simple_Mathematical_Operations|abs]]),
* ''''arithmetic'''': simple arithmetic operations,
* ''''autoscale'''': centers columns to zero mean and scales to unit variance (see [[auto]]),
* ''''autoscalenomean'''': variance (std) scaling, scales each variable by its standard deviation without mean-centering,
* ''''baseline''': baselining using an iterative weighted least square algorithm (see [[wlsbaseline]]),
* ''''whittaker'''': baselining using an automatic Whittaker filter,
* ''''simple baseline'''': baselining base on user specified points (see [[baseline]]),
* ''''classcenter'''': centers classes in data to the mean of each class (see [[classcenter]]).
* ''''classcentroid'''': centers data to the centroid of all classes (see [[classcentroid]]).
* ''''classcentroidscale'''': centers data to the centroid of all classes and scales to intra-class variance (see [[classcentroid]]).
* ''''derivative'''': Savitzky-Golay smoothing and derivative across rows (see [[savgol]]),
* ''''derivative columns'''': Savitzky-Golay smoothing and derivative down columns (see [[savgol]]),
* ''''detrend'''': remove a linear trend (see [[baseline]]),
* ''''eemfilter'''': EEM filtering,
* ''''emsc'''': extended multiplicative scatter correction (see [[emscorr]]),
* ''''epo'''': External Parameter Orthogonalization - remove clutter covariance (see [[glsw]]),
* ''''gapsegment'''': gap segment derivatives (see [[gapsegment]]),
* ''''gls weighting'''': generalized least squares weighting (see [[glsw]]),
* ''''gscale'''': group/block scaling (see [[gscale]]),
* ''''holoreact'''': Kaiser HoloReact Method (see [[hrmethodreadr]]),
* ''''logdecay'''': log decay scaling,
* ''''logdecay'''': log decay scaling,
 
* ''''log10'''': calculate base 10 logarithm of data([[Advanced_Preprocessing:_Simple_Mathematical_Operations|log10]]),
* ''''log10'''': calculate base 10 logarithm of data,
* ''''mean center'''': center columns to have zero mean (see [[mncn]]),
 
* ''''median center'''': center columns to have zero median (see [[medcn]]),
* ''''mean''' center': center columns to have zero mean (see MNCN),
* ''''minmax'''': min-max scaling, scales each row or column to have a minimum of 0 and a maximum of 1 (see [[minmax]]),
 
* ''''msc'''': multiplicative scatter correction with offset, the mean is the reference spectrum (see [[mscorr]]),
* ''''msc''' (mean)': multiplicative scatter correction with offset, the mean is the reference spectrum (see MSCORR),
* ''''msc_median'''': multiplicative scatter correction with offset, the median is the reference spectrum (see [[mscorr]]),
 
* ''''median''' center': center columns to have zero median (see MEDIAN),
 
* ''''centering'''': multiway center,
* ''''centering'''': multiway center,
* ''''scaling'''': multiway scale,
* ''''scaling'''': multiway scale,
* ''''normalize'''': normalization of the rows (see [[normaliz]]),
* ''''osc'''': orthogonal signal correction (see [[osccalc]] and [[oscapp]]),
* ''''pareto'''': Pareto (sqrt std) scaling, scales each variable by the square root of its standard deviation,
* ''''sqmnsc'''': Poisson (sqrt mean) scaling, scales each variable by the square root of its mean (see [[poissonscale]]),
* ''''referencecorrection'''': reference/background correction,
* ''''smooth'''': Savitzky-Golay smoothing (see [[savgol]]),
* ''''snv'''': standard normal deviate (autoscale the rows, see [[snv]]),
* ''''specalign'''': variable alignment via [[cow]] and [[registerspec]],
* ''''trans2abs'''': transmission to absorbance ([[Advanced_Preprocessing:_Simple_Mathematical_Operations|log(1/T)]]),
* ''''window_filter'''': spectral filtering (see [[windowfilter]]).


* ''''normalize'''': normalization of the rows (see NORMALIZ),
Additional methods are available with MIA_Toolbox. The valid method names for 'methodname' follow.
 
* ''''Image_Flatfield'''': background subtraction (flatfield),
* ''''osc'''': orthogonal signal correction (see OSCCALC and OSCAPP),
* ''''Image_Close'''': close (dilate+erode)],
 
* ''''Image_Dilate'''': dilate,
* ''''smooth'''': Savitsky-Golay smoothing and deriviatives (see SAVGOL), and
* ''''Image_Erode'''': erode,
 
* ''''Image_Max'''': replaces window of pixels with the max (see [[box_filter]]),
* ''''snv'''': standard normal deviate (autoscale the rows, see SNV),
* ''''Image_Mean'''': replaces window of pixels with the mean (see [[box_filter]]),
 
* ''''Image_Median'''': replaces window of pixels with the median (see [[box_filter]]),
* ''''sqmnsc'''': sqrt mean scale, scale each variable by the square root of its mean.
* ''''Image_Min'''': replaces window of pixels with the min (see [[box_filter]]),
 
* ''''Image_Open''': open (erode+dilate),
The output is a standard preprocessing structure array s where each method to apply is a separate record.
* ''''Image_Smooth'''': smooth,
 
* ''''Image_TrimmedMean'''': replaces window of pixels with the trimmed mean (see [[box_filter]]),
2) CALIBRATE.
* ''''Image_TrimmedMedian'''': replaces window of pixels with the trimmed median (see [[box_filter]]).
 
The objective of the following calls to PREPROCESS is to estimate preprocessing parameters, if any, from a calibration data set and perform preprocessing on the calibration data set. The I/O format is:
 
:[datap,sp] = preprocess('calibrate',s,data);
 
The inputs are s a standard preprocessing structure and data the calibration data. The preprocessed data is returned in datap, and preprocessing parameters are returned in a modified preprocessing structure sp. Note that sp is used as an input with the 'apply' and 'undo' commands described below.
 
Short cuts for each method can also be used. Examples for 'mean center' and 'autoscale' are
 
:[datap,sp] = preprocess('calibrate','mean center',data);


:[datap,sp] = preprocess('calibrate','autoscale',data);
The following command generates a multi-record structure of the default preprocessing steps included in PREPROCESS.
list = prprocess('initcatalog');


Preprocessing for some multi-block methods require that the y-block be passed also. The I/O format in these cases is:
====Case 2) Estimate preprocessing parameters (calibrate)====


:[datap,sp] = preprocess('calibrate',s,xblock,yblock);
Many preprocessing methods derive statistics and other numerical values from the calibration data. These values must be stored and used when new data (test or other future data) is going to be preprocessed in the same way as the calibration data. Examples include the mean or variance for each variable of the calibration data.


Preprocessing 'methodname' that require a y-block are:
The objective of the 'calibrate' call to PREPROCESS is to estimate preprocessing parameters, if any, from the calibration data set and perform preprocessing on the data. The I/O format is:
[datap,sp] = preprocess('calibrate',s,data);


: 'osc'
The inputs are <tt>s</tt> a standard preprocessing structure and <tt>data</tt> the calibration data. The preprocessed data is returned in <tt>datap</tt>, and preprocessing parameters are returned in a modified preprocessing structure <tt>sp</tt>. Note that <tt>sp</tt> is used as an input with the 'apply' and 'undo' commands described below.


: 'gls weighting'
Short-cuts for each method can also be used. Examples for 'mean center' and 'autoscale' are
[datap,sp] = preprocess('calibrate','mean center',data);
[datap,sp] = preprocess('calibrate','autoscale',data);


3) APPLY.
Preprocessing for some multi-block methods (specifically, 'osc' and 'gls weighting') require that the y-block be passed also. The I/O format in these cases is:
[datap,sp] = preprocess('calibrate',s,xblock,yblock);


The objective of the following call to PREPROCESS
====Case 3) Apply preprocessing to new data (apply)====


:datap = preprocess('apply',sp,data)
Once the preprocessing steps have been calibrated on a set of data (see Case 2), the preprocessing can be "applied" to new data. The parameters determined during calibration are now used to preprocess the new data. For example, consider mean-centering. In this case, the parameters correspond to the mean of the calibration set. During 'apply', the new data are centered to the mean of the calibration data.


is to apply the calibrated preprocessing in sp to new data. Inputs are sp the modified preprocessing structure (See 2 above) and the data, data, to apply the preprocessing to. The output is preprocessed data datap that is class "dataset".
The following call to PREPROCESS
datap = preprocess('apply',sp,data);
applies the calibrated preprocessing <tt>sp</tt> to new data <tt>data</tt> and returns the preprocessed data <tt>datap</tt> that is class "dataset".


4) UNDO.
====Case 4) Remove preprocessing from preprocessed data (undo)====


The inverse of applying preprocessing is perfromed in the following call to PREPROCESS
The inverse operation of applying preprocessing is performed in the following call to PREPROCESS
data = preprocess('undo',sp,datap);
Inputs are <tt>sp</tt>, the calibrated preprocessing structure (See Case 2 above) and the preprocessed data, <tt>datap</tt> [class "double" or "dataset"]. The output is the "unpreprocessed" data <tt>data</tt>.


:data = preprocess('undo',sp,datap);
The 'undo' operation is most often used on y-block predictions in regression models and in missing data replacement algorithms (see [[mdcheck]] and [[replace]]) in which the data is preprocessed and then an estimate of the data is converted back to the original unpreprocessed form.


Inputs are sp the modified preprocessing structure (See 2 above) and the data, datap, (class "double" or "dataset") from which the preprocessing is removed. Note that for some preprocessing methods an inverse does not exist or has not been defined and an 'undo' call will cause an error to occur. For example, 'osc' and 'sg'. One reason for not defining an inverse, or undo, is because it would require a significant amount of memory storage when data sets get large.
Note that some preprocessing can not be undone (for example, 'osc' and 'sg'). In these cases, an inverse does not exist or has not been defined and an 'undo' call will result in a warning. Using 'undo_silent' instead of 'undo' suppresses the warning message. One reason for not defining an inverse, or undo, is because the procedure requires a significant amount of memory storage (e.g., when data sets are large).


===See Also===
===See Also===


[[crossval]], [[pca]], [[pcr]], [[pls]], [[preprouser]]
[[analysis]], [[crossval]], [[pca]], [[pcr]], [[pls]], [[preprocessiterator]], [[preprocatalog]], [[preprouser]]

Latest revision as of 07:54, 1 September 2020

Purpose

Selection and application of standard preprocessing methods.

Synopsis

s = preprocess; %Modal GUI to select preprocessing
[s,changed] = preprocess(s); %Modal GUI to modify preprocessing
list = preprocess('initcatalog'); % Gives a list of the available methods
preprocess('keywords'); %Lists valid method names.
s = preprocess('default','methodname'); %Non-GUI interactive preprocessing selection
[datap,sp] = preprocess('calibrate',s,data); %single block calibration of preprocessing
[datap,sp] = preprocess('calibrate',s,xblock,yblock); %multi-block calibration of preprocessing
datap = preprocess('apply',sp,data); %apply to new data
data = preprocess('undo',sp,datap) ; %undo preprocessing
data = preprocess('undo_silent',sp,datap); %undo preprocessing (no warnings)
[datap,s] = preprocess(data); %Modal GUI to preprocess selected data
[datap,s] = preprocess(data,s); %Modal GUI to preprocess selected data

Description

PREPROCESS is a general tool to choose preprocessing steps and to perform the steps on data. It can be used as a graphical interface or as a command-line tool. See Model Building - PreProcessing Methods for a description of the use of the graphical user interface. See User Defined Preprocessing and preprouser for a description on how custom preprocessing can be added to the standard preprocessing options listed below.

From the command line, PREPROCESS can be used to perform four different tasks:

  • 1) Specification of Preprocessing (or preprocessing steps),
  • 2) Estimate preprocessing parameters (calibrate),
  • 3) Apply preprocessing to new data (apply), and
  • 4) Remove the preprocessing previously performed on the data (undo).

Case 1) Specification of Preprocessing

The purpose of the following calls to PREPROCESS is to generate standard preprocessing structure arrays that contain the desired preprocessing steps. The commands are listed here.

s = preprocess;

creates a GUI that allows the user to select preprocessing steps interactively. The output s is a standard preprocessing structure. If multiple preprocessing steps are selected, s is a multi-record structure with each record corresponding to a preprocessing step.

[s,changed] = preprocess(s);

allows the user to interactively edit a previously-built preprocessing structure s. The output s is the edited preprocessing structure. The second output changed is a flag that indicates whether the user clicked "OK" (==1) or "Cancel" (==0) to close the interface. If the user cancels, the output will be the same as the input (no changes have been made.)

s = preprocess('default','methodname');

returns the default preprocessing structure for method methodname. A list of valid method names, methodname, can be obtained using the command:

preprocess('keywords')

The technical description of the different types of preprocessing can be found on the Model Building: Preprocessing Methods page. Below is list of standard methods that can be used for 'methodname':

  • 'abs': takes the absolute value of the data (see abs),
  • 'arithmetic': simple arithmetic operations,
  • 'autoscale': centers columns to zero mean and scales to unit variance (see auto),
  • 'autoscalenomean': variance (std) scaling, scales each variable by its standard deviation without mean-centering,
  • 'baseline: baselining using an iterative weighted least square algorithm (see wlsbaseline),
  • 'whittaker': baselining using an automatic Whittaker filter,
  • 'simple baseline': baselining base on user specified points (see baseline),
  • 'classcenter': centers classes in data to the mean of each class (see classcenter).
  • 'classcentroid': centers data to the centroid of all classes (see classcentroid).
  • 'classcentroidscale': centers data to the centroid of all classes and scales to intra-class variance (see classcentroid).
  • 'derivative': Savitzky-Golay smoothing and derivative across rows (see savgol),
  • 'derivative columns': Savitzky-Golay smoothing and derivative down columns (see savgol),
  • 'detrend': remove a linear trend (see baseline),
  • 'eemfilter': EEM filtering,
  • 'emsc': extended multiplicative scatter correction (see emscorr),
  • 'epo': External Parameter Orthogonalization - remove clutter covariance (see glsw),
  • 'gapsegment': gap segment derivatives (see gapsegment),
  • 'gls weighting': generalized least squares weighting (see glsw),
  • 'gscale': group/block scaling (see gscale),
  • 'holoreact': Kaiser HoloReact Method (see hrmethodreadr),
  • 'logdecay': log decay scaling,
  • 'log10': calculate base 10 logarithm of data(log10),
  • 'mean center': center columns to have zero mean (see mncn),
  • 'median center': center columns to have zero median (see medcn),
  • 'minmax': min-max scaling, scales each row or column to have a minimum of 0 and a maximum of 1 (see minmax),
  • 'msc': multiplicative scatter correction with offset, the mean is the reference spectrum (see mscorr),
  • 'msc_median': multiplicative scatter correction with offset, the median is the reference spectrum (see mscorr),
  • 'centering': multiway center,
  • 'scaling': multiway scale,
  • 'normalize': normalization of the rows (see normaliz),
  • 'osc': orthogonal signal correction (see osccalc and oscapp),
  • 'pareto': Pareto (sqrt std) scaling, scales each variable by the square root of its standard deviation,
  • 'sqmnsc': Poisson (sqrt mean) scaling, scales each variable by the square root of its mean (see poissonscale),
  • 'referencecorrection': reference/background correction,
  • 'smooth': Savitzky-Golay smoothing (see savgol),
  • 'snv': standard normal deviate (autoscale the rows, see snv),
  • 'specalign': variable alignment via cow and registerspec,
  • 'trans2abs': transmission to absorbance (log(1/T)),
  • 'window_filter': spectral filtering (see windowfilter).

Additional methods are available with MIA_Toolbox. The valid method names for 'methodname' follow.

  • 'Image_Flatfield': background subtraction (flatfield),
  • 'Image_Close': close (dilate+erode)],
  • 'Image_Dilate': dilate,
  • 'Image_Erode': erode,
  • 'Image_Max': replaces window of pixels with the max (see box_filter),
  • 'Image_Mean': replaces window of pixels with the mean (see box_filter),
  • 'Image_Median': replaces window of pixels with the median (see box_filter),
  • 'Image_Min': replaces window of pixels with the min (see box_filter),
  • 'Image_Open: open (erode+dilate),
  • 'Image_Smooth': smooth,
  • 'Image_TrimmedMean': replaces window of pixels with the trimmed mean (see box_filter),
  • 'Image_TrimmedMedian': replaces window of pixels with the trimmed median (see box_filter).

The following command generates a multi-record structure of the default preprocessing steps included in PREPROCESS.

list = prprocess('initcatalog');

Case 2) Estimate preprocessing parameters (calibrate)

Many preprocessing methods derive statistics and other numerical values from the calibration data. These values must be stored and used when new data (test or other future data) is going to be preprocessed in the same way as the calibration data. Examples include the mean or variance for each variable of the calibration data.

The objective of the 'calibrate' call to PREPROCESS is to estimate preprocessing parameters, if any, from the calibration data set and perform preprocessing on the data. The I/O format is:

[datap,sp] = preprocess('calibrate',s,data);

The inputs are s a standard preprocessing structure and data the calibration data. The preprocessed data is returned in datap, and preprocessing parameters are returned in a modified preprocessing structure sp. Note that sp is used as an input with the 'apply' and 'undo' commands described below.

Short-cuts for each method can also be used. Examples for 'mean center' and 'autoscale' are

[datap,sp] = preprocess('calibrate','mean center',data);
[datap,sp] = preprocess('calibrate','autoscale',data);

Preprocessing for some multi-block methods (specifically, 'osc' and 'gls weighting') require that the y-block be passed also. The I/O format in these cases is:

[datap,sp] = preprocess('calibrate',s,xblock,yblock);

Case 3) Apply preprocessing to new data (apply)

Once the preprocessing steps have been calibrated on a set of data (see Case 2), the preprocessing can be "applied" to new data. The parameters determined during calibration are now used to preprocess the new data. For example, consider mean-centering. In this case, the parameters correspond to the mean of the calibration set. During 'apply', the new data are centered to the mean of the calibration data.

The following call to PREPROCESS

datap = preprocess('apply',sp,data);

applies the calibrated preprocessing sp to new data data and returns the preprocessed data datap that is class "dataset".

Case 4) Remove preprocessing from preprocessed data (undo)

The inverse operation of applying preprocessing is performed in the following call to PREPROCESS

data = preprocess('undo',sp,datap);

Inputs are sp, the calibrated preprocessing structure (See Case 2 above) and the preprocessed data, datap [class "double" or "dataset"]. The output is the "unpreprocessed" data data.

The 'undo' operation is most often used on y-block predictions in regression models and in missing data replacement algorithms (see mdcheck and replace) in which the data is preprocessed and then an estimate of the data is converted back to the original unpreprocessed form.

Note that some preprocessing can not be undone (for example, 'osc' and 'sg'). In these cases, an inverse does not exist or has not been defined and an 'undo' call will result in a warning. Using 'undo_silent' instead of 'undo' suppresses the warning message. One reason for not defining an inverse, or undo, is because the procedure requires a significant amount of memory storage (e.g., when data sets are large).

See Also

analysis, crossval, pca, pcr, pls, preprocessiterator, preprocatalog, preprouser