Class InternalUtils
java.lang.Object
org.apache.commons.rng.sampling.distribution.InternalUtils
Functions used by some of the samplers.
This class is not part of the public API, as it would be
better to group these utilities in a dedicated component.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Class for computing the natural logarithm of the factorial ofn
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
The first array index with a non-zero log factorial.private static final double
The multiplier to convert the least significant 53-bits of along
to adouble
.private static final long[]
All long-representable factorials. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static long
factorial
(int n) (package private) static double
makeNonZeroDouble
(long v) Creates adouble
in the interval(0, 1]
from along
value.(package private) static NormalizedGaussianSampler
Create a new instance of the given sampler usingSharedStateSampler.withUniformRandomProvider(UniformRandomProvider)
.(package private) static double
validateProbabilities
(double[] probabilities) Validate the probabilities sum to a finite positive number.(package private) static void
validateProbability
(double probability) Validate the probability is a finite positive number.
-
Field Details
-
FACTORIALS
private static final long[] FACTORIALSAll long-representable factorials. -
BEGIN_LOG_FACTORIALS
private static final int BEGIN_LOG_FACTORIALSThe first array index with a non-zero log factorial.- See Also:
-
DOUBLE_MULTIPLIER
private static final double DOUBLE_MULTIPLIERThe multiplier to convert the least significant 53-bits of along
to adouble
. Taken from org.apache.commons.rng.core.util.NumberFactory.- See Also:
-
-
Constructor Details
-
InternalUtils
private InternalUtils()Utility class.
-
-
Method Details
-
factorial
static long factorial(int n) - Parameters:
n
- Argument.- Returns:
n!
- Throws:
IndexOutOfBoundsException
- if the result is too large to be represented by along
(i.e. ifn > 20
), orn
is negative.
-
validateProbabilities
static double validateProbabilities(double[] probabilities) Validate the probabilities sum to a finite positive number.- Parameters:
probabilities
- the probabilities- Returns:
- the sum
- Throws:
IllegalArgumentException
- ifprobabilities
is null or empty, a probability is negative, infinite orNaN
, or the sum of all probabilities is not strictly positive.
-
validateProbability
static void validateProbability(double probability) Validate the probability is a finite positive number.- Parameters:
probability
- Probability.- Throws:
IllegalArgumentException
- ifprobability
is negative, infinite orNaN
.
-
newNormalizedGaussianSampler
static NormalizedGaussianSampler newNormalizedGaussianSampler(NormalizedGaussianSampler sampler, UniformRandomProvider rng) Create a new instance of the given sampler usingSharedStateSampler.withUniformRandomProvider(UniformRandomProvider)
.- Parameters:
sampler
- Source sampler.rng
- Generator of uniformly distributed random numbers.- Returns:
- the new sampler
- Throws:
UnsupportedOperationException
- if the underlying sampler is not aSharedStateSampler
or does not return aNormalizedGaussianSampler
when sharing state.
-
makeNonZeroDouble
static double makeNonZeroDouble(long v) Creates adouble
in the interval(0, 1]
from along
value.- Parameters:
v
- Number.- Returns:
- a
double
value in the interval(0, 1]
.
-