IMP logo
IMP Reference Guide  2.10.0
The Integrative Modeling Platform
write_a_metric.py
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 import sys
8 
9 IMP.setup_from_argv(sys.argv, "write a metric")
10 
11 
13 
14  """Define a metric on a list of floating point numbers based on their difference"""
15 
16  def __init__(self, nums):
17  """Store the list of numbers to measure distances between"""
18  IMP.statistics.Metric.__init__(self, "MyMetric%1%")
19  self._nums = nums
20 
21  def get_distance(self, i, j):
22  """Return the magnitude of the distance between the ith and jth number"""
23  return math.fabs(self._nums[i] - self._nums[j])
24 
25  def get_number_of_items(self):
26  return len(self._nums)
27 
28 
29 mm = MyMetric([random.uniform(0, 1) for i in range(0, 15)])
30 
32 print(cc.get_number_of_clusters())
PartitionalClustering * create_centrality_clustering(Embedding *d, double far, int k)
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Code to compute statistical measures.
Store data to be clustered for distance metric based algorithms.
Definition: Metric.h:25