                                Single Class Classification READ ME

There are 3 function files that need to be used sequentially to perform single class classification.

Functions: 
(1)	SingClassLMOCVfusIn.m 
(2)	SingClassFusion.m
(3)	SingClassROC.m

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I.	SingClassLMOCVfusIn.m is ran first

Function:
inStructGenFus  = SingClassLMOCVfusIn(Xin, wave, tuneMax, nCV, nCal, nOutPure, nInNonPure, Outlier, seed)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Inputs:  
    Xin        - a cell array (n instruments [nInst] by n Classes [nC]) of spectral data
		         where each cell is n samples by p wavelenghs (nC should only be 2 i.e. two classes)
		         NOTE: if  using more than two class, you can put the values in the second column of the 
		         cell array
    wave       - a cell array (1 by nInst) of the actual wavelengths used for each Instrument (listed in 
		         the same order as the rows of Xin)
                 NOTE: If no wavelength, enter 0
    nCV        - The number of cross validations desired
    nCal       - The number of samples that define the target class
    tuneMax    - The maximum tuning parameter used for the eigenvector based outlier measures
    nOutPure   - The number of validation samples from the target class
    nInNonPure - The number of validation samples from the non-target class
    Outlier    - Enter true to run outlier detection on the target class
                 Enter false to NOT run outlier detection on the target class
    seed       - Random number generator index; The same seed values produces the same random numbers
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


Outputs: 
   input       - The inputs that are used to run one-class classification
                    Xin           - See above
                    wave          - See above
                    tuneMax       - See above
                    nCV           - See above
                    nCal          - See above
                    nOutPure      - See above
                    nInNonPure    - See above
                    PureSampVal   - A matrix that contains the index of the target test samples for each
				                    cross validation split
                    NonPureSampIn - A matrix that contains the index of the non-target
                                    test samples for each cross validation split
                    rpP           - A matrix that contains the reshuffled index for each sample in the
			                        target class for each cross validation split
                    rpNP 	      - A matrix that contains the reshuffled index for each sample in the
			                        non-target class for each cross validation split
                    seed          - See above
                                    
    fusInSing - A cell array (nInst by nC by nCV) that contains all of the outlier measures for each 
                split used for one-class classification. This is the input for SingClassFusion.m

		fusInSing Contains: 	
			       Rows: 
			                Number of fields correspond to each validation sample
			       Columns:
                  	 		- input: The input used to calcuated the outlier measures
					          Within Input:
                            			  X     - The target class samples with the the validation 
						                        sample as the very last row
                             			  wave  - The wavelengths for the spectra
                             			  tune  - The maximum tuning parameter window
                             			  tuneR - The maximum tuning parameter window as a vector
                             		      xval  - NOT USED
                             			  sig   - The standard deviations for outlier detection
                		    - srdin: The calculated outlier measures for each sample that are normalized
                                     to unit length
                  			- srdinunc: The calculated oulier measures for each samples (Raw values)
                  			- fusMerit: The names of the outlier measure which correspond to each cell
                                        array in srdin and srdinunc
    XOutDet  - (This output only there when Outlier = true) A cell array (1 by nCV) that contains the 
		       clean target samples for each of the cross validation splits            




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
II.	SingClassfusion.m is ran second

Function: 
inStructGenFus2 = SingClassFusion(inStructGenFus)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Inputs:
    inStructGenFus: struct file generated from the output of SingClassLMOCVfusIn.m
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Outputs:
    input      - the inputs used to run one-class classfication (see SingClassfusIn.m in (I) for more)

    fusOutSing: A cell array (nCV by nClasses)containing the SRD results
                for each validation split for all classes. Contain a Struct file 
                (n Test samples by max tuning parameter) that has the SRD output at each 
                 tuning parameter window: 
  
                     nrow:     s the number of rows used
                     max:      the largest SRD values possible
                     scale:    How the SRD raw ranks are scaled by (100/max)
                     raw:      N x ncol matrix of raw SRD values
                     norm:     N x ncol matrix of normalized SRD values
                     prob:     N x ncol matrix of probabilities associated with srd.raw
                     x:        N x p matrix of raw SRD values corresponding to the 
                               x-coordinates of the probability density function (PDF) 
                               curves in Figure 1
                     relFreq:  N x p matrix of PDF values corresponding to the 
                               y-coordinates PDF curves in Figure 1
                     S:        1 x 100,000 vector of the similuated random SRD ranks to obtain the random ranking distribution
                               which is then fitted to a gassian distribution 
                     mu:       the mean of random ranking distribution (raw)
                     sig:      the standard deviation of the random ranking distribution (raw)
                     muS:      the mean of random rankin distribution (scaled)
                     sigS:     the standard deviation of the rankom ranking distribution (scaled)
                     srdRank:  N x ncol matrix of rankings (1:ncol) associated with srd.raw 
                     rank:     N z ncol matrix parameter postion of order ranks (1:col)
                     display:  srd.display is a struct containing four fields.
                     x: x-axis of Figure 1
                     relFreq: y-axis of Figure 1
                     norm: x-axis of Figure 2
                     prob: y-axis of Figure 2
                     data:     struct returned by srdPreProcess.m
                              Contains:
                                     [1] A: Input matrices. 
                                            The variable A is a p x 1 cell array where each component 
                                            corresponds to an input matrix where each row correspond 
                                            to a sample and each column corrresponds to a metaparameter 
                                            such as latent dimension, lambda value, etc.   
 
                                     [2] T: Target information.
                                            The input format for the variable T can be different:  
                                                 a) T is cell array of numeric values (target vector 
                                                    values) or strings (e.g., {'min','max'})
                                                 b) T is a string, e.g., T='min'.  In this, T will 
                                                    be made into a cell array, 
                                                    i.e., T=repmat( {T}, p, 1);

                     options: This is a struct containing the option and "knob" settings for the 
                              SRD suite of scripts.  Below is an example for k=1:     
                                          >> disp(options)
                                          nblock: 1
                                          nsample: 100
                                          exact: 0
                                          cv: 'none'
                                          niter: 'none'
                                          percent: 50
                                          allmix: 1
                                          fusionRule: {'sum'  'min'  'max'  'med'  'l2'  'std'}
                                          targetRule: {'min'}


    tuneMax: The maximum tuning parameter window that is used (it could
             have changed from the original max window because one of the 
             outliers had NaN at the later windows)



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
III.	SingClassROC.m is ran third.

Function:
Classification Table = SingClassClassify(inStructFusion2)


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Inputs:
     inStructGenFus2: struct file generated from the output of SingClassFusion.m

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Outputs:
   ClassificationTable: Table containing the following information at max and optimal threshold:
              - Window
              - SRD Rank Threshold
              - Area Under the Curve
              - Sensitivity
              - Specificity
              - Accuracy
   Figures: 7 Figures a produced when this function is used
              - Area under the curve
              - ROC curves for all windows
              - ROC curves for max and optimal window only
              - Single class classifiction result for max and optimal
                windows (at their respective SRD thesholds)
              - Distribution of SRD ranks for all test samples at max and
                optimal window
            



/// Created by Brett Brownfield & Tony Lemos August 1, 2018 (Last edited on 7/10/19)
/// Department of Chemistry, Idaho State University, Pocatello, Idaho 83209 USA


