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:gedi.util.math.stat.distributions.PoissonBinomial.java

private void preprocess() {
    int n = pp.length;
    m = n + 1;/* w  w  w .  ja  va  2s  .c  om*/
    int nextPowerOf2 = Integer.highestOneBit(m);
    if (nextPowerOf2 != m)
        nextPowerOf2 <<= 1;
    m = nextPowerOf2;
    n = m - 1;

    int ins = 0;
    int start = 0;
    for (int i = 1; i < pp.length; i++) {
        if (Math.abs(pp[i] - pp[start]) > 1E-10) {
            if (i - start > 1) {
                double p = pp[start];
                pp[ins++] = -(i - start);
                pp[ins++] = p;
            } else {
                pp[ins++] = pp[i - 1];
            }
            start = i;
        }
    }

    if (pp.length - start > 1) {
        double p = pp[start];
        pp[ins++] = -(pp.length - start);
        pp[ins++] = p;
    } else {
        pp[ins++] = pp[pp.length - 1];
    }

    double delta = 2 * Math.PI / m;
    z = new Complex[m];
    z[0] = new Complex(1, 0);

    for (int i = 1; i <= Math.ceil(n / 2.0); i++) {
        double tt = i * delta;

        //         for(int j=0;j<pp.length;j++)
        //         {
        //            double pj=j<opp.length?opp[j]:0;
        //            double ax=1-pj+pj*Math.cos(tt);
        //            double bx=pj*Math.sin(tt);
        //            double tmp1=Math.sqrt(ax*ax+bx*bx);
        //            double tmp2=Math.atan2(bx,ax); //atan2(x,y)
        //            c1o+=Math.log(tmp1);
        //            c2o+=tmp2;
        //         }

        double c1 = 0.00;
        double c2 = 0.00;
        for (int j = 0; j < ins; j++) {
            double pj = pp[j];
            double f = 1;
            if (pj < 0) {
                f = -pj;
                pj = pp[++j];
            }

            double ax = 1 - pj + pj * Math.cos(tt);
            double bx = pj * Math.sin(tt);
            double tmp1 = Math.sqrt(ax * ax + bx * bx);
            double tmp2 = Math.atan2(bx, ax); //atan2(x,y)
            c1 += Math.log(tmp1) * f;
            c2 += tmp2 * f;
        }
        z[i] = new Complex(Math.exp(c1) * Math.cos(c2), Math.exp(c1) * Math.sin(c2));
        z[z.length - i] = z[i].conjugate();
    }
    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
    z = fft.transform(z, TransformType.FORWARD);
}

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

private double getLambda1(final double sigma, final double t, final double skew) {
    final double q = Math.sqrt(Math.exp(sigma * sigma * t) - 1);
    final double skewDistribution = q * (3 + q * q);
    return skew - skewDistribution;
}

From source file:distributions.Gamma.java

public double getGammaDistribution(double gamma_func, double x, double alfa, double beta) {
    double value = 0;
    value = value + Math.pow(x, alfa - 1);
    value = value * (Math.exp(-(x / beta)));
    value = value / ((Math.pow(beta, alfa)) * gamma_func);
    return value;
}

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

/**
 * @param x The parameters for the function, $(x, y, \rho$, with $-1 \geq \rho \geq 1$, not null
 * @return The pdf  //from   ww  w  .  j  a  va 2  s .c  o  m
 */
@Override
public double getPDF(final double[] x) {
    Validate.notNull(x);
    Validate.isTrue(x.length == 3, "Need a, b and rho values");
    Validate.isTrue(x[2] >= -1 && x[2] <= 1, "Correlation must be >= -1 and <= 1");
    final double denom = 1 - x[2] * x[2];
    return Math.exp(-(x[0] * x[0] - 2 * x[2] * x[0] * x[1] + x[1] * x[1]) / (2 * denom))
            / (TWO_PI * Math.sqrt(denom));
}

From source file:etomica.math.SpecialFunctions.java

private static double gcf(double a, double x) {
    int imax = 500;
    double epsilon = 3.0e-12;
    double b = x + 1.0 - a;
    double c = 1.0 / Double.MIN_VALUE;
    double d = 1.0 / b;
    double h = d;
    for (int i = 0; i <= imax; i++) {
        double an = -i * (i - a);
        b += 2.0;//  w  w w .j  ava 2  s.c om
        d = an * d + b;
        if (Math.abs(d) < Double.MIN_VALUE)
            d = Double.MIN_VALUE;
        c = b + an / c;
        if (Math.abs(c) < Double.MIN_VALUE)
            c = Double.MIN_VALUE;
        d = 1.0 / d;
        double del = d * c;
        h *= del;
        if (Math.abs(del - 1.0) < epsilon)
            break;
    }
    return Math.exp(-x + a * Math.log(x) - lnGamma(a)) * h;
}

From source file:eagle.security.userprofile.model.kde.UserProfileKDEModeler.java

private void computeProbabilityDensityEstimation(RealMatrix inputMat) {

    probabilityEstimation = new double[inputMat.getRowDimension()];
    for (int i = 0; i < probabilityEstimation.length; i++)
        probabilityEstimation[i] = 1.0;//  ww w  .  j a v a 2  s. com

    for (int i = 0; i < inputMat.getRowDimension(); i++) {
        for (int j = 0; j < inputMat.getColumnDimension(); j++) {
            if (statistics[j].getStddev() > 0) {
                double stddev = statistics[j].getStddev();
                double mean = statistics[j].getMean();
                double sqrt2PI = Math.sqrt(2.0 * Math.PI);
                double denominatorFirstPart = sqrt2PI * stddev;
                double squareMeanNormal = Math.pow((inputMat.getEntry(i, j) - mean), 2);
                double twoPowStandardDev = Math.pow(stddev, 2);
                double twoTimesTwoPowStandardDev = 2.0 * twoPowStandardDev;
                probabilityEstimation[i] *= ((1.00 / denominatorFirstPart)
                        * (Math.exp(-(squareMeanNormal / twoTimesTwoPowStandardDev))));
            }
        }
    }

    java.util.List<Double> listProb = new ArrayList<Double>();
    for (int i = 0; i < probabilityEstimation.length; i++) {
        probabilityEstimation[i] = Math.log10(probabilityEstimation[i]);
        listProb.add(probabilityEstimation[i]);
    }

    Collections.sort(listProb);
    int i = 0;
    for (double d : listProb)
        probabilityEstimation[i++] = d;

    minProbabilityEstimate = probabilityEstimation[probabilityEstimation.length - 1];
    maxProbabilityEstimate = probabilityEstimation[0];

    int len = probabilityEstimation.length;
    int nintyFivePercentIndex = (int) Math.round(0.05 * len);
    int medianPercentIndex = (int) Math.round(0.5 * len);
    if (medianPercentIndex >= len)
        medianProbabilityEstimate = probabilityEstimation[medianPercentIndex - 1];
    else
        medianProbabilityEstimate = probabilityEstimation[medianPercentIndex];
    nintyFivePercentileEstimate = probabilityEstimation[nintyFivePercentIndex];
}

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

@Override
public final double evalEnergy(Value[] arguments) {
    int index = 0;
    if (!_NParameterConstant) {
        _N = arguments[index++].getInt(); // First argument is N parameter
        if (_N < 0)
            return Double.POSITIVE_INFINITY;
        _negativeLogFactorialN = -org.apache.commons.math3.special.Gamma.logGamma(_N + 1);
    }//w w  w.j a  v a2s. co  m

    for (int i = 0; i < _dimension; i++)
        _alpha[i] = arguments[index++].getDouble(); // Next _dimension arguments are vector of Alpha parameters

    if (arguments.length - index != _dimension)
        throw new DimpleException(
                "Number of count variables must equal the dimension of the parameter vector.");

    int countSum = 0;
    double parameterSum = 0;
    double sum = _negativeLogFactorialN;
    for (int i = 0; i < _dimension; i++) {
        final double alphai = _alpha[i];
        parameterSum += Math.exp(-alphai);

        final int x = arguments[index++].getInt(); // Remaining arguments are discrete count variables
        if (x < 0)
            return Double.POSITIVE_INFINITY;
        countSum += x;

        sum += x * alphai + org.apache.commons.math3.special.Gamma.logGamma(x + 1);
    }
    if (countSum != _N)
        return Double.POSITIVE_INFINITY;

    final double energy = sum + _N * Math.log(parameterSum);
    if (energy != energy) // Faster isNaN
        return Double.POSITIVE_INFINITY;

    return energy;
}

From source file:com.opengamma.analytics.financial.interestrate.annuity.YieldSensitivityCalculator.java

/**
 * Calculate the present value of a set of cash flows given a yield 
 * @param annuity  Set of known cash flows 
 * @param yield Continuously compounded constant interest rate 
 * @return Present value (dirty price)/*from  w ww  . java  2 s . c o  m*/
 */
public double calculatePriceForYield(final AnnuityCouponFixed annuity, final double yield) {
    Validate.notNull(annuity, "annuity");
    double sum = 0;

    final int n = annuity.getNumberOfPayments();
    CouponFixed temp;
    for (int i = 0; i < n; i++) {
        temp = annuity.getNthPayment(i);
        sum += temp.getAmount() * Math.exp(-yield * temp.getPaymentTime());
    }
    return sum;
}

From source file:moa.classifiers.core.statisticaltests.Cramer.java

private double phiBahr(double x) {
    return (1 - Math.exp(-x / 2));
}

From source file:edu.cmu.tetrad.data.GeneralAndersonDarlingTest.java

private void runTest() {
    int n = data.size();
    double h = 0.0;

    int numSummed = 0;

    for (int i = 1; i <= n; i++) {
        double x1 = data.get(i - 1);
        double a1 = Math.log(dist.cumulativeProbability(x1));

        double x2 = data.get(n + 1 - i - 1);
        double a2 = Math.log(1.0 - dist.cumulativeProbability(x2));

        double k = (2 * i - 1) * (a1 + a2);

        if (!(Double.isNaN(a1) || Double.isNaN(a2) || Double.isInfinite(a1) || Double.isInfinite(a2))) {
            h += k;/*from w ww  .  j  av  a  2  s  . c  o m*/
            numSummed++;
        }
    }

    double a = -n - (1.0 / numSummed) * h;
    double aa = (1 + 0.75 / numSummed + 2.25 / Math.pow(numSummed, 2)) * a;
    double p;

    if (aa < 0.2) {
        p = 1 - Math.exp(-13.436 + 101.14 * aa - 223.73 * aa * aa);
    } else if (aa < 0.34) {
        p = 1 - Math.exp(-8.318 + 42.796 * aa - 59.938 * aa * aa);
    } else if (aa < 0.6) {
        p = Math.exp(0.9177 - 4.279 * aa - 1.38 * aa * aa);
    } else {
        p = Math.exp(1.2937 - 5.709 * aa + 0.0186 * aa * aa);
    }

    this.aSquared = a;
    this.aSquaredStar = aa;
    this.p = p;
}