function [param,L] = runmix(X,nmix)
% Creates mixture of Gaussians model via EM.  'nmix' is number of Gaussians.
% 'X' is data.

eps = 1e-8;

[n,m] = size(X);

param = inimix(X,nmix);

cont = 1; it = 1; L = [];

while (cont), 
   param = em(X,param); 
   loglik = sum(evalmix(X,param));
   
   %if (length(L)>=it), L(it) = loglik; else L = [L;loglik]; end;
   if (length(L)<1), L = [loglik]; else L = [L;loglik]; end;

   if (it>2), cont = (L(it)-L(it-1)>eps) & (it<10000); end;
   it = it + 1;
end;

