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

Method test_distance

test/test_vector.py:733–744  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

731 print "pattern.vector.centroid()"
732
733 def test_distance(self):
734 # Assert distance metrics.
735 v1 = vector.Vector({"cat":1})
736 v2 = vector.Vector({"cat":0.5, "dog":1})
737 for d, method in (
738 (0.55, vector.COSINE), # 1 - ((1*0.5 + 0*1) / (sqrt(1**2 + 0**2) * sqrt(0.5**2 + 1**2)))
739 (1.25, vector.EUCLIDEAN), # (1-0.5)**2 + (0-1)**2
740 (1.50, vector.MANHATTAN), # abs(1-0.5) + abs(0-1)
741 (1.00, vector.HAMMING), # (True + True) / 2
742 (1.11, lambda v1, v2: 1.11)):
743 self.assertAlmostEqual(vector.distance(v1, v2, method), d, places=2)
744 print "pattern.vector.distance()"
745
746 def test_distancemap(self):
747 # Assert distance caching mechanism.

Callers

nothing calls this directly

Calls 1

distanceMethod · 0.45

Tested by

no test coverage detected