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:br.upe.ecomp.doss.algorithm.apso.APSO.java

private void adaptParameters(double evolFactor) {
    RandomData random = new RandomDataImpl();
    double accelerationRate = random.nextUniform(0.05, 0.1);
    double c1 = getC1();
    double c2 = getC2();
    if (currentEvolutionaryState.equals(EnumEvolutionaryState.CONVERGENCE)) {
        // C1 - increase slightly | C2 increase slightly
        c1 = c1 + (c1 * accelerationRate * 0.5);
        c2 = c2 + (c2 * accelerationRate * 0.5);
    } else if (currentEvolutionaryState.equals(EnumEvolutionaryState.EXPLOITATION)) {
        // C1 - increase | C2 decrease
        c1 = c1 + (c1 * accelerationRate);
        c2 = c2 - (c2 * accelerationRate);
    } else if (currentEvolutionaryState.equals(EnumEvolutionaryState.EXPLORATION)) {
        // C1 - increase slightly | C2 decrease slightly
        c1 = c1 + (c1 * accelerationRate * 0.5);
        c2 = c2 - (c2 * accelerationRate * 0.5);
    } else if (currentEvolutionaryState.equals(EnumEvolutionaryState.JUMPING_OUT)) {
        // C1 - decrease | C2 increase
        c1 = c1 - (c1 * accelerationRate);
        c2 = c2 + (c2 * accelerationRate);
    }/*from w  w  w.ja  va  2 s . c  o m*/
    // Normalization
    if ((c1 + c2) > (cMin + cMax)) {
        double c1Temp = c1;
        double c2Temp = c2;
        c1Temp = c1 * (cMin + cMax) / (c1 + c2);
        c2Temp = c2 * (cMin + cMax) / (c1 + c2);
        c1 = c1Temp;
        c2 = c2Temp;
    }

    // Verify and adjust C1 and C2 by bounds
    if (c1 < cMin) {
        c1 = cMin;
    }
    if (c2 < cMin) {
        c2 = cMin;
    }
    if (c1 > cMax) {
        c1 = cMax;
    }
    if (c2 > cMax) {
        c2 = cMax;
    }

    setC1(c1);
    setC2(c2);

    // Adapt inertia weight
    double inertiaWeight = 1 / (1 + 1.5 * Math.exp(-2.6 * evolFactor));
    // Verify and adjust inertia weight by bounds
    if (inertiaWeight < inertiaWeightMin) {
        inertiaWeight = inertiaWeightMin;
    }
    if (inertiaWeight > inertiaWeightMax) {
        inertiaWeight = inertiaWeightMax;
    }
    setInertiaWeight(inertiaWeight);
}

From source file:common.Utilities.java

public static double getMapDenom(Map<Integer, Integer> map) {
    double sum = 0.0;
    if (map != null) {
        for (Integer val : map.values()) {
            sum += Math.exp((double) val);
        }/*from w ww  .  jav  a 2s.c om*/
    }
    return sum;
}

From source file:com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve.java

/**
 * A ISDA model zero default curve // w  w w.j a v a  2s .  c om
 * @param name The curve name
 * @param curveDates The dates of points on the curve 
 * @param times Time in years to points on the curve (these should have been calculated from a base date using some day-count convention)
 * @param rates The zero default rates at points on the curve. <b>Note:</b>These are continually compounded rates, while the other constructors take
 * annually compounded rates    
 * @param offset TODO find out what this does 
 */
public ISDADateCurve(final String name, final ZonedDateTime[] curveDates, final double[] times,
        final double[] rates, final double offset) {
    super(name);
    ArgumentChecker.notNull(name, "name");
    ArgumentChecker.noNulls(curveDates, "curve dates");
    ArgumentChecker.notEmpty(times, "times");
    ArgumentChecker.notEmpty(rates, "rates");
    _n = curveDates.length;
    ArgumentChecker.isTrue(_n != 0, "Data arrays were empty");
    // TODO why commented out?
    // ArgumentChecker.isTrue(_n == times.length, "Have {} times for {} dates", times.length, _n);
    // ArgumentChecker.isTrue(_n == rates.length, "Have {} rates for {} dates", rates.length, _n);

    _baseDates = null;

    _name = name;
    _offset = offset;
    _curveDates = new ZonedDateTime[_n];
    System.arraycopy(curveDates, 0, _curveDates, 0, _n);

    // Choose interpolation/extrapolation to match the behavior of curves in the ISDA CDS reference code
    if (_n > 1) {
        _curve = InterpolatedDoublesCurve.fromSorted(times, rates, INTERPOLATOR);
    } else {
        _curve = ConstantDoublesCurve.from(rates[0]); // Unless the curve is flat, in which case use a constant curve
    }

    _shiftedTimePoints = new double[times.length];
    for (int i = 0; i < times.length; ++i) {
        _shiftedTimePoints[i] = times[i] + _offset;
    }
    _zeroDiscountFactor = Math.exp(_offset * getInterestRate(0.0));
}

From source file:beast.evolution.operators.GMRFMultilocusSkyrideBlockUpdateOperator.java

private static SPDTridiagMatrix jacobian(double[] data2, DenseVector value, SymmTridiagMatrix Q) {
    SPDTridiagMatrix jacobian = new SPDTridiagMatrix(Q, true);
    for (int i = 0, n = value.size(); i < n; i++) {
        jacobian.set(i, i, jacobian.get(i, i) + Math.exp(-value.get(i)) * data2[i]);
    }//from  w  w  w . java  2  s.  c om
    return jacobian;
}

From source file:es.emergya.geo.util.Lambert.java

/**
 * Initializes from geographic coordinates. Note that reference ellipsoid
 * used by Lambert is the Clark ellipsoid.
 *
 * @param lat latitude in grad/*from   w  w w  .ja v  a  2s  .c  o  m*/
 * @param lon longitude in grad
 * @param Xs  false east (coordinate system origin) in meters
 * @param Ys  false north (coordinate system origin) in meters
 * @param c   projection constant
 * @param n   projection exponent
 * @return EastNorth projected coordinates in meter
 */
private EastNorth ConicProjection(double lat, double lon, double Xs, double Ys, double c, double n) {
    double eslt = Ellipsoid.clarke.e * Math.sin(lat);
    double l = Math.log(Math.tan(Math.PI / 4.0 + (lat / 2.0))
            * Math.pow((1.0 - eslt) / (1.0 + eslt), Ellipsoid.clarke.e / 2.0));
    double east = Xs + c * Math.exp(-n * l) * Math.sin(n * (lon - lg0));
    double north = Ys - c * Math.exp(-n * l) * Math.cos(n * (lon - lg0));
    return new EastNorth(east, north);
}

From source file:classif.fuzzycmeans.EUCFUZZYCMEANSSymbolicSequence.java

private double computeProbaForQueryAndCluster(double sigma, double d) {
    double pqk = 0.0;
    if (sigma == 0) {
        if (d == 0) {
            pqk = 1;/*ww  w .j  av  a  2 s .c  o m*/
        } else
            pqk = 0;
    } else
        pqk = Math.exp(-(d * d) / (2 * sigma * sigma)) / (sigma * sqrt2Pi);
    return pqk;
}

From source file:de.unidue.langtech.teaching.rp.detector.LanguageDetectorWeb1T.java

@SuppressWarnings("unused")
/* Show certainty for each language in numeric probabilities
 * Mathematics mainly based on http://stats.stackexchange.com/a/66621
 * Can slightly increase detection time 
 *///w w w  .  java  2s.  com
private Map<String, Double> getCertainty(Map<String, Double> map) {

    double maxProb = Collections.max(map.values());

    Map<String, Double> newMap = new HashMap<String, Double>();
    double sum = 0.0;

    Map<String, Double> languageProbabilities = new HashMap<String, Double>();

    for (Entry<String, Double> entry : map.entrySet()) {
        newMap.put(entry.getKey(), Math.exp(entry.getValue() - maxProb));
        sum += Math.exp(entry.getValue() - maxProb);
    }

    for (Entry<String, Double> entry : newMap.entrySet()) {
        double certainty = entry.getValue() / sum;

        if (certainty > 0.1) {
            languageProbabilities.put(entry.getKey(), certainty);
        }

    }

    return languageProbabilities;

}

From source file:com.datumbox.framework.core.statistics.distributions.ContinuousDistributions.java

/**
 * Internal function used by gammaCdf/*from w  ww.  j  a  va 2s  .  co m*/
 * 
 * @param x
 * @param a
 * @return
 */
protected static double gammaCdf(double x, double a) {
    if (x < 0) {
        throw new IllegalArgumentException("The x parameter must be positive.");
    }

    double GI;
    if (a > 200) {
        double z = (x - a) / Math.sqrt(a);
        double y = gaussCdf(z);
        double b1 = 2 / Math.sqrt(a);
        double phiz = 0.39894228 * Math.exp(-z * z / 2);
        double w = y - b1 * (z * z - 1) * phiz / 6; //Edgeworth1
        double b2 = 6 / a;
        int zXor4 = ((int) z) ^ 4;
        double u = 3 * b2 * (z * z - 3) + b1 * b1 * (zXor4 - 10 * z * z + 15);
        GI = w - phiz * z * u / 72; //Edgeworth2
    } else if (x < a + 1) {
        GI = gSer(x, a);
    } else {
        GI = gCf(x, a);
    }

    return GI;
}

From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java

/**
 * VLE diagrams using sigma profile by MOPAC
 * //w  w  w .j a va 2  s  .  c  o  m
 * @return
 * @throws Exception 
 */
@SuppressWarnings("deprecation")
public JPanel calcEthTolMOPAC() throws Exception {
    super.setTitle("P vs x1");
    double T = 60;
    setLayout(new BorderLayout());

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();

    COSMOSACCompound comps[] = new COSMOSACCompound[2];
    comps[0] = db.getComp("ethanol");
    comps[1] = db.getComp("toluene");

    COSMOSAC cosmosac = new COSMOPAC();
    cosmosac.setComponents(comps);

    cosmosac.setTemperature(T + 273.15);

    double[] x1 = new double[n];
    double[] x2 = new double[n];
    double[] gamma1 = new double[n];
    double[] gamma2 = new double[n];
    double[] z = new double[2];
    double[] lnGamma = new double[2];
    z[0] = 0.00;
    int j = 0;
    while (z[0] < 1.0001) {
        z[1] = 1 - z[0];
        x1[j] = z[0];
        x2[j] = z[1];
        cosmosac.setComposition(z);
        cosmosac.activityCoefficient(lnGamma);
        gamma1[j] = Math.exp(lnGamma[0]);
        gamma2[j] = Math.exp(lnGamma[1]);
        z[0] += 0.05;
        j++;
    }

    double[][] parAntoine = new double[3][3];
    parAntoine[0][0] = 16.8958;
    parAntoine[0][1] = 3795.17;
    parAntoine[0][2] = 230.918;
    parAntoine[1][0] = 13.9320;
    parAntoine[1][1] = 3056.96;
    parAntoine[1][2] = 217.625;

    double[] Psat = pSat(parAntoine, T);
    double[] P = calcPx(x1, x2, gamma1, gamma2, Psat);
    double[] y1 = calcY(x1, gamma1, Psat, P);

    XYPlot plot1;
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries liq = new XYSeries("liquid");
    XYSeries vap = new XYSeries("vapor");
    XYSeries raoult = new XYSeries("Raoult's Law");
    for (int i = 0; i < n; i++) {
        liq.add(x1[i], P[i]);
        vap.add(y1[i], P[i]);
    }
    ;
    raoult.add(0, Psat[1]);
    raoult.add(1, Psat[0]);
    dataset.addSeries(liq);
    dataset.addSeries(vap);
    dataset.addSeries(raoult);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null,
            PlotOrientation.VERTICAL, true, true, false);
    plot1 = (XYPlot) chart.getPlot();
    plot1.getDomainAxis().setRange(new Range(0.0, 1.0));
    plot1.getRangeAxis().setRange(new Range(15.0, 50.0));

    plot1.setDataset(dataset);

    XYSplineRenderer r = new XYSplineRenderer();
    BasicStroke stroke = new BasicStroke(2f);
    r.setStroke(stroke);
    plot1.setRenderer(r);
    r.setBaseShapesVisible(false);

    ChartPanel chartPanel = new ChartPanel(chart);
    JPanel jp = new JPanel(new BorderLayout());
    jp.add(chartPanel);

    add(jp, BorderLayout.CENTER);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 500);

    return jp;
}

From source file:eu.amidst.core.utils.Utils.java

/**
 * Returns the Inverse digamma of a given {@code double} value.
 * <p> The digamma function is the derivative of the log gamma function.
 * It calculates the value Y &gt; 0 for a value X such that digamma(Y) = X.
 * This algorithm is from Paul Fackler and Harvard Univesity:
 * http://www4.ncsu.edu/~pfackler//* ww w . j  a v  a  2  s  . c  o m*/
 * http://hips.seas.harvard.edu/content/inverse-digamma-function-matlab </p>
 * @param X a {@code double} value.
 * @return a {@code double} value Y, such as Digamma(Y) = X.
 */
public static double invDigamma(double X) {
    double L = 1;
    double Y = Math.exp(X);
    while (L > 10e-8) {
        Y = Y + L * Math.signum(X - org.apache.commons.math3.special.Gamma.digamma(Y));
        L = L / 2;
    }
    return Y;
}