bundles / scipy latest / scipy / stats / _multivariate / dirichlet_gen
class
scipy.stats._multivariate:dirichlet_gen
source: build-install/usr/lib/python3.14/site-packages/scipy/stats/_multivariate.py:2265
Signature
class dirichlet_gen(seed = None)Members
Summary
A Dirichlet random variable.
Extended Summary
The alpha keyword specifies the concentration parameters of the distribution.
Parameters
%(_dirichlet_doc_default_callparams)s%(_doc_random_state)s
Methods
pdf(x, alpha)Probability density function.
logpdf(x, alpha)Log of the probability density function.
rvs(alpha, size=1, random_state=None)Draw random samples from a Dirichlet distribution.
mean(alpha)The mean of the Dirichlet distribution
var(alpha)The variance of the Dirichlet distribution
cov(alpha)The covariance of the Dirichlet distribution
entropy(alpha)Compute the differential entropy of the Dirichlet distribution.
Notes
Each entry must be positive. The distribution has only support on the simplex defined by
where .
If the quantiles don't lie within the simplex, a ValueError is raised.
The probability density function for dirichlet is
where
and , the concentration parameters and is the dimension of the space where takes values.
Note that the dirichlet interface is somewhat inconsistent. The array returned by the rvs function is transposed with respect to the format expected by the pdf and logpdf.
Examples
import numpy as np from scipy.stats import dirichlet✓
quantiles = np.array([0.2, 0.2, 0.6]) # specify quantiles alpha = np.array([0.4, 5, 15]) # specify concentration parameters✓
dirichlet.pdf(quantiles, alpha)
✗np.float64(0.2843831684937255)The same PDF but following a log scale
dirichlet.logpdf(quantiles, alpha)
✗np.float64(-1.2574327653159187)Once we specify the dirichlet distribution we can then calculate quantities of interest
dirichlet.mean(alpha) # get the mean of the distribution dirichlet.var(alpha) # get variance dirichlet.entropy(alpha) # calculate the differential entropy✗
np.float64(-4.3280162474082715)We can also return random samples from the distribution
dirichlet.rvs(alpha, size=1, random_state=1) dirichlet.rvs(alpha, size=2, random_state=2)✗
array([[0.01639, 0.12923, 0.85438],
[0.00157, 0.19034, 0.80809]])
Alternatively, the object may be called (as a function) to fix
concentration parameters, returning a "frozen" Dirichlet
random variable:
rv = dirichlet(alpha)
✓Aliases
scipy.stats._multivariate.dirichlet_gen