function classification = classifySVM(type, data)
%
% classification = classifySVM(type, data)
% 
% The 'type' input specifies which "error" metric to use for the
% classifier. The function expects "data" to be an Nxm matrix, where N is
% the number of data points and m is the number of features (such as
% distance, etc.).
%
% The function returns the classification based on the input data.
%

%% Check arguments
if (nargin ~= 2), error('Too few input parameters. Need a type and a data matrix.'); end
if (~ischar(type)), error('Data ''type'' must be a string: ''sCIELAB'', ''CIELAB'', or ''hasler'''); end
if (strcmp(upper(type),'SCIELAB') == 0 & strcmp(upper(type),'CIELAB') == 0 & strcmp(upper(type),'HASLER') ==0)
    error('You must specify the metric to use: ''sCIELAB'', ''CIELAB'', or ''hasler''');
end

%% Load appropriate model
load SVMmodels.mat
if (strcmp(upper(type),'SCIELAB') == 1)
    net = SVMmodels.net_sCIELAB; % use sCIELAB model
elseif (strcmp(upper(type),'CIELAB') == 1)
    net = SVMmodels.net_CIELAB;
elseif (strcmp(upper(type), 'HASLER') == 1)
    net = SVMmodels.net_hasler;
end

norm_dat = [];
for M = 1:size(data,1),
    norm_dat = [norm_dat; norm(data(M,:))];
end

data = data./repmat(norm_dat, 1,size(data,2));

%[Ytest, Xtest] = svmlread('example1/test.dat'); read test data
% Compute prediction on the test data
classification = svmlfwd(net, data);
classification(find(classification >= 0)) = 1;
classification(find(classification < 0)) = -1;