Skip to content

Instantly share code, notes, and snippets.

@cuent
Created July 11, 2019 04:14
Show Gist options
  • Select an option

  • Save cuent/20473299e0153300e2987cdb9b23b834 to your computer and use it in GitHub Desktop.

Select an option

Save cuent/20473299e0153300e2987cdb9b23b834 to your computer and use it in GitHub Desktop.
Sample from a dirichlet multinomial distribution
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