Skip to content

Commit

Permalink
Make the 'rows must sum to 1' phrasing clearer (#530)
Browse files Browse the repository at this point in the history
* Make the 'rows must sum to 1' phrasing clearer
* Shorten line lengths
  • Loading branch information
beyarkay authored Aug 31, 2023
1 parent e6a2447 commit 23c0f13
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/hmmlearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,11 @@ def _check_sum_1(self, name):
s = getattr(self, name).sum(axis=-1)
if not np.allclose(s, 1):
raise ValueError(
f"{name} must sum to 1 (got {s:.4f})" if s.ndim == 0 else
f"{name} rows must sum to 1 (got {s})" if s.ndim == 1 else
"Expected 1D or 2D array")
f"{name} must sum to 1 (got {s:.4f})"
if s.ndim == 0
else f"{name} rows must sum to 1 (got row sums of {s})"
if s.ndim == 1
else "Expected 1D or 2D array")

def _check(self):
"""
Expand Down Expand Up @@ -929,9 +931,11 @@ def _check_sum_1(self, name):
s = getattr(self, name).sum(axis=-1)
if not np.allclose(s, 1):
raise ValueError(
f"{name} must sum to 1 (got {s:.4f})" if s.ndim == 0 else
f"{name} rows must sum to 1 (got {s})" if s.ndim == 1 else
"Expected 1D or 2D array")
f"{name} must sum to 1 (got {s:.4f})"
if s.ndim == 0
else f"{name} rows must sum to 1 (got row sums of {s})"
if s.ndim == 1
else "Expected 1D or 2D array")

def _check(self):
"""
Expand Down Expand Up @@ -1002,6 +1006,7 @@ def bic(self, X, lengths=None):
n_params = sum(self._get_n_fit_scalars_per_param().values())
return -2 * self.score(X, lengths=lengths) + n_params * np.log(len(X))


_BaseHMM = BaseHMM # Backcompat name, will be deprecated in the future.


Expand Down

0 comments on commit 23c0f13

Please sign in to comment.