Description
Add sampling from a Dirichlet distribution.
Samples can be produced by generating Gamma(shape=alpha, scale=1) deviates for each category with concentration alpha, summing the deviates and dividing by the sum.
Proposed public API.
public abstract class DirichletSampler implements SharedStateObjectSampler<double[]> { public double[] sample(); public DirichletSampler withUniformRandomProvider(UniformRandomProvider rng); public static DirichletSampler of(UniformRandomProvider rng, double... alpha); public static DirichletSampler symmetric(UniformRandomProvider rng, int k, double alpha); }
The symmetric case is a special case where the alpha concentration parameters are the same for all categories. This can be implemented with a single sampler which reduces memory footprint. This is especially true when alpha > 1 as a AhrensDieterMarsagliaTsangGammaSampler holds two precomputed values and a normalised Gaussian sampler.
An example of using a symmetric case is a unit Simplex which uses dimension k and alpha=1.
Attachments
Issue Links
- relates to
-
RNG-132 Package rng.sampling.shape for sampling coordinates from shapes
- Closed