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


Java FastMath.log1p方法代码示例

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


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

示例1: logDensity

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} **/
@Override
public double logDensity(double x) {
    /*
     * see the comment in {@link #density(double)} for computation details
     */
    if (x < 0) {
        return Double.NEGATIVE_INFINITY;
    }
    final double y = x / scale;
    if ((y <= minY) || (FastMath.log(y) >= maxLogY)) {
        /*
         * Overflow.
         */
        final double aux1 = (y - shiftedShape) / shiftedShape;
        final double aux2 = shape * (FastMath.log1p(aux1) - aux1);
        final double aux3 = -y * (Gamma.LANCZOS_G + 0.5) / shiftedShape +
                Gamma.LANCZOS_G + aux2;
        return logDensityPrefactor2 - FastMath.log(x) + aux3;
    }
    /*
     * Natural calculation.
     */
    return logDensityPrefactor1 - y + FastMath.log(y) * (shape - 1);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:GammaDistribution.java

示例2: logDensity

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} **/
@Override
public double logDensity(double x) {
    recomputeZ();
    if (x < 0 || x > 1) {
        return Double.NEGATIVE_INFINITY;
    } else if (x == 0) {
        if (alpha < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, alpha, 1, false);
        }
        return Double.NEGATIVE_INFINITY;
    } else if (x == 1) {
        if (beta < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, beta, 1, false);
        }
        return Double.NEGATIVE_INFINITY;
    } else {
        double logX = FastMath.log(x);
        double log1mX = FastMath.log1p(-x);
        return (alpha - 1) * logX + (beta - 1) * log1mX - z;
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:23,代码来源:BetaDistribution.java

示例3: PascalDistribution

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Create a Pascal distribution with the given number of successes and
 * probability of success.
 *
 * @param rng Random number generator.
 * @param r Number of successes.
 * @param p Probability of success.
 * @throws NotStrictlyPositiveException if the number of successes is not positive
 * @throws OutOfRangeException if the probability of success is not in the
 * range {@code [0, 1]}.
 * @since 3.1
 */
public PascalDistribution(RandomGenerator rng,
                          int r,
                          double p)
    throws NotStrictlyPositiveException, OutOfRangeException {
    super(rng);

    if (r <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SUCCESSES,
                                               r);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    numberOfSuccesses = r;
    probabilityOfSuccess = p;
    logProbabilityOfSuccess = FastMath.log(p);
    log1mProbabilityOfSuccess = FastMath.log1p(-p);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:PascalDistribution.java

示例4: logGammaSum

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the value of log Γ(a + b) for 1 ≤ a, b ≤ 2. Based on the
 * <em>NSWC Library of Mathematics Subroutines</em> double precision
 * implementation, {@code DGSMLN}. In {@code BetaTest.testLogGammaSum()},
 * this private method is accessed through reflection.
 *
 * @param a First argument.
 * @param b Second argument.
 * @return the value of {@code log(Gamma(a + b))}.
 * @throws OutOfRangeException if {@code a} or {@code b} is lower than
 * {@code 1.0} or greater than {@code 2.0}.
 */
private static double logGammaSum(final double a, final double b)
    throws OutOfRangeException {

    if ((a < 1.0) || (a > 2.0)) {
        throw new OutOfRangeException(a, 1.0, 2.0);
    }
    if ((b < 1.0) || (b > 2.0)) {
        throw new OutOfRangeException(b, 1.0, 2.0);
    }

    final double x = (a - 1.0) + (b - 1.0);
    if (x <= 0.5) {
        return Gamma.logGamma1p(1.0 + x);
    } else if (x <= 1.5) {
        return Gamma.logGamma1p(x) + FastMath.log1p(x);
    } else {
        return Gamma.logGamma1p(x - 1.0) + FastMath.log(x * (1.0 + x));
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:Beta.java

示例5: log1p

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** Computes shifted logarithm of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param result array where result must be stored (for
 * shifted logarithm the result array <em>cannot</em> be the input array)
 * @param resultOffset offset of the result in its array
 */
public void log1p(final double[] operand, final int operandOffset,
                  final double[] result, final int resultOffset) {

    // create the function value and derivatives
    double[] function = new double[1 + order];
    function[0] = FastMath.log1p(operand[operandOffset]);
    if (order > 0) {
        double inv = 1.0 / (1.0 + operand[operandOffset]);
        double xk  = inv;
        for (int i = 1; i <= order; ++i) {
            function[i] = xk;
            xk *= -i * inv;
        }
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:27,代码来源:DSCompiler.java

示例6: GeometricDistribution

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Creates a geometric distribution.
 *
 * @param rng Random number generator.
 * @param p Probability of success.
 * @throws OutOfRangeException if {@code p <= 0} or {@code p > 1}.
 */
public GeometricDistribution(RandomGenerator rng, double p) {
    super(rng);

    if (p <= 0 || p > 1) {
        throw new OutOfRangeException(LocalizedFormats.OUT_OF_RANGE_LEFT, p, 0, 1);
    }

    probabilityOfSuccess = p;
    logProbabilityOfSuccess = FastMath.log(p);
    log1mProbabilityOfSuccess = FastMath.log1p(-p);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:19,代码来源:GeometricDistribution.java

示例7: algorithmBB

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns one sample using Cheng's BB algorithm, when both &alpha; and &beta; are greater than 1.
 * @param random random generator to use
 * @param a0 distribution first shape parameter (&alpha;)
 * @param a min(&alpha;, &beta;) where &alpha;, &beta; are the two distribution shape parameters
 * @param b max(&alpha;, &beta;) where &alpha;, &beta; are the two distribution shape parameters
 * @return sampled value
 */
private static double algorithmBB(RandomGenerator random,
                                  final double a0,
                                  final double a,
                                  final double b) {
    final double alpha = a + b;
    final double beta = FastMath.sqrt((alpha - 2.) / (2. * a * b - alpha));
    final double gamma = a + 1. / beta;

    double r;
    double w;
    double t;
    do {
        final double u1 = random.nextDouble();
        final double u2 = random.nextDouble();
        final double v = beta * (FastMath.log(u1) - FastMath.log1p(-u1));
        w = a * FastMath.exp(v);
        final double z = u1 * u1 * u2;
        r = gamma * v - 1.3862944;
        final double s = a + r - w;
        if (s + 2.609438 >= 5 * z) {
            break;
        }

        t = FastMath.log(z);
        if (s >= t) {
            break;
        }
    } while (r + alpha * (FastMath.log(alpha) - FastMath.log(b + w)) < t);

    w = FastMath.min(w, Double.MAX_VALUE);
    return Precision.equals(a, a0) ? w / (b + w) : b / (b + w);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:41,代码来源:BetaDistribution.java

示例8: helper1

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Helper function that calculates {@code log(1+x)/x}.
 * <p>
 * A Taylor series expansion is used, if x is close to 0.
 *
 * @param x a value larger than or equal to -1
 * @return {@code log(1+x)/x}
 */
static double helper1(final double x) {
    if (FastMath.abs(x)>1e-8) {
        return FastMath.log1p(x)/x;
    }
    else {
        return 1.-x*((1./2.)-x*((1./3.)-x*(1./4.)));
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:17,代码来源:ZipfDistribution.java

示例9: logGamma1p

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the value of log &Gamma;(1 + x) for -0&#46;5 &le; x &le; 1&#46;5.
 * This implementation is based on the double precision implementation in
 * the <em>NSWC Library of Mathematics Subroutines</em>, {@code DGMLN1}.
 *
 * @param x Argument.
 * @return The value of {@code log(Gamma(1 + x))}.
 * @throws NumberIsTooSmallException if {@code x < -0.5}.
 * @throws NumberIsTooLargeException if {@code x > 1.5}.
 * @since 3.1
 */
public static double logGamma1p(final double x)
    throws NumberIsTooSmallException, NumberIsTooLargeException {

    if (x < -0.5) {
        throw new NumberIsTooSmallException(x, -0.5, true);
    }
    if (x > 1.5) {
        throw new NumberIsTooLargeException(x, 1.5, true);
    }

    return -FastMath.log1p(invGamma1pm1(x));
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:24,代码来源:Gamma.java

示例10: logGammaMinusLogGammaSum

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the value of log[Γ(b) / Γ(a + b)] for a ≥ 0 and b ≥ 10. Based on
 * the <em>NSWC Library of Mathematics Subroutines</em> double precision
 * implementation, {@code DLGDIV}. In
 * {@code BetaTest.testLogGammaMinusLogGammaSum()}, this private method is
 * accessed through reflection.
 *
 * @param a First argument.
 * @param b Second argument.
 * @return the value of {@code log(Gamma(b) / Gamma(a + b))}.
 * @throws NumberIsTooSmallException if {@code a < 0.0} or {@code b < 10.0}.
 */
private static double logGammaMinusLogGammaSum(final double a,
                                               final double b)
    throws NumberIsTooSmallException {

    if (a < 0.0) {
        throw new NumberIsTooSmallException(a, 0.0, true);
    }
    if (b < 10.0) {
        throw new NumberIsTooSmallException(b, 10.0, true);
    }

    /*
     * d = a + b - 0.5
     */
    final double d;
    final double w;
    if (a <= b) {
        d = b + (a - 0.5);
        w = deltaMinusDeltaSum(a, b);
    } else {
        d = a + (b - 0.5);
        w = deltaMinusDeltaSum(b, a);
    }

    final double u = d * FastMath.log1p(a / b);
    final double v = a * (FastMath.log(b) - 1.0);

    return u <= v ? (w - u) - v : (w - v) - u;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:42,代码来源:Beta.java

示例11: density

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double density(double x) {
   /* The present method must return the value of
    *
    *     1       x a     - x
    * ---------- (-)  exp(---)
    * x Gamma(a)  b        b
    *
    * where a is the shape parameter, and b the scale parameter.
    * Substituting the Lanczos approximation of Gamma(a) leads to the
    * following expression of the density
    *
    * a              e            1         y      a
    * - sqrt(------------------) ---- (-----------)  exp(a - y + g),
    * x      2 pi (a + g + 0.5)  L(a)  a + g + 0.5
    *
    * where y = x / b. The above formula is the "natural" computation, which
    * is implemented when no overflow is likely to occur. If overflow occurs
    * with the natural computation, the following identity is used. It is
    * based on the BOOST library
    * http://www.boost.org/doc/libs/1_35_0/libs/math/doc/sf_and_dist/html/math_toolkit/special/sf_gamma/igamma.html
    * Formula (15) needs adaptations, which are detailed below.
    *
    *       y      a
    * (-----------)  exp(a - y + g)
    *  a + g + 0.5
    *                              y - a - g - 0.5    y (g + 0.5)
    *               = exp(a log1pm(---------------) - ----------- + g),
    *                                a + g + 0.5      a + g + 0.5
    *
    *  where log1pm(z) = log(1 + z) - z. Therefore, the value to be
    *  returned is
    *
    * a              e            1
    * - sqrt(------------------) ----
    * x      2 pi (a + g + 0.5)  L(a)
    *                              y - a - g - 0.5    y (g + 0.5)
    *               * exp(a log1pm(---------------) - ----------- + g).
    *                                a + g + 0.5      a + g + 0.5
    */
    if (x < 0) {
        return 0;
    }
    final double y = x / scale;
    if ((y <= minY) || (FastMath.log(y) >= maxLogY)) {
        /*
         * Overflow.
         */
        final double aux1 = (y - shiftedShape) / shiftedShape;
        final double aux2 = shape * (FastMath.log1p(aux1) - aux1);
        final double aux3 = -y * (Gamma.LANCZOS_G + 0.5) / shiftedShape +
                Gamma.LANCZOS_G + aux2;
        return densityPrefactor2 / x * FastMath.exp(aux3);
    }
    /*
     * Natural calculation.
     */
    return densityPrefactor1 * FastMath.exp(-y) * FastMath.pow(y, shape - 1);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:60,代码来源:GammaDistribution.java

示例12: value

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.log1p(x);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:5,代码来源:Log1p.java

示例13: log1p

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public SparseGradient log1p() {
    return new SparseGradient(FastMath.log1p(value), 1.0 / (1.0 + value), derivatives);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:5,代码来源:SparseGradient.java


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