function mu = clusterInit(X, K)
% we want to initalize K clusters centers according to the furthest-first
% heuristic.  write the answers into 'mu', which should be KxD
  
[N,D] = size(X);

% find the first "bogus" center

%Prev = X(ceil(rand * N),:);     % Previous points
myrand = ceil(rand * N);
Prev = X(myrand,:);

% find the real clusters
for k=1:K,
    %P = size(Prev, 1);
    max_point = zeros(1,D);     % the point that has max distantance 
                                % previous points.
    max_dist = 0;
    for i = 1:N
        min_dist = inf;         % the min distance btw point i and all previous points.
        for l = 1:size(Prev,1)
            if norm(X(i,:) - Prev(l,:)) < min_dist
                min_dist = norm(X(i,:) - Prev(l,:));
            end;
        end;
        if min_dist > max_dist
            max_dist = min_dist;
            max_point = X(i,:);
        end;
    end;
   
    if k == 1
        Prev = max_point;
    else
        Prev = [Prev; max_point];
    end;
end;
       
mu = Prev;
