The Dirichlet Distribution

The Dirichlet distribution is a generalization of the The Beta Distribution to the multivariate case. The Dirichlet distribution is often used in Bayesian analysis.

A Dirichlet distribution of order K is defined on the K-dimensional hyperplane with Condition on the variates of a Dirichlet distribution.. It has K shape parameters, usually denoted by the Greek letter α. Its probability density function (PDF) is:

Probability density of the Dirichlet distribution.

When K = 2, the Dirichlet distribution reduces to the Beta distribution. The Dirichlet distribution is implemented by the DirichletDistribution class. It has three constructors. The first constructor takes a Vector<T> that contains the shape parameters.

var alpha = Vector.Create(3.0, 7.0, 5.0);
var dirichlet1 = new DirichletDistribution(alpha);

The two remaining constructors estimate the distribution parameters from a set of variables. One constructor takes a Vector<T> array. The other takes a Matrix<T> whose columns contain the variables.

The GetParameters method returns a copy of the parameters α. The GetMeans method returns a Vector<T> that contains the mean of the distribution. The GetVarianceCovarianceMatrix method returns a SymmetricMatrix<T> that contains the variance-covariance matrix of the distribution.

There are two options to generate random samples from the distribution. One is to use the Sample method. Sample takes a System.Random and returns a vector with a single sample from the distribution. There are also FillSample and FillSamples methods, which copy the sample(s) into the vector or matrix that is supplied as an additional parameter. The example below shows how to generate random samples using each of these techniques:

MersenneTwister random = new MersenneTwister();
var sample = dirichlet1.Sample(random);
var samples = dirichlet1.Sample(random, 10000);
dirichlet1.FillSample(random, sample);
dirichlet1.FillSamples(random, samples);