@Test public void testLogFactorial() { myAssertEpsilonEquals(lnFactorial(6), Math.log(720)); myAssertEpsilonEquals(lnFactorial(3), Math.log(6)); myAssertEpsilonEquals(lnFactorial(1), 0); }
public static double lnFactorial(int x) { if (x < 0) throw new IllegalArgumentException("Invalid input to factorial: " + x); else if (x > 32) return lnGamma(x + 1); else { int l = factorialsBuffer.size(); for (int i = l; i <= x; i++) { factorialsBuffer.add(log(i) + factorialsBuffer.get(i - 1)); } return factorialsBuffer.get(x); } }
MathUtilities { public static double lnFactorial(int x) { if (x < 0) throw new IllegalArgumentException("Invalid input to factorial: " + x); else if (x > 32) return lnGamma(x + 1); else { int l = factorialsBuffer.size(); for (int i = l; i <= x; i++) { factorialsBuffer.add(log(i) + factorialsBuffer.get(i - 1)); } return factorialsBuffer.get(x); } } }
MathUtilities { public static double lnFactorial(int x) { if (x < 0) throw new IllegalArgumentException("Invalid input to factorial: " + x); else if (x > 32) return lnGamma(x + 1); else { int l = factorialsBuffer.size(); for (int i = l; i <= x; i++) { factorialsBuffer.add(log(i) + factorialsBuffer.get(i - 1)); } return factorialsBuffer.get(x); } }  }
MathUtilities { public static double lnFactorial(int x) { if (x < 0) throw new IllegalArgumentException("Invalid input to factorial: " + x); else if (x > 32) return lnGamma(x + 1); else { int l = factorialsBuffer.size(); for (int i = l; i <= x; i++) { factorialsBuffer.add(log(i) + factorialsBuffer.get(i - 1)); } return factorialsBuffer.get(x); } }  static Pair<Integer, Double> max(double[] array); static Pair<Integer, Integer> max(int[] array); static Pair<Integer, T> max(Collection<T> list); static Pair<Integer, T> max(T[] array); static Pair<T, S> max(Map<T, S> map); static Pair<Integer, Double> min(double[] array); static Pair<Integer, Integer> min(int[] array); static Pair<Integer, T> min(Collection<T> list); static Pair<T, S> min(Map<T, S> map); static Pair<Integer, T> min(T[] array); static List<Double> multiply(List<Double> l, double m); static List<Double> multiply(List<Double> d1, List<Double> d2); static double[] multiply(double[] d1, double[] d2); static double[] multiply(double[] d, double m); static double[] softmax(double[] input); static double[] softmax(double[] input, double[] multiplier); static List<Double> softmax(List<Double> input); static List<Double> softmax(List<Double> input, List<Double> multiplier); static boolean epsilonEquals(double d1, double d2); static double logAdd(double x1, double x2); static double logAdd(double[] doubles); static double logAdd(Collection<Double> doubles); static double lnGamma(double xx); static double lnFactorial(int x); static int binomialCoeffs(int n, int k); static double beta(double x, double w); static double incompleteGammaP(double a, double x); static double incompleteGammaQ(double a, double x); static double erf(double x); static double erfc(double x); }
MathUtilities { public static double lnFactorial(int x) { if (x < 0) throw new IllegalArgumentException("Invalid input to factorial: " + x); else if (x > 32) return lnGamma(x + 1); else { int l = factorialsBuffer.size(); for (int i = l; i <= x; i++) { factorialsBuffer.add(log(i) + factorialsBuffer.get(i - 1)); } return factorialsBuffer.get(x); } }  static Pair<Integer, Double> max(double[] array); static Pair<Integer, Integer> max(int[] array); static Pair<Integer, T> max(Collection<T> list); static Pair<Integer, T> max(T[] array); static Pair<T, S> max(Map<T, S> map); static Pair<Integer, Double> min(double[] array); static Pair<Integer, Integer> min(int[] array); static Pair<Integer, T> min(Collection<T> list); static Pair<T, S> min(Map<T, S> map); static Pair<Integer, T> min(T[] array); static List<Double> multiply(List<Double> l, double m); static List<Double> multiply(List<Double> d1, List<Double> d2); static double[] multiply(double[] d1, double[] d2); static double[] multiply(double[] d, double m); static double[] softmax(double[] input); static double[] softmax(double[] input, double[] multiplier); static List<Double> softmax(List<Double> input); static List<Double> softmax(List<Double> input, List<Double> multiplier); static boolean epsilonEquals(double d1, double d2); static double logAdd(double x1, double x2); static double logAdd(double[] doubles); static double logAdd(Collection<Double> doubles); static double lnGamma(double xx); static double lnFactorial(int x); static int binomialCoeffs(int n, int k); static double beta(double x, double w); static double incompleteGammaP(double a, double x); static double incompleteGammaQ(double a, double x); static double erf(double x); static double erfc(double x); final static double EPSILON; }