function [indexWithSelf indexWithoutSelf] = mostRepVector(simMatrix) % Determines the most representative element in a set C1 % Inputs: % 1. simMatrix: n*n matrix of pairwise similarities % simMatrix(i,j) = similarity between points c_i and c_j (both in the % same class) % Outputs: % 1. indexWithSelf: index of the most representative element, with self % similarities % 2. indexWithoutSelf: index of the most representative element, without % self similarities. maxWithSelf = -Inf; maxWithoutSelf = -Inf; indexWithSelf = 0; indexWithoutSelf = 0; n = size(simMatrix, 1); %disp(simMatrix); % Checking if the matrix is symmetric % isSym = 1; % for i=1:n % for j=1:n % if(simMatrix(i,j) ~= simMatrix(j,i)) % isSym = 0; % break; % end % end % if(isSym == 0) % break; % end % end % isSym = 0; % hack for testing- DELETE %isSym =1; for i= 1:n % simWithDiags=0; % simWithoutDiags = 0; for j=1:n %if(i ~= j) % not self similarity value simWithDiags(i) = simWithDiags(i) + simMatrix(i,j); %simWithoutDiags = simWithoutDiags + simMatrix(i,j); %if(isSym == 0) % asymmetric: add i,j and j,i % simWithDiags = simWithDiags + simMatrix(j,i); % simWithoutDiags = simWithoutDiags + simMatrix(j,i); %end %else % self similarity % simWithDiags = simWithDiags + simMatrix(i,j); %end simWithoutDiags(i) = simWithDiags; end % if(simWithDiags > maxWithSelf) % maxWithSelf = simWithDiags; % indexWithSelf = i; % end % if(simWithoutDiags > maxWithoutSelf) % maxWithoutSelf = simWithoutDiags; % indexWithoutSelf = i; % end end [what, where] = max(simWithDiags); indexWithSelf = where; indexWithoutSelf