function [CC,prior] = SeedCluster(D,K,option)
% Usage:
% [CC,prior] = SeedCluster(D,K,option)
%
% input:
%   D(N,M) - data matrix containing N vectors of length M
%   K - initial number of clusters
%   option:
%     option ==1 => treat first cluster as centered about 0
%     option ==0 => treat first cluster the same as others
% output:
%   CC(M,K) - initial values for K cluster component vectors, each of length M
%   prior(K) - initial prior probabilities for K clustered components


% Determine size of data matrix
[N,M] = size(D);

% Seed clustered components by sampling data vector
%CC = D( ((0:(K-1))*floor(N/K)+1) ,:)';
%CC = CC + 0.01*randn(size(CC));


% Seed clustered components using principal components
R = D'*D;
[U,S,V] = svd(R);

% determine number of compents to get from eigenanalysis
if option==1
  num = min(M+1,K);
  CC(:,1) = zeros(M,1);
  CC(:,2:num) = U(:,1:(num-1));
else
  num = min(M,K);
  CC(:,1:num) = U(:,1:num);
end

% Select additional components from data
if K>num
  num2 = K-num;
  CC2 = D( ((0:(num2-1))*floor(N/num2)+1) ,:)';
  CC2 = CC2 + 0.01*randn(size(CC2));
  CC(:,(num+1):K) = CC2;
end

% Initialize prior to uniform distribution
prior = ones(1,K)/K;


