IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
5import math
6import random
7import sys
8
9IMP.setup_from_argv(sys.argv, "write a metric")
10
11
13
14 """Define a metric on a list of floating point numbers based on
15 their difference"""
16
17 def __init__(self, nums):
18 """Store the list of numbers to measure distances between"""
19 super().__init__("MyMetric%1%")
20 self._nums = nums
21
22 def get_distance(self, i, j):
23 "Return the magnitude of the distance between the ith and jth number"
24 return math.fabs(self._nums[i] - self._nums[j])
25
26 def get_number_of_items(self):
27 return len(self._nums)
28
29
30mm = MyMetric([random.uniform(0, 1) for i in range(0, 15)])
31
33print(cc.get_number_of_clusters())
Store data to be clustered for distance metric based algorithms.
Definition Metric.h:25
Code to compute statistical measures.
PartitionalClustering * create_centrality_clustering(Metric *d, double far, int k)
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.