Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does numpy.random.dirichlet do?

Tags:

dirichlet

I need a Dirichlet distribution and I am using numpy.random.dirichlet. when I give alpha=[1,1,1,1] according to the Dirichlet PDF formula, it should result a uniform function. but it doesn't give me a uniform vector. anybody knows why?

like image 685
bbb Avatar asked Nov 03 '25 14:11

bbb


1 Answers

As far as I can tell, the numpy.random.dirichlet function works as intended. I think you may be slightly misunderstanding what the Dirichlet distribution is.

A k-dimensional Dirichlet distribution will have k parameters (x_1 through to x_k), which must all sum to 1. If you try sum(np.random.dirichlet([1, 1, 1, 1])), the result will always be 1 (give or take some rounding error). So while np.random.dirichlet([1, 1, 1, 1])) is indeed uniform on its support, this support is constrained by the requirement that x_1 + x_2 + x_3 + x_4 = 1, and the output array will not be Unif(0, 1) distributed.

This article gives a relatively simple and non-technical explanation of the concept.

like image 77
James L Avatar answered Nov 06 '25 04:11

James L