MathUtilities { public static double erf(double x) { if (x < 0) return -incompleteGammaP(0.5, x * x); else return incompleteGammaP(0.5, x * 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; }
@Test public void testErf() { myAssertEpsilonEquals(erf(0), 0); myAssertEpsilonEquals(erfc(0), 1); myAssertEpsilonEquals(erf(1e20), 1); myAssertEpsilonEquals(erfc(1e20), 0); for (double x : new double[] {0.001, 0.01, 0.1, 1, 10}) { myAssertEpsilonEquals(erf(-x), -erf(x)); myAssertEpsilonEquals(erfc(-x), 2 - erfc(x)); } myAssertEpsilonEquals(erf(0.1), 0.1124629); myAssertEpsilonEquals(erf(0.75), 0.7111556); myAssertEpsilonEquals(erfc(0.5), 0.4795001); myAssertEpsilonEquals(erfc(0.3), 0.6713732); }