Class AhrensDieterMarsagliaTsangGammaSampler.MarsagliaTsangGammaSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.AhrensDieterMarsagliaTsangGammaSampler.BaseGammaSampler
org.apache.commons.rng.sampling.distribution.AhrensDieterMarsagliaTsangGammaSampler.MarsagliaTsangGammaSampler
- All Implemented Interfaces:
ContinuousSampler
,SharedStateContinuousSampler
,SharedStateSampler<SharedStateContinuousSampler>
- Enclosing class:
AhrensDieterMarsagliaTsangGammaSampler
private static class AhrensDieterMarsagliaTsangGammaSampler.MarsagliaTsangGammaSampler
extends AhrensDieterMarsagliaTsangGammaSampler.BaseGammaSampler
Class to sample from the Gamma distribution when the
alpha >= 1
.
Marsaglia and Tsang, A Simple Method for Generating Gamma Variables. ACM Transactions on Mathematical Software, Volume 26 Issue 3, September, 2000.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double
Optimization (see code).private final double
Optimization (see code).private final NormalizedGaussianSampler
Gaussian sampling.private static final double
1/3.Fields inherited from class org.apache.commons.rng.sampling.distribution.AhrensDieterMarsagliaTsangGammaSampler.BaseGammaSampler
alpha, rng, theta
-
Constructor Summary
ConstructorsConstructorDescriptionMarsagliaTsangGammaSampler
(UniformRandomProvider rng, double alpha, double theta) MarsagliaTsangGammaSampler
(UniformRandomProvider rng, AhrensDieterMarsagliaTsangGammaSampler.MarsagliaTsangGammaSampler source) -
Method Summary
Modifier and TypeMethodDescriptiondouble
sample()
Creates adouble
sample.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 org.apache.commons.rng.sampling.distribution.AhrensDieterMarsagliaTsangGammaSampler.BaseGammaSampler
toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.commons.rng.sampling.distribution.ContinuousSampler
samples, samples
-
Field Details
-
ONE_THIRD
private static final double ONE_THIRD1/3.- See Also:
-
dOptim
private final double dOptimOptimization (see code). -
cOptim
private final double cOptimOptimization (see code). -
gaussian
Gaussian sampling.
-
-
Constructor Details
-
MarsagliaTsangGammaSampler
MarsagliaTsangGammaSampler(UniformRandomProvider rng, double alpha, double theta) - Parameters:
rng
- Generator of uniformly distributed random numbers.alpha
- Alpha parameter of the distribution.theta
- Theta parameter of the distribution.- Throws:
IllegalArgumentException
- ifalpha <= 0
ortheta <= 0
-
MarsagliaTsangGammaSampler
MarsagliaTsangGammaSampler(UniformRandomProvider rng, AhrensDieterMarsagliaTsangGammaSampler.MarsagliaTsangGammaSampler source) - Parameters:
rng
- Generator of uniformly distributed random numbers.source
- Source to copy.
-
-
Method Details
-
sample
public double sample()Description copied from interface:ContinuousSampler
Creates adouble
sample.- Returns:
- a sample.
-
withUniformRandomProvider
Description copied from interface:SharedStateSampler
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-