org.apache.commons.math3.special.Gamma类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(240)

本文整理了Java中org.apache.commons.math3.special.Gamma类的一些代码示例,展示了Gamma类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Gamma类的具体详情如下:
包路径:org.apache.commons.math3.special.Gamma
类名称:Gamma

Gamma介绍

[英]This is a utility class that provides computation methods related to the Γ (Gamma) family of functions.

Implementation of #invGamma1pm1(double) and #logGamma1p(double) is based on the algorithms described in

  • Didonato and Morris (1986), Computation of the Incomplete Gamma Function Ratios and their Inverse, TOMS 12(4), 377-393,
  • Didonato and Morris (1992), Algorithm 708: Significant Digit Computation of the Incomplete Beta Function Ratios, TOMS 18(3), 360-373,
    and implemented in the NSWC Library of Mathematical Functions, available here. This library is "approved for public release", and the Copyright guidance indicates that unless otherwise stated in the code, all FORTRAN functions in this library are license free. Since no such notice appears in the code these functions can safely be ported to Commons-Math.
    [中]

代码示例

代码示例来源:origin: org.apache.commons/commons-math3

ret = 1.0 - regularizedGammaQ(a, x, epsilon, maxIterations);
} else {
  double an = 1.0 / a; // n-th element in the series
  double sum = an; // partial sum
  while (FastMath.abs(an/sum) > epsilon &&
      n < maxIterations &&
      sum < Double.POSITIVE_INFINITY) {
    ret = 1.0;
  } else {
    ret = FastMath.exp(-x + (a * FastMath.log(x)) - logGamma(a)) * sum;

代码示例来源:origin: org.apache.commons/commons-math3

return FastMath.log(x) - 0.5 / x - inv * ((1.0 / 12) + inv * (1.0 / 120 - inv / 252));
return digamma(x + 1) - 1 / x;

代码示例来源:origin: org.apache.commons/commons-math3

tempa = FastMath.pow(halfx, alpha) /
      (alpha * Gamma.gamma(alpha));
final double xc = FastMath.sqrt(PI2 / x);
final double mul = 0.125 / x;
final double xin = mul * mul;
double vsin = FastMath.sin(z);
double vcos = FastMath.cos(z);
double gnu = 2 * alpha;
if (FastMath.abs(alpha) > 1e-16) {
  sum *= Gamma.gamma(alpha) * FastMath.pow(x * 0.5, -alpha);

代码示例来源:origin: org.apache.commons/commons-math3

ret = 1.0 - regularizedGammaP(a, x, epsilon, maxIterations);
} else {
  ret = FastMath.exp(-x + (a * FastMath.log(x)) - logGamma(a)) * ret;

代码示例来源:origin: org.apache.commons/commons-math3

(Gamma.logGamma(ared) +
       logGammaMinusLogGammaSum(ared, b));
} else {
        (Gamma.logGamma(ared) +
        (Gamma.logGamma(bred) -
        logGammaSum(ared, bred)));
        Gamma.logGamma(ared) +
        logGammaMinusLogGammaSum(ared, b);
        (Gamma.logGamma(a) +
        (Gamma.logGamma(bred) -
         logGammaSum(a, bred)));
  } else {
    return Gamma.logGamma(a) +
        logGammaMinusLogGammaSum(a, b);
  return Gamma.logGamma(a) +
      Gamma.logGamma(b) -
      logGammaSum(a, b);
  return Gamma.logGamma(a) +
      logGammaMinusLogGammaSum(a, b);
} else {
  return FastMath.log(Gamma.gamma(a) * Gamma.gamma(b) /
            Gamma.gamma(a + b));

代码示例来源:origin: deeplearning4j/nd4j

if (z < 15.0) {
  double z2 = 2.0 * z;
  if (FastMath.floor(z2) == z2) {
    ret = EXACT_STIRLING_ERRORS[(int) z2];
  } else {
    ret = Gamma.logGamma(z + 1.0) - (z + 0.5) * FastMath.log(z) + z - HALF_LOG_2_PI;

代码示例来源:origin: org.apache.commons/commons-math3

/** {@inheritDoc} */
public double density(double x) {
  if (x <= 0) {
    return 0.0;
  }
  return 2.0 * FastMath.pow(mu, mu) / (Gamma.gamma(mu) * FastMath.pow(omega, mu)) *
         FastMath.pow(x, 2 * mu - 1) * FastMath.exp(-mu * x * x / omega);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * used by {@link #getNumericalMean()}
 *
 * @return the mean of this distribution
 */
protected double calculateNumericalMean() {
  final double sh = getShape();
  final double sc = getScale();
  return sc * FastMath.exp(Gamma.logGamma(1 + (1 / sh)));
}

代码示例来源:origin: org.apache.commons/commons-math3

/** {@inheritDoc} */
public double getNumericalMean() {
  return Gamma.gamma(mu + 0.5) / Gamma.gamma(mu) * FastMath.sqrt(omega / mu);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Creates a t distribution.
 *
 * @param rng Random number generator.
 * @param degreesOfFreedom Degrees of freedom.
 * @param inverseCumAccuracy the maximum absolute error in inverse
 * cumulative probability estimates
 * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code degreesOfFreedom <= 0}
 * @since 3.1
 */
public TDistribution(RandomGenerator rng,
           double degreesOfFreedom,
           double inverseCumAccuracy)
  throws NotStrictlyPositiveException {
  super(rng);
  if (degreesOfFreedom <= 0) {
    throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM,
                        degreesOfFreedom);
  }
  this.degreesOfFreedom = degreesOfFreedom;
  solverAbsoluteAccuracy = inverseCumAccuracy;
  final double n = degreesOfFreedom;
  final double nPlus1Over2 = (n + 1) / 2;
  factor = Gamma.logGamma(nPlus1Over2) -
       0.5 * (FastMath.log(FastMath.PI) + FastMath.log(n)) -
       Gamma.logGamma(n / 2);
}

代码示例来源:origin: org.apache.commons/commons-math3

/** Recompute the normalization factor. */
private void recomputeZ() {
  if (Double.isNaN(z)) {
    z = Gamma.logGamma(alpha) + Gamma.logGamma(beta) - Gamma.logGamma(alpha + beta);
  }
}

代码示例来源:origin: improbable-research/keanu

@Override
public DoubleTensor digammaInPlace() {
  value = Gamma.digamma(value);
  return this;
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Returns the error function.
 *
 * <p>erf(x) = 2/&radic;&pi; <sub>0</sub>&int;<sup>x</sup> e<sup>-t<sup>2</sup></sup>dt </p>
 *
 * <p>This implementation computes erf(x) using the
 * {@link Gamma#regularizedGammaP(double, double, double, int) regularized gamma function},
 * following <a href="http://mathworld.wolfram.com/Erf.html"> Erf</a>, equation (3)</p>
 *
 * <p>The value returned is always between -1 and 1 (inclusive).
 * If {@code abs(x) > 40}, then {@code erf(x)} is indistinguishable from
 * either 1 or -1 as a double, so the appropriate extreme value is returned.
 * </p>
 *
 * @param x the value.
 * @return the error function erf(x)
 * @throws org.apache.commons.math3.exception.MaxCountExceededException
 * if the algorithm fails to converge.
 * @see Gamma#regularizedGammaP(double, double, double, int)
 */
public static double erf(double x) {
  if (FastMath.abs(x) > 40) {
    return x > 0 ? 1 : -1;
  }
  final double ret = Gamma.regularizedGammaP(0.5, x * x, 1.0e-15, 10000);
  return x < 0 ? -ret : ret;
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Returns the complementary error function.
 *
 * <p>erfc(x) = 2/&radic;&pi; <sub>x</sub>&int;<sup>&infin;</sup> e<sup>-t<sup>2</sup></sup>dt
 * <br/>
 *    = 1 - {@link #erf(double) erf(x)} </p>
 *
 * <p>This implementation computes erfc(x) using the
 * {@link Gamma#regularizedGammaQ(double, double, double, int) regularized gamma function},
 * following <a href="http://mathworld.wolfram.com/Erf.html"> Erf</a>, equation (3).</p>
 *
 * <p>The value returned is always between 0 and 2 (inclusive).
 * If {@code abs(x) > 40}, then {@code erf(x)} is indistinguishable from
 * either 0 or 2 as a double, so the appropriate extreme value is returned.
 * </p>
 *
 * @param x the value
 * @return the complementary error function erfc(x)
 * @throws org.apache.commons.math3.exception.MaxCountExceededException
 * if the algorithm fails to converge.
 * @see Gamma#regularizedGammaQ(double, double, double, int)
 * @since 2.2
 */
public static double erfc(double x) {
  if (FastMath.abs(x) > 40) {
    return x > 0 ? 0 : 2;
  }
  final double ret = Gamma.regularizedGammaQ(0.5, x * x, 1.0e-15, 10000);
  return x < 0 ? 2 - ret : ret;
}

代码示例来源:origin: lenskit/lenskit

double lambdaShpIK = lambdaShp.getEntry(item, k);
double lambdaRteIK = lambdaRte.getEntry(item, k);
double phiUIK = Gamma.digamma(gammaShpUK) - Math.log(gammaRteUK) + Gamma.digamma(lambdaShpIK) - Math.log(lambdaRteIK);
phiUI.setEntry(k, phiUIK);
  pLL = (rating == 0) ? (-eThetaBeta) : Math.log(1 - Math.exp(-eThetaBeta));
} else {
  pLL = rating * Math.log(eThetaBeta) - eThetaBeta - Gamma.logGamma(rating + 1);

代码示例来源:origin: geogebra/geogebra

ret = 1.0 - regularizedGammaP(a, x, epsilon, maxIterations);
} else {
  ret = Math.exp(-x + (a * Math.log(x)) - logGamma(a)) * ret;

代码示例来源:origin: geogebra/geogebra

(Gamma.logGamma(ared) +
       logGammaMinusLogGammaSum(ared, b));
} else {
        (Gamma.logGamma(ared) +
        (Gamma.logGamma(bred) -
        logGammaSum(ared, bred)));
  } else {
    return Math.log(prod1) +
        Gamma.logGamma(ared) +
        logGammaMinusLogGammaSum(ared, b);
        (Gamma.logGamma(a) +
        (Gamma.logGamma(bred) -
         logGammaSum(a, bred)));
  } else {
    return Gamma.logGamma(a) +
        logGammaMinusLogGammaSum(a, b);
  return Gamma.logGamma(a) +
      Gamma.logGamma(b) -
      logGammaSum(a, b);
  return Gamma.logGamma(a) +
      logGammaMinusLogGammaSum(a, b);
} else {
  return Math.log(Gamma.gamma(a) * Gamma.gamma(b) /
            Gamma.gamma(a + b));

代码示例来源:origin: geogebra/geogebra

ret = 1.0 - regularizedGammaQ(a, x, epsilon, maxIterations);
} else {
    ret = 1.0;
  } else {
    ret = Math.exp(-x + (a * Math.log(x)) - logGamma(a)) * sum;

代码示例来源:origin: geogebra/geogebra

/**
 * @param order
 *            polynomial order
 * @param x
 *            real number
 * @return polyGamma_order(x)
 */
final public static double polyGamma(NumberValue order, double x) {
  int o = (int) order.getDouble();
  switch (o) {
  case 0:
    return Gamma.digamma(x);
  case 1:
    return Gamma.trigamma(x);
  // case 2:
  // return PolyGamma.tetragamma(x);
  // case 3:
  // return PolyGamma.pentagamma(x);
  // default:
  // return PolyGamma.psigamma(x, o);
  default:
    return Double.NaN;
  }
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Returns the regularized gamma function P(a, x).
 *
 * @param a Parameter.
 * @param x Value.
 * @return the regularized gamma function P(a, x).
 * @throws MaxCountExceededException if the algorithm fails to converge.
 */
public static double regularizedGammaP(double a, double x) {
  return regularizedGammaP(a, x, DEFAULT_EPSILON, Integer.MAX_VALUE);
}

相关文章