function x=MCE(N,rho,alpha,k,y)

if nargin <5,
    fprintf('\nPlease supply parameters and data.\n')
    x=0;
    return;
end

g=ceil(rho*N);

[n,d]=size(y);

p=ones(n,k)./k; % initial probabilities

ind=1;

dd=10;
st=rand(dd,1)+n*n;
count=0;
while ind~=0;

    count=count+1;
    X=zeros(N,n);
    S=zeros(N,1);
    for i=1:N,
        
        % Assign points to clusters
        
        X(i,:)=genMCE(p);
        
        % Score points
        
        S(i)=scoreMCE(X(i,:),y,k);
        
    end
    
    % Order Scores
    
    [S,I]=sort(S);
    
    S(1:g);
    
    % Update p's based on elite samples
        fprintf('t = %d , g_hat_t = %g , S_star_t = %g\n',count,S(g),S(1))
        st(1:(dd-1))=st(2:dd);
        st(dd)=floor(S(1)*100);
       if (sum(st==floor(S(1)*100))==dd),
            break;
        end

w=zeros(n,k);
for i=1:n,
    for j=1:k,
    w(i,j)=w(i,j)+sum(X(I(1:g),i)==j);
end
end

    w=w./g;
    p=alpha*w + (1-alpha)*p;
    
end

x=X(I(1),:);
