Class TSampler.StudentsTSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.TSampler
-
- org.apache.commons.rng.sampling.distribution.TSampler.StudentsTSampler
-
- All Implemented Interfaces:
ContinuousSampler
,SharedStateContinuousSampler
,SharedStateSampler<SharedStateContinuousSampler>
- Enclosing class:
- TSampler
private static final class TSampler.StudentsTSampler extends TSampler
Sample from a t-distribution using Bailey's algorithm.
-
-
Field Summary
Fields Modifier and Type Field Description private double
df
Degrees of freedom.private static double
DOUBLE_MULTIPLIER
The multiplier to convert the least significant 53-bits of along
to a uniformdouble
.private static double
LARGE_DF
Threshold for large degrees of freedom.private java.util.function.DoubleUnaryOperator
powm1
Function to compute pow(x, -2/v) - 1, where v = degrees of freedom.
-
Constructor Summary
Constructors Modifier Constructor Description (package private)
StudentsTSampler(UniformRandomProvider rng, double v)
private
StudentsTSampler(UniformRandomProvider rng, TSampler.StudentsTSampler source)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static double
makeSignedDouble(long bits)
Creates a signed double in the range[-1, 1)
.double
sample()
Creates adouble
sample.TSampler.StudentsTSampler
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.TSampler
nextLong, of, toString
-
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
samples, samples
-
-
-
-
Field Detail
-
LARGE_DF
private static final double LARGE_DF
Threshold for large degrees of freedom.- See Also:
- Constant Field Values
-
DOUBLE_MULTIPLIER
private static final double DOUBLE_MULTIPLIER
The multiplier to convert the least significant 53-bits of along
to a uniformdouble
.- See Also:
- Constant Field Values
-
df
private final double df
Degrees of freedom.
-
powm1
private final java.util.function.DoubleUnaryOperator powm1
Function to compute pow(x, -2/v) - 1, where v = degrees of freedom.
-
-
Constructor Detail
-
StudentsTSampler
StudentsTSampler(UniformRandomProvider rng, double v)
- Parameters:
rng
- Generator of uniformly distributed random numbers.v
- Degrees of freedom.
-
StudentsTSampler
private StudentsTSampler(UniformRandomProvider rng, TSampler.StudentsTSampler source)
- Parameters:
rng
- Generator of uniformly distributed random numbers.source
- Source to copy.
-
-
Method Detail
-
sample
public double sample()
Creates adouble
sample.- Returns:
- a sample.
-
withUniformRandomProvider
public TSampler.StudentsTSampler 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>
- Specified by:
withUniformRandomProvider
in classTSampler
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-
makeSignedDouble
private static double makeSignedDouble(long bits)
Creates a signed double in the range[-1, 1)
. The magnitude is sampled evenly from the 254 dyadic rationals in the range.Note: This method will not return samples for both -0.0 and 0.0.
- Parameters:
bits
- the bits- Returns:
- the double
-
-