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:change_point_detection.BetaDistributionChangePoint.java

public int/*estimated change point*/ detectChange() throws Exception {
    int estimatedChangePoint = -1;
    int N = this.dynamicWindow.size();
    this.cushion = Math.max(100, (int) Math.floor(Math.pow(N, gamma)));
    //mean conf. should not fall below 0.3
    if (N > (2 * this.cushion) && calculateMean(0, N - 1) <= 0.3)
        return N - 1;
    double threshold = -Math.log(this.sensitivity);

    double w = 0;
    int kAtMaxW = -1;
    for (int k = this.cushion; k <= N - this.cushion; k++) {
        if (calculateMean(k, N - 1) <= 0.95 * calculateMean(0, k - 1)) {
            double skn = 0;
            /* estimate pre and post change parameters */
            double alphaPreChange = calcBetaDistAlpha(0, k - 1);
            double betaPreChange = calculateBetaDistBeta(alphaPreChange, 0, k - 1);
            double alphaPostChange = calcBetaDistAlpha(k, N - 1);
            double betaPostChange = calculateBetaDistBeta(alphaPostChange, k, N - 1);

            BetaDistributionImpl preBetaDist = new BetaDistributionImpl(alphaPreChange, betaPreChange);
            BetaDistributionImpl postBetaDist = new BetaDistributionImpl(alphaPostChange, betaPostChange);

            for (int i = k; i < N; i++) {
                try {
                    skn += Math.log(postBetaDist.density(this.dynamicWindow.get(i).doubleValue())
                            / preBetaDist.density(this.dynamicWindow.get(i).doubleValue()));
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("continuing...");
                    skn = 0;/*from w  w  w  .  j a  v  a2s  . c o m*/
                    break;
                }
            }
            if (skn > w) {
                w = skn;
                kAtMaxW = k;
            }
        }
    }
    if (w >= threshold && kAtMaxW != -1) {
        System.out.println("\nChangePoint Found!");
        estimatedChangePoint = kAtMaxW;
        System.out.println("Estimated change point is " + estimatedChangePoint);
    }
    //force change point if confidence falls down terribly
    if (estimatedChangePoint == -1 && N >= 100 && calculateMean(0, N - 1) < 0.3)
        estimatedChangePoint = N - 1;
    return estimatedChangePoint;
}

From source file:etymology.util.EtyMath.java

public static double[][] initLogRegret(int K, int N) {
    logRegret = new double[K][N];
    int row;/*  ww w .j a v  a  2  s . c o m*/
    int col;

    //init: L(1,n) = 0 for all n in N
    for (int n = 1; n <= N; n++) {
        System.out.println("n: " + n);
        col = n - 1;

        //init k=1 (row 0)
        logRegret[0][col] = 0;
        logRegret[1][col] = 0;

        //init k==2 (row 1)
        for (int i = 0; i <= n; i++) {
            double a = logRegret[1][col];
            double b = lnFactorial(n) - lnFactorial(i) - lnFactorial(n - i) + xlogx(i) + xlogx(n - i)
                    - xlogx(n);

            logRegret[1][col] = logPlus(a, b);
        }

        //init k>=3 (row 2 -->)
        for (int k = 3; k <= K; k++) {
            row = k - 1;
            double a = logRegret[row - 1][col];
            double b = Math.log(n) - Math.log(k) + logRegret[row - 2][col];

            logRegret[row][col] = logPlus(a, b);
        }
    }

    //        for (double[] roww : logRegret) {
    //            System.out.println(Arrays.toString(roww));
    //        }

    return logRegret;

    //
}

From source file:beast.evolution.coalescent.DemographicFunction.java

default double getLogDemographic(double t) {
    return Math.log(getDemographic(t));
}

From source file:com.opengamma.analytics.financial.interestrate.market.description.MarketForwardTimeDecorated.java

@Override
public double getForwardRate(IborIndex index, double startTime, double endTime, double accuralFactor) {
    if (index == _index) {
        if (_time == startTime) {
            double rateStart = -Math.log(_forwardCurve.getDiscountFactor(_time)) / _time;
            double dfStart = Math.exp(-(rateStart + _shift) * _time);
            return (dfStart / _forwardCurve.getDiscountFactor(endTime) - 1) / accuralFactor;
        }/*w w w . j a  v  a 2  s  .c  om*/
        if (_time == endTime) {
            double rateEnd = -Math.log(_forwardCurve.getDiscountFactor(_time)) / _time;
            double dfEnd = Math.exp(-(rateEnd + _shift) * _time);
            return (_forwardCurve.getDiscountFactor(startTime) / dfEnd - 1) / accuralFactor;
        }
    }
    return super.getForwardRate(index, startTime, endTime, accuralFactor);
}

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

public double logPdf(double x) {

    double pdf = distribution.probability(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  . ja v  a  2  s.c o  m
    return Math.log(pdf);

}

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

@Override
public Function1D<StandardOptionDataBundle, Double> getPricingFunction(final LogOptionDefinition definition) {
    Validate.notNull(definition);/* w w  w .  j  a  va  2s  .  c om*/
    final Function1D<StandardOptionDataBundle, Double> pricingFunction = new Function1D<StandardOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final StandardOptionDataBundle data) {
            Validate.notNull(data);
            final double s = data.getSpot();
            final double k = definition.getStrike();
            final double t = definition.getTimeToExpiry(data.getDate());
            final double b = data.getCostOfCarry();
            final double r = data.getInterestRate(t);
            final double sigma = data.getVolatility(t, k);
            final double df = Math.exp(-r * t);
            final double sigmaT = sigma * Math.sqrt(t);
            final double x = (Math.log(s / k) + t * (b - sigma * sigma * 0.5)) / sigmaT;
            return df * sigmaT
                    * (_normalProbabilityDistribution.getPDF(x) + x * _normalProbabilityDistribution.getCDF(x));
        }

    };
    return pricingFunction;
}

From source file:com.opengamma.analytics.math.TrigonometricFunctionUtils.java

public static double atanh(final double x) {
    return 0.5 * Math.log((1 + x) / (1 - x));
}

From source file:com.opengamma.analytics.math.statistics.estimation.StudentTDistributionMaximumLikelihoodEstimator.java

@Override
public ProbabilityDistribution<Double> evaluate(final double[] x) {
    Validate.notNull(x, "x");
    ArgumentChecker.notEmpty(x, "x");
    final double[] standardized = getStandardizedData(x);
    final Function1D<Double, Double> f = new Function1D<Double, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override//from  w  ww.j ava 2  s .  c om
        public Double evaluate(final Double nu) {
            double sum = 0;
            for (final double t : standardized) {
                sum += Math.log(_gamma.evaluate((nu + 1) / 2.) * Math.pow(1 + t * t / (nu - 2), -(nu + 1) / 2.)
                        / Math.sqrt(Math.PI * (nu - 2)) / _gamma.evaluate(nu / 2.));
            }
            return -sum;
        }

    };
    return new StudentTDistribution(_minimizer.minimize(f, 0.0, 3., 10.));
}

From source file:com.cloudera.oryx.kmeans.common.Weighted.java

/**
 * Sample items from a {@code List<Weighted>} where items with higher weights
 * have a higher probability of being included in the sample.
 * /*www  .  ja  va 2s  . co m*/
 * @param things The iterable to sample from
 * @param size The number of items to sample
 * @return A list containing the sampled items
 */
public static <T extends Weighted<?>> List<T> sample(Iterable<T> things, int size, RandomGenerator random) {
    if (random == null) {
        random = RandomManager.getRandom();
    }
    SortedMap<Double, T> sampled = Maps.newTreeMap();
    for (T thing : things) {
        if (thing.weight() > 0) {
            double score = Math.log(random.nextDouble()) / thing.weight();
            if (sampled.size() < size || score > sampled.firstKey()) {
                sampled.put(score, thing);
            }
            if (sampled.size() > size) {
                sampled.remove(sampled.firstKey());
            }
        }
    }
    return Lists.newArrayList(sampled.values());
}

From source file:com.cloudera.oryx.kmeans.computation.local.SamplingRun.java

@Override
public Collection<RealVector> call() throws Exception {
    SortedMap<Double, RealVector> reservoir = Maps.newTreeMap();
    for (RealVector v : vecs) {
        Distance d = index.getDistance(v, foldId, true);
        if (d.getSquaredDistance() > 0.0) {
            double score = Math.log(random.nextDouble()) / d.getSquaredDistance();
            if (reservoir.size() < sampleCount) {
                reservoir.put(score, v);
            } else if (score > reservoir.firstKey()) {
                reservoir.remove(reservoir.firstKey());
                reservoir.put(score, v);
            }//w  ww .java2s.c om
        }
    }
    return reservoir.values();
}