%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Class to train the collected data sets.  Uses all the data in the 
% collected data sets
% This will load all the data collected with build_class and
% store in an array to send to the training_ljmNL3 function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% input parameters
function ris = train_classes(classnames, class_mfiles, trainingdatafile)

%modified variable to store class names, number of classes and index
ncltr = length(classnames);

filemetadata = [];
data = [];

%initialize class data to pass to training function
for cc = 1 : ncltr
    
    N_GAUSS{cc} = 4;
    %tipo{cc} = 'spherical';
    tipo{cc} = 'full';   
    
    f1=class_mfiles{cc,1};
    f2=class_mfiles{cc,2};
    
    if(exist(f2,'file') && exist(f2,'file'))
        fprintf(1,'Loading %s\n', f1);
        load(f2);        
        load(f1);
        filemetadata{cc} = classfilemetadata;
        data{cc} = classdata;
    else
        fprintf(1, 'Cannot find %s or %s\n', f1,f2);
        error('Class not built - run build_class first');
    end
end

%set training parameters for input to train function
scale = 3;
comp = 8;
%comp = 12;

% modified determine size of each class and create an index for it
for i = 1:ncltr
    indxtr{i} = 0:length(filemetadata{i})-1;
end

% modified TRAINING - using new function
ris = training_ljmNL3 (classnames, filemetadata, data, indxtr, N_GAUSS, comp, scale, tipo);

% modified save training results
fprintf(1,'Saving %s\n',[trainingdatafile]);
save ([trainingdatafile], 'ris');

end
