Beta { private static double logGammaMinusLogGammaSum(final double a, final double b) throws NumberIsTooSmallException { if (a < 0.0) { throw new NumberIsTooSmallException(a, 0.0, true); } if (b < 10.0) { throw new NumberIsTooSmallException(b, 10.0, true); } final double d; final double w; if (a <= b) { d = b + (a - 0.5); w = deltaMinusDeltaSum(a, b); } else { d = a + (b - 0.5); w = deltaMinusDeltaSum(b, a); } final double u = d * FastMath.log1p(a / b); final double v = a * (FastMath.log(b) - 1.0); return u <= v ? (w - u) - v : (w - v) - u; } private  Beta(); static double regularizedBeta(double x, double a, double b); static double regularizedBeta(double x,
                                         double a, double b,
                                         double epsilon); static double regularizedBeta(double x,
                                         double a, double b,
                                         int maxIterations); static double regularizedBeta(double x,
                                         final double a, final double b,
                                         double epsilon, int maxIterations); @Deprecated static double logBeta(double a, double b,
                                 double epsilon,
                                 int maxIterations); static double logBeta(final double p, final double q);  }
@Test public void testLogGammaMinusLogGammaSum() { final int ulps = 4; for (int i = 0; i < LOG_GAMMA_MINUS_LOG_GAMMA_SUM_REF.length; i++) { final double[] ref = LOG_GAMMA_MINUS_LOG_GAMMA_SUM_REF[i]; final double a = ref[0]; final double b = ref[1]; final double expected = ref[2]; final double actual = logGammaMinusLogGammaSum(a, b); final double tol = ulps * FastMath.ulp(expected); final StringBuilder builder = new StringBuilder(); builder.append(a).append(", ").append(b); Assert.assertEquals(builder.toString(), expected, actual, tol); } }
@Test(expected = NumberIsTooSmallException.class) public void testLogGammaMinusLogGammaSumPrecondition1() { logGammaMinusLogGammaSum(-1.0, 8.0); }
@Test(expected = NumberIsTooSmallException.class) public void testLogGammaMinusLogGammaSumPrecondition2() { logGammaMinusLogGammaSum(1.0, 7.0); }