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?

1 Answer

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.