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:utils.RandomVariable.java

/**
 * Generate a random number from a Gaussian (Normal) random variable.
 *
 * @param mu mean of the random variable.
 * @param sigma standard deviation of the random variable.
 * @return a double.//from   w w  w  .j ava 2 s . co  m
 */
public static double normal(double mu, double sigma) {
    double x = mu + sigma * Math.cos(2 * Math.PI * rand()) * Math.sqrt(-2 * Math.log(rand()));
    return x;
}

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

@Override
public double getInterestRate(final Double time) {
    if (Math.abs(time) > SMALL_TIME) {
        return -Math.log(getDiscountFactor(time)) / time;
    }//from   w  w w . java 2 s.c  o m
    // Implementation note: if time too close to 0, compute the limit for t->0.
    final double dfP = getDiscountFactor(time + SMALL_TIME);
    final double df = getDiscountFactor(time);
    return (df - dfP) / (SMALL_TIME * df);
}

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

@org.junit.Test
public void test() {
    double[] a = { .3, .03, .01 };

    List<Double> logs = new ArrayList<>();

    for (double _a : a) {
        logs.add(Math.log(_a));
    }//from  w w  w . j  a  va  2s.c  om

    double sum = 0.0;

    for (double _a : a) {
        sum += _a;
    }

    double logsum = logOfSum(logs);

    System.out.println(Math.exp(logsum) + " " + sum);
}

From source file:it.unibo.alchemist.modelchecker.AlchemistASMC.java

/**
 * Given the runs and the confidence, computes an upper bound for the
 * approximation (see manual)./*from w  w  w  .j  a v  a2s .  c  om*/
 * 
 * @param n
 *            number of runs
 * @param alpha
 *            confidence
 * @return the approximation
 */
public static double computeDeltaUB(final int n, final double alpha) {
    return Math.sqrt((LOG_MUL * Math.log(2 / alpha)) / n);
}

From source file:master.steppers.SALStepper.java

/**
 * Generate appropriate random state change according to Sehl's
 * step anticipation tau-leaping algorithm.
 *
 * @param reaction/*  ww  w.j a  va  2 s  .  co m*/
 * @param state PopulationState to modify.
 * @param model
 * @param calcLogP
 * @param thisdt
 */
public void leap(Reaction reaction, PopulationState state, Model model, boolean calcLogP, double thisdt) {

    // Calculate corrected rate
    double rho = reaction.getPropensity() * thisdt + 0.5 * corrections.get(reaction) * thisdt * thisdt;

    // Draw number of reactions to fire within time tau:
    double q = Randomizer.nextPoisson(rho);

    if (calcLogP) {
        if (rho > 0)
            stepLogP += -rho + q * Math.log(rho / thisdt) - Gamma.logGamma(q + 1);
    }

    // Implement reactions:
    state.implementReaction(reaction, q);

    // Increment event counter:
    eventCount += q;

}

From source file:com.analog.lyric.dimple.solvers.core.parameterizedMessages.GammaParameters.java

@Override
public double evalEnergy(Value value) {
    final double x = value.getDouble();
    if (x < 0) {
        return Double.POSITIVE_INFINITY;
    }/*from   ww w.ja v  a2s. c  o m*/

    if (_alphaMinusOne == 0.0) {
        return x * _beta;
    } else {
        return x * _beta - Math.log(x) * _alphaMinusOne;
    }
}

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

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

        @SuppressWarnings("synthetic-access")
        @Override/*ww  w . ja  va  2  s.  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();
            if (CompareUtils.closeEquals(nu, 0, EPS)) {
                if (CompareUtils.closeEquals(beta, 1.0, EPS)) {
                    return alpha; // this is just log-normal
                }
                throw new NotImplementedException("Have not implemented the case where nu = 0, beta != 0");
            }
            if (beta > 0) {
                final double sigmaDD = alpha * beta * Math.pow(forward, beta - 1);
                final double eta = (1 - beta) / beta * forward;
                double sigmaBlend;
                if (CompareUtils.closeEquals(forward, k, EPS)) {
                    sigmaBlend = sigmaDD;
                } else {
                    final double z = nu / sigmaDD * Math.log((forward + eta) / (k + eta));
                    final double sigmaBBF = sigmaDD * z
                            / Math.log((z - rho + Math.sqrt(1 - 2 * rho * z + z * z)) / (1 - rho));
                    final double sigmaTrunc = sigmaDD
                            * Math.pow(1 - 4 * rho * z + (4.0 / 3.0 + 5 * rho * rho) * z * z, 1.0 / 8.0);
                    final double w = Math.min(1.0, 1.0 / nu / Math.sqrt(t));
                    sigmaBlend = 1.0 / (w / sigmaBBF + (1 - w) / sigmaTrunc);
                }
                sigmaBlend *= 1 + (rho * nu * sigmaDD / 4 + (2 - 3 * rho * rho) * nu * nu / 24) * t;
                final double sigmaCEV = sigmaBlend * Math.pow(forward, 1 - beta) / beta;
                final CEVFunctionData cevData = new CEVFunctionData(forward, 1, sigmaCEV, beta);
                final double price = priceFunction.evaluate(cevData);
                return BLACK_IMPLIED_VOL.getImpliedVolatility(new BlackFunctionData(forward, 1, sigmaCEV),
                        option, price);
            }
            throw new NotImplementedException("Have not implemented the case where b <= 0");
        }
    };
}

From source file:com.github.gdfm.shobaidogu.StatsUtils.java

/**
 * Computes the KullbackLeibler divergence between two distributions. Assumes that m = (p + q) / 2. Thus p and q are
 * subsets of m and I can ignore corner cases where frequencies are zero.
 * //ww  w  .j  a  v  a2 s .co m
 * @param pq
 * @param m
 * @return
 */
private static <K, V extends Number> double KLdivergence(Map<K, V> pq, Map<K, Double> m) {
    checkNotNull(pq);
    checkNotNull(m);
    double sum = 0;
    for (Entry<K, V> pEntry : pq.entrySet()) {
        double pi = pEntry.getValue().doubleValue();
        double mi = m.get(pEntry.getKey()).doubleValue();
        sum += pi * Math.log(pi / mi);
    }
    return sum;
}

From source file:eu.amidst.core.exponentialfamily.EF_InverseGamma.java

/**
 * {@inheritDoc}/* ww  w .j a v a  2  s . com*/
 */
@Override
public SufficientStatistics getSufficientStatistics(double val) {
    SufficientStatistics vec = this.createZeroSufficientStatistics();
    vec.set(LOGX, Math.log(val));
    vec.set(INVX, 1.0 / val);
    return vec;
}

From source file:com.opengamma.analytics.math.statistics.distribution.LaplaceDistribution.java

/**
 * {@inheritDoc}//w w  w  .ja v a2 s  . c  o  m
 */
@Override
public double nextRandom() {
    final double u = _engine.nextDouble() - 0.5;
    return _mu - _b * Math.signum(u) * Math.log(1 - 2 * Math.abs(u));
}