Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BH collapse #235

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)