function [sim] = simRe1(AintersectB, AnotB, BnotA, distrib, inputsDistrib) % One form of calculating residual entropy similarity. % Assume A and B have the same distribution (ie distrib) % Inputs: % 1. AintersectB: common features between A and B % 2. AnotB: A's exclusive features % 3. BnotA: B's exclusive features % 4. distrib: distribution of the set of objects O % 5. inputsDistrib: parameters that describe the distribution % Outputs: % 1. residual entropy similarity value. d = length(AintersectB); max = 2 .^ d; probR = trueProbability(distrib, inputsDistrib); HIntersect = 0; HA = 0; HB = 0; % find all r's such that a intersect b is in r rintersect = zeros(max, d); numInt = 0; numA = 0; ra = zeros(max,d); numB = 0; rb = zeros(max,d); for i=1:max fint = 0; fa = 0; fb = 0; b = dec2bin(i-1,d); for k = 1:d if(AintersectB(k) ~=1 && AintersectB(k) ~= bin2dec(b(k))) fint = 1; end if(AnotB(k) ~=1 && AnotB(k) ~=bin2dec(b(k))) fa = 1; end if(BnotA(k) ~=1 && BnotA(k) ~= bin2dec(b(k))) fb = 1; end end if (fint==0) numInt = numInt+1; for z = 1:d if(b(z) == '1') rintersect(numInt,z) = 1; else rintersect(numInt,z) = 0; end end end if (fa==0) numA = numA+1; for z = 1:d if(b(z) == '1') ra(numA,z) = 1; else ra(numA,z) = 0; end end end if (fb==0) numB = numB+1; for z = 1:d if(b(z) == '1') rb(numB,z) = 1; else rb(numB,z) = 0; end end end end for i=1:max bin = dec2bin(i-1, d); % We are only interested in r if it satisfies % AintersectB is in r flagInt = 0; flagA = 0; flagB = 0; for k = 1:d if(AintersectB(k) ~=-1 && AintersectB(k) ~= bin2dec(bin(k))) flagInt = 1; end if(AnotB(k) ~=1 && AnotB(k) ~= bin2dec(bin(k))) flagA = 1; end if(BnotA(k) ~=1 && BnotA(k) ~= bin2dec(bin(k))) flagB = 1; end end for j= 1:d if(bin(j) == '1') r(j) = probR(j); elseif(bin(j) == '0') r(j) = 1-probR(j); end end prod1 = 1; prod2 = 1; prod3 = 1; for j = 1:d if(flagInt == 0) prod1 = prod1 .* r(j) .* log(r(j)); else prod1 = 0; end if(flagA==0) prod2 = prod2 .* r(j) .* log(r(j)); else prod2 = 0; end if(flagB ==0) prod3 = prod3 .* r(j) .* log(r(j)); else prod3 = 0; end end HIntersect = HIntersect + prod1; HA = HA + prod2; HB = HB + prod3; %disp(bin2dec(bin)); %disp(prod1); %disp(prod2); %disp(prod3); %disp('**'); end sim = HIntersect - HA./2 - HB ./2;