IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
kmeans.py
1## \example statistics/kmeans.py
2# Clustering is very simple. The example generates some random points in
3# clusters and extracts the clusters. To cluster density, configurations
4# or particles, replace the IMP.statistics.Vector3DEmbedding with a
5# IMP.statistics.Vector3DEmbedding with a
6# IMP::statistics::HighDensityEmbedding,
7# IMP::statistics::ConfigurationSetXYZEmbedding or a
8# IMP::statistics::ParticleEmbedding.
9
10import IMP.algebra
11import IMP.statistics
12import sys
13
14IMP.setup_from_argv(sys.argv, "kmeans")
15
16# generate some clusters of points
17vs = []
18centers = (IMP.algebra.Vector3D(0, 0, 0),
19 IMP.algebra.Vector3D(10, 15, 20),
20 IMP.algebra.Vector3D(60, 30, 12))
21for i in range(0, 3):
22 for j in range(0, 100):
24 IMP.algebra.Sphere3D(centers[i], 10)))
25
26# cluster them into 3 clusters
29 3, 1000)
30
31# print out the cluster results
32print(c.get_cluster_center(0))
33print(c.get_cluster_center(1))
34print(c.get_cluster_center(2))
Simply return the coordinates of a VectorD.
Definition embeddings.h:79
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
VectorD< 3 > Vector3D
Definition VectorD.h:407
VectorD< D > get_random_vector_in(const BoundingBoxD< D > &bb)
Generate a random vector in a box with uniform density.
Code to compute statistical measures.
PartitionalClusteringWithCenter * create_lloyds_kmeans(Embedding *embedding, unsigned int k, unsigned int iterations)
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.