Skip to content

Commit 483dfb0

Browse files
fonnesbeckricardoV94
authored andcommitted
Refactored pymc3_random_discrete to use histograms instead of raw counts
1 parent f1bd401 commit 483dfb0

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

pymc/tests/test_distributions_random.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,12 @@ def pymc_random_discrete(
144144
e = intX(ref_rand(size=size, **pt))
145145
o = np.atleast_1d(o).flatten()
146146
e = np.atleast_1d(e).flatten()
147-
observed = dict(zip(*np.unique(o, return_counts=True)))
148-
expected = dict(zip(*np.unique(e, return_counts=True)))
149-
for e in expected.keys():
150-
expected[e] = (observed.get(e, 0), expected[e])
151-
k = np.array([v for v in expected.values()])
152-
if np.all(k[:, 0] == k[:, 1]):
147+
observed, _ = np.histogram(o, bins=min(7, len(set(o))))
148+
expected, _ = np.histogram(e, bins=min(7, len(set(o))))
149+
if np.all(observed == expected):
153150
p = 1.0
154151
else:
155-
_, p = st.chisquare(k[:, 0], k[:, 1])
152+
_, p = st.chisquare(observed + 1, expected + 1)
156153
f -= 1
157154
assert p > alpha, str(pt)
158155

0 commit comments

Comments
 (0)