public double evaluate(double gam) { if (gam <= 0) return 1.0e100; double sum = 0.0; for (int j = 0; j < m; j++) sum += Num.digamma(gam + x[j]); return sum / m + Math.log(p) - Num.digamma(gam); }
/** Computes the probability <SPAN CLASS="MATH"><I>p</I>(<I>x</I>)</SPAN>. */ public static double prob(double n, double p, int x) { final int SLIM = 15; // To avoid overflow final double MAXEXP = (Num.DBL_MAX_EXP - 1) * Num.LN2; // To avoid overflow final double MINEXP = (Num.DBL_MIN_EXP - 1) * Num.LN2; // To avoid underflow double y; if (p < 0.0 || p > 1.0) throw new IllegalArgumentException("p not in [0, 1]"); if (n <= 0.0) throw new IllegalArgumentException("n <= 0.0"); if (x < 0) return 0.0; if (p >= 1.0) { // In fact, p == 1 if (x == 0) return 1.0; else return 0.0; } if (p <= 0.0) // In fact, p == 0 return 0.0; y = Num.lnGamma(n + x) - (Num.lnFactorial(x) + Num.lnGamma(n)) + n * Math.log(p) + x * Math.log1p(-p); if (y >= MAXEXP) throw new IllegalArgumentException("term overflow"); return Math.exp(y); }
/** Computes the inverse distribution function @f$F^{-1}(u)@f$. */ public static double inverseF(double alpha, double lambda, double u) { if (lambda <= 0) throw new IllegalArgumentException("lambda <= 0"); if (u < 0.0 || u > 1.0) throw new IllegalArgumentException("u not in [0, 1]"); if (u >= 1.0) return Double.POSITIVE_INFINITY; if (u <= 0.0) return Double.NEGATIVE_INFINITY; return Math.log(u / (1.0 - u)) / lambda + alpha; }
public double evaluate(double s) { if (s <= 0) return 1.0e100; double sum = 0.0; double p = s / (s + mean); for (int j = 0; j < max; j++) sum += Fj[j] / (s + (double) j); return sum + m * Math.log(p); }