当前位置: 首页>>代码示例>>Java>>正文


Java DoubleVector.isNaN方法代码示例

本文整理汇总了Java中org.renjin.sexp.DoubleVector.isNaN方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleVector.isNaN方法的具体用法?Java DoubleVector.isNaN怎么用?Java DoubleVector.isNaN使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.renjin.sexp.DoubleVector的用法示例。


在下文中一共展示了DoubleVector.isNaN方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: psigamma

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double psigamma(double x, double deriv) {
  /* n-th derivative of psi(x);  e.g., psigamma(x,0) == digamma(x) */
  int k, n;

  if (DoubleVector.isNaN(x)) {
    return x;
  }
  deriv = Math.floor(deriv + 0.5);
  n = (int) deriv;
  //if(n > n_max) {
  //MATHLIB_WARNING2(_("deriv = %d > %d (= n_max)\n"), n, n_max);
  //return ML_NAN;
  //}
  double[] ans = new double[1];
  double[] xd = new double[]{x};
  int[] nz = new int[1];
  int[] ierr = new int[1];
  dpsifn.dpsifn(x, n, 1, 1, ans, nz, ierr);
  //ML_TREAT_psigam(ierr);
  /* Now, ans ==  A := (-1)^(n+1) / gamma(n+1) * psi(n, x) */
  ans[0] = -ans[0]; /* = (-1)^(0+1) * gamma(0+1) * A */
  for (k = 1; k <= n; k++) {
    ans[0] *= (-k);/* = (-1)^(k+1) * gamma(k+1) * A */
  }
  return ans[0];/* = psi(n, x) */
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:27,代码来源:PsiGamma.java

示例2: pnbeta

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double pnbeta(double x, double a, double b, double ncp, boolean lower_tail, boolean log_p) {

    if (DoubleVector.isNaN(x) || DoubleVector.isNaN(a) || DoubleVector.isNaN(b) || DoubleVector.isNaN(ncp)) {
      return x + a + b + ncp;
    }


    //R_P_bounds_01(x, 0., 1.);
    if (x <= 0.0) {
      return SignRank.R_DT_0(lower_tail, log_p);
    }
    if (x >= 1.0) {
      return SignRank.R_DT_1(lower_tail, log_p);
    }

    return pnbeta2(x, 1 - x, a, b, ncp, lower_tail, log_p);
  }
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:18,代码来源:Beta.java

示例3: dlnorm

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double dlnorm(double x, double meanlog, double sdlog, boolean give_log) {
  double y;


  if (DoubleVector.isNaN(x) || DoubleVector.isNaN(meanlog) || DoubleVector.isNaN(sdlog)) {
    return x + meanlog + sdlog;
  }

  if (sdlog <= 0) {
    return DoubleVector.NaN;
  }

  //if(x <= 0) return R_D__0;
  if (x <= 0) {
    return SignRank.R_D__0(true, give_log);
  }

  y = (Math.log(x) - meanlog) / sdlog;
  return (give_log ? -(Math.log(Math.sqrt(2 * Math.PI)) + 0.5 * y * y + Math.log(x * sdlog))
          : (1 / Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * y * y) / (x * sdlog));
  /* M_1_SQRT_2PI = 1 / sqrt(2 * pi) */

}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:24,代码来源:LNorm.java

示例4: pnf

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double pnf(double x, double df1, double df2, double ncp, boolean lower_tail, boolean log_p) {
  double y;
  if (DoubleVector.isNaN(x) || DoubleVector.isNaN(df1) || DoubleVector.isNaN(df2) || DoubleVector.isNaN(ncp)) {
    return x + df2 + df1 + ncp;
  }
  if (df1 <= 0. || df2 <= 0. || ncp < 0) {
    return DoubleVector.NaN;
  }
  if (!DoubleVector.isFinite(ncp)) {
    return DoubleVector.NaN;
  }
  if (!DoubleVector.isFinite(df1) && !DoubleVector.isFinite(df2)) { /* both +Inf */
    return DoubleVector.NaN;
  }

  //R_P_bounds_01(x, 0., ML_POSINF);
  if (x <= 0.0) {
    return SignRank.R_DT_0(lower_tail, log_p);
  }
  if (x >= Double.POSITIVE_INFINITY) {
    return SignRank.R_DT_1(lower_tail, log_p);
  }

  if (df2 > 1e8) /* avoid problems with +Inf and loss of accuracy */ {
    return Distributions.pnchisq(x * df1, df1, ncp, lower_tail, log_p);
  }

  y = (df1 / df2) * x;
  return Beta.pnbeta2(y / (1. + y), 1. / (1. + y), df1 / 2., df2 / 2.,
          ncp, lower_tail, log_p);
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:32,代码来源:F.java

示例5: qnf

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double qnf(double p, double df1, double df2, double ncp, boolean lower_tail, boolean log_p) {
  double y;

  if (DoubleVector.isNaN(p) || DoubleVector.isNaN(df1) || DoubleVector.isNaN(df2) || DoubleVector.isNaN(ncp)) {
    return p + df1 + df2 + ncp;
  }

  if (df1 <= 0. || df2 <= 0. || ncp < 0) {
    return DoubleVector.NaN;
  }
  if (!DoubleVector.isFinite(ncp)) {
    return DoubleVector.NaN;
  }
  if (!DoubleVector.isFinite(df1) && !DoubleVector.isFinite(df2)) {
    return DoubleVector.NaN;
  }

  //R_Q_P01_boundaries(p, 0, ML_POSINF);
  if ((log_p && p > 0) || (!log_p && (p < 0 || p > 1))) {
    return DoubleVector.NaN;
  }
  if (p == SignRank.R_DT_0(lower_tail, log_p)) {
    return 0;
  }
  if (p == SignRank.R_DT_1(lower_tail, log_p)) {
    return Double.POSITIVE_INFINITY;
  }
  //end of R_Q_P01_boundaries

  if (df2 > 1e8) /* avoid problems with +Inf and loss of accuracy */ {
    return Distributions.qnchisq(p, df1, ncp, lower_tail, log_p) / df1;
  }

  y = Beta.qnbeta(p, df1 / 2., df2 / 2., ncp, lower_tail, log_p);
  return y / (1 - y) * (df2 / df1);
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:37,代码来源:F.java

示例6: pnchisq

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double pnchisq(double x, double df, double ncp, boolean lower_tail, boolean log_p) {
  double ans;

  if (DoubleVector.isNaN(x) || DoubleVector.isNaN(df) || DoubleVector.isNaN(ncp)) {
    return x + df + ncp;
  }

  if (!DoubleVector.isFinite(df) || !DoubleVector.isFinite(ncp)) {
    return DoubleVector.NaN;
  }

  if (df < 0. || ncp < 0.) {
    return DoubleVector.NaN;
  }

  ans = pnchisq_raw(x, df, ncp, 1e-12, 8 * SignRank.DBL_EPSILON, 1000000, lower_tail);
  if (ncp >= 80) {
    if (lower_tail) {
      ans = Math.min(ans, 1.0);  /* e.g., pchisq(555, 1.01, ncp = 80) */
    } else { /* !lower_tail */
      /* since we computed the other tail cancellation is likely */
      if (ans < 1e-10) {
        /*
         * Is there any function for ML_ERROR?????
         */
        //ML_ERROR(ME_PRECISION, "pnchisq");
      }
      ans = Math.max(ans, 0.0);  /* Precaution PR#7099 */
    }
  }
  if (!log_p) {
    return ans;
  }
  /* if ans is near one, we can do better using the other tail */
  if (ncp >= 80 || ans < 1 - 1e-8) {
    return Math.log(ans);
  }
  ans = pnchisq_raw(x, df, ncp, 1e-12, 8 * SignRank.DBL_EPSILON, 1000000, !lower_tail);
  return Math.log1p(-ans);
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:41,代码来源:ChiSquare.java

示例7: pgeom

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double pgeom(double x, double p, boolean lower_tail, boolean log_p) {

    if (DoubleVector.isNaN(x) || DoubleVector.isNaN(p)) {
      return x + p;
    }

    if (p <= 0 || p > 1) {
      return DoubleVector.NaN;
    }

    if (x < 0.) {
      return SignRank.R_DT_0(lower_tail, log_p);
    }

    if (!DoubleVector.isFinite(x)) {
      return SignRank.R_DT_1(lower_tail, log_p);
    }

    x = Math.floor(x + 1e-7);

    if (p == 1.) { /* we cannot assume IEEE */
      x = lower_tail ? 1 : 0;
      return log_p ? Math.log(x) : x;
    }
    x = Math.log1p(-p) * (x + 1);
    if (log_p) {
      return SignRank.R_DT_Clog(x, lower_tail, log_p);
    } else {
      return lower_tail ? -Math.expm1(x) : Math.exp(x);
    }
  }
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:32,代码来源:Geometric.java

示例8: dgeom

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double dgeom(double x, double p, boolean give_log) {
  double prob;


  if (DoubleVector.isNaN(x) || DoubleVector.isNaN(p)) {
    return x + p;
  }


  if (p <= 0 || p > 1) {
    return DoubleVector.NaN;
  }

  if (SignRank.R_D_nonint(x, true, give_log)) {
    return SignRank.R_D__0(true, give_log);
  }

  if (x < 0 || !DoubleVector.isFinite(x) || p == 0) {
    return SignRank.R_D__0(true, give_log);
  }
  x = SignRank.R_D_forceint(x);

  /* prob = (1-p)^x, stable for small p */
  prob = Binom.dbinom_raw(0., x, p, 1 - p, give_log);

  return ((give_log) ? Math.log(p) + prob : p * prob);
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:28,代码来源:Geometric.java

示例9: qgeom

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double qgeom(double p, double prob, boolean lower_tail, boolean log_p) {
  if (prob <= 0 || prob > 1) {
    return DoubleVector.NaN;
  }

  //R_Q_P01_boundaries(p, 0, Double.POSITIVE_INFINITY);
  if (log_p) {
    if (p > 0) {
      return DoubleVector.NaN;
    }
    if (p == 0) /* upper bound*/ {
      return lower_tail ? Double.POSITIVE_INFINITY : 0;
    }
    if (p == Double.NEGATIVE_INFINITY);
    return lower_tail ? 0 : Double.POSITIVE_INFINITY;
  } else { /* !log_p */
    if (p < 0 || p > 1) {
      return DoubleVector.NaN;
    }
    if (p == 0) {
      return lower_tail ? 0 : Double.POSITIVE_INFINITY;
    }
    if (p == 1) {
      return lower_tail ? Double.POSITIVE_INFINITY : 0;
    }
  }


  if (DoubleVector.isNaN(p) || DoubleVector.isNaN(prob)) {
    return p + prob;
  }

  if (prob == 1) {
    return (0);
  }
  /* add a fuzz to ensure left continuity */
  return Math.ceil(SignRank.R_DT_Clog(p, lower_tail, log_p) / Math.log1p(-prob) - 1 - 1e-7);
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:39,代码来源:Geometric.java

示例10: pnbinom_mu

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double pnbinom_mu(double x, double size, double mu, boolean lower_tail, boolean log_p) {

    if (DoubleVector.isNaN(x) || DoubleVector.isNaN(size) || DoubleVector.isNaN(mu)) {
      return x + size + mu;
    }
    if (!DoubleVector.isFinite(size) || !DoubleVector.isFinite(mu)) {
      return DoubleVector.NaN;
    }

    if (size <= 0 || mu < 0) {
      return DoubleVector.NaN;
    }

    if (x < 0) {
      SignRank.R_DT_0(lower_tail, log_p);
    }
    if (!DoubleVector.isFinite(x)) {
      return SignRank.R_DT_1(lower_tail, log_p);
    }
    x = Math.floor(x + 1e-7);
    /* return
     * pbeta(pr, size, x + 1, lower_tail, log_p);  pr = size/(size + mu), 1-pr = mu/(size+mu)
     *
     *= pbeta_raw(pr, size, x + 1, lower_tail, log_p)
     *            x.  pin   qin
     *=  bratio (pin,  qin, x., 1-x., &w, &wc, &ierr, log_p),  and return w or wc ..
     *=  bratio (size, x+1, pr, 1-pr, &w, &wc, &ierr, log_p) */
    {
      int[] ierr = new int[1];
      double[] w = new double[1];
      double[] wc = new double[1];
      Utils.bratio(size, x + 1, size / (size + mu), mu / (size + mu), w, wc, ierr, log_p);
      return lower_tail ? w[0] : wc[0];
    }
  }
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:36,代码来源:Binom.java

示例11: psigamma

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
@Primitive("psigamma")
public static double psigamma(double x, double deriv) {
  /* n-th derivative of psi(x);  e.g., psigamma(x,0) == digamma(x) */
  int k, n;

  if (DoubleVector.isNaN(x)) {
    return x;
  }
  deriv = Math.floor(deriv + 0.5);
  n = (int) deriv;
  //if(n > n_max) {
  //MATHLIB_WARNING2(_("deriv = %d > %d (= n_max)\n"), n, n_max);
  //return ML_NAN;
  //}
  double[] ans = new double[1];
  double[] xd = new double[]{x};
  int[] nz = new int[1];
  int[] ierr = new int[1];
  dpsifn.dpsifn(x, n, 1, 1, ans, nz, ierr);
  //ML_TREAT_psigam(ierr);
  /* Now, ans ==  A := (-1)^(n+1) / gamma(n+1) * psi(n, x) */
  ans[0] = -ans[0]; /* = (-1)^(0+1) * gamma(0+1) * A */
  for (k = 1; k <= n; k++) {
    ans[0] *= (-k);/* = (-1)^(k+1) * gamma(k+1) * A */
  }
  return ans[0];/* = psi(n, x) */
}
 
开发者ID:bedatadriven,项目名称:renjin-statet,代码行数:28,代码来源:PsiGamma.java

示例12: dnf

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double dnf(double x, double df1, double df2, double ncp, boolean give_log) {
  double y, z, f;

  if (DoubleVector.isNaN(x) || DoubleVector.isNaN(df1) || DoubleVector.isNaN(df2) || DoubleVector.isNaN(ncp)) {
    return x + df2 + df1 + ncp;
  }

  /* want to compare dnf(ncp=0) behavior with df() one, hence *NOT* :
   * if (ncp == 0)
   *   return df(x, df1, df2, give_log); */

  if (df1 <= 0. || df2 <= 0. || ncp < 0) {
    return DoubleVector.NaN;
  }
  if (x < 0.) {
    return (SignRank.R_D__0(true, give_log));
  }
  if (!DoubleVector.isFinite(ncp)) { /* ncp = +Inf -- FIXME?: in some cases, limit exists */
    return DoubleVector.NaN;
  }

  /* This is not correct for  df1 == 2, ncp > 0 - and seems unneeded:
   *  if (x == 0.) return(df1 > 2 ? R_D__0 : (df1 == 2 ? R_D__1 : ML_POSINF));
   */
  if (!DoubleVector.isFinite(df1) && !DoubleVector.isFinite(df2)) { /* both +Inf */
    /* PR: not sure about this (taken from  ncp==0)  -- FIXME ? */
    if (x == 1.) {
      return Double.POSITIVE_INFINITY;
    }
    /* else */ return SignRank.R_D__0(true, give_log);
  }
  if (!DoubleVector.isFinite(df2)) /* i.e.  = +Inf */ {
    return df1 * Distributions.dnchisq(x * df1, df1, ncp, give_log);
  }
  /*	 ==  dngamma(x, df1/2, 2./df1, ncp, give_log)  -- but that does not exist */
  if (df1 > 1e14 && ncp < 1e7) {
    /* includes df1 == +Inf: code below is inaccurate there */
    f = 1 + ncp / df1; /* assumes  ncp << df1 [ignores 2*ncp^(1/2)/df1*x term] */
    z = Distributions.dgamma(1. / x / f, df2 / 2, 2. / df2, give_log);
    return give_log ? z - 2 * Math.log(x) - Math.log(f) : z / (x * x) / f;
  }

  y = (df1 / df2) * x;
  z = Distributions.dnbeta(y / (1 + y), df1 / 2., df2 / 2., ncp, give_log);
  return give_log
          ? z + Math.log(df1) - Math.log(df2) - 2 * Math.log1p(y)
          : z * (df1 / df2) / (1 + y) / (1 + y);
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:49,代码来源:F.java

示例13: qtukey

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double qtukey(double p, double rr, double cc, double df,boolean lower_tail, boolean log_p){
    final double eps = 0.0001;
    final int maxiter = 50;

    double ans = 0.0, valx0, valx1, x0, x1, xabs;
    int iter;


    if (DoubleVector.isNaN(p) || DoubleVector.isNaN(rr) || DoubleVector.isNaN(cc) || DoubleVector.isNaN(df)) {
	//ML_ERROR(ME_DOMAIN, "qtukey");
	return p + rr + cc + df;
    }

    /* df must be > 1 ; there must be at least two values */
    if (df < 2 || rr < 1 || cc < 2) {
      return DoubleVector.NaN;
    }

    //R_Q_P01_boundaries(p, 0, ML_POSINF);
    // * R_Q_P01_boundaries(p, _LEFT_, _RIGHT_)  :<==>
 
      if ((log_p	&& p > 0) || (!log_p && (p < 0 || p > 1)) ){
	return DoubleVector.NaN;
      }
      if (p == SignRank.R_DT_0(lower_tail, log_p)) return 0.0;
      if (p == SignRank.R_DT_1(lower_tail, log_p)) return Double.POSITIVE_INFINITY;
    
    

    p = Normal.R_DT_qIv(p, log_p ? 1.0 : 0.0, lower_tail ? 1.0 : 0.0); /* lower_tail,non-log "p" */

    /* Initial value */

    x0 = qinv(p, cc, df);

    /* Find prob(value < x0) */

    valx0 = ptukey(x0, rr, cc, df, true, false) - p;

    /* Find the second iterate and prob(value < x1). */
    /* If the first iterate has probability value */
    /* exceeding p then second iterate is 1 less than */
    /* first iterate; otherwise it is 1 greater. */

    if (valx0 > 0.0)
	x1 = Math.max(0.0, x0 - 1.0);
    else
	x1 = x0 + 1.0;
    valx1 = ptukey(x1, rr, cc, df, true, false) - p;

    /* Find new iterate */

    for(iter=1 ; iter < maxiter ; iter++) {
	ans = x1 - ((valx1 * (x1 - x0)) / (valx1 - valx0));
	valx0 = valx1;

	/* New iterate must be >= 0 */

	x0 = x1;
	if (ans < 0.0) {
	    ans = 0.0;
	    valx1 = -p;
	}
	/* Find prob(value < new iterate) */

	valx1 = ptukey(ans, rr, cc, df, true, false) - p;
	x1 = ans;

	/* If the difference between two successive */
	/* iterates is less than eps, stop */

	xabs = Math.abs(x1 - x0);
	if (xabs < eps)
	    return ans;
    }

    /* The process did not converge in 'maxiter' iterations */
    //ML_ERROR(ME_NOCONV, "qtukey");
    return ans;
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:81,代码来源:Tukey.java

示例14: qnt

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double qnt(double p, double df, double ncp, boolean lower_tail, boolean log_p) {
  final double accu = 1e-13;
  final double Eps = 1e-11; /* must be > accu */

  double ux, lx, nx, pp;


  if (DoubleVector.isNaN(p) || DoubleVector.isNaN(df) || DoubleVector.isNaN(ncp)) {
    return p + df + ncp;
  }

  if (!DoubleVector.isFinite(df)) {
    return DoubleVector.NaN;
  }

  /* Was
   * df = floor(df + 0.5);
   * if (df < 1 || ncp < 0) ML_ERR_return_NAN;
   */
  if (df <= 0.0) {
    return (DoubleVector.NaN);
  }

  if (ncp == 0.0 && df >= 1.0) {
    return Distributions.qt(p, df, lower_tail, log_p);
  }

  //R_Q_P01_boundaries(p, ML_NEGINF, ML_POSINF);
  //#define R_Q_P01_boundaries(p, _LEFT_, _RIGHT_)
  if (log_p) {
    if (p > 0) {
      return DoubleVector.NaN;
    }
    if (p == 0) /* upper bound*/ {
      return lower_tail ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
    }
    if (p == Double.NEGATIVE_INFINITY) {
      return lower_tail ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
    }
  } else { /* !log_p */
    if (p < 0 || p > 1) {
      return DoubleVector.NaN;
    }
    if (p == 0) {
      return lower_tail ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
    }
    if (p == 1) {
      return lower_tail ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
    }
  }

  p = Normal.R_DT_qIv(p, log_p ? 1.0 : 0.0, lower_tail ? 1.0 : 0.0);
  /* Invert pnt(.) :
   * 1. finding an upper and lower bound */
  if (p > 1 - SignRank.DBL_EPSILON) {
    return Double.POSITIVE_INFINITY;
  }
  pp = Math.min(1 - SignRank.DBL_EPSILON, p * (1 + Eps));
  for (ux = Math.max(1., ncp);
          ux < Double.MAX_VALUE && pnt(ux, df, ncp, true, false) < pp;
          ux *= 2);
  pp = p * (1 - Eps);
  for (lx = Math.min(-1., -ncp);
          lx > -Double.MAX_VALUE && pnt(lx, df, ncp, true, false) > pp;
          lx *= 2);

  /* 2. interval (lx,ux)  halving : */
  do {
    nx = 0.5 * (lx + ux);
    if (pnt(nx, df, ncp, true, false) > p) {
      ux = nx;
    } else {
      lx = nx;
    }
  } while ((ux - lx) / Math.abs(nx) > accu);

  return 0.5 * (lx + ux);
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:79,代码来源:StudentsT.java

示例15: dnt

import org.renjin.sexp.DoubleVector; //导入方法依赖的package包/类
public static double dnt(double x, double df, double ncp, boolean give_log) {
  double u;

  if (DoubleVector.isNaN(x) || DoubleVector.isNaN(df)) {
    return x + df;
  }

  /* If non-positive df then error */
  if (df <= 0.0) {
    return DoubleVector.NaN;
  }

  if (ncp == 0.0) {
    return Distributions.dt(x, df, give_log);
  }

  /* If x is infinite then return 0 */
  if (!DoubleVector.isFinite(x)) {
    return SignRank.R_D__0(true, give_log);
  }

  /* If infinite df then the density is identical to a
  normal distribution with mean = ncp.  However, the formula
  loses a lot of accuracy around df=1e9
   */
  if (!DoubleVector.isFinite(df) || df > 1e8) {
    return Distributions.dnorm(x, ncp, 1., give_log);
  }

  /* Do calculations on log scale to stabilize */

  /* Consider two cases: x ~= 0 or not */
  if (Math.abs(x) > Math.sqrt(df * SignRank.DBL_EPSILON)) {
    u = Math.log(df) - Math.log(Math.abs(x))
            + Math.log(Math.abs(Distributions.pnt(x * Math.sqrt((df + 2) / df), df + 2, ncp, true, false)
            - Distributions.pnt(x, df, ncp, true, false)));
    /* FIXME: the above still suffers from cancellation (but not horribly) */
  } else {  /* x ~= 0 : -> same value as for  x = 0 */
    u = org.apache.commons.math.special.Gamma.logGamma((df + 1) / 2) - org.apache.commons.math.special.Gamma.logGamma(df / 2)
            - .5 * (Math.log(Math.PI) + Math.log(df) + ncp * ncp);
  }

  return (give_log ? u : Math.exp(u));
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:45,代码来源:StudentsT.java


注:本文中的org.renjin.sexp.DoubleVector.isNaN方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。