Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.random.dirichlet

numpy.random.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

Parameter of the distribution (k dimension for sample ofdimension k).

size : int or tuple of ints, optional

Output shape. If the given shape is, e.g.,(m,n,k), thenm*n*k samples are drawn. Default is None, in which case asingle value is returned.

Returns:

samples : ndarray,

The drawn samples, of shape (size, alpha.ndim).

Notes

X \approx \prod_{i=1}^{k}{x^{\alpha_i-1}_i}

Uses the following property for computation: for each dimension,draw a random sample y_i from a standard gamma generator of shapealpha_i, thenX = \frac{1}{\sum_{i=1}^k{y_i}} (y_1, \ldots, y_n) isDirichlet distributed.

References

[R219]David McKay, “Information Theory, Inference and LearningAlgorithms,” chapter 23,http://www.inference.phy.cam.ac.uk/mackay/
[R220]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")

Previous topic

numpy.random.chisquare

Next topic

numpy.random.exponential

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp