function [class] = centroid(test,trainMat1, trainMat2) % Classify the point 'test' in the following way: % 1. find the most representative element of each class % 2. compare the similarity of test to each most rep element % 3. sim(test,u1) > sim(test, u0) => class 1 % Inputs: % 1. test: vector length m % 2. trainMat0 : n*m matrix of elements from class0 % 3. trainMat1: n*m matrix of elements from class1 % Output: % 1. 0 if classified as class0, else 1 [u1] = getMostRepElement(trainMat1); [u2] = getMostRepElement(trainMat2); centroid1 = trainMat1(u1, :); centroid2 = trainMat2(u2, :); sim1 = getSimCounting(centroid1, test); sim2 = getSimCounting(centroid2, test); if(sim1 > sim2) class = 1; else class = 2; end