Class InternalUtils.FactorialLog
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.InternalUtils.FactorialLog
-
- Enclosing class:
- InternalUtils
public static final class InternalUtils.FactorialLog extends java.lang.ObjectClass for computing the natural logarithm of the factorial ofn. It allows to allocate a cache of precomputed values. In case of cache miss, computation is performed by a call toInternalGamma.logGamma(double).
-
-
Field Summary
Fields Modifier and Type Field Description private double[]logFactorialsPrecomputed values of the function:LOG_FACTORIALS[i] = log(i!).
-
Constructor Summary
Constructors Modifier Constructor Description privateFactorialLog(int numValues, double[] cache)Creates an instance, reusing the already computed values if available.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static InternalUtils.FactorialLogcreate()Creates an instance with no precomputed values.doublevalue(int n)Computeslog(n!).InternalUtils.FactorialLogwithCache(int cacheSize)Creates an instance with the specified cache size.
-
-
-
Constructor Detail
-
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:
java.lang.NegativeArraySizeException- ifnumValues < 0.
-
-
Method Detail
-
create
public static InternalUtils.FactorialLog create()
Creates an instance with no precomputed values.- Returns:
- an instance with no precomputed values.
-
withCache
public InternalUtils.FactorialLog withCache(int cacheSize)
Creates an instance with the specified cache size.- Parameters:
cacheSize- Number of precomputed values of the function.- Returns:
- a new instance where
cacheSizevalues have been precomputed. - Throws:
java.lang.IllegalArgumentException- ifn < 0.
-
value
public double value(int n)
Computeslog(n!).- Parameters:
n- Argument.- Returns:
log(n!).- Throws:
java.lang.IndexOutOfBoundsException- ifnumValues < 0.
-
-