function [withDiag withoutDiag] = totalSim(pairwiseSims) % Calculate the average similarity of elements in a set C1 % Inputs: % 1. pairwiseSims: n*n matrix where pairwiseSims(i,j) = similarity value % between elements i and j; n is the number of elements in C1. % Outputs: % 1. withDiag: average similarity including diagonal elements (sim(i,i)).s % 2. withoutDiag: average similarity without taking self similarity into % consideration. % Assumptions: % 1. pairwiseSims is a square matrix. withDiag = 0; withoutDiag = 0; n = size(pairwiseSims, 1); for i=1:n for j=1:n if(i ~= j) withoutDiag = withoutDiag + pairwiseSims(i,j); withDiag = withDiag + pairwiseSims(i,j); else withDiag = withDiag + pairwiseSims(i,j); end end end withDiag = withDiag ./ (n.^2); withoutDiag = withoutDiag ./ (n .* (n-1));