%  [processed, preproc] = findpreproc(train_data, train_labelm procoptions, preproc)

%

%    Find and perform optimal preprocessing for given training data, or apply

%    given preprocessing method over given input data.

%

%    Input:   train_data   =  training set / runtime data, upon which preprocessing

%                             is performed

%             train_label  =  labels for the training set, used to feedback 

%                             supervised learning

%             procoptions  =  specific options for preprocessing. The following struct:

%                             .method    = 'minimal entropy' OR 'k-means clustering'

%                             .inputdim  = desired input dimension (after reducing)

%             preproc      =  parameters of previously found preprocessing (optional)

%                             NOTE: if supplied, the function will use this preprocessing

%                                   over the given data to return preprocessed data

%

%    Output:  processed    =  processed data

%             preproc      =  preprocessing method parameters, which may be used later on

%



function [processed, preproc] = findpreproc(train_data, train_label, procoptions, preproc)



disp('findpreproc / Yuval Lifshitz, Liron Weissman, Gilad Arnold');



% check arguments

if ((nargin < 3) | (nargin > 4))

   error('findpreproc: invalid number of arguments');

end



if ((nargin < 4) | isempty(preproc))

   % preprocessing architecture is not supplied, therefore we'll define it here

   if (strcmp(procoptions.method, 'minimal entropy'))

      % Case-1: use minimal entropy preprocessing

      [preproc, processed] = procminentropy(train_data, [], procoptions.inputdim);

   elseif (strcmp(procoptions.method, 'k-means clustering'))

      % Case-2: use k-means clustering preprocessing

      [preproc, processed] = prockmeans(train_data, [], procoptions.inputdim);

   else

      error('findpreproc: preprocessing options not supplied or invalid');

   end

else

   % preprocessing supplied, apply to data

   if (strcmp(procoptions.method, 'minimal entropy'))

      % Case-1: use minimal entropy preprocessing

      [preproc, processed] = procminentropy(train_data, preproc);

   elseif (strcmp(procoptions.method, 'k-means clustering'))

      % Case-2: use k-means clustering preprocessing

      [preproc, processed] = prockmeans(train_data, preproc);

   else

      error('findpreproc: preprocessing options not supplied or invalid');

   end

end

