Class TSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.TSampler
-
- All Implemented Interfaces:
ContinuousSampler,SharedStateContinuousSampler,SharedStateSampler<SharedStateContinuousSampler>
- Direct Known Subclasses:
TSampler.NormalTSampler,TSampler.StudentsTSampler
public abstract class TSampler extends java.lang.Object implements SharedStateContinuousSampler
Sampling from a T distribution.Uses Bailey's algorithm for t-distribution sampling:
Bailey, R. W. (1994) "Polar Generation of Random Variates with the t-Distribution." Mathematics of Computation 62, 779-781.
Sampling uses
UniformRandomProvider.nextLong().- Since:
- 1.5
- See Also:
- Student's T distribution (wikipedia), Mathematics of Computation, 62, 779-781
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classTSampler.NormalTSamplerSample from a t-distribution using a normal distribution.private static classTSampler.StudentsTSamplerSample from a t-distribution using Bailey's algorithm.
-
Field Summary
Fields Modifier and Type Field Description private static doubleHUGE_DFThreshold for huge degrees of freedom.private UniformRandomProviderrngSource of randomness.
-
Constructor Summary
Constructors Constructor Description TSampler(UniformRandomProvider rng)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) longnextLong()Generates alongvalue.static TSamplerof(UniformRandomProvider rng, double degreesOfFreedom)Create a new t distribution sampler.java.lang.StringtoString()abstract TSamplerwithUniformRandomProvider(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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.rng.sampling.distribution.ContinuousSampler
sample, samples, samples
-
-
-
-
Field Detail
-
HUGE_DF
private static final double HUGE_DF
Threshold for huge degrees of freedom. Above this value the CDF of the t distribution matches the normal distribution. Value is 2/eps (where eps is the machine epsilon) or approximately 9.0e15.- See Also:
- Constant Field Values
-
rng
private final UniformRandomProvider rng
Source of randomness.
-
-
Constructor Detail
-
TSampler
TSampler(UniformRandomProvider rng)
- Parameters:
rng- Generator of uniformly distributed random numbers.
-
-
Method Detail
-
withUniformRandomProvider
public abstract TSampler 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
-
nextLong
long nextLong()
Generates alongvalue. Used by algorithm implementations without exposing access to the RNG.- Returns:
- the next random value
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
of
public static TSampler of(UniformRandomProvider rng, double degreesOfFreedom)
Create a new t distribution sampler.- Parameters:
rng- Generator of uniformly distributed random numbers.degreesOfFreedom- Degrees of freedom.- Returns:
- the sampler
- Throws:
java.lang.IllegalArgumentException- ifdegreesOfFreedom <= 0
-
-