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:com.opengamma.analytics.financial.timeseries.returns.ContinuouslyCompoundedTimeSeriesReturnCalculator.java

/**
 * @param x/*from  w  ww . ja va2 s.com*/
 *          An array of DoubleTimeSeries. If the array has only one element,
 *          then this is assumed to be the price series and the result is the
 *          continuously-compounded return. The dividend series is assumed to
 *          be the second element. It does not have to be the same length as
 *          the price series (in which case, dates without dividends are
 *          treated as if the dividend was zero), and the dividend data points
 *          do not have to correspond to any of the dates in the price series
 *          (in which case, the result is the continuously-compounded return).
 * @throws IllegalArgumentException
 *           If the array is null
 * @throws TimeSeriesException
 *           Throws an exception if: it has no elements;
 *           the time series has less than two entries; if the calculation
 *           mode is strict and there are zeroes in the price series.
 * @return A DoubleTimeSeries containing the return series. This will always
 *         be one element shorter than the original price series.
 */
@Override
public LocalDateDoubleTimeSeries evaluate(final LocalDateDoubleTimeSeries... x) {
    Validate.notNull(x, "x");
    ArgumentChecker.notEmpty(x, "x");
    Validate.notNull(x[0], "first time series");
    final FastIntDoubleTimeSeries ts = (FastIntDoubleTimeSeries) x[0].getFastSeries();
    if (ts.size() < 2) {
        throw new TimeSeriesException("Need at least two data points to calculate return series");
    }
    FastIntDoubleTimeSeries d = null;
    if (x.length > 1) {
        if (x[1] != null) {
            d = (FastIntDoubleTimeSeries) x[1].getFastSeries();
        }
    }

    final int[] times = ts.timesArrayFast();
    final double[] values = ts.valuesArrayFast();

    final int[] resultTimes = new int[times.length];
    final double[] resultValues = new double[times.length];

    int index = 0;
    //int previousTime = times[index];
    double previousValue = values[index];
    index++;

    double dividend;
    Double dividendTSData;
    int resultIndex = 0;

    while (index < times.length) {
        int time = times[index];
        double value = values[index];
        index++;

        if (isValueNonZero(previousValue) && isValueNonZero(value)) {
            resultTimes[resultIndex] = time;
            if (d == null) {
                dividend = 0;
            } else {
                dividendTSData = d.getValue(time); // Arghh, this makes it n log(n) instead of n...  Improve this.
                dividend = dividendTSData == null ? 0 : dividendTSData;
            }
            resultValues[resultIndex] = Math.log((value + dividend) / previousValue);
            resultIndex++;
        }
        //previousTime = time;
        previousValue = value;
    }
    return getSeries(x[0], resultTimes, resultValues, resultIndex);
}

From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java

public static double funcLog(double x) {
    return Math.log(x);
}

From source file:edu.jhu.hlt.parma.inference.transducers.UnigramLM.java

/**
 * Does the regression in log-space.// w  w w  .j  ava 2  s.co m
 * 
 * @param cntCounter
 * @return
 */
// private double[] runLogSpaceRegression(Counter<Integer> cntCounter) {
//    double[] xData = new double[cntCounter.keySet().size()];
//    double[] yData = new double[cntCounter.keySet().size()];
//    double[] wts = new double[cntCounter.keySet().size()];
//    int dataPtr = 0;
//    for(int cnt : cntCounter.keySet()) {
//       xData[dataPtr] = cnt;
//       yData[dataPtr++] = Math.log(cntCounter.getCount(cnt));
//    }
//    Regression reg = new Regression(xData,yData,wts);
//    reg.linear();
//    double[] coeffs = reg.getBestEstimates();
//    assert coeffs.length == 2;

//    return coeffs;
// }

private double[] runLogSpaceRegression(Counter<Integer> cntCounter) {
    SimpleRegression reg = new SimpleRegression();

    for (int cnt : cntCounter.keySet()) {
        reg.addData(cnt, Math.log(cntCounter.getCount(cnt)));
    }

    //System.out.println(reg.getIntercept());
    //System.out.println(reg.getSlope());
    //System.out.println(regression.getSlopeStdErr());

    double[] coeffs = new double[] { reg.getIntercept(), reg.getSlope() };

    return coeffs;
}

From source file:com.opengamma.analytics.math.interpolation.ExponentialExtrapolator1D.java

private double[] getLeftSensitivities(final Interpolator1DDataBundle data, final double value) {
    Validate.notNull(data, "data");
    Validate.notNull(value, "value");
    final double x = data.firstKey();
    final double y = data.firstValue();
    final double m = Math.log(y) / x;
    final double ex = Math.exp(m * value);
    final double[] result = new double[data.size()];
    result[0] = ex * value / (x * y);/*from   w  w  w  . j a v  a 2 s  .  co  m*/
    return result;
}

From source file:feast.expressions.ExpCalculatorParametricDistribution.java

@Override
public Distribution getDistribution() {

    return new ContinuousDistribution() {

        @Override/*  ww w.  j av a 2  s . c  om*/
        public double inverseCumulativeProbability(double p) throws MathException {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public double density(double x) {
            if (isLogInput.get())
                return Math.exp(getExpressionValue(x));
            else
                return getExpressionValue(x);
        }

        @Override
        public double logDensity(double x) {
            if (isLogInput.get())
                return getExpressionValue(x);
            else
                return Math.log(getExpressionValue(x));
        }

        @Override
        public double cumulativeProbability(double x) throws MathException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public double cumulativeProbability(double x0, double x1) throws MathException {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };

}

From source file:com.graphhopper.jsprit.core.algorithm.acceptor.ExperimentalSchrimpfAcceptance.java

private double getThreshold(int iteration) {
    double scheduleVariable = (double) iteration / (double) nOfTotalIterations;
    //      logger.debug("iter={} totalIter={} scheduling={}", iteration, nOfTotalIterations, scheduleVariable);
    double currentThreshold = initialThreshold * Math.exp(-Math.log(2) * scheduleVariable / alpha);
    return currentThreshold;
}

From source file:edu.cmu.tetrad.data.MultiGeneralAndersonDarlingTest.java

private void runTest() {
    int n = data.get(0).size();
    double h = 0.0;

    int numSummed = 0;

    for (int g = 0; g < data.size(); g++) {
        List<Double> _data = data.get(g);

        for (int i = 1; i <= n; i++) {
            double x1 = _data.get(i - 1);
            double a1 = Math.log(distributions.get(g).cumulativeProbability(x1));

            double x2 = _data.get(n + 1 - i - 1);
            double a2 = Math.log(1.0 - distributions.get(g).cumulativeProbability(x2));

            double k = (2 * i - 1) * (a1 + a2);

            if (!(Double.isNaN(a1) || Double.isNaN(a2) || Double.isInfinite(a1) || Double.isInfinite(a2))) {
                h += k;//www . ja v a 2  s.  co  m
                numSummed++;
            }
        }
    }

    System.out.println("n = " + n + " numSummed = " + numSummed);

    double a = -n - (1.0 / numSummed) * h;
    double aa = (1 + 0.75 / numSummed + 2.25 / Math.pow(numSummed, 2)) * a;
    double p;

    if (aa < 0.2) {
        p = 1 - Math.exp(-13.436 + 101.14 * aa - 223.73 * aa * aa);
    } else if (aa < 0.34) {
        p = 1 - Math.exp(-8.318 + 42.796 * aa - 59.938 * aa * aa);
    } else if (aa < 0.6) {
        p = Math.exp(0.9177 - 4.279 * aa - 1.38 * aa * aa);
    } else {
        p = Math.exp(1.2937 - 5.709 * aa + 0.0186 * aa * aa);
    }

    this.aSquared = a;
    this.aSquaredStar = aa;
    this.p = p;
}

From source file:edu.oregonstate.eecs.mcplan.ml.GaussianMixtureModel.java

public double logLikelihood() {
    double l = 0.0;
    for (final double[] x : data_) {
        double lx = 0.0;
        for (int i = 0; i < k_; ++i) {
            lx += posterior(x, i);/*from  w  w w.  ja  va  2s  . co  m*/
        }
        l += Math.log(lx);
    }
    return l;
}

From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.CappedPowerOptionModel.java

double getD(final double x, final double y, final double z) {
    return (Math.log(x) + y) / z;
}

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

@Override
public double getInterestRate(final Double time) {
    final double rate = _curve.getYValue(time);
    return _compoundingPeriodsPerYear * Math.log(1 + rate / _compoundingPeriodsPerYear);
}