function [class] = classifier(test, trainingSet, classifier, ... classifierInputs, simMetric, class0, inputs0, class1, ... inputs1) % Classifies an object as being in class1 or class0 % Inputs: % 1. test: object that needs to be classified. % 2. trainingSet: matrix(n*m+1) of n objects, each of dimension m % The last column indicates if the object is in class 1 (1) or % class 0 (0). % 3. classifier: type of classifier to be used. Options so far: % a. 'kNN-simple': picks the class where the max number of k % nearest neighbours are from. % b. 'mostRepElement': picks the class whose most representative % element is closest to the object. % c. (email) % 4. classifierInputs: inputs to the classifer % a. kNN-simple: k % b. mostRepElement: ? % 5. simMetric: type of similarity metric to use % 6. class0: Name of the distribution followed by class 0 % 7. inputs0: parameters of class 0's distribution % 8. class1: Name of the distribution followed by class 1 % 9. inputs1: parameters of class 1's distribution m = length(test); switch(classifier) case 'kNN-simple': numCols = size(trainingSet, 2); % Q. k-NN currently assumes that the point and the training set are % from the same class. [countNN linNN indexCount indexLin] = kNN(test, trainingSet(:,1:numCols-1), classifierInputs(1), class0, inputs0); indices = 0; if(simMetric == 'count') indices = indexCount; else indices = indexLin; end count1 =0; count0 = 0; for i=1:size(indices,1) if(trainingSet(i,m) == 0) count0 = count0 + 1; else count1 = count1 + 1; end end if(count0 > count1) class = 0; else class = 1; end case 'mostRepElement' simMatrix = zeros(size(trainingSet,1), size(trainingSet,1)); for i =1:size(trainingSet,1) for j=1:size(trainingSet,1) a = trainingSet(i,1:m); b= trainingSet(j,1:m); [AintersectB AnotB BnotA] = featurescomp(a,b); if(simMetric == 'count') simMatrix(i,j) = simCounting(AintersectB, AnotB, BnotA, 1 0.5 0.5); elseif(simMetric == 'lin') [probAintersectB] = calcProbIntersect(AintersectB end