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
.
It has K shape parameters, usually denoted by the Greek letter α. Its
probability density function (PDF) is:
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
VectorT that contains
the shape parameters.
var alpha = Vector.Create(3.0, 7.0, 5.0);
var dirichlet1 = new DirichletDistribution(alpha);
Dim alpha = Vector.Create(3.0, 7.0, 5.0)
Dim dirichlet1 = New DirichletDistribution(alpha)
No code example is currently available or this language may not be supported.
let alpha = Vector.Create(3.0, 7.0, 5.0)
let dirichlet1 = DirichletDistribution(alpha)
The two remaining constructors estimate the distribution parameters
from a set of variables. One constructor takes a
VectorT array.
The other takes a MatrixT
whose columns contain the variables.
The GetParameters
method returns a copy of the parameters α. The
GetMeans method
returns a VectorT that contains the mean of the distribution.
The GetVarianceCovarianceMatrix method
returns a SymmetricMatrixT 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 SystemRandom 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);
Dim Random = New MersenneTwister()
Dim sample = dirichlet1.Sample(Random)
Dim samples = dirichlet1.Sample(Random, 10000)
dirichlet1.FillSample(Random, sample)
dirichlet1.FillSamples(Random, samples)
No code example is currently available or this language may not be supported.
let random = MersenneTwister()
let sample = dirichlet1.Sample(random)
let samples = dirichlet1.Sample(random, 10000)
dirichlet1.FillSample(random, sample)
dirichlet1.FillSamples(random, samples)