MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / is_stochastic

Function is_stochastic

numpy_ml/utils/testing.py:30–35  ·  view source on GitHub ↗

True if `X` contains probabilities that sum to 1 along the columns

(X)

Source from the content-addressed store, hash-verified

28
29
30def is_stochastic(X):
31 """True if `X` contains probabilities that sum to 1 along the columns"""
32 msg = "Array should be stochastic along the columns"
33 assert len(X[X < 0]) == len(X[X > 1]) == 0, msg
34 assert np.allclose(np.sum(X, axis=1), np.ones(X.shape[0])), msg
35 return True
36
37
38def is_number(a):

Callers 2

lossMethod · 0.85
gradMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected