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:math2605.gn_log.java

private static void setJ(List<String[]> pairs, double a, double b, double c, RealMatrix r, RealMatrix J) {
    for (int i = 0; i < r.getRowDimension(); i++) {
        double x = Double.parseDouble(pairs.get(i)[0]);
        for (int j = 0; j < 3; j++) {
            double entry = -1;
            if (j == 0) {
                entry = -(Math.log(x + b));
            } else if (j == 1) {
                entry = -a / (x + b);// www .j a  v  a2 s  . co m
            }
            J.setEntry(i, j, entry);
        }
    }
}

From source file:com.opengamma.analytics.financial.model.volatility.smile.function.SABRBerestyckiVolatilityFunction.java

@Override
public Function1D<SABRFormulaData, Double> getVolatilityFunction(final EuropeanVanillaOption option,
        final double forward) {
    Validate.notNull(option, "option");
    final double strike = option.getStrike();

    final double cutoff = forward * CUTOFF_MONEYNESS;
    final double k;
    if (strike < cutoff) {
        s_logger.info("Given strike of " + strike + " is less than cutoff at " + cutoff
                + ", therefore the strike is taken as " + cutoff);
        k = cutoff;//from  w  w  w. j a  v  a 2  s  .  com
    } else {
        k = strike;
    }

    final double t = option.getTimeToExpiry();
    return new Function1D<SABRFormulaData, Double>() {

        @Override
        public final Double evaluate(final SABRFormulaData data) {
            Validate.notNull(data, "data");
            final double alpha = data.getAlpha();
            final double beta = data.getBeta();
            final double rho = data.getRho();
            final double nu = data.getNu();
            double i0;
            final double beta1 = 1 - beta;

            if (CompareUtils.closeEquals(forward, k, EPS)) {
                i0 = alpha / Math.pow(k, beta1);
            } else {

                final double x = Math.log(forward / k);

                if (CompareUtils.closeEquals(nu, 0, EPS)) {
                    if (CompareUtils.closeEquals(beta, 1.0, EPS)) {
                        return alpha; // this is just log-normal
                    }
                    i0 = x * alpha * beta1 / (Math.pow(forward, beta1) - Math.pow(k, beta1));
                } else {

                    double z;
                    if (beta == 1.0) {
                        z = nu * x / alpha;

                    } else {
                        z = nu * (Math.pow(forward, beta1) - Math.pow(k, beta1)) / alpha / beta1;
                    }
                    final double temp = (Math.sqrt(1 + z * (z - 2 * rho)) + z - rho) / (1 - rho);
                    i0 = nu * x / Math.log(temp);

                }
            }

            final double f1sqrt = Math.pow(forward * k, beta1 / 2);
            final double i1 = beta1 * beta1 * alpha * alpha / 24 / f1sqrt / f1sqrt
                    + rho * alpha * beta * nu / 4 / f1sqrt + nu * nu * (2 - 3 * rho * rho) / 24;

            return i0 * (1 + i1 * t);
        }
    };
}

From source file:com.cloudera.oryx.rdf.common.information.NumericalInformation.java

static Pair<Decision, Double> bestGain(Iterable<Decision> decisions, ExampleSet examples) {

    UpdatableVariance varianceNegativeStat = new UpdatableVariance();

    // Start with everything considered a negative example:
    for (Example example : examples) {
        float value = ((NumericFeature) example.getTarget()).getValue();
        varianceNegativeStat.increment(value);
    }//from   www .  j ava  2s  .c o  m

    // Save this off
    double varianceAll = varianceNegativeStat.getResult();
    if (Double.isNaN(varianceAll) || varianceAll <= 0.0) {
        // Weird case, no information at all
        return null;
    }
    // Entropy in nats is ln (stdev * sqrt(2*pi*e)) = ln(stdev) + 0.5*ln(2*pi*e) = 0.5*ln(variance) + ...
    // Actually to compute gain, we only need to know the ln(variance) since the additive constants will
    // fall out when we take the difference in entropies.
    //double entropyAll = 0.5 * Math.log(varianceAll) + HALF_LN_2_PI_E;
    double logVarianceAll = Math.log(varianceAll);

    List<Example> exampleList = examples.getExamples();
    BitSet notYetPositiveExamples = new BitSet(exampleList.size());
    notYetPositiveExamples.set(0, exampleList.size());
    Decision bestDecision = null;
    double bestGain = Double.NEGATIVE_INFINITY;
    UpdatableVariance variancePositiveStat = new UpdatableVariance();

    for (Decision decision : decisions) {
        boolean noChange = true;
        int nextNotYetPositive = -1;
        while ((nextNotYetPositive = notYetPositiveExamples.nextSetBit(nextNotYetPositive + 1)) >= 0) {
            Example example = exampleList.get(nextNotYetPositive);
            if (decision.isPositive(example)) {
                noChange = false;
                float value = ((NumericFeature) example.getTarget()).getValue();
                varianceNegativeStat.decrement(value);
                variancePositiveStat.increment(value);
                notYetPositiveExamples.clear(nextNotYetPositive);
            }
        }
        if (noChange) {
            continue;
        }

        double variancePositive = variancePositiveStat.getResult();
        double varianceNegative = varianceNegativeStat.getResult();
        if (Double.isNaN(variancePositive) || variancePositive <= 0.0 || Double.isNaN(varianceNegative)
                || varianceNegative <= 0.0) {
            continue;
        }

        //double entropyNegative = 0.5 * Math.log(varianceNegative) + HALF_LN_2_PI_E;
        //double entropyPositive = 0.5 * Math.log(variancePositive) + HALF_LN_2_PI_E;
        double logVarianceNegative = Math.log(varianceNegative);
        double logVariancePositive = Math.log(variancePositive);
        long numNegative = varianceNegativeStat.getN();
        long numPositive = variancePositiveStat.getN();
        //double oldgain = entropyAll -
        //    (numNegative * entropyNegative + numPositive * entropyPositive) / (numNegative + numPositive);
        double gain = 0.5
                * (logVarianceAll - (numNegative * logVarianceNegative + numPositive * logVariancePositive)
                        / (numNegative + numPositive));
        if (gain > bestGain) {
            bestGain = gain;
            bestDecision = decision;
        }
    }

    return bestDecision == null ? null : new Pair<Decision, Double>(bestDecision, bestGain);
}

From source file:com.opengamma.analytics.financial.model.volatility.smile.function.SABRHaganAlternativeVolatilityFunction.java

@Override
public Function1D<SABRFormulaData, Double> getVolatilityFunction(final EuropeanVanillaOption option,
        final double forward) {
    Validate.notNull(option, "option");
    final double strike = option.getStrike();
    final double t = option.getTimeToExpiry();
    return new Function1D<SABRFormulaData, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override//from www  . ja v a2s . c om
        public final Double evaluate(final SABRFormulaData data) {
            Validate.notNull(data, "data");
            final double alpha = data.getAlpha();
            final double beta = data.getBeta();
            final double rho = data.getRho();
            final double nu = data.getNu();

            final double cutoff = forward * CUTOFF_MONEYNESS;
            final double k;
            if (strike < cutoff) {
                s_logger.info("Given strike of " + strike + " is less than cutoff at " + cutoff
                        + ", therefore the strike is taken as " + cutoff);
                k = cutoff;
            } else {
                k = strike;
            }

            double i0;
            final double beta1 = 1 - beta;
            if (CompareUtils.closeEquals(forward, k, EPS)) {
                i0 = alpha / Math.pow(k, beta1);
            } else {
                final double x = Math.log(forward / k);
                if (CompareUtils.closeEquals(nu, 0, EPS)) {
                    if (CompareUtils.closeEquals(beta, 1.0, EPS)) {
                        return alpha; // this is just log-normal
                    }
                    i0 = x * alpha * beta1 / (Math.pow(forward, beta1) - Math.pow(k, beta1));
                } else {
                    double z, zeta;
                    if (beta == 1.0) {
                        z = nu * x / alpha;
                        zeta = z;
                    } else {
                        z = nu * (Math.pow(forward, beta1) - Math.pow(k, beta1)) / alpha / beta1;
                        zeta = nu * (forward - k) / alpha / Math.pow(forward * k, beta / 2);
                    }
                    final double temp = (Math.sqrt(1 + zeta * (zeta - 2 * rho)) + zeta - rho) / (1 - rho);
                    i0 = nu * x * zeta / z / Math.log(temp);
                }
            }
            final double f1sqrt = Math.pow(forward * k, beta1 / 2);
            final double i1 = beta1 * beta1 * alpha * alpha / 24 / f1sqrt / f1sqrt
                    + rho * alpha * beta * nu / 4 / f1sqrt + nu * nu * (2 - 3 * rho * rho) / 24;
            return i0 * (1 + i1 * t);
        }
    };
}

From source file:mastodon.algorithms.SABisectionAlgorithm.java

protected void initialize() {
    stub = "SA Bi.";

    pruningFreq = new HashMap<Integer, Integer>();
    for (int i = 0; i < bts.getTaxaCount(); i++) {
        pruningFreq.put(i, 0);/*from w w  w  .j a  v  a2 s  .  co  m*/
    }

    currTemp = initTemp;

    kLeft = minPrunedSpeciesCount;
    kRight = maxPrunedSpeciesCount;
    currPrunedSpeciesCount = (int) ((kRight + kLeft) / 2);

    int numberOfSteps = (int) ((Math.log(maxPrunedSpeciesCount - minPrunedSpeciesCount)) / Math.log(2));
    stepIterations = totalIterations / numberOfSteps;
    totalIterations = numberOfSteps * stepIterations; //adjust for rounding

    maxScore = new double[2];

    coolingRate = Math.pow(finalTemp / initTemp, 1.0 / stepIterations);

    iterationCounter = 0;
}

From source file:de.unijena.bioinf.IsotopePatternAnalysis.scoring.MassDifferenceDeviationScorer.java

@Override
public double score(Spectrum<Peak> measured, Spectrum<Peak> theoretical, Normalization norm,
        Ms2Experiment experiment, MeasurementProfile profile) {
    final double mz0 = measured.getMzAt(0);
    final double thMz0 = theoretical.getMzAt(0);
    double score = 0d;
    for (int i = 0; i < measured.size(); ++i) {
        final double mz = measured.getMzAt(i) - (i == 0 ? 0 : measured.getMzAt(i - 1));
        final double thMz = theoretical.getMzAt(i) - (i == 0 ? 0 : theoretical.getMzAt(i - 1));
        final double intensity = measured.getIntensityAt(i);
        // TODO: thMz hier richtig?
        final double sd = profile.getStandardMassDifferenceDeviation().absoluteFor(measured.getMzAt(i))
                * dependency.getValueAt(intensity);
        score += Math.log(Erf.erfc(Math.abs(thMz - mz) / (root2 * sd)));
    }//from w  ww .j a v a2s  .  c om
    return score;
}

From source file:edu.asu.ca.kaushik.algorithms.twostage.TwoStageColoring.java

@Override
protected int partialArraySize(int t, int k, int v) {
    double vpowt = Math.pow(v, t);
    double n1 = Math.ceil(
            Math.log(CombinatoricsUtils.binomialCoefficientDouble(k, t) * vpowt * Math.log(vpowt / (vpowt - 1)))
                    / Math.log(vpowt / (vpowt - 1)));
    double denom = Math.log(1 - (1 / vpowt));
    double n = (Math.log(this.times) + n1 * denom) / denom;
    return (int) Math.ceil(n);
}

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

/**
 * the natural log of the probability density function of the distribution
 *
 * @param x  argument/*from w  ww .  ja  va2 s  .co m*/
 * @param m  mean
 * @param sd standard deviation
 * @return log pdf at x
 */
public static double logPdf(double x, double m, double sd) {
    double a = 1.0 / (Math.sqrt(2.0 * Math.PI) * sd);
    double b = -(x - m) * (x - m) / (2.0 * sd * sd);

    return Math.log(a) + b;
}

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

public InverseGamma(double alpha, double beta) {
    this();/* www  .ja va2  s. co m*/
    _alpha = alpha;
    _beta = beta;
    _alphaPlusOne = _alpha + 1;
    _logGammaAlphaMinusAlphaLogBeta = org.apache.commons.math3.special.Gamma.logGamma(_alpha)
            - _alpha * Math.log(_beta);
    _parametersConstant = true;
    _firstDirectedToIndex = 0;
    if (_alpha <= 0)
        throw new DimpleException("Non-positive alpha parameter. This must be a positive value.");
    if (_beta <= 0)
        throw new DimpleException("Non-positive beta parameter. This must be a positive value.");
}

From source file:etymology.util.EtyMath.java

public static double xlogx(double x) {
    if (x == 0) {
        return 0;
    }/*from  w w  w .  j  av a  2s . c  o  m*/
    return x * Math.log(x);
}