Skip to content

Commit d4a9f14

Browse files
authored
Fix Categorical.rvs to sample categories using probabilities (#684)
* fix categorical distribution sampling * ensure type consistency
1 parent d9b8ec1 commit d4a9f14

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

preliz/distributions/categorical.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ def kurtosis(self):
127127

128128
def rvs(self, size=None, random_state=None):
129129
random_state = np.random.default_rng(random_state)
130-
return random_state.choice(self.p, size)
130+
support_array = np.arange(self.support[0], self.support[1] + 1)
131+
return random_state.choice(support_array, size, p=self.p)
131132

132133
def _fit_mle(self, sample):
133134
optimize_ml(self, sample)

0 commit comments

Comments
 (0)