function [mix,scores] = mixtureModSel(data,K);

n = size(data,1);
d = size(data,2);

mix   = cell(1,K);
scores= zeros(1,K);  

for i=1:K,
  [mix{i},loglikes] = EM(data,i); 

  LL = max(loglikes);
  penalty = (i*(d+d*(d+1)/2)+i-1)*log(n)/2;
  scores(i) = LL-penalty;

  fprintf('Score for %d components = %f\n',i,scores(i));
end;

[dummy,k] = max(scores); 

mix = mix{k}; 
fprintf('Selecting %d components\n',k);
