當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。