Skip to content

Commit

Permalink
change the l2 normalization test to reflect the change in normalizati…
Browse files Browse the repository at this point in the history
…on method
  • Loading branch information
jlowryduda committed Nov 30, 2017
1 parent c913038 commit c6b9584
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions conceptnet5/vectors/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def l2_normalize_rows(frame):
L_2-normalize the rows of this DataFrame, so their lengths in Euclidean
distance are all 1. This enables cosine similarities to be computed as
dot-products between these rows.
DataFrame of zeros will be normalized to zeros.
"""
index = frame.index
return pd.DataFrame(data=normalize(frame, norm='l2', copy=False, axis=1), index=index)
Expand Down
4 changes: 2 additions & 2 deletions tests/small-build/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def test_l2_normalize_rows(frame=None):
for length in lengths:
assert_almost_equal(length, 1.0, places=4)

# Check if a data frame of all zeroes will be normalized to NaN
# Check if a data frame of all zeros will be normalized to zeros
frame = pd.DataFrame(np.zeros(shape=(1, 10)))
frame = l2_normalize_rows(frame)
lengths = np.sqrt(np.sum(np.power(frame, 2), axis=1))
ok_(all(np.isnan(length) for length in lengths))
ok_(all(length == 0 for length in lengths))


def test_shrink_and_sort(frame=None):
Expand Down

0 comments on commit c6b9584

Please sign in to comment.