Example usage for java.lang Math log

List of usage examples for java.lang Math log

Introduction

In this page you can find the example usage for java.lang Math log.

Prototype

@HotSpotIntrinsicCandidate
public static double log(double a) 

Source Link

Document

Returns the natural logarithm (base e) of a double value.

Usage

From source file:peakml.util.jfreechart.LognAxis.java

public void setLogScale(int logscale) {
    this.logscale = logscale;
    this.lognvalue = Math.log(logscale);
}

From source file:beast.math.distributions.PoissonDistribution.java

public double logPdf(double x) {

    double pdf = distribution.probability((int) x);
    if (pdf == 0 || Double.isNaN(pdf)) { // bad estimate
        final double mean = mean();
        return x * Math.log(mean) - Poisson.gammln(x + 1) - mean;
    }//w ww  .java2 s .c  om
    return Math.log(pdf);

}

From source file:Main.java

/**
 * Returns the natural logarithm of n!.//from w  w  w .j av  a2s .  co  m
 * <p>
 * <Strong>Preconditions</strong>:
 * <ul>
 * <li> <code>n >= 0</code> (otherwise
 * <code>IllegalArgumentException</code> is thrown)</li>
 * </ul></p>
 * 
 * @param n argument
 * @return <code>n!</code>
 * @throws IllegalArgumentException if preconditions are not met.
 */
public static double factorialLog(final int n) {
    if (n < 0) {
        throw new IllegalArgumentException("must have n > 0 for n!");
    }
    double logSum = 0;
    for (int i = 2; i <= n; i++) {
        logSum += Math.log((double) i);
    }
    return logSum;
}

From source file:dfs.OLSTrendLine.java

@Override
public void setValues(double[] y, double[] x) {
    if (x.length != y.length) {
        throw new IllegalArgumentException(
                String.format("The numbers of y and x values must be equal (%d != %d)", y.length, x.length));
    }//from  w  w  w .  ja v a2  s.  co  m
    double[][] xData = new double[x.length][];
    for (int i = 0; i < x.length; i++) {
        // the implementation determines how to produce a vector of predictors from a single x
        xData[i] = xVector(x[i]);
    }
    if (logY()) { // in some models we are predicting ln y, so we replace each y with ln y
        y = Arrays.copyOf(y, y.length); // user might not be finished with the array we were given
        for (int i = 0; i < x.length; i++) {
            y[i] = Math.log(y[i]);
        }
    }
    OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();
    ols.setNoIntercept(true); // let the implementation include a constant in xVector if desired
    ols.newSampleData(y, xData); // provide the data to the model
    coef = MatrixUtils.createColumnRealMatrix(ols.estimateRegressionParameters()); // get our coefs
}

From source file:hyperheuristics.algorithm.moeadfrrmab.UCBSelector.java

protected double equation(LowLevelHeuristic op, HashMap<String, Double> frr, HashMap<String, Integer> nt,
        double sumNt) {
    /*  KE LI code/* www.j  av  a  2 s . c om*/
     http://www.cs.cityu.edu.hk/~51888309/code/bandits.zip
     temp1 = 2 * Math.log(total_usage);
     temp2 = temp1 / strategy_usage[i];
     temp3 = Math.sqrt(temp2);
     quality[i] = rewards[i] + scale_ * temp3;
     */

    double numerator = 2 * Math.log(((int) sumNt));
    double denominator = nt.get(op.getName());
    double fraction = numerator / denominator;
    double sqrt = Math.sqrt(fraction);
    double frr_value = frr.get(op.getName());
    return frr_value + this.C * sqrt;
}

From source file:com.analog.lyric.chimple.monkeys.ChimpDirichlet.java

@Override
public double calculateLogLikelihood(Object result, Object[] parameters) {
    double[] alphas = (double[]) parameters[0];
    double[] value = (double[]) result;

    double retval = 0;

    double sum = 0;
    for (int i = 0; i < alphas.length; i++) {
        retval -= (alphas[i] - 1) * Math.log(value[i]);
        retval += Gamma.logGamma(alphas[i]);
        sum += alphas[i];//from  w w w . ja  va  2s .c  o  m
    }

    retval -= Gamma.logGamma(sum);

    //result=sum(gammaln(alphas))-gammaln(sum(alphas))-sum((alphas-1).*log(value));

    return retval;
}

From source file:fr.ens.transcriptome.teolenn.util.MathUtils.java

/**
 * Return the log 2 of a double.// w w  w .  jav  a2  s  .c  o m
 * @param d a double
 * @return the log 2 of a double
 */
public static double log2(final double d) {
    return Math.log(d) / Math.log(BASE_2);
}

From source file:com.opengamma.analytics.financial.model.interestrate.HoLeeInterestRateModel.java

@Override
public Function1D<StandardDiscountBondModelDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time,
        final ZonedDateTime maturity) {
    Validate.notNull(time);//www . j  a v  a2 s . co m
    Validate.notNull(maturity);
    return new Function1D<StandardDiscountBondModelDataBundle, Double>() {

        @Override
        public Double evaluate(final StandardDiscountBondModelDataBundle data) {
            Validate.notNull(data);
            final double t = DateUtils.getDifferenceInYears(data.getDate(), time);
            final double s = DateUtils.getDifferenceInYears(data.getDate(), maturity);
            final double b = s - t;
            final double sigma = data.getShortRateVolatility(t);
            final double rT = data.getShortRate(t);
            final double rS = data.getShortRate(s);
            final double pT = Math.exp(-rT * t);
            final double pS = Math.exp(-rS * s);
            final double dlnPdt = -rT;
            final double lnA = Math.log(pS / pT) - b * dlnPdt - 0.5 * sigma * sigma * b * b;
            return Math.exp(lnA - b * rT);
        }
    };
}

From source file:emlab.util.GeometricTrendRegression.java

public void removeData(double[][] data) {
    for (int i = 0; i < data.length && super.getN() > 0; i++) {
        removeData(data[i][0], Math.log(data[i][1]));
    }/*from  w w  w  . j  a va  2 s.c  om*/
}

From source file:com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve.java

/**
 * Builder of an interpolated yield  (continuously compounded) curve from discount factors.
 * @param nodePoints The node points for the interpolated curve.
 * @param discountFactors The discount factors at the node points.
 * @param interpolator The yield (cc) interpolator.
 * @param name The curve name./*w  w  w.java  2 s. c  o m*/
 * @return The yield curve.
 */
public static YieldCurve fromDiscountFactorInterpolated(final double[] nodePoints,
        final double[] discountFactors, final Interpolator1D interpolator, final String name) {
    final int nbDF = discountFactors.length;
    ArgumentChecker.isTrue(nodePoints.length == nbDF, "Yields array of incorrect length");
    final double[] yields = new double[nbDF];
    for (int loopy = 0; loopy < nbDF; loopy++) {
        yields[loopy] = -Math.log(discountFactors[loopy]) / nodePoints[loopy];
    }
    final InterpolatedDoublesCurve curve = new InterpolatedDoublesCurve(nodePoints, yields, interpolator,
            false);
    return new YieldCurve(name, curve);
}