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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classImplements the rejection-inversion method for the Zipf distribution. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SharedStateDiscreteSamplerThe implementation of the sample method. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor used by to prevent partially initialized object if the construction of the delegate throws.RejectionInversionZipfSampler(UniformRandomProvider rng, int numberOfElements, double exponent) This instance delegates sampling. -
Method Summary
Modifier and TypeMethodDescriptionstatic SharedStateDiscreteSamplerof(UniformRandomProvider rng, int numberOfElements, double exponent) Creates a new Zipf distribution sampler.intsample()Rejection inversion sampling method for a discrete, bounded Zipf distribution that is based on the method described in Wolfgang Hörmann and Gerhard Derflinger.toString()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, nextLongMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.rng.sampling.distribution.DiscreteSampler
samples, samples
-
Field Details
-
delegate
The implementation of the sample method.
-
-
Constructor Details
-
RejectionInversionZipfSampler
public RejectionInversionZipfSampler(UniformRandomProvider rng, int numberOfElements, double exponent) This instance delegates sampling. Use the factory methodof(UniformRandomProvider, int, double)to create an optimal sampler.- Parameters:
rng- Generator of uniformly distributed random numbers.numberOfElements- Number of elements.exponent- Exponent.- Throws:
IllegalArgumentException- ifnumberOfElements <= 0orexponent < 0.
-
-
Method Details
-
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:
samplein interfaceDiscreteSampler- Returns:
- a sample.
-
toString
- Overrides:
toStringin classSamplerBase
-
withUniformRandomProvider
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<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.Note when
exponent = 0the Zipf distribution reduces to a discrete uniform distribution over the interval[1, n]withnthe number of elements.- Parameters:
rng- Generator of uniformly distributed random numbers.numberOfElements- Number of elements.exponent- Exponent.- Returns:
- the sampler
- Throws:
IllegalArgumentException- ifnumberOfElements <= 0orexponent < 0.- Since:
- 1.3
-