Class AhrensDieterMarsagliaTsangGammaSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.SamplerBase
org.apache.commons.rng.sampling.distribution.AhrensDieterMarsagliaTsangGammaSampler
- All Implemented Interfaces:
ContinuousSampler, SharedStateContinuousSampler, SharedStateSampler<SharedStateContinuousSampler>
public class AhrensDieterMarsagliaTsangGammaSampler
extends SamplerBase
implements SharedStateContinuousSampler
Sampling from the gamma distribution.
-
For
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.
-
For
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 foralpha >= 1)
- Since:
- 1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classClass to sample from the Gamma distribution when0 < alpha < 1.private static classBase class for a sampler from the Gamma distribution.private static final classClass to sample from the Gamma distribution when thealpha >= 1. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SharedStateContinuousSamplerThe appropriate gamma sampler for the parameters. -
Constructor Summary
ConstructorsConstructorDescriptionAhrensDieterMarsagliaTsangGammaSampler(UniformRandomProvider rng, double alpha, double theta) This instance delegates sampling. -
Method Summary
Modifier and TypeMethodDescriptionstatic SharedStateContinuousSamplerof(UniformRandomProvider rng, double alpha, double theta) Creates a new gamma distribution sampler.doublesample()Creates adoublesample.toString()Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.Methods inherited from class SamplerBase
nextDouble, nextInt, nextInt, nextLongMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ContinuousSampler
samples, samples
-
Field Details
-
delegate
The appropriate gamma sampler for the parameters.
-
-
Constructor Details
-
AhrensDieterMarsagliaTsangGammaSampler
public AhrensDieterMarsagliaTsangGammaSampler(UniformRandomProvider rng, double alpha, double theta) This instance delegates sampling. Use the factory methodof(UniformRandomProvider, double, double)to create an optimal sampler.- Parameters:
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).- Throws:
IllegalArgumentException- ifalpha <= 0ortheta <= 0
-
-
Method Details
-
sample
public double sample()Creates adoublesample.- Specified by:
samplein interfaceContinuousSampler- Returns:
- a sample.
-
toString
- Overrides:
toStringin classSamplerBase
-
withUniformRandomProvider
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.- Specified by:
withUniformRandomProviderin interfaceSharedStateSampler<SharedStateContinuousSampler>- Parameters:
rng- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Since:
- 1.3
-
of
public static SharedStateContinuousSampler of(UniformRandomProvider rng, double alpha, double theta) Creates a new gamma distribution sampler.- Parameters:
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).- Returns:
- the sampler
- Throws:
IllegalArgumentException- ifalpha <= 0ortheta <= 0- Since:
- 1.3
-