IMP logo

IMP.statistics examples

kmeans.py

Clustering is very simple. The example generates some random points in clusters and extracts the clusters. To cluster density, configurations or particles, replace the IMP.statistics.Vector3DEmbedding with a IMP.statistics.Vector3DEmbedding with a IMP::statistics::HighDensityEmbedding, IMP::statistics::ConfigurationSetXYZEmbedding or a IMP::statistics::ParticleEmbedding.

import IMP.algebra
import IMP.statistics

# generate some clusters of points
vs= IMP.algebra.Vector3Ds()
centers=(IMP.algebra.Vector3D(0,0,0),
         IMP.algebra.Vector3D(10,15,20),
         IMP.algebra.Vector3D(60,30,12))
for i in range(0,3):
    for j in range(0,100):
        vs.push_back(IMP.algebra.get_random_vector_in(IMP.algebra.Sphere3D(centers[i], 10)))

# cluster them into 3 clusters
e= IMP.statistics.Vector3DEmbedding(vs)
c= IMP.statistics.get_lloyds_kmeans(e,
                                    3, 1000)

# print out the cluster results
print c.get_cluster_center(0)
print c.get_cluster_center(1)
print c.get_cluster_center(2)

Generated on Mon Mar 8 23:08:33 2010 for IMP by doxygen 1.5.8