Class ChengBetaSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.SamplerBase
-
- org.apache.commons.rng.sampling.distribution.ChengBetaSampler
-
- All Implemented Interfaces:
ContinuousSampler,SharedStateContinuousSampler,SharedStateSampler<SharedStateContinuousSampler>
public class ChengBetaSampler extends SamplerBase implements SharedStateContinuousSampler
Sampling from a beta distribution.Uses Cheng's algorithms for beta distribution sampling:
R. C. H. Cheng, "Generating beta variates with nonintegral shape parameters", Communications of the ACM, 21, 317-322, 1978.
Sampling uses
UniformRandomProvider.nextDouble().- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classChengBetaSampler.BaseChengBetaSamplerBase class to implement Cheng's algorithms for the beta distribution.private static classChengBetaSampler.ChengBBBetaSamplerComputes one sample using Cheng's BB algorithm, when beta distributionalphaandbetashape parameters are both larger than 1.private static classChengBetaSampler.ChengBCBetaSamplerComputes one sample using Cheng's BC algorithm, when at least one of beta distributionalphaorbetashape parameters is smaller than 1.
-
Field Summary
Fields Modifier and Type Field Description private SharedStateContinuousSamplerdelegateThe appropriate beta sampler for the parameters.private static doubleLN_4Natural logarithm of 4.
-
Constructor Summary
Constructors Modifier Constructor Description privateChengBetaSampler(SharedStateContinuousSampler delegate)ChengBetaSampler(UniformRandomProvider rng, double alpha, double beta)Creates a sampler instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SharedStateContinuousSamplerof(UniformRandomProvider rng, double alpha, double beta)Creates a new beta distribution sampler.doublesample()Creates adoublesample.java.lang.StringtoString()SharedStateContinuousSamplerwithUniformRandomProvider(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.-
Methods inherited from class org.apache.commons.rng.sampling.distribution.SamplerBase
nextDouble, nextInt, nextInt, nextLong
-
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 Detail
-
LN_4
private static final double LN_4
Natural logarithm of 4.
-
delegate
private final SharedStateContinuousSampler delegate
The appropriate beta sampler for the parameters.
-
-
Constructor Detail
-
ChengBetaSampler
public ChengBetaSampler(UniformRandomProvider rng, double alpha, double beta)
Creates a sampler instance.- Parameters:
rng- Generator of uniformly distributed random numbers.alpha- Distribution first shape parameter.beta- Distribution second shape parameter.- Throws:
java.lang.IllegalArgumentException- ifalpha <= 0orbeta <= 0
-
ChengBetaSampler
private ChengBetaSampler(SharedStateContinuousSampler delegate)
- Parameters:
delegate- Beta sampler.
-
-
Method Detail
-
sample
public double sample()
Creates adoublesample.- Specified by:
samplein interfaceContinuousSampler- Returns:
- a sample.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classSamplerBase
-
withUniformRandomProvider
public 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.- 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 beta)
Creates a new beta distribution sampler.- Parameters:
rng- Generator of uniformly distributed random numbers.alpha- Distribution first shape parameter.beta- Distribution second shape parameter.- Returns:
- the sampler
- Throws:
java.lang.IllegalArgumentException- ifalpha <= 0orbeta <= 0- Since:
- 1.3
-
-