Example usage for java.lang Math exp

List of usage examples for java.lang Math exp

Introduction

In this page you can find the example usage for java.lang Math exp.

Prototype

@HotSpotIntrinsicCandidate
public static double exp(double a) 

Source Link

Document

Returns Euler's number e raised to the power of a double value.

Usage

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

protected double getH(final double r, final double t) {
    return 1 - Math.exp(-r * t);
}

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

private double getA(final double d2, final double k, final double sigmaT) {
    return Math.exp(-d2 * d2 / 2.) / k / sigmaT / Math.sqrt(2 * Math.PI);
}

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

protected Function1D<Double, Double> getMedian(final double sigma, final int i, final double dt,
        final double[][] q, final double p) {
    return new Function1D<Double, Double>() {

        @Override/* www . j ava 2 s  .com*/
        public Double evaluate(final Double u) {
            double sum = 0.;
            final double dtSqrt = Math.sqrt(dt);
            for (int j = -i, k = 0; j <= i; j += 2, k++) {
                sum += q[i][k] / (1 + u * Math.exp(sigma * j * dtSqrt) * dt);

            }
            return sum - p;
        }
    };
}

From source file:com.opengamma.analytics.financial.interestrate.inflation.method.InflationMarketModelConvexityAdjustmentForCoupon.java

/**
 * Computes the convexity adjustment for year on year inflation coupon with a monthly index.
 * @param coupon The year on year coupon.
 * @param inflationConvexity The inflation provider.
 * @return The convexity adjustment./* w w  w  .j a  v  a2  s.  c o  m*/
 */
public double getYearOnYearConvexityAdjustment(final CouponInflationYearOnYearMonthly coupon,
        final InflationConvexityAdjustmentProviderInterface inflationConvexity) {
    Validate.notNull(coupon, "Coupon");
    Validate.notNull(inflationConvexity, "Inflation");

    final double firstFixingTime = coupon.getReferenceStartTime();
    final double secondFixingTime = coupon.getReferenceEndTime();
    final double firstNaturalPaymentTime = coupon.getNaturalPaymentStartTime();
    final double secondNaturalPaymentTime = coupon.getNaturalPaymentEndTime();
    final double paymentTime = coupon.getPaymentTime();
    final double volatilityStart = inflationConvexity.getInflationConvexityAdjustmentParameters()
            .getPriceIndexAtmVolatility()[0];
    final double volatilityEnd = inflationConvexity.getInflationConvexityAdjustmentParameters()
            .getPriceIndexAtmVolatility()[1];
    final double correlationInflation = inflationConvexity.getInflationConvexityAdjustmentParameters()
            .getPriceIndexCorrelation().getZValue(firstFixingTime, secondFixingTime);
    final double correlationInflationRateStart = inflationConvexity.getInflationConvexityAdjustmentParameters()
            .getPriceIndexRateCorrelation().getYValue(firstFixingTime);
    final double correlationInflationRateEnd = inflationConvexity.getInflationConvexityAdjustmentParameters()
            .getPriceIndexRateCorrelation().getYValue(secondFixingTime);
    final double volBondForwardStart = getVolBondForward(firstNaturalPaymentTime, paymentTime,
            inflationConvexity);
    final double volBondForwardEnd = getVolBondForward(secondNaturalPaymentTime, paymentTime,
            inflationConvexity);
    final double adjustment = volatilityStart
            * (volatilityStart - volatilityEnd * correlationInflation
                    - volBondForwardStart * correlationInflationRateStart)
            * firstNaturalPaymentTime
            + volatilityEnd * volBondForwardEnd * correlationInflationRateEnd * secondNaturalPaymentTime;
    return Math.exp(adjustment);

}

From source file:com.itemanalysis.psychometrics.irt.model.IrmPCM.java

private double numer(double theta, double[] iparam, int category, double D) {
    double Zk = 0;
    double b = iparam[0];
    double[] s = Arrays.copyOfRange(iparam, 1, iparam.length);

    //first category
    Zk = D * (theta - b);//w  ww. ja  v a 2  s  .  c o  m

    for (int k = 0; k < category; k++) {
        Zk += D * (theta - b - s[k]);
    }
    return Math.exp(Zk);
}

From source file:edu.tum.cs.vis.model.util.HandleComparator.java

/**
 * Returns the result of (input it to Wolfram Alpha to get nicer view):
 * Piecewise[{{(exp(x*8/a)-1)/exp(8), x < a}, {1, a <= x <= b},{1/Gamma((1/(b-a))*(x+b-2a))
 * ,x>b}}] Where a = minVal, b=maxVal
 * /*from w ww. j  a va 2  s .  com*/
 * @param x
 *            value to calculate weight for
 * @param minVal
 *            min value
 * @param maxVal
 *            max value
 * @return the weight for x
 */
private static double getWeight(double x, double minVal, double maxVal) {
    if (x == 0)
        return minVal > 0 ? 0 : 1;
    if (x < minVal)
        return (Math.exp(x * 8 / minVal) - 1) / Math.exp(8);
    else if (x > maxVal)
        return 1 / Gamma.gamma((1 / (maxVal - minVal)) * (x + maxVal - 2 * minVal));
    else
        return 1;
}

From source file:de.tudarmstadt.ukp.dkpro.spelling.detector.ngram.LMBasedDetector.java

protected double getSentenceProbability(List<String> words) throws AnalysisEngineProcessException {
    double sentenceProbability = 0.0;

    if (words.size() < 1) {
        return 0.0;
    }/*from  w  ww.  j av  a2s  .co  m*/

    long nrOfUnigrams;
    try {
        nrOfUnigrams = provider.getNrOfTokens();
    } catch (Exception e) {
        throw new AnalysisEngineProcessException(e);
    }

    List<String> trigrams = new ArrayList<String>();

    // in the google n-grams this is not represented (only single BOS markers)
    // but I leave it in place in case we add another n-gram provider
    trigrams.add(NGramDetectorUtils.getTrigram(BOS, BOS, words.get(0)));

    if (words.size() > 1) {
        trigrams.add(NGramDetectorUtils.getTrigram(BOS, words.get(0), words.get(1)));
    }

    for (String trigram : new NGramStringIterable(words, 3, 3)) {
        trigrams.add(trigram);
    }

    // FIXME - implement backoff or linear interpolation

    for (String trigram : trigrams) {
        long trigramFreq = getNGramCount(trigram);

        String[] parts = StringUtils.split(trigram, " ");

        String bigram = StringUtils.join(Arrays.copyOfRange(parts, 0, 2), " ");
        long bigramFreq = getNGramCount(bigram);

        String unigram = StringUtils.join(Arrays.copyOfRange(parts, 0, 1), " ");
        long unigramFreq = getNGramCount(unigram);

        if (trigramFreq < 1) {
            trigramFreq = 1;
        }
        if (bigramFreq < 1) {
            bigramFreq = 1;
        }
        if (unigramFreq < 1) {
            unigramFreq = 1;
        }

        double trigramProb = Math.log((double) trigramFreq / bigramFreq);
        double bigramProb = Math.log((double) bigramFreq / unigramFreq);
        double unigramProb = Math.log((double) unigramFreq / nrOfUnigrams);

        double interpolated = (trigramProb + bigramProb + unigramProb) / 3.0;

        sentenceProbability += interpolated;
    }

    return Math.exp(sentenceProbability);
}

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

/**
 * probability density function of the Gamma distribution
 *
 * @param x     argument//from w ww .ja v a 2  s .c  o  m
 * @param shape shape parameter
 * @param scale scale parameter
 * @return pdf value
 */
public static double pdf(double x, double shape, double scale) {
    // return Math.pow(scale,-shape)*Math.pow(x, shape-1.0)/
    // Math.exp(x/scale + GammaFunction.lnGamma(shape));
    if (x < 0)
        return 0; // to make BEAUti plot continue
    //            throw new IllegalArgumentException();
    if (x == 0) {
        if (shape == 1.0)
            return 1.0 / scale;
        else
            return 0.0;
    }

    if (shape == 0.0) // uninformative
        return 1.0 / x;

    if (shape == -0.5) { // Gelman 2008, hierarchical variance, -1 degrees of freedom
        return Math.sqrt(x);
    }

    final double xs = x / scale;

    if (shape == 1.0) {
        return Math.exp(-xs) / scale;
    }

    final double a = Math.exp((shape - 1.0) * Math.log(xs) - xs - GammaFunction.lnGamma(shape));

    return a / scale;
}

From source file:com.itemanalysis.psychometrics.irt.model.Irm4PL.java

private double probRight(double theta) {
    if (guessing < 0)
        return 0;
    double top = Math.exp(D * discrimination * (theta - difficulty));
    double prob = guessing + (slipping - guessing) * top / (1 + top);
    return prob;//  w ww  .j a v  a 2s .  c o m
}

From source file:geogebra.kernel.AlgoBinomial.java

private double BinomLog(double n, double r) {
    // exact for n<=37
    // also  if r<2.8+Math.exp((250-n)/100) && n<59000
    // eg Binom2(38,19) is wrong
    return Math.floor(
            0.5 + Math.exp(Gamma.logGamma(n + 1d) - Gamma.logGamma(r + 1) - Gamma.logGamma((n - r) + 1)));
}