Class InternalUtils.FactorialLog
java.lang.Object
org.apache.commons.rng.sampling.distribution.InternalUtils.FactorialLog
- Enclosing class:
InternalUtils
Class for computing the natural logarithm of the factorial of
n
.
It allows to allocate a cache of precomputed values.
In case of cache miss, computation is performed by a call to
InternalGamma.logGamma(double)
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double[]
Precomputed values of the function:LOG_FACTORIALS[i] = log(i!)
. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
FactorialLog
(int numValues, double[] cache) Creates an instance, reusing the already computed values if available. -
Method Summary
Modifier and TypeMethodDescriptionstatic InternalUtils.FactorialLog
create()
Creates an instance with no precomputed values.double
value
(int n) Computeslog(n!)
.withCache
(int cacheSize) Creates an instance with the specified cache size.
-
Field Details
-
logFactorials
private final double[] logFactorialsPrecomputed values of the function:LOG_FACTORIALS[i] = log(i!)
.
-
-
Constructor Details
-
FactorialLog
private FactorialLog(int numValues, double[] cache) Creates an instance, reusing the already computed values if available.- Parameters:
numValues
- Number of values of the function to compute.cache
- Existing cache.- Throws:
NegativeArraySizeException
- ifnumValues < 0
.
-
-
Method Details
-
create
Creates an instance with no precomputed values.- Returns:
- an instance with no precomputed values.
-
withCache
Creates an instance with the specified cache size.- Parameters:
cacheSize
- Number of precomputed values of the function.- Returns:
- a new instance where
cacheSize
values have been precomputed. - Throws:
IllegalArgumentException
- ifn < 0
.
-
value
public double value(int n) Computeslog(n!)
.- Parameters:
n
- Argument.- Returns:
log(n!)
.- Throws:
IndexOutOfBoundsException
- ifnumValues < 0
.
-