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:lanchester.AthenaArena.java

public void step() {
    //        this.currentTime++;
    Truncator truncator = new Truncator();
    double currentF1 = f1.getForceSize();
    double currentF2 = f2.getForceSize();
    double ratio1to2 = currentF1 / currentF2;
    double minRx = 1.;
    double minRy = 1.;
    if (ratio1to2 > f1.attackDefendRatio) {
        f1.setStance(AthenaConstants.ATTACK_POSTURE);
        minRx *= f1.attackDefendRatio;/*  www .j ava2  s .  c  o  m*/
    } else if (ratio1to2 > f1.defendWithdrawRatio) {
        f1.setStance(AthenaConstants.DEFEND_POSTURE);
        minRx *= f1.defendWithdrawRatio;
    } else {
        f1.setStance(AthenaConstants.WITHDRAW_POSTURE);
        minRx *= 0.;
    }
    double ratio2to1 = currentF2 / currentF1;
    if (ratio2to1 > f2.attackDefendRatio) {
        f2.setStance(AthenaConstants.ATTACK_POSTURE);
        minRy *= f2.attackDefendRatio;
    } else if (ratio2to1 > f2.defendWithdrawRatio) {
        f2.setStance(AthenaConstants.DEFEND_POSTURE);
        minRy *= f2.defendWithdrawRatio;
    } else {
        f2.setStance(AthenaConstants.WITHDRAW_POSTURE);
        minRy *= 0.;
    }
    double x0 = f1.getForceSize();
    double y0 = f2.getForceSize();
    double a1 = f1.getAttrition();
    double b2 = f2.getAttrition();
    if (isBattle) {
        a1 *= AthenaConstants.battle[f1.getCurrentStance()][f2.getCurrentStance()];
        b2 *= AthenaConstants.battle[f2.getCurrentStance()][f1.getCurrentStance()];
    } else {
        a1 *= AthenaConstants.skirmish[f1.getCurrentStance()][f2.getCurrentStance()];
        b2 *= AthenaConstants.skirmish[f2.getCurrentStance()][f1.getCurrentStance()];
    }
    double rootA = Math.sqrt(a1);
    double rootB = Math.sqrt(b2);
    double c1 = 0.5 * ((x0 / rootA) - (y0 / rootB));
    double c2 = 0.5 * ((x0 / rootA) + (y0 / rootB));
    double time = 1.;
    if (c1 < 0.) {
        time *= (0.5 / (rootA * rootB))
                * Math.log((c2 / c1) * ((minRx * rootB - rootA) / (minRx * rootB + rootA)));
    } else {
        time *= (0.5 / (rootA * rootB))
                * Math.log((c2 / c1) * ((rootB - minRy * rootA) / (rootB + minRy * rootA)));
    }
    if (true) {
        //            System.out.println("time = " + time);
    }
    double remainingTime = this.maxTime - time - this.currentTime;
    //        if (remainingTime < 0) {
    //            time = this.maxTime - this.currentTime;
    //            remainingTime = 0.;
    //        }
    double nextD1 = getX(time, c1, c2, rootA, rootB);
    double nextD2 = getY(time, c1, c2, rootA, rootB);
    System.out.println("time = " + time + "  C1 = " + c1 + "  C2 = " + c2);
    int nextN1 = (int) (0.5 + nextD1);
    if (nextN1 < 1) {
        nextN1 = 0;
    }
    int nextN2 = (int) (0.5 + nextD2);
    if (nextN2 < 1) {
        nextN2 = 0;
    }

    this.currentTime += time;
    nextD1 = truncator.truncate(nextD1, 1.e-15);
    nextD2 = truncator.truncate(nextD2, 1.e-15);
    TimeStep step = new TimeStep((int) (0.5 + this.currentTime), nextN1, nextN2);
    DTimeStep dStep = new DTimeStep(this.currentTime, nextD1, nextD2);
    history.add(step);
    dHistory.add(dStep);
    f1.previousForceSize = f1.getForceSize();
    f1.setForceSize(nextD1);
    f2.previousForceSize = f2.getForceSize();
    f2.setForceSize(nextD2);
    //        System.out.println("del 1 = "+(f1.previousForceSize-f1.forceSize)+"  del 2 = "+(f2.previousForceSize-f2.forceSize));
}

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

/**
 * {@inheritDoc}//  w  w  w  .  j  a va  2  s  .co  m
 */
@Override
public Function1D<BatesGeneralizedJumpDiffusionModelDataBundle, Double> getPricingFunction(
        final OptionDefinition definition) {
    Validate.notNull(definition);
    final Function1D<BatesGeneralizedJumpDiffusionModelDataBundle, Double> pricingFunction = new Function1D<BatesGeneralizedJumpDiffusionModelDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final BatesGeneralizedJumpDiffusionModelDataBundle data) {
            Validate.notNull(data);
            final double s = data.getSpot();
            final YieldAndDiscountCurve discountCurve = data.getInterestRateCurve();
            final VolatilitySurface volSurface = data.getVolatilitySurface();
            final ZonedDateTime date = data.getDate();
            final double t = definition.getTimeToExpiry(date);
            final double k = definition.getStrike();
            final double sigma = data.getVolatility(t, k);
            double b = data.getCostOfCarry();
            final double lambda = data.getLambda();
            final double expectedJumpSize = data.getExpectedJumpSize();
            final double delta = data.getDelta();
            final double gamma = Math.log(1 + expectedJumpSize);
            final double sigmaSq = sigma * sigma;
            double z;
            final double lambdaT = lambda * t;
            double mult = Math.exp(-lambdaT);
            b -= lambda * expectedJumpSize;
            StandardOptionDataBundle bsmData = new StandardOptionDataBundle(discountCurve, b, volSurface, s,
                    date);
            final Function1D<StandardOptionDataBundle, Double> bsmFunction = BSM.getPricingFunction(definition);
            double price = mult * bsmFunction.evaluate(bsmData);
            for (int i = 1; i < N; i++) {
                z = Math.sqrt(sigmaSq + delta * delta * i / t);
                b += gamma / t;
                bsmData = bsmData.withVolatilitySurface(new VolatilitySurface(ConstantDoublesSurface.from(z)))
                        .withCostOfCarry(b);
                mult *= lambdaT / i;
                price += mult * bsmFunction.evaluate(bsmData);
            }
            return price;
        }
    };
    return pricingFunction;
}

From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.ranking.ProbabilityBased.java

/**
 * Calculates the weight for a split/*from   w w w.  ja  va 2  s.  c o  m*/
 * @param split
 * @return
 */
private float calcRank(Split split) {
    float result = 0;

    for (SplitElement elem : split.getSplits()) {
        result += -1 * Math.log(this.freq(elem).doubleValue() / FREQUENCY.doubleValue());
    }

    return result;
}

From source file:Randoms.java

/** Return a random double drawn from a Gaussian distribution with mean 0 and variance 1. */
public synchronized double nextGaussian() {
    if (!haveNextGaussian) {
        double v1 = nextUniform(), v2 = nextUniform();
        double x1, x2;
        x1 = Math.sqrt(-2 * Math.log(v1)) * Math.cos(2 * Math.PI * v2);
        x2 = Math.sqrt(-2 * Math.log(v1)) * Math.sin(2 * Math.PI * v2);
        nextGaussian = x2;//www . j  a  v  a 2  s  .com
        haveNextGaussian = true;
        return x1;
    } else {
        haveNextGaussian = false;
        return nextGaussian;
    }
}

From source file:com.itemanalysis.psychometrics.irt.estimation.ItemParamPriorLogNormal.java

/**
 * Second derivative of log density. Only compute part of the log of the density that depends on the parameter.
 *
 * @param p/*from w w  w  .  ja v a2 s. co  m*/
 * @return
 */
public double logDensityDeriv2(double p) {
    //Outside limits of distribution density does not change, so derivative is zero
    if (zeroDensity(p))
        return 0.0;
    double value = Math.log(p) - parameters[0] + variance - 1.0;
    value /= p * p * variance;
    return value;
}

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

private Double rightExtrapolateDerivative(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(data, "data");
    Validate.notNull(value, "value");
    final double x = data.lastKey();
    final double y = data.lastValue();
    final double m = Math.log(y) / x;
    return m * Math.exp(m * value);
}

From source file:ditl.sim.pnt.NodesPerCCReport.java

@Override
public void handle(long time, Collection<Object> arg1) throws IOException {
    int n_in_cc = 0;
    for (Integer n : group_sizes.values()) {
        n_in_cc += n;/*  w ww . j a v  a2  s  . c  o  m*/
    }
    int n_singletons = n_nodes - n_in_cc;
    int n_ccs = group_sizes.size() + n_singletons;
    double avg_cc_size = (double) n_nodes / (double) n_ccs;
    double score = Math.log(avg_cc_size) / Math.log(n_nodes);
    append(time, n_nodes + " " + group_sizes.size() + " " + n_singletons + " " + avg_cc_size + " " + score);
}

From source file:com.analog.lyric.dimple.factorfunctions.Gamma.java

@Override
public final double evalEnergy(Value[] arguments) {
    int index = 0;
    if (!_parametersConstant) {
        _alpha = arguments[index++].getDouble(); // First input is alpha parameter (must be non-negative)
        if (_alpha <= 0)
            return Double.POSITIVE_INFINITY;
        _beta = arguments[index++].getDouble(); // Second input is beta parameter (must be non-negative)
        if (_beta <= 0)
            return Double.POSITIVE_INFINITY;
        _logBeta = Math.log(_beta);
    }// w w  w  .ja v  a  2s  .  c o m
    final int length = arguments.length;
    final int N = length - index; // Number of non-parameter variables
    double sum = 0;
    if (_alpha == 1) {
        for (; index < length; index++) {
            double x = arguments[index].getDouble(); // Remaining inputs are Gamma variables
            if (x < 0)
                return Double.POSITIVE_INFINITY;
            else
                sum += x;
        }
        return sum * _beta - N * _logBeta;
    } else {
        if (!_parametersConstant) {
            _alphaMinusOne = _alpha - 1;
            _logGammaAlphaMinusAlphaLogBeta = org.apache.commons.math3.special.Gamma.logGamma(_alpha)
                    - _alpha * _logBeta;
        }
        for (; index < length; index++) {
            final double x = arguments[index].getDouble(); // Remaining inputs are Gamma variables
            if (x < 0)
                return Double.POSITIVE_INFINITY;
            else
                sum += x * _beta - Math.log(x) * _alphaMinusOne;
        }
        return sum + N * _logGammaAlphaMinusAlphaLogBeta;
    }
}

From source file:edu.cmu.tetrad.search.EstimateRank.java

public int Estimate(double[][] A, double[][] B, double alpha) {
    this.alpha = alpha;
    this.A = A;/*  w  w w  . ja  va  2 s  .  com*/
    this.B = B;
    double[] Cors = CanCor(A, B);
    int rank = 0;
    boolean reject = true;

    while (reject) {
        double sum = 0;
        int i;
        for (i = rank; i < Math.min(A[0].length, B[0].length); i++) {
            sum += Math.log(1 - Math.pow(Cors[i], 2));
        }
        double stat = -(A.length - .5 * (A[0].length + B[0].length + 3)) * sum;
        reject = ProbUtils.chisqCdf(stat, (A[0].length - rank) * (B[0].length - rank)) > (1 - alpha);
        if (reject & rank < Math.min(A[0].length, B[0].length)) {
            rank++;
        } else {
            reject = false;
        }
    }
    return rank;
}

From source file:main.java.repartition.RBPTA.java

private static double getEntropy(int p_a_trData, int p_b_trData) {
    double entropy = 0.0d;

    double p_total = p_a_trData + p_b_trData;
    entropy = (-(p_a_trData / p_total) * (Math.log(p_a_trData / p_total) / Math.log(2))
            - (p_b_trData / p_total) * (Math.log(p_b_trData / p_total) / Math.log(2)));

    return entropy;
}