public class AhrensDieterMarsagliaTsangGammaSampler extends SamplerBase implements SharedStateContinuousSampler
0 < alpha < 1:
Ahrens, J. H. and Dieter, U., Computer methods for sampling from gamma, beta, Poisson and binomial distributions, Computing, 12, 223-246, 1974.
alpha >= 1:
Marsaglia and Tsang, A Simple Method for Generating Gamma Variables. ACM Transactions on Mathematical Software, Volume 26 Issue 3, September, 2000.
Sampling uses:
UniformRandomProvider.nextDouble() (both algorithms)
UniformRandomProvider.nextLong() (only for alpha >= 1)
| Constructor and Description |
|---|
AhrensDieterMarsagliaTsangGammaSampler(UniformRandomProvider rng,
double alpha,
double theta)
This instance delegates sampling.
|
| Modifier and Type | Method and Description |
|---|---|
static SharedStateContinuousSampler |
of(UniformRandomProvider rng,
double alpha,
double theta)
Creates a new gamma distribution sampler.
|
double |
sample()
Creates a
double sample. |
String |
toString() |
SharedStateContinuousSampler |
withUniformRandomProvider(UniformRandomProvider rng)
Create a new instance of the sampler with the same underlying state using the given
uniform random provider as the source of randomness.
|
nextDouble, nextInt, nextInt, nextLongclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitsamples, samplespublic AhrensDieterMarsagliaTsangGammaSampler(UniformRandomProvider rng, double alpha, double theta)
of(UniformRandomProvider, double, double) to create an optimal sampler.rng - Generator of uniformly distributed random numbers.alpha - Alpha parameter of the distribution (this is a shape parameter).theta - Theta parameter of the distribution (this is a scale parameter).IllegalArgumentException - if alpha <= 0 or theta <= 0public double sample()
double sample.sample in interface ContinuousSamplerpublic String toString()
toString in class SamplerBasepublic SharedStateContinuousSampler withUniformRandomProvider(UniformRandomProvider rng)
withUniformRandomProvider in interface SharedStateSampler<SharedStateContinuousSampler>rng - Generator of uniformly distributed random numbers.public static SharedStateContinuousSampler of(UniformRandomProvider rng, double alpha, double theta)
rng - Generator of uniformly distributed random numbers.alpha - Alpha parameter of the distribution (this is a shape parameter).theta - Theta parameter of the distribution (this is a scale parameter).IllegalArgumentException - if alpha <= 0 or theta <= 0Copyright © 2016–2022 The Apache Software Foundation. All rights reserved.