Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
  /** 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);
  }
Exemplo n.º 3
0
    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);
    }