IMP  2.0.0
The Integrative Modeling Platform
statistics/write_a_metric.py

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

1 ## \example statistics/write_a_metric.py
2 ## This simple example shows how to write an IMP.statistics.Metric in python.
3 
4 import IMP.statistics
5 import math
6 import random
7 class MyMetric(IMP.statistics.Metric):
8  """Define a metric on a list of floating point numbers based on their difference"""
9  def __init__(self, nums):
10  """Store the list of numbers to measure distances between"""
11  IMP.statistics.Metric.__init__(self, "MyMetric%1%")
12  self._nums=nums
13  def get_distance(self, i, j):
14  """Return the magnitude of the distance between the ith and jth number"""
15  return math.fabs(self._nums[i]-self._nums[j])
16  def get_number_of_items(self):
17  return len(self._nums)
18 
19 
20 mm= MyMetric([random.uniform(0,1) for i in range(0,15)])
21 
23 print cc.get_number_of_clusters()