@@ -0,0 +1,1834 @@
+package cc.mrlda.util;%0A%0Apublic class Approximation %7B%0A%0A  /**%0A   * Approximate digamma of x.%0A   * %0A   * @param x%0A   * @return%0A   */%0A  public static double digamma(double x) %7B%0A    double r = 0.0;%0A%0A    while (x %3C= 5) %7B%0A      r -= 1 / x;%0A      x += 1;%0A    %7D%0A%0A    double f = 1.0 / (x * x);%0A    double t = f%0A        * (-1.0 / 12.0 + f%0A            * (1.0 / 120.0 + f%0A                * (-1.0 / 252.0 + f%0A                    * (1.0 / 240.0 + f%0A                        * (-1.0 / 132.0 + f%0A                            * (691.0 / 32760.0 + f * (-1.0 / 12.0 + f * 3617.0 / 8160.0)))))));%0A    return r + Math.log(x) - 0.5 / x + t;%0A  %7D%0A%0A  /**%0A   * Approximate the trigamma of x.%0A   * %0A   * @param x%0A   * @return%0A   */%0A  public static double trigamma(double x) %7B%0A    double p;%0A    int i;%0A%0A    x = x + 6;%0A    p = 1 / (x * x);%0A    p = (((((0.075757575757576 * p - 0.033333333333333) * p + 0.0238095238095238) * p - 0.033333333333333)%0A        * p + 0.166666666666667)%0A        * p + 1)%0A        / x + 0.5 * p;%0A    for (i = 0; i %3C 6; i++) %7B%0A      x = x - 1;%0A      p = 1 / (x * x) + p;%0A    %7D%0A%0A    if (new Double(p).equals(Double.NaN)) %7B%0A      throw new ArithmeticException(%22invalid input at trigamma function: %22 + x);%0A    %7D%0A%0A    return p;%0A  %7D%0A%0A  /**%0A   * Approximate the lngamma of x.%0A   * %0A   * @param x%0A   * @return%0A   */%0A  public static double lnGamma(double x) %7B%0A    double z = 1 / (x * x);%0A%0A    x = x + 6;%0A    z = (((-0.000595238095238 * z + 0.000793650793651) * z - 0.002777777777778) * z + 0.083333333333333)%0A        / x;%0A    z = (x - 0.5) * Math.log(x) - x + 0.918938533204673 + z - Math.log(x - 1) - Math.log(x - 2)%0A        - Math.log(x - 3) - Math.log(x - 4) - Math.log(x - 5) - Math.log(x - 6);%0A%0A    if (new Double(z).equals(Double.NaN)) %7B%0A      throw new ArithmeticException(%22invalid input at lnGamma function: %22 + x);%0A    %7D%0A%0A    return z;%0A  %7D%0A%7D%0A

add in Approximation.java