Skip to content

Commit

Permalink
corrected ordering of Eudex weights supplied as lists
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislit committed Dec 9, 2018
1 parent 266cb82 commit e4c0a1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions abydos/distance/_eudex.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def __init__(self, weights='exponential', max_length=8, **kwargs):
- If set to an iterable, the iterable's values should be
integers and will be used as the weights.
In all cases, the weights should be ordered or generated from least
significant to most significant, so larger values should generally
come first.
max_length : int
The number of characters to encode as a eudex hash
**kwargs
Expand Down Expand Up @@ -181,13 +185,13 @@ def dist_abs(self, src, tar, normalized=False):
>>> # Using the OEIS A000142:
>>> cmp = Eudex(weights=[1, 1, 2, 6, 24, 120, 720, 5040])
>>> cmp.dist_abs('cat', 'hat')
1
5040
>>> cmp.dist_abs('Niall', 'Neil')
720
1
>>> cmp.dist_abs('Colin', 'Cuilen')
744
7
>>> cmp.dist_abs('ATCG', 'TAGC')
6243
15130
.. versionadded:: 0.3.0
.. versionchanged:: 0.3.6
Expand Down Expand Up @@ -217,7 +221,7 @@ def dist_abs(self, src, tar, normalized=False):
elif self._weights == 'fibonacci':
weights = Eudex.gen_fibonacci()
elif hasattr(self._weights, '__iter__'):
weights = list(self._weights)
weights = self._weights[::-1]

if isinstance(weights, GeneratorType):
weights = [next(weights) for _ in range(self._max_length)][::-1]
Expand Down Expand Up @@ -334,13 +338,13 @@ def eudex_hamming(
>>> # Using the OEIS A000142:
>>> eudex_hamming('cat', 'hat', [1, 1, 2, 6, 24, 120, 720, 5040])
1
5040
>>> eudex_hamming('Niall', 'Neil', [1, 1, 2, 6, 24, 120, 720, 5040])
720
1
>>> eudex_hamming('Colin', 'Cuilen', [1, 1, 2, 6, 24, 120, 720, 5040])
744
7
>>> eudex_hamming('ATCG', 'TAGC', [1, 1, 2, 6, 24, 120, 720, 5040])
6243
15130
.. versionadded:: 0.3.0
Expand Down
2 changes: 1 addition & 1 deletion tests/distance/test_distance_eudex.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_eudex_dist_abs(self):
self.assertEqual(self.cmp.dist_abs('Niall', 'Colin'), 524)
self.assertEqual(Eudex(None).dist_abs('Niall', 'Colin'), 10)
self.assertEqual(Eudex('fibonacci').dist_abs('Niall', 'Colin'), 146)
self.assertEqual(Eudex([10, 1, 1, 1]).dist_abs('Niall', 'Colin'), 6)
self.assertEqual(Eudex([10, 1, 1, 1]).dist_abs('Niall', 'Colin'), 42)
self.assertEqual(Eudex(_yield_1).dist_abs('Niall', 'Colin'), 10)
self.assertAlmostEqual(
self.cmp.dist_abs('Niall', 'Colin', normalized=True), 0.25686274
Expand Down

0 comments on commit e4c0a1b

Please sign in to comment.