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


Java FastMath.log方法代码示例

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


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

示例1: calculateShape

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
public static double calculateShape(double percentile, List<Double> scores) {
	int pos = (int)(scores.size() * percentile);
	double loc = scores.get(pos);

	// calculate Pareto shape
	double shape = 0;
	for (int i = pos; i < scores.size() ; i++) {
		double d = scores.get(i) - loc + 1;
		shape += FastMath.log(d);
	}
	
	shape /= (scores.size() - pos);
	shape = 1/shape;
	
	return shape;
}
 
开发者ID:Auraya,项目名称:armorvox-client,代码行数:17,代码来源:DistUtils.java

示例2: 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

示例3: log

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** Compute natural 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
 * logarithm the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void log(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.log(operand[operandOffset]);
    if (order > 0) {
        double inv = 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,代码行数:28,代码来源:DSCompiler.java

示例4: digamma

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * <p>Computes the digamma function of x.</p>
 *
 * <p>This is an independently written implementation of the algorithm described in
 * Jose Bernardo, Algorithm AS 103: Psi (Digamma) Function, Applied Statistics, 1976.</p>
 *
 * <p>Some of the constants have been changed to increase accuracy at the moderate expense
 * of run-time.  The result should be accurate to within 10^-8 absolute tolerance for
 * x >= 10^-5 and within 10^-8 relative tolerance for x > 0.</p>
 *
 * <p>Performance for large negative values of x will be quite expensive (proportional to
 * |x|).  Accuracy for negative values of x should be about 10^-8 absolute for results
 * less than 10^5 and 10^-8 relative for results larger than that.</p>
 *
 * @param x Argument.
 * @return digamma(x) to within 10-8 relative or absolute error whichever is smaller.
 * @see <a href="http://en.wikipedia.org/wiki/Digamma_function">Digamma</a>
 * @see <a href="http://www.uv.es/~bernardo/1976AppStatist.pdf">Bernardo&apos;s original article </a>
 * @since 2.0
 */
public static double digamma(double x) {
    if (Double.isNaN(x) || Double.isInfinite(x)) {
        return x;
    }

    if (x > 0 && x <= S_LIMIT) {
        // use method 5 from Bernardo AS103
        // accurate to O(x)
        return -GAMMA - 1 / x;
    }

    if (x >= C_LIMIT) {
        // use method 4 (accurate to O(1/x^8)
        double inv = 1 / (x * x);
        //            1       1        1         1
        // log(x) -  --- - ------ + ------- - -------
        //           2 x   12 x^2   120 x^4   252 x^6
        return FastMath.log(x) - 0.5 / x - inv * ((1.0 / 12) + inv * (1.0 / 120 - inv / 252));
    }

    return digamma(x + 1) - 1 / x;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:43,代码来源:Gamma.java

示例5: log2

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Computes the binary logarithm. (logarithm base 2)
 *
 * @param x
 *            the input
 * @return the log to the base 2 of x
 */
public static final double log2(final double x) {
    if (x == 0) {
        return 0;
    } else {
        return FastMath.log(x) / LOG2;
    }
}
 
开发者ID:knime,项目名称:knime-activelearning,代码行数:15,代码来源:MathUtils.java

示例6: calLogCompoundDens

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
private static double calLogCompoundDens(RealVector betas, RealVector betaDens, int n, int k) {
	double logComb = CombinatoricsUtils.binomialCoefficientLog(n,k);
	int nBetas = betas.getDimension();
	RealVector dens = new ArrayRealVector(nBetas);
	for (int i = 0; i < nBetas; i++) {
		dens.setEntry(i, betaDens.getEntry(i) * FastMath.pow(betas.getEntry(i), k)
				* FastMath.pow(1 - betas.getEntry(i), n - k));
	}
	double prob = integSimpson(betas,dens);
	double logProb=(prob==0)?-1000:FastMath.log(prob); // avoid -Inf
	return logComb+logProb;
}
 
开发者ID:jasminezhoulab,项目名称:CancerLocator,代码行数:13,代码来源:CancerLocator.java

示例7: inverseCumulativeProbability

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * Returns {@code 0} when {@code p= = 0} and
 * {@code Double.POSITIVE_INFINITY} when {@code p == 1}.
 */
@Override
public double inverseCumulativeProbability(double p) throws OutOfRangeException {
    double ret;

    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0.0, 1.0);
    } else if (p == 1.0) {
        ret = Double.POSITIVE_INFINITY;
    } else {
        ret = -mean * FastMath.log(1.0 - p);
    }

    return ret;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:21,代码来源:ExponentialDistribution.java

示例8: entropy

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Calculates the <a href="http://en.wikipedia.org/wiki/Entropy_%28information_theory%29">
 * Shannon entropy</a> for a vector.  The values of {@code k} are taken to be
 * incidence counts of the values of a random variable. What is returned is <br/>
 * &sum;p<sub>i</sub>log(p<sub>i</sub><br/>
 * where p<sub>i</sub> = k[i] / (sum of elements in k)
 *
 * @param k Vector (for ex. Row Sums of a trials)
 * @return Shannon Entropy of the given Vector
 *
 */
private double entropy(final long[] k) {
    double h = 0d;
    double sum_k = 0d;
    for (int i = 0; i < k.length; i++) {
        sum_k += (double) k[i];
    }
    for (int i = 0; i < k.length; i++) {
        if (k[i] != 0) {
            final double p_i = (double) k[i] / sum_k;
            h += p_i * FastMath.log(p_i);
        }
    }
    return -h;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:GTest.java

示例9: log

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * @param m Input matrix
 * @return Matrix representing the element-wise logarithm of m.
 */
private static RealMatrix log(final RealMatrix m) {
    final double[][] d = new double[m.getRowDimension()][m.getColumnDimension()];
    for (int r = 0; r < m.getRowDimension(); r++) {
        for (int c = 0; c < m.getColumnDimension(); c++) {
            d[r][c] = FastMath.log(m.getEntry(r, c));
        }
    }
    return new Array2DRowRealMatrix(d, false);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:14,代码来源:CMAESOptimizer.java

示例10: logProbability

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double logProbability(int x) {
    double ret;
    if (x < 0 || x == Integer.MAX_VALUE) {
        ret = Double.NEGATIVE_INFINITY;
    } else if (x == 0) {
        ret = -mean;
    } else {
        ret = -SaddlePointExpansion.getStirlingError(x) -
              SaddlePointExpansion.getDeviancePart(x, mean) -
              0.5 * FastMath.log(MathUtils.TWO_PI) - 0.5 * FastMath.log(x);
    }
    return ret;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:16,代码来源:PoissonDistribution.java

示例11: value

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * @param x Value at which to compute the logit.
 * @param lo Lower bound.
 * @param hi Higher bound.
 * @return the value of the logit function at {@code x}.
 */
private static double value(double x,
                            double lo,
                            double hi) {
    if (x < lo || x > hi) {
        throw new OutOfRangeException(x, lo, hi);
    }
    return FastMath.log((x - lo) / (hi - x));
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:15,代码来源:Logit.java

示例12: 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

示例13: GammaDistribution

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Creates a Gamma distribution.
 *
 * @param rng Random number generator.
 * @param shape the shape parameter
 * @param scale the scale parameter
 * @param inverseCumAccuracy the maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code shape <= 0} or
 * {@code scale <= 0}.
 * @since 3.1
 */
public GammaDistribution(RandomGenerator rng,
                         double shape,
                         double scale,
                         double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (shape <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape);
    }
    if (scale <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale);
    }

    this.shape = shape;
    this.scale = scale;
    this.solverAbsoluteAccuracy = inverseCumAccuracy;
    this.shiftedShape = shape + Gamma.LANCZOS_G + 0.5;
    final double aux = FastMath.E / (2.0 * FastMath.PI * shiftedShape);
    this.densityPrefactor2 = shape * FastMath.sqrt(aux) / Gamma.lanczos(shape);
    this.logDensityPrefactor2 = FastMath.log(shape) + 0.5 * FastMath.log(aux) -
                                FastMath.log(Gamma.lanczos(shape));
    this.densityPrefactor1 = this.densityPrefactor2 / scale *
            FastMath.pow(shiftedShape, -shape) *
            FastMath.exp(shape + Gamma.LANCZOS_G);
    this.logDensityPrefactor1 = this.logDensityPrefactor2 - FastMath.log(scale) -
            FastMath.log(shiftedShape) * shape +
            shape + Gamma.LANCZOS_G;
    this.minY = shape + Gamma.LANCZOS_G - FastMath.log(Double.MAX_VALUE);
    this.maxLogY = FastMath.log(Double.MAX_VALUE) / (shape - 1.0);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:45,代码来源:GammaDistribution.java

示例14: 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

示例15: addValue

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
private void addValue(double val) {
    this.value += FastMath.log(val);
    n++;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:5,代码来源:GeometricMeanAggregation.java


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