probs = np.array([1e-6 for _ in range(300)])
results = [math.Categorical(probs, "") for _ in range(100)]
assert len(set(results)) > 1
When using the numpy backend, the code above fails: results contains 100 identical values.
This is because math.Categorical uses np.random.multinomial, which assumes that the probabilities sum up to 1 (if not, the last probability is increased such that the resulting probabilities sum up to 1)
Context:
When using the numpy backend, the code above fails:
results
contains 100 identical values. This is becausemath.Categorical
usesnp.random.multinomial
, which assumes that the probabilities sum up to1
(if not, the last probability is increased such that the resulting probabilities sum up to1
)