From dfba2c48c04217b7000a16b74ee3cd0d58859642 Mon Sep 17 00:00:00 2001 From: Thomas Fan Date: Wed, 26 Jun 2019 21:07:49 -0400 Subject: [PATCH 1/5] TST Uses float32 --- sklearn/cluster/optics_.py | 2 +- sklearn/cluster/tests/test_optics.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sklearn/cluster/optics_.py b/sklearn/cluster/optics_.py index 4f7eb11ab2f72..1d3b1327af53a 100755 --- a/sklearn/cluster/optics_.py +++ b/sklearn/cluster/optics_.py @@ -233,7 +233,7 @@ def fit(self, X, y=None): self : instance of OPTICS The instance. """ - X = check_array(X, dtype=np.float) + X = check_array(X, dtype=np.float32) if self.cluster_method not in ['dbscan', 'xi']: raise ValueError("cluster_method should be one of" diff --git a/sklearn/cluster/tests/test_optics.py b/sklearn/cluster/tests/test_optics.py index 1e3d99746c9e9..09654e3d5aa65 100644 --- a/sklearn/cluster/tests/test_optics.py +++ b/sklearn/cluster/tests/test_optics.py @@ -351,7 +351,8 @@ def test_compare_to_ELKI(): assert_array_equal(clust1.ordering_, np.array(o1)) assert_array_equal(clust1.predecessor_[clust1.ordering_], np.array(p1)) - assert_allclose(clust1.reachability_[clust1.ordering_], np.array(r1)) + assert_allclose(clust1.reachability_[clust1.ordering_], np.array(r1), + rtol=2e-6) # ELKI currently does not print the core distances (which are not used much # in literature, but we can at least ensure to have this consistency: for i in clust1.ordering_[1:]: @@ -385,7 +386,8 @@ def test_compare_to_ELKI(): assert_array_equal(clust2.ordering_, np.array(o2)) assert_array_equal(clust2.predecessor_[clust2.ordering_], np.array(p2)) - assert_allclose(clust2.reachability_[clust2.ordering_], np.array(r2)) + assert_allclose(clust2.reachability_[clust2.ordering_], np.array(r2), + rtol=2e-6) index = np.where(clust1.core_distances_ <= 0.5)[0] assert_allclose(clust1.core_distances_[index], @@ -421,5 +423,5 @@ def test_precomputed_dists(): clust2 = OPTICS(min_samples=10, algorithm='brute', metric='euclidean').fit(redX) - assert_allclose(clust1.reachability_, clust2.reachability_) + assert_allclose(clust1.reachability_, clust2.reachability_, rtol=2e-7) assert_array_equal(clust1.labels_, clust2.labels_) From 97b39eb890353abb6dfa42484f7aa55b319c56ea Mon Sep 17 00:00:00 2001 From: Thomas Fan Date: Thu, 27 Jun 2019 10:22:51 -0400 Subject: [PATCH 2/5] Revert "TST Uses float32" This reverts commit dfba2c48c04217b7000a16b74ee3cd0d58859642. --- sklearn/cluster/optics_.py | 2 +- sklearn/cluster/tests/test_optics.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sklearn/cluster/optics_.py b/sklearn/cluster/optics_.py index 1d3b1327af53a..4f7eb11ab2f72 100755 --- a/sklearn/cluster/optics_.py +++ b/sklearn/cluster/optics_.py @@ -233,7 +233,7 @@ def fit(self, X, y=None): self : instance of OPTICS The instance. """ - X = check_array(X, dtype=np.float32) + X = check_array(X, dtype=np.float) if self.cluster_method not in ['dbscan', 'xi']: raise ValueError("cluster_method should be one of" diff --git a/sklearn/cluster/tests/test_optics.py b/sklearn/cluster/tests/test_optics.py index 09654e3d5aa65..1e3d99746c9e9 100644 --- a/sklearn/cluster/tests/test_optics.py +++ b/sklearn/cluster/tests/test_optics.py @@ -351,8 +351,7 @@ def test_compare_to_ELKI(): assert_array_equal(clust1.ordering_, np.array(o1)) assert_array_equal(clust1.predecessor_[clust1.ordering_], np.array(p1)) - assert_allclose(clust1.reachability_[clust1.ordering_], np.array(r1), - rtol=2e-6) + assert_allclose(clust1.reachability_[clust1.ordering_], np.array(r1)) # ELKI currently does not print the core distances (which are not used much # in literature, but we can at least ensure to have this consistency: for i in clust1.ordering_[1:]: @@ -386,8 +385,7 @@ def test_compare_to_ELKI(): assert_array_equal(clust2.ordering_, np.array(o2)) assert_array_equal(clust2.predecessor_[clust2.ordering_], np.array(p2)) - assert_allclose(clust2.reachability_[clust2.ordering_], np.array(r2), - rtol=2e-6) + assert_allclose(clust2.reachability_[clust2.ordering_], np.array(r2)) index = np.where(clust1.core_distances_ <= 0.5)[0] assert_allclose(clust1.core_distances_[index], @@ -423,5 +421,5 @@ def test_precomputed_dists(): clust2 = OPTICS(min_samples=10, algorithm='brute', metric='euclidean').fit(redX) - assert_allclose(clust1.reachability_, clust2.reachability_, rtol=2e-7) + assert_allclose(clust1.reachability_, clust2.reachability_) assert_array_equal(clust1.labels_, clust2.labels_) From e14af4628f08c4c1a4b99490ee30bb4eb4c78d54 Mon Sep 17 00:00:00 2001 From: Thomas Fan Date: Thu, 27 Jun 2019 10:24:32 -0400 Subject: [PATCH 3/5] TST Uses float32 when 32bit --- sklearn/cluster/tests/test_optics.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sklearn/cluster/tests/test_optics.py b/sklearn/cluster/tests/test_optics.py index 1e3d99746c9e9..77200c34f1c8b 100644 --- a/sklearn/cluster/tests/test_optics.py +++ b/sklearn/cluster/tests/test_optics.py @@ -13,6 +13,7 @@ from sklearn.metrics.pairwise import pairwise_distances from sklearn.cluster.dbscan_ import DBSCAN from sklearn.utils import shuffle +from sklearn.utils import _IS_32BIT from sklearn.utils.testing import assert_equal from sklearn.utils.testing import assert_array_equal from sklearn.utils.testing import assert_raise_message @@ -97,6 +98,9 @@ def test_extract_xi(): -1, [4] * 5] X, expected_labels = shuffle(X, expected_labels, random_state=rng) + if _IS_32BIT: + X = X.astype(np.float32) + clust = OPTICS(min_samples=3, min_cluster_size=2, max_eps=20, cluster_method='xi', xi=0.4).fit(X) From 6b42e135ebeba8e98e6df370292d633018811f03 Mon Sep 17 00:00:00 2001 From: Thomas Fan Date: Thu, 27 Jun 2019 10:40:26 -0400 Subject: [PATCH 4/5] REV Remove float32 --- sklearn/cluster/tests/test_optics.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sklearn/cluster/tests/test_optics.py b/sklearn/cluster/tests/test_optics.py index 77200c34f1c8b..1e3d99746c9e9 100644 --- a/sklearn/cluster/tests/test_optics.py +++ b/sklearn/cluster/tests/test_optics.py @@ -13,7 +13,6 @@ from sklearn.metrics.pairwise import pairwise_distances from sklearn.cluster.dbscan_ import DBSCAN from sklearn.utils import shuffle -from sklearn.utils import _IS_32BIT from sklearn.utils.testing import assert_equal from sklearn.utils.testing import assert_array_equal from sklearn.utils.testing import assert_raise_message @@ -98,9 +97,6 @@ def test_extract_xi(): -1, [4] * 5] X, expected_labels = shuffle(X, expected_labels, random_state=rng) - if _IS_32BIT: - X = X.astype(np.float32) - clust = OPTICS(min_samples=3, min_cluster_size=2, max_eps=20, cluster_method='xi', xi=0.4).fit(X) From f6999afadde345c1c88d6c60efa6f4ce9bdf6c3a Mon Sep 17 00:00:00 2001 From: Thomas Fan Date: Sun, 30 Jun 2019 21:28:42 -0400 Subject: [PATCH 5/5] TST Updates xi to 0.3 --- sklearn/cluster/tests/test_optics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/cluster/tests/test_optics.py b/sklearn/cluster/tests/test_optics.py index 1e3d99746c9e9..1028d7174bb4e 100644 --- a/sklearn/cluster/tests/test_optics.py +++ b/sklearn/cluster/tests/test_optics.py @@ -109,7 +109,7 @@ def test_extract_xi(): clust = OPTICS(min_samples=3, min_cluster_size=3, max_eps=20, cluster_method='xi', - xi=0.1).fit(X) + xi=0.3).fit(X) # this may fail if the predecessor correction is not at work! assert_array_equal(clust.labels_, expected_labels)