Skip to content

Commit

Permalink
Merge pull request #235 from pavlin-policar/fix-bh-collapse
Browse files Browse the repository at this point in the history
Fix BH collapse
  • Loading branch information
pavlin-policar authored Feb 15, 2023
2 parents 153ad71 + 3c561f2 commit 75a0a03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openTSNE/quad_tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ cdef void split_node(Node * node):
PyMem_Free(new_center)


cdef inline bint is_duplicate(Node * node, double * point, double duplicate_eps=1e-6) nogil:
cdef inline bint is_duplicate(Node * node, double * point, double duplicate_eps=1e-16) nogil:
cdef Py_ssize_t d
for d in range(node.n_dims):
if fabs(node.center_of_mass[d] - point[d]) >= duplicate_eps:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_correctness.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,18 @@ def test_spectral_agreement_with_sklearn(self):
np.testing.assert_almost_equal(
np.abs(np.corrcoef(embedding1[:,1], embedding2[:,1])[0,1]), 1
)


class TestEarlyExaggerationCollapse(unittest.TestCase):
"""In some cases, the BH implementation was producing a collapsed embedding
for all data points. For more information, see #233, #234."""
def test_early_exaggeration_does_not_collapse(self):
n_samples = [100, 150, 200]
n_dims = [5, 10, 20]

np.random.seed(42)
for n in n_samples:
for d in n_dims:
x = np.random.randn(n, d)
embedding = openTSNE.TSNE(random_state=42).fit(x)
self.assertGreater(np.max(np.abs(embedding)), 1e-8)

0 comments on commit 75a0a03

Please sign in to comment.