IMP logo
statistics examples

kmeans

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.

# generate some clusters of points
vs= []
centers=(IMP.algebra.Vector3D(0,0,0),
for i in range(0,3):
for j in range(0,100):
vs.append(IMP.algebra.get_random_vector_in(IMP.algebra.Sphere3D(centers[i], 10)))
# cluster them into 3 clusters
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)

write a metric

This simple example shows how to write an IMP.statistics.Metric in python.

import math
import random
class MyMetric(IMP.statistics.Metric):
"""Define a metric on a list of floating point numbers based on their difference"""
def __init__(self, nums):
"""Store the list of numbers to measure distances between"""
IMP.statistics.Metric.__init__(self, "MyMetric%1%")
self._nums=nums
def get_distance(self, i, j):
"""Return the magnitude of the distance between the ith and jth number"""
return math.fabs(self._nums[i]-self._nums[j])
def get_number_of_items(self):
return len(self._nums)
mm= MyMetric([random.uniform(0,1) for i in range(0,15)])
print cc.get_number_of_clusters()


Generated on Tue May 22 2012 23:33:21 for IMP by doxygen 1.8.1