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:eu.amidst.core.inference.MPEInferenceExperiments.java

/**
 * The class constructor.// ww  w  .jav  a  2 s.  co m
 * @param args Array of options: "filename variable a b N useVMP" if variable is continuous or "filename variable w N useVMP" for discrete
 */
public static void main(String[] args) throws Exception {

    int seedNetwork = 61236719 + 123;

    int numberOfGaussians = 20;

    int numberOfMultinomials = numberOfGaussians;
    BayesianNetworkGenerator.setSeed(seedNetwork);
    BayesianNetworkGenerator.setNumberOfGaussianVars(numberOfGaussians);
    BayesianNetworkGenerator.setNumberOfMultinomialVars(numberOfMultinomials, 2);
    BayesianNetworkGenerator.setNumberOfLinks((int) 1.3 * (numberOfGaussians + numberOfMultinomials));

    BayesianNetwork bn = BayesianNetworkGenerator.generateBayesianNetwork();

    int seed = seedNetwork + 231591;

    //if (Main.VERBOSE) System.out.println(bn.getDAG());
    if (Main.VERBOSE)
        System.out.println(bn.toString());

    MPEInference mpeInference = new MPEInference();
    mpeInference.setModel(bn);
    mpeInference.setParallelMode(true);

    if (Main.VERBOSE)
        System.out.println("CausalOrder: "
                + Arrays.toString(Utils.getTopologicalOrder(mpeInference.getOriginalModel().getDAG()).stream()
                        .map(Variable::getName).toArray()));
    List<Variable> modelVariables = Utils.getTopologicalOrder(bn.getDAG());
    if (Main.VERBOSE)
        System.out.println();

    // Including evidence:
    //double observedVariablesRate = 0.00;
    //Assignment evidence = randomEvidence(seed, observedVariablesRate, bn);
    //mpeInference.setEvidence(evidence);

    int parallelSamples = 100;
    int samplingMethodSize = 10000;

    mpeInference.setSampleSize(parallelSamples);

    /***********************************************
     *        SIMULATED ANNEALING
     ************************************************/

    // MPE INFERENCE WITH SIMULATED ANNEALING, ALL VARIABLES
    if (Main.VERBOSE)
        System.out.println();
    long timeStart = System.nanoTime();
    mpeInference.runInference(MPEInference.SearchAlgorithm.SA_GLOBAL);

    Assignment mpeEstimate = mpeInference.getEstimate();
    if (Main.VERBOSE)
        System.out.println("MPE estimate (SA.All): " + mpeEstimate.outputString(modelVariables)); //toString(modelVariables)
    if (Main.VERBOSE)
        System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
    long timeStop = System.nanoTime();
    double execTime = (double) (timeStop - timeStart) / 1000000000.0;
    if (Main.VERBOSE)
        System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    //if (Main.VERBOSE) System.out.println(.toString(mapInference.getOriginalModel().getStaticVariables().iterator().));
    if (Main.VERBOSE)
        System.out.println();

    // MPE INFERENCE WITH SIMULATED ANNEALING, SOME VARIABLES AT EACH TIME
    timeStart = System.nanoTime();
    mpeInference.runInference(MPEInference.SearchAlgorithm.SA_LOCAL);

    mpeEstimate = mpeInference.getEstimate();
    if (Main.VERBOSE)
        System.out.println("MPE estimate  (SA.Some): " + mpeEstimate.outputString(modelVariables)); //toString(modelVariables)
    if (Main.VERBOSE)
        System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
    timeStop = System.nanoTime();
    execTime = (double) (timeStop - timeStart) / 1000000000.0;
    if (Main.VERBOSE)
        System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    //if (Main.VERBOSE) System.out.println(.toString(mapInference.getOriginalModel().getStaticVariables().iterator().));
    if (Main.VERBOSE)
        System.out.println();

    /***********************************************
     *        HILL CLIMBING
     ************************************************/

    // MPE INFERENCE WITH HILL CLIMBING, ALL VARIABLES
    timeStart = System.nanoTime();
    mpeInference.runInference(MPEInference.SearchAlgorithm.HC_GLOBAL);

    mpeEstimate = mpeInference.getEstimate();
    //modelVariables = mpeInference.getOriginalModel().getVariables().getListOfVariables();
    if (Main.VERBOSE)
        System.out.println("MPE estimate (HC.All): " + mpeEstimate.outputString(modelVariables));
    if (Main.VERBOSE)
        System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
    timeStop = System.nanoTime();
    execTime = (double) (timeStop - timeStart) / 1000000000.0;
    if (Main.VERBOSE)
        System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    if (Main.VERBOSE)
        System.out.println();

    //  MPE INFERENCE WITH HILL CLIMBING, ONE VARIABLE AT EACH TIME
    timeStart = System.nanoTime();
    mpeInference.runInference(MPEInference.SearchAlgorithm.HC_LOCAL);

    mpeEstimate = mpeInference.getEstimate();
    if (Main.VERBOSE)
        System.out.println("MPE estimate  (HC.Some): " + mpeEstimate.outputString(modelVariables)); //toString(modelVariables)
    if (Main.VERBOSE)
        System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
    timeStop = System.nanoTime();
    execTime = (double) (timeStop - timeStart) / 1000000000.0;
    if (Main.VERBOSE)
        System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    if (Main.VERBOSE)
        System.out.println();

    /***********************************************
     *        SAMPLING AND DETERMINISTIC
     ************************************************/

    // MPE INFERENCE WITH SIMULATION AND PICKING MAX

    mpeInference.setSampleSize(samplingMethodSize);

    timeStart = System.nanoTime();
    mpeInference.runInference(MPEInference.SearchAlgorithm.SAMPLING);

    mpeEstimate = mpeInference.getEstimate();
    //modelVariables = mpeInference.getOriginalModel().getVariables().getListOfVariables();
    if (Main.VERBOSE)
        System.out.println("MPE estimate (SAMPLING): " + mpeEstimate.outputString(modelVariables));
    if (Main.VERBOSE)
        System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
    timeStop = System.nanoTime();
    execTime = (double) (timeStop - timeStart) / 1000000000.0;
    if (Main.VERBOSE)
        System.out.println("computed in: " + Double.toString(execTime) + " seconds");
    if (Main.VERBOSE)
        System.out.println();

    if (bn.getNumberOfVars() <= 50) {

        // MPE INFERENCE, DETERMINISTIC
        timeStart = System.nanoTime();
        mpeInference.runInference(MPEInference.SearchAlgorithm.EXHAUSTIVE);

        mpeEstimate = mpeInference.getEstimate();
        //modelVariables = mpeInference.getOriginalModel().getVariables().getListOfVariables();
        if (Main.VERBOSE)
            System.out.println("MPE estimate (DETERM.): " + mpeEstimate.outputString(modelVariables));
        if (Main.VERBOSE)
            System.out.println("with probability: " + Math.exp(mpeInference.getLogProbabilityOfEstimate())
                    + ", logProb: " + mpeInference.getLogProbabilityOfEstimate());
        timeStop = System.nanoTime();
        execTime = (double) (timeStop - timeStart) / 1000000000.0;
        if (Main.VERBOSE)
            System.out.println("computed in: " + Double.toString(execTime) + " seconds");
        if (Main.VERBOSE)
            System.out.println();

    }
}

From source file:Main.java

public static double getLat(int inY, int zoom) {
    double y = Math.floor(inY * 256);
    double efactor = Math.exp((0.5 - y / 256 / Math.pow(2, zoom)) * 4 * Math.PI);
    double latitude = Math.asin((efactor - 1) / (efactor + 1)) * 180 / Math.PI;
    if (latitude < -90.0) {
        latitude = -90.0;//from   w w w  .ja va2s . co  m
    } else if (latitude > 90.0) {
        latitude = 90.0;
    }
    return latitude;
}

From source file:Main.java

public static float viscousFluid(float x) {
    x *= sViscousFluidScale;/* www. j a  va 2s . com*/
    if (x < 1.0f) {
        x -= (1.0f - (float) Math.exp(-x));
    } else {
        float start = 0.36787944117f; // 1/e == exp(-1)
        x = 1.0f - (float) Math.exp(1.0f - x);
        x = start + x * (1.0f - start);
    }
    x *= sViscousFluidNormalize;
    return x;
}

From source file:Main.java

public static double[] mercatorToGeo(double[] e) {
    double j = Math.PI, f = j / 2, i = 6378137, n = 0.003356551468879694, k = 0.00000657187271079536,
            h = 1.764564338702e-8, m = 5.328478445e-11;
    double g = f - 2 * Math.atan(1 / Math.exp(e[1] / i));
    double l = g + n * Math.sin(2 * g) + k * Math.sin(4 * g) + h * Math.sin(6 * g) + m * Math.sin(8 * g);
    double d = e[0] / i;
    return new double[] { d * 180 / Math.PI, l * 180 / Math.PI };
}

From source file:Main.java

public static double logSumExp(double a, double b) {
    double x = (a < b) ? a : b;
    double y = (a < b) ? b : a;
    if (y - x > 50) {
        return y;
    } else {//from   www .  j a  v a2  s .co m
        return x + Math.log(1.0 + Math.exp(y - x));
    }
}

From source file:Main.java

public static void MercatorToBD(double mercatorX, double mercatorY) {
    CbdX = mercatorY / 20037508.34 * 180;
    CbdX = 180 / Math.PI * (2 * Math.atan(Math.exp(CbdX * Math.PI / 180)) - Math.PI / 2);
    CbdY = mercatorX / 20037508.34 * 180;

    Log.d("CustomerActivity", "x" + Double.toString(CbdX));
    Log.d("CustomerActivity", "y" + Double.toString(CbdY));
}

From source file:Main.java

public static double pixelYToLatitude(int pixelY, double zoomLevel, int tileSize) {
    int mapSize = getMapSize(zoomLevel, tileSize);
    if (pixelY < 0 || pixelY > mapSize) {
        throw new IllegalArgumentException(
                "invalid pixelY coordinate at zoom level " + zoomLevel + ": " + pixelY);
    }/*  w  w w.ja  va  2s .c om*/
    double y = .5d - ((double) pixelY / mapSize);
    return 90d - 360d * Math.atan(Math.exp(-y * (2d * Math.PI))) / Math.PI;
}

From source file:Main.java

public static double tile2lat(int y, int aZoom) {

    final double MerkElipsK = 0.0000001;
    final long sradiusa = 6378137;
    final long sradiusb = 6356752;
    final double FExct = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa;
    final int TilesAtZoom = 1 << aZoom;
    double result = (y - TilesAtZoom / 2) / -(TilesAtZoom / (2 * Math.PI));
    result = (2 * Math.atan(Math.exp(result)) - Math.PI / 2) * 180 / Math.PI;
    double Zu = result / (180 / Math.PI);
    double yy = ((y) - TilesAtZoom / 2);

    double Zum1 = Zu;
    Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct))
            / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI)))
                    * Math.pow(1 + FExct * Math.sin(Zum1), FExct)));
    while (Math.abs(Zum1 - Zu) >= MerkElipsK) {
        Zum1 = Zu;//  www.  j a  v  a  2  s .c  om
        Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct))
                / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI)))
                        * Math.pow(1 + FExct * Math.sin(Zum1), FExct)));
    }

    result = Zu * 180 / Math.PI;

    return result;

}

From source file:Main.java

/**
 * Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84
 * Datum//from w ww .  j  a  va2  s  .c o m
 * 
 * @return
 */
public static double[] MetersToLatLon(double mx, double my) {

    double lon = (mx / originShift) * 180.0;
    double lat = (my / originShift) * 180.0;

    lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0);
    return new double[] { lat, lon };
}

From source file:Main.java

/**
 * Returns a value that approaches yInf from y0 as xDelta increases.
 * The values for the function range from (0, y0) to (inf, yInf).
 * For each xHalfLife, the function moves 50% closer to yInf.
 *
 * @param x//from w  ww  . j  ava2 s .  c o m
 * @param xHalfLife
 * @param y0
 * @param yInf
 * @return
 */
public static double toAsymptote(double x, double xHalfLife, double y0, double yInf) {
    assert (x > 0);
    double hl = x / xHalfLife;
    return y0 + (1.0 - Math.exp(-hl)) * (yInf - y0);
}