%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Script to initialize the classifier, given a list of training classnames
%
% Author: dcline@mbari.org
% Date: July 2005
%
function init_classifier(dbroot, trainclasses)

%declare the training model data ris global
global RIS;

%format the training data file
trainclassdata_mfile = [dbroot '/' ];

%insert the training classes matlab files names into an array
for ii=1:length(trainclasses)
    trainclass_mfiles{ii,1} = [dbroot '/' trainclasses{ii} '_data_collection_avljNL3_cl_pcsnew' '.mat'];
    trainclass_mfiles{ii,2} = [dbroot '/' trainclasses{ii} '_image_file_metadata' '.mat'];
    %cat the training class names to the training data file - this is where
    %the trained matlab data will be stored to test against
    trainclassdata_mfile = [trainclassdata_mfile trainclasses{ii}];
    if(ii < length(trainclasses) )
        trainclassdata_mfile = [trainclassdata_mfile '_'];
    else
        %pad ending to matlab training data file
        trainclassdata_mfile = [trainclassdata_mfile '_training_data' '.mat'];
    end
end


%if<trainclassdata_mfile> does not exist, train and save combined classes into <trainclassdata_mfile>
if (~exist(trainclassdata_mfile))
  fprintf(1, 'Training classes\n'); 
  RIS = train_classes(trainclasses, trainclass_mfiles, trainclassdata_mfile);
else
  fprintf(1, 'Loading classes \n'); 
  load(trainclassdata_mfile);
  RIS = ris;
end
end
