public class RejectionInversionZipfSampler extends SamplerBase implements SharedStateDiscreteSampler
Sampling uses UniformRandomProvider.nextDouble()
.
Constructor and Description |
---|
RejectionInversionZipfSampler(UniformRandomProvider rng,
int numberOfElements,
double exponent)
This instance delegates sampling.
|
Modifier and Type | Method and Description |
---|---|
static SharedStateDiscreteSampler |
of(UniformRandomProvider rng,
int numberOfElements,
double exponent)
Creates a new Zipf distribution sampler.
|
int |
sample()
Rejection inversion sampling method for a discrete, bounded Zipf
distribution that is based on the method described in
Wolfgang Hörmann and Gerhard Derflinger.
|
String |
toString() |
SharedStateDiscreteSampler |
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, nextLong
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
samples, samples
public RejectionInversionZipfSampler(UniformRandomProvider rng, int numberOfElements, double exponent)
of(UniformRandomProvider, int, double)
to create an optimal sampler.rng
- Generator of uniformly distributed random numbers.numberOfElements
- Number of elements.exponent
- Exponent.IllegalArgumentException
- if numberOfElements <= 0
or exponent < 0
.public int sample()
Wolfgang Hörmann and Gerhard Derflinger. "Rejection-inversion to generate variates from monotone discrete distributions",
ACM Transactions on Modeling and Computer Simulation (TOMACS) 6.3 (1996): 169-184.
sample
in interface DiscreteSampler
public String toString()
toString
in class SamplerBase
public SharedStateDiscreteSampler withUniformRandomProvider(UniformRandomProvider rng)
withUniformRandomProvider
in interface SharedStateSampler<SharedStateDiscreteSampler>
rng
- Generator of uniformly distributed random numbers.public static SharedStateDiscreteSampler of(UniformRandomProvider rng, int numberOfElements, double exponent)
Note when exponent = 0
the Zipf distribution reduces to a
discrete uniform distribution over the interval [1, n]
with n
the number of elements.
rng
- Generator of uniformly distributed random numbers.numberOfElements
- Number of elements.exponent
- Exponent.IllegalArgumentException
- if numberOfElements <= 0
or
exponent < 0
.Copyright © 2016–2022 The Apache Software Foundation. All rights reserved.