Skip to content

Commit

Permalink
Slightly more reliable comparison of learned gaussian models in a test (
Browse files Browse the repository at this point in the history
  • Loading branch information
blckmaxima authored Jan 15, 2024
1 parent 1a8e2d6 commit 95c2b11
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/hmmlearn/tests/test_gaussian_hmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,20 @@ def test_fit_with_priors(self, implementation, init_params='mc',
assert_log_likelihood_increasing(h_learn, X, lengths, n_iter)

# Make sure we've converged to the right parameters.
# In general, to account for state switching,
# compare sorted values.
# a) means
assert_allclose(sorted(h.means_.tolist()),
sorted(h_learn.means_.tolist()),
assert_allclose(sorted(h.means_.ravel().tolist()),
sorted(h_learn.means_.ravel().tolist()),
0.01)
# b) covars are hard to estimate precisely from a relatively small
# sample, thus the large threshold

# account for how we store the covars_compressed
orig = np.broadcast_to(h._covars_, h_learn._covars_.shape)
assert_allclose(
*np.broadcast_arrays(sorted(h._covars_.tolist()),
sorted(h_learn._covars_.tolist())),
sorted(orig.ravel().tolist()),
sorted(h_learn._covars_.ravel().tolist()),
10)


Expand Down

0 comments on commit 95c2b11

Please sign in to comment.