
function J = kmeans_metric(y,X)

[n,d] = size(X);
k = max(y);

J = 0.0;
for j=1:k
  Ij = find(y==j);
  mu_j = mean(X(Ij,:));
  for i=1:n
    del = (X(i,:) - mu_j)';
    J = J + del'*del;
  end
end
