%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%
%  R E A D M E 
%
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

%--------------------------------------------------------------------------
%
1. Setting up the MATLAB code.  
%
%--------------------------------------------------------------------------
The following is for Windows but the directions should be applicable 
for MAC or LINUX users.


(a) Create a directory pathway at the MATLAB prompt, e.g., 

>> filepath = 'C:\Users\YourDirectory\SAFA';

Change the string variable to something appropriate on your computer.


(b) Add all directories and subdirectories in the file path.

>>  addpath(genpath( filepath ));


(c) If you want, change the current working directory to the file path.

>>  cd( filepath );

That should do it.


%--------------------------------------------------------------------------
%
2. Running a demo.
%
%--------------------------------------------------------------------------

(a) For a demonstration on the SOY SEED data set, you can run the 
following to perform the calibration updating and generate the barplots
that was done in the paer---see below.

% Perform Calibration Updating 
>> CaseNum = 1; 							% SOY SEED case number
>> nsplit = 20; 							% Number of data splits
>> output = safaDemo( CaseNum, nsplit );   	% Calibration updating  
>> safaPlots( output );                     % Barplots


(b) For a demonstration on the GOAT data set, you can run the following:
(the same as (a) but CaseNum is different)

% Perform Calibration Updating 
>> CaseNum = 2; 							% GOAT case number
>> nsplit = 20; 							
>> output = safaDemo( CaseNum, nsplit );   	 
>> safaPlots( output ) 


%--------------------------------------------------------------------------
%
3. Reference
%
%--------------------------------------------------------------------------

If code is used, please cite the following: 

Erik Andries, John H. Kalivas, Anit Gurung,
Sample and Feature Augmentation Strategies for Calibation Updating.
Journal of Chemometrics; 2018 (to appear)


%--------------------------------------------------------------------------
4. Socket in your own data set. 
%--------------------------------------------------------------------------


A) You need a data loader.

You need to create your own data loader.  For example, we have created 
a data loader for the CORN data set 
    http://www.eigenvector.com/data/Corn/
that you can use as a template to construct your own data loader.  Hence, 
look at the safaCORN.m script.  This MATLAB script can create a data set 
similar to the GOAT data set ("distinct"), or it can create a data set 
similar to the SOY SEED data set (not distinct).  This is explained in 
the safaCORN.m documentation.

The purpose of the data loader is to create a canonical or archetypal data 
struct that is the same across the data sets.  In this waym the subsequent 
SAFA suite of MATLAB scripts can work smoothly.


B) Call the data loader script from the safaData.m script.  

Again, we have an example call to the the corn data set (it's commented 
but you can uncomment it).  See safaData.m.


C) Specify the data set in the safeDemo.m script.

Here, you need to pick a Case Number (CaseNum) for your data set.  
Again, we have an example case number for the CORN data set.  (It is 
commented out.)	 See safaDemo.m.


%--------------------------------------------------------------------------
5. Contact Info. 
%--------------------------------------------------------------------------
Contact Erik Andries (erik.andries@gmail.com) if you have questions
regarding the code.  Please feel free to use for academic, commercial 
or hobby pursuits.  

Have fun!