function K = correlation(Y)


[m,n] = size(Y);

for i = 1:n
	% known ratings
    k = find(isnan(Y(:,i)) == 0);    
    Y(k,i) = (Y(k,i) - mean(Y(k,i)))/max(std(Y(k,i)), eps);    

    % (normalized) 0-ratings
    z = find(abs(Y(:,i)) < eps);
    Y(z,i) = eps;

    % unknown ratings
    u = find(isnan(Y(:,i)) == 1);
    Y(u,i) = 0;
end

K = zeros(n, n);
for i = 1:n
	Z = Y .* repmat(Y(:,i), 1, n);
    K(i,:) = sum(Z)./max(sum(Z ~= 0) - 1, eps);
end

end
