function [sim] = simReBinary(probMatrix, AintersectB, AnotB, BnotA) % Residual entropy method % (ref: Information-theoretic and Set-theoretic Similarity - Cazzanti and % Gupta) % Inputs: % probMatrix(m,n): m = number of possible values of any feature (2 for % discrete case) % n = number of features % probMatrix(i,j) = probability of seeing value i in feature j % AintersectB: intersection of feature vectors of a and b % AnotB: features of a not in b % BnotA: features of b not in a % number of columns in probMatrix = length of AintersectB = length of AnotB % = length BnotA % Output: similarity value as calculated by residual entropy method numValues = size(probMatrix,1); numFeatures = size(probMatrix, 2); sim = 0; for i = 1:numValues intersect = 1; flagIntersect = 0; exclusiveA = 1; flagA = 0; exclusiveB = 1; flagB = 0; for j = 1:numFeatures if(AintersectB(j)~= 0 && flagIntersect == 0) intersect = intersect .* probMatrix(i,j).*log(probMatrix(i,j)); else % if any of the features have 0 intersection, the rest are % disregarded intersect = 0; flagIntersect = 1; end if(AnotB(j)~=0 && flagA == 0) exclusiveA = exclusiveA .* probMatrix(i,j).*log(probMatrix(i,j)); else exclusiveA = 0; flagA = 1; end if(BnotA(j)~=0 && flagB == 0) exclusiveB = exclusiveB .* probMatrix(i,j).*log(probMatrix(i,j)); else exclusiveB = 0; flagB = 1; end end sim = sim - intersect + exclusiveA./2 + exclusiveB./2 end