From 9b96ee68ffb72bb87c158a4e21d6aa40f3a5c769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 14 Apr 2025 16:42:34 +0200 Subject: [PATCH 1/2] Adding global random seed --- sklearn/decomposition/tests/test_fastica.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sklearn/decomposition/tests/test_fastica.py b/sklearn/decomposition/tests/test_fastica.py index 4d3319c0ee32b..6f8c9c55db621 100644 --- a/sklearn/decomposition/tests/test_fastica.py +++ b/sklearn/decomposition/tests/test_fastica.py @@ -32,10 +32,10 @@ def center_and_norm(x, axis=-1): x /= x.std(axis=0) -def test_gs(): +def test_gs(global_random_seed): # Test gram schmidt orthonormalization # generate a random orthogonal matrix - rng = np.random.RandomState(0) + rng = np.random.RandomState(global_random_seed) W, _, _ = np.linalg.svd(rng.randn(10, 10)) w = rng.randn(10) _gs_decorrelation(w, W, 10) @@ -188,11 +188,11 @@ def test_fastica_nowhiten(): assert hasattr(ica, "mixing_") -def test_fastica_convergence_fail(): +def test_fastica_convergence_fail(global_random_seed): # Test the FastICA algorithm on very simple data # (see test_non_square_fastica). # Ensure a ConvergenceWarning raised if the tolerance is sufficiently low. - rng = np.random.RandomState(0) + rng = np.random.RandomState(global_random_seed) n_samples = 1000 # Generate two sources: @@ -219,9 +219,9 @@ def test_fastica_convergence_fail(): @pytest.mark.parametrize("add_noise", [True, False]) -def test_non_square_fastica(add_noise): +def test_non_square_fastica(global_random_seed, add_noise): # Test the FastICA algorithm on very simple data. - rng = np.random.RandomState(0) + rng = np.random.RandomState(global_random_seed) n_samples = 1000 # Generate two sources: @@ -372,12 +372,12 @@ def test_fastica_errors(): fastica(X, w_init=w_init) -def test_fastica_whiten_unit_variance(): +def test_fastica_whiten_unit_variance(global_random_seed): """Test unit variance of transformed data using FastICA algorithm. Bug #13056 """ - rng = np.random.RandomState(0) + rng = np.random.RandomState(global_random_seed) X = rng.random_sample((100, 10)) n_components = X.shape[1] ica = FastICA(n_components=n_components, whiten="unit-variance", random_state=0) From 6fb71f8b9f23b853a2546f81ed450799ceab822b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 14 Apr 2025 16:48:31 +0200 Subject: [PATCH 2/2] Run the CI for tests that take global_random_seed [all random seeds] test_gs test_fastica_convergence_fail test_non_square_fastica test_fastica_whiten_unit_variance