Class RejectionInversionZipfSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.SamplerBase
-
- org.apache.commons.rng.sampling.distribution.RejectionInversionZipfSampler
-
- All Implemented Interfaces:
DiscreteSampler
,SharedStateDiscreteSampler
,SharedStateSampler<SharedStateDiscreteSampler>
public class RejectionInversionZipfSampler extends SamplerBase implements SharedStateDiscreteSampler
Implementation of the Zipf distribution.Sampling uses
UniformRandomProvider.nextDouble()
.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description RejectionInversionZipfSampler(UniformRandomProvider rng, int numberOfElements, double exponent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class org.apache.commons.rng.sampling.distribution.SamplerBase
nextDouble, nextInt, nextInt, nextLong
-
-
-
-
Constructor Detail
-
RejectionInversionZipfSampler
public RejectionInversionZipfSampler(UniformRandomProvider rng, int numberOfElements, double exponent)
- Parameters:
rng
- Generator of uniformly distributed random numbers.numberOfElements
- Number of elements.exponent
- Exponent.- Throws:
IllegalArgumentException
- ifnumberOfElements <= 0
orexponent <= 0
.
-
-
Method Detail
-
sample
public int sample()
Rejection inversion sampling method for a discrete, bounded Zipf distribution that is based on the method described inWolfgang 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.- Specified by:
sample
in interfaceDiscreteSampler
- Returns:
- a sample.
-
toString
public String toString()
- Overrides:
toString
in classSamplerBase
-
withUniformRandomProvider
public 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.- Specified by:
withUniformRandomProvider
in interfaceSharedStateSampler<SharedStateDiscreteSampler>
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Since:
- 1.3
-
of
public static SharedStateDiscreteSampler of(UniformRandomProvider rng, int numberOfElements, double exponent)
Creates a new Zipf distribution sampler.- Parameters:
rng
- Generator of uniformly distributed random numbers.numberOfElements
- Number of elements.exponent
- Exponent.- Returns:
- the sampler
- Throws:
IllegalArgumentException
- ifnumberOfElements <= 0
orexponent <= 0
.- Since:
- 1.3
-
-