function postprob = regroup(D,CC,prior,option)


% determine size of arrays
[N,M] = size(D);
[M,K] = size(CC);

% Compute Log Likelihood of data give principle components
LogLike = LogLikeGivenCC(D,CC,option);

% Compute maximum to avoid underflow problems
maxLogLike = repmat(max(LogLike,[],2),[1,K]);

% Compute posterior class probabilities
prob = exp(LogLike-maxLogLike).*repmat(prior,[N,1]);
normalize = sum(prob,2);
postprob = prob.*repmat(1./normalize,[1,K]);



