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
Sample from a t-distribution using Bailey's algorithm.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double
Degrees of freedom.private static final double
The multiplier to convert the least significant 53-bits of along
to a uniformdouble
.private static final double
Threshold for large degrees of freedom.private final DoubleUnaryOperator
Function to compute pow(x, -2/v) - 1, where v = degrees of freedom. -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
StudentsTSampler
(UniformRandomProvider rng, double v) private
-
Method Summary
Modifier and TypeMethodDescriptionprivate static double
makeSignedDouble
(long bits) Creates a signed double in the range[-1, 1)
.double
sample()
Creates adouble
sample.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 Details
-
LARGE_DF
private static final double LARGE_DFThreshold for large degrees of freedom.- See Also:
-
DOUBLE_MULTIPLIER
private static final double DOUBLE_MULTIPLIERThe multiplier to convert the least significant 53-bits of along
to a uniformdouble
.- See Also:
-
df
private final double dfDegrees of freedom. -
powm1
Function to compute pow(x, -2/v) - 1, where v = degrees of freedom.
-
-
Constructor Details
-
StudentsTSampler
StudentsTSampler(UniformRandomProvider rng, double v) - Parameters:
rng
- Generator of uniformly distributed random numbers.v
- Degrees of freedom.
-
StudentsTSampler
- Parameters:
rng
- Generator of uniformly distributed random numbers.source
- Source to copy.
-
-
Method Details
-
sample
public double sample()Creates adouble
sample.- Returns:
- a sample.
-
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:
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
-