function stuff = meanfitness(means,Xin,yin,alpha)

[K,d,mm] = size(means);
n = size(Xin,1);
beta = 1-alpha;
sout = [];

% return a fitness for each mean separately
for m=1:mm
    
    %2. partition the data by distance to cluster center
    for i=1:n
        dmat = [Xin(i,:);means(:,:,m)];
        d = dist(dmat');
        [a,b] = min(d(1,2:size(d,2)));
        soft_assn(i,:,m) = [a,b];
    end;
        
    %3. assign a label to non-empty clusters by voting
    % -- (implicit in the implementation)
    
    %4. compute the fitness of the means
    dispersion(m) = sum(soft_assn(:,1,m));
    for j=1:K
        clust = find(soft_assn(:,2,m) == j);
        tot = length(clust);
        if(tot)
            pij = hist(yin(clust),K);
            gp(j,m) = sum((pij ./ tot).^2);
        else
            gp(j,m) = 0;
        end;
    end;
    purity(m) = sum(gp(:,m));
    
    fitness(m) = -1 * (alpha * dispersion(m) + beta * purity(m));
    sout = [sout soft_assn(:,2,m)];
end;

stuff{1} = fitness;
stuff{2} = sout;