Created
July 11, 2019 04:14
-
-
Save cuent/20473299e0153300e2987cdb9b23b834 to your computer and use it in GitHub Desktop.
Sample from a dirichlet multinomial distribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| alpha = np.array([3,1,2]) | |
| D = 100 | |
| def sample_polya(alpha, D, minimum=1, maximum=10): | |
| p = np.random.dirichlet(alpha,D) | |
| n = np.random.randint(minimum,maximum, D) | |
| r = np.zeros_like(p) | |
| for i in range(l): | |
| r[i] = np.random.multinomial(n[i], p[i,:]) | |
| return r | |
| sample_polya(alpha, D) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment