Beta { private static double logGammaSum(final double a, final double b) throws OutOfRangeException { if ((a < 1.0) || (a > 2.0)) { throw new OutOfRangeException(a, 1.0, 2.0); } if ((b < 1.0) || (b > 2.0)) { throw new OutOfRangeException(b, 1.0, 2.0); } final double x = (a - 1.0) + (b - 1.0); if (x <= 0.5) { return Gamma.logGamma1p(1.0 + x); } else if (x <= 1.5) { return Gamma.logGamma1p(x) + FastMath.log1p(x); } else { return Gamma.logGamma1p(x - 1.0) + FastMath.log(x * (1.0 + x)); } } 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 testLogGammaSum() { final int ulps = 2; for (int i = 0; i < LOG_GAMMA_SUM_REF.length; i++) { final double[] ref = LOG_GAMMA_SUM_REF[i]; final double a = ref[0]; final double b = ref[1]; final double expected = ref[2]; final double actual = logGammaSum(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 = OutOfRangeException.class) public void testLogGammaSumPrecondition1() { logGammaSum(0.0, 1.0); }
@Test(expected = OutOfRangeException.class) public void testLogGammaSumPrecondition2() { logGammaSum(3.0, 1.0); }
@Test(expected = OutOfRangeException.class) public void testLogGammaSumPrecondition3() { logGammaSum(1.0, 0.0); }
@Test(expected = OutOfRangeException.class) public void testLogGammaSumPrecondition4() { logGammaSum(1.0, 3.0); }