function similarity=intersection(rd,pd)
%INTERSECTION	Calculate the average intersection between the predicted label
%               distribution and the real label distribution.
%
%	Description
%   SIMILARITY = INTERSECTION(RD, PD)	Calculate the average intersection
%   between the predicted label distribution and the real label distribution.
%
%   Inputs,
%       RD: real label distribution
%       PD: predicted label distribution
%
%   Outputs,
%       SIMILARITY: the average of intersection
%
%	See also
%	FIDELITY
%	

[rows,cols]=size(rd); % Size of rd, rows*cols
for i=1:rows
    dist(i)=0;
    for j=1:cols
        dist(i)=dist(i)+min(rd(i,j),pd(i,j));
    end
end
totalDist=0;
for i=1:rows
    totalDist=totalDist+dist(i);
end
averageDist=totalDist/rows;  % Average similarity
similarity=averageDist;
end