MCPcopy Index your code
hub / github.com/clips/pattern / distance

Method distance

pattern/vector/__init__.py:1434–1446  ·  view source on GitHub ↗

Returns the cached distance between two vectors.

(self, v1, v2)

Source from the content-addressed store, hash-verified

1432 return self.distance(v1, v2)
1433
1434 def distance(self, v1, v2):
1435 """ Returns the cached distance between two vectors.
1436 """
1437 try:
1438 # Two Vector objects for which the distance was already calculated.
1439 d = self._cache[(v1.id, v2.id)]
1440 except KeyError:
1441 # Two Vector objects for which the distance has not been calculated.
1442 d = self._cache[(v1.id, v2.id)] = distance(v1, v2, method=self.method)
1443 except AttributeError:
1444 # No "id" property, so not a Vector but a plain dict.
1445 d = distance(v1, v2, method=self.method)
1446 return d
1447
1448def cluster(method=KMEANS, vectors=[], **kwargs):
1449 """ Clusters the given list of vectors using the k-means or hierarchical algorithm.

Callers 2

__call__Method · 0.95
test_distancemapMethod · 0.95

Calls 1

distanceFunction · 0.85

Tested by 1

test_distancemapMethod · 0.76