From e6a2447ce8850bd7de577cabd26f901c1691197e Mon Sep 17 00:00:00 2001 From: Matthew Danielson <93564181+blckmaxima@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:59:04 -0600 Subject: [PATCH] Account for different ordering of result (#531) Use consistent random seed for reproducibility --- lib/hmmlearn/tests/test_gaussian_hmm.py | 6 +++--- lib/hmmlearn/tests/test_variational_gaussian.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/hmmlearn/tests/test_gaussian_hmm.py b/lib/hmmlearn/tests/test_gaussian_hmm.py index 6bf6c9eb..af11b07f 100644 --- a/lib/hmmlearn/tests/test_gaussian_hmm.py +++ b/lib/hmmlearn/tests/test_gaussian_hmm.py @@ -122,7 +122,7 @@ def test_fit_ignored_init_warns(self, implementation, caplog): h = hmm.GaussianHMM(self.n_components, self.covariance_type, implementation=implementation) h.startprob_ = self.startprob - h.fit(np.random.randn(100, self.n_components)) + h.fit(self.prng.randn(100, self.n_components)) assert len(caplog.records) == 1, caplog assert "will be overwritten" in caplog.records[0].getMessage() @@ -135,7 +135,7 @@ def test_fit_too_little_data(self, implementation, caplog): h.transmat_ = self.transmat h.means_ = 20 * self.means h.covars_ = np.maximum(self.covars, 0.1) - h._init(np.random.randn(5, self.n_components), 5) + h._init(self.prng.randn(5, self.n_components), 5) assert len(caplog.records) == 1 assert "degenerate solution" in caplog.records[0].getMessage() @@ -295,7 +295,7 @@ class TestGaussianHMMWithDiagonalCovars(GaussianHMMTestMixin): def test_covar_is_writeable(self, implementation): h = hmm.GaussianHMM(n_components=1, covariance_type="diag", init_params="c", implementation=implementation) - X = np.random.normal(size=(1000, 5)) + X = self.prng.normal(size=(1000, 5)) h._init(X, 1000) # np.diag returns a read-only view of the array in NumPy 1.9.X. diff --git a/lib/hmmlearn/tests/test_variational_gaussian.py b/lib/hmmlearn/tests/test_variational_gaussian.py index 33413ee8..0a4635a5 100644 --- a/lib/hmmlearn/tests/test_variational_gaussian.py +++ b/lib/hmmlearn/tests/test_variational_gaussian.py @@ -74,7 +74,7 @@ def test_fit_mcgrory_titterington1d(self, implementation): vi_uniform_startprob_and_transmat(model, lengths) model.fit(sequences, lengths) # Perform one check that we are converging to the right answer - assert (model.means_posterior_[-1][0] + assert (list(sorted(model.means_posterior_.ravel()))[3] == pytest.approx(self.test_fit_mcgrory_titterington1d_mean)), \ model.means_posterior_