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
-
-
Constructor Summary
Constructors Constructor Description 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 SharedStateContinuousSampler
of(UniformRandomProvider rng, double alpha, double beta)
Creates a new beta distribution sampler.double
sample()
Creates a 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.-
Methods inherited from class org.apache.commons.rng.sampling.distribution.SamplerBase
nextDouble, nextInt, nextInt, nextLong
-
-
-
-
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:
IllegalArgumentException
- ifalpha <= 0
orbeta <= 0
-
-
Method Detail
-
sample
public double sample()
Creates a sample.- Specified by:
sample
in interfaceContinuousSampler
- Returns:
- a sample.
-
toString
public String toString()
- Overrides:
toString
in 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:
withUniformRandomProvider
in 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:
IllegalArgumentException
- ifalpha <= 0
orbeta <= 0
- Since:
- 1.3
-
-