function outCorr = getYcCorr(inY, inX)
% calculate the corrleation of multi-class single label
% input:  inY: n by c
%         inX: n by d
% output: outCorr:  c by c

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Yvec = mapMat2Vec(inY);
[n1, c] = size(inY);
[n2, d] = size(inX);
% check the size
if(n1 ~= n2)
    error(' incompatible size !')
else
    n = n1;
    clear n1 n2
end
num_per_class = sum(inY);
global_mean = mean(inX);
class_mean = zeros(c, d);
Sb_per_class = zeros(d, d, c);
for i = 1: c
    data_idx = find(Yvec == i);
    class_mean(i,:) = mean(inX(data_idx, :));
    Sb_per_class(:,:,i) = num_per_class(i) * (class_mean(i,:) - global_mean)'* (class_mean(i,:) - global_mean);
end
outCorr = getFDist(Sb_per_class);

end

function outCorr = getFDist(inSb_per_class)
[d, d, c ] = size(inSb_per_class);
outCorr = zeros(c,c);
sumSb = sum(inSb_per_class, 3);
for i = 1: c
    for j = (i+1) : c
        outCorr(i, j) = norm(inSb_per_class(:,:,i) - inSb_per_class(:,:,j), 'fro')/norm(sumSb, 'fro');
        outCorr(j, i) = outCorr(i, j);
    end
    outCorr(i,:) = outCorr(i,:)./sum(outCorr(i,:),2);
end

% symmetric
outCorr = (outCorr + outCorr')/2;


end