Class InternalUtils.FactorialLog

java.lang.Object
org.apache.commons.rng.sampling.distribution.InternalUtils.FactorialLog
Enclosing class:
InternalUtils

public static final class InternalUtils.FactorialLog extends Object
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 Details

    • logFactorials

      private final double[] logFactorials
      Precomputed 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 - if numValues < 0.
  • Method Details

    • 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 cacheSize values have been precomputed.
      Throws:
      IllegalArgumentException - if n < 0.
    • value

      public double value(int n)
      Computes log(n!).
      Parameters:
      n - Argument.
      Returns:
      log(n!).
      Throws:
      IndexOutOfBoundsException - if numValues < 0.