image thumbnail

Rapid Centroid Estimation

by

 

10 Sep 2012 (Updated )

An efficient particle swarm approach for rapid optimization of cluster centroids.

plot_swarm(in, labels, centroids, particle_trajectory, randomProjectionMatrix)
function plot_swarm(in, labels, centroids, particle_trajectory, randomProjectionMatrix)

    dimension = size(in,1);
    
    if(dimension > 1)
    
        projectedInputs = (randomProjectionMatrix*in)';


        scatter(projectedInputs(:,1), projectedInputs(:,2),50,labels, '.');

        hold on;
        px =(randomProjectionMatrix*centroids);
        k = size(centroids,2);
        for i = 1:k
            scatter(px(1,i),px(2,i),100,'x','linewidth',3,'MarkerEdgeColor','k');
            a = particle_trajectory(:,i);        
            a = reshape(a,dimension,numel(a)/dimension);
            p_traj = randomProjectionMatrix*a;
            plot(p_traj(1,:),p_traj(2,:),'marker','none','linewidth',1,'Color','k');
            scatter(p_traj(1),p_traj(2),50,'s','filled','MarkerEdgeColor','k', 'MarkerFaceColor','w');
        end

    else
        
        projectedInputs = (randomProjectionMatrix*in)';
        scatter(projectedInputs, projectedInputs,50,labels, '.');

        hold on;
        px =(randomProjectionMatrix*centroids);
        k = size(centroids,2);
        for i = 1:k
            scatter(px,px,100,'x','linewidth',3,'MarkerEdgeColor','k');
            a = particle_trajectory(:,i);        
            a = reshape(a,dimension,numel(a)/dimension);
            p_traj = randomProjectionMatrix*a;
            plot(p_traj,p_traj,'marker','none','linewidth',1,'Color','k');
            scatter(p_traj(1),p_traj(1),50,'s','filled','MarkerEdgeColor','k', 'MarkerFaceColor','w');
        end
    end
    
    grid on;
    hold off;
end

Contact us