IMP
2.0.1
The Integrative Modeling Platform
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
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
10
import
IMP.algebra
11
import
IMP.statistics
12
13
# generate some clusters of points
14
vs= []
15
centers=(
IMP.algebra.Vector3D
(0,0,0),
16
IMP.algebra.Vector3D
(10,15,20),
17
IMP.algebra.Vector3D
(60,30,12))
18
for
i
in
range(0,3):
19
for
j
in
range(0,100):
20
vs.append(
IMP.algebra.get_random_vector_in
(
IMP.algebra.Sphere3D
(centers[i], 10)))
21
22
# cluster them into 3 clusters
23
e=
IMP.statistics.VectorDEmbedding
(vs)
24
c=
IMP.statistics.create_lloyds_kmeans
(e,
25
3, 1000)
26
27
# print out the cluster results
28
print
c.get_cluster_center(0)
29
print
c.get_cluster_center(1)
30
print
c.get_cluster_center(2)