Skip to content

Commit

Permalink
Increase epsilon for comparing in KL tests (piskvorky#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmylk authored and Pranaydeep Singh committed Mar 21, 2017
1 parent 8e360f0 commit 5235637
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gensim/test/test_similarity_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_distributions(self):
vec_2 = [(1, 0.1), (3, 0.8), (4, 0.1)]
result = matutils.kullback_leibler(vec_2, vec_1, 8)
expected = 0.55451775
self.assertAlmostEqual(expected, result)
self.assertAlmostEqual(expected, result, places=5)

# KL is not symetric; vec1 compared with vec2 will contain log of zeros and return infinity
vec_1 = [(2, 0.1), (3, 0.4), (4, 0.1), (5, 0.1), (1, 0.1), (7, 0.2)]
Expand All @@ -201,14 +201,14 @@ def test_distributions(self):
vec_2 = csr_matrix([[1, 0.4], [0, 0.2], [2, 0.2]])
result = matutils.kullback_leibler(vec_1, vec_2, 3)
expected = 0.0894502
self.assertAlmostEqual(expected, result)
self.assertAlmostEqual(expected, result, places=5)

# checking ndarray, list as inputs
vec_1 = np.array([0.6, 0.1, 0.1, 0.2])
vec_2 = [0.2, 0.2, 0.1, 0.5]
result = matutils.kullback_leibler(vec_1, vec_2)
expected = 0.40659450877
self.assertAlmostEqual(expected, result)
self.assertAlmostEqual(expected, result, places=5)

# testing LDA distribution vectors
np.random.seed(0)
Expand All @@ -217,7 +217,7 @@ def test_distributions(self):
lda_vec2 = model[[(2, 2), (1, 3)]]
result = matutils.kullback_leibler(lda_vec1, lda_vec2)
expected = 4.283407e-12
self.assertAlmostEqual(expected, result)
self.assertAlmostEqual(expected, result, places=5)

class TestJaccard(unittest.TestCase):
def test_inputs(self):
Expand Down

0 comments on commit 5235637

Please sign in to comment.