function [probAintersectB] = calcProbIntersect(AintersectB,distribA, ... distribB, inputsDistribA, inputsDistribB, typeProbability) % Calculates the probability(true or empirical) of AintersectB % Inputs % 1. vector representing AintersectB % 2. distribA: A's distribution. % 3. distribB: B's distribution % 4. inputsDistribA: input parameters to A's distribution % 5. inputsDistribB: input parameters to B's distribution % 6. typeProbability: 0 => true probability. 1=> empirical probability dim = length(AintersectB); if(typeProbability == 0) % pA(i) = P(A(i) = 1) pA = trueProbability(distribA, inputsDistribA); pB = trueProbability(distribB, inputsDistribB); else pA = empiricalProbability(distribA, inputsDistribA); pB = empiricalProbability(distribB, inputsDistribB); end probAintersectB = 1; for i=1:dim % p1 = P(A(i) =1) . P(B(i) = 1) p1 = pA(i) * pB(i); % p0 = p(A(i) = 0) .P(B(i) = 0) p0 = (1 - pA(i)) * (1-pB(i)); if(AintersectB(i) == 1) probAintersectB = probAintersectB .* p1; elseif(AintersectB(i) == 0) probAintersectB = probAintersectB .* p0; else % AintersectB = null, ie A and B have different features %probAintersectB = probAintersectB .* (1-p1-p0); probAintersectB = probAintersectB * 1; end end