RandomState.dirichlet(alpha,size=None)¶Draw samples from the Dirichlet distribution.
Drawsize samples of dimension k from a Dirichlet distribution. ADirichlet-distributed random variable can be seen as a multivariategeneralization of a Beta distribution. Dirichlet pdf is the conjugateprior of a multinomial in Bayesian inference.
| Parameters: | alpha : array
size : int or tuple of ints, optional
|
|---|---|
| Returns: | samples : ndarray,
|
Notes

Uses the following property for computation: for each dimension,draw a random sample y_i from a standard gamma generator of shapealpha_i, then
isDirichlet distributed.
References
| [R148] | David McKay, “Information Theory, Inference and LearningAlgorithms,” chapter 23,http://www.inference.phy.cam.ac.uk/mackay/ |
| [R149] | Wikipedia, “Dirichlet distribution”,http://en.wikipedia.org/wiki/Dirichlet_distribution |
Examples
Taking an example cited in Wikipedia, this distribution can be used ifone wanted to cut strings (each of initial length 1.0) into K pieceswith different lengths, where each piece had, on average, a designatedaverage length, but allowing some variation in the relative sizes ofthe pieces.
>>>s=np.random.dirichlet((10,5,3),20).transpose()
>>>plt.barh(range(20),s[0])>>>plt.barh(range(20),s[1],left=s[0],color='g')>>>plt.barh(range(20),s[2],left=s[0]+s[1],color='r')>>>plt.title("Lengths of Strings")