Example usage for java.lang Math pow

List of usage examples for java.lang Math pow

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double pow(double a, double b) 

Source Link

Document

Returns the value of the first argument raised to the power of the second argument.

Usage

From source file:de.termininistic.serein.examples.benchmarks.functions.unimodal.DixonPriceFunction.java

@Override
public double map(RealVector v) {

    double[] x = v.toArray();
    int n = x.length;
    double fx = (x[0] - 1) * (x[0] - 1);
    for (int i = 1; i < n; i++) {
        fx += i * Math.pow((2 * x[i] * x[i] - x[i - 1]), 2);
    }/* w  w w .ja  v  a2  s.  c om*/
    return fx;
}

From source file:eu.flatworld.worldexplorer.layer.bmng.BMNGHTTPProvider.java

@Override
public Tile getTile(int id, int x, int y, int l) throws Exception {
    BMNGTile tile = null;//from w ww.  j  a v  a  2s . c o m
    tile = new BMNGTile();
    tile.setX(x);
    tile.setY(y);
    tile.setGx(x);
    tile.setGy((int) Math.pow(2, l) * BMNGLayer.SURFACE_HEIGHT - 1 - y);
    tile.setL(l);
    tile.setMonth(month);
    tile.setYear(year);
    LogX.log(Level.FINEST, NAME + " queueing: " + tile);
    firePropertyChange(P_IDLE, true, false);
    queueTile(tile);
    return tile;
}

From source file:com.mawujun.utils.EncodeUtils.java

private static long alphabetDecode(String str, int base) {
    Assert.hasText(str);/*from ww  w .  java2s.  c  om*/

    long result = 0;
    for (int i = 0; i < str.length(); i++) {
        result += ALPHABET.indexOf(str.charAt(i)) * Math.pow(base, i);
    }

    return result;
}

From source file:net.atos.ari.vital.taastrustcalculator.StatisticsCalculator.java

public boolean calculateNumericVariance(double[] values) {
    double alpha = 0.05;
    double mean = StatUtils.mean(values);
    double variance = StatUtils.variance(values);
    double expected = Math.pow(mean * 0.05, 2);
    //double expected = 0.01;
    double degFreedom = values.length - 1.0;

    double T = (degFreedom * variance) / expected;
    logger.debug("Mean = " + mean);
    logger.debug("Standard Deviation = " + Math.sqrt(variance));
    logger.debug("Test Statistic calculated T = " + T);

    if (degFreedom <= 0)
        return false;
    ChiSquaredDistribution myDist = new ChiSquaredDistribution(degFreedom);
    double myTLeft = myDist.inverseCumulativeProbability(alpha / 2.0);
    double myTRight = myDist.inverseCumulativeProbability(1.0 - alpha / 2.0);

    logger.debug("Boundaries: " + myTLeft + " to " + myTRight);

    // Determine if z score is in the region of acceptance
    if ((myTLeft <= T) && (T <= myTRight)) {
        // H0 -> Variance of the data is equal to the expected one
        return true;
    }//from ww  w .  ja  v a2  s .  c om

    // H1 -> Variance of the data is different to the expected one
    return false;
}

From source file:edu.byu.nlp.stats.RandomGenerators.java

/**
 * This routine generates a random number between 0 and n inclusive, following
 * the binomial distribution with probability p and n trials. The routine is
 * based on the BTPE algorithm, described in:
 * //from  w  w w.j  a va  2s.  c  o m
 * Voratas Kachitvichyanukul and Bruce W. Schmeiser:
 * Binomial Random Variate Generation
 * Communications of the ACM, Volume 31, Number 2, February 1988, pages 216-222.
 * 
 * Snagged on March 19, 2009 from:
 * 
 * http://chianti.ucsd.edu/svn/csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/kmeans/KCluster.java
 * 
 * by Robbie who also converted the uniform() calls to RandomGenerator.nextDouble()
 * 
 * @param p The probability of a single event.  This should be less than or equal to 0.5.
 * @param n The number of trials
 * @return An integer drawn from a binomial distribution with parameters (p, n).
 */
public static int nextBinom(RandomGenerator rnd, int n, double p) {
    // rah67 March 19, 2007; didn't properly handle the degenerate case
    if (p == 1.0)
        return n;

    double q = 1 - p;
    if (n * p < 30.0) /* Algorithm BINV */
    {
        double s = p / q;
        double a = (n + 1) * s;
        //         double r = Math.exp(n*Math.log(q)); /* pow() causes a crash on AIX */
        double r = Math.pow(q, n); /* rah67 March 19, 2007 */
        int x = 0;
        double u = rnd.nextDouble();
        while (true) {
            if (u < r)
                return x;
            u -= r;
            x++;
            r *= (a / x) - s;
        }
    } else /* Algorithm BTPE */
    { /* Step 0 */
        double fm = n * p + p;
        int m = (int) fm;
        double p1 = Math.floor(2.195 * Math.sqrt(n * p * q) - 4.6 * q) + 0.5;
        double xm = m + 0.5;
        double xl = xm - p1;
        double xr = xm + p1;
        double c = 0.134 + 20.5 / (15.3 + m);
        double a = (fm - xl) / (fm - xl * p);
        double b = (xr - fm) / (xr * q);
        double lambdal = a * (1.0 + 0.5 * a);
        double lambdar = b * (1.0 + 0.5 * b);
        double p2 = p1 * (1 + 2 * c);
        double p3 = p2 + c / lambdal;
        double p4 = p3 + c / lambdar;
        while (true) { /* Step 1 */
            int y;
            int k;
            double u = rnd.nextDouble();
            double v = rnd.nextDouble();
            u *= p4;
            if (u <= p1)
                return (int) (xm - p1 * v + u);
            /* Step 2 */
            if (u > p2) { /* Step 3 */
                if (u > p3) { /* Step 4 */
                    y = (int) (xr - Math.log(v) / lambdar);
                    if (y > n)
                        continue;
                    /* Go to step 5 */
                    v = v * (u - p3) * lambdar;
                } else {
                    y = (int) (xl + Math.log(v) / lambdal);
                    if (y < 0)
                        continue;
                    /* Go to step 5 */
                    v = v * (u - p2) * lambdal;
                }
            } else {
                double x = xl + (u - p1) / c;
                v = v * c + 1.0 - Math.abs(m - x + 0.5) / p1;
                if (v > 1)
                    continue;
                /* Go to step 5 */
                y = (int) x;
            }
            /* Step 5 */
            /* Step 5.0 */
            k = Math.abs(y - m);
            if (k > 20 && k < 0.5 * n * p * q - 1.0) { /* Step 5.2 */
                double rho = (k / (n * p * q))
                        * ((k * (k / 3.0 + 0.625) + 0.1666666666666) / (n * p * q) + 0.5);
                double t = -k * k / (2 * n * p * q);
                double A = Math.log(v);
                if (A < t - rho)
                    return y;
                else if (A > t + rho)
                    continue;
                else { /* Step 5.3 */
                    double x1 = y + 1;
                    double f1 = m + 1;
                    double z = n + 1 - m;
                    double w = n - y + 1;
                    double x2 = x1 * x1;
                    double f2 = f1 * f1;
                    double z2 = z * z;
                    double w2 = w * w;
                    if (A > xm * Math.log(f1 / x1) + (n - m + 0.5) * Math.log(z / w)
                            + (y - m) * Math.log(w * p / (x1 * q))
                            + (13860. - (462. - (132. - (99. - 140. / f2) / f2) / f2) / f2) / f1 / 166320.
                            + (13860. - (462. - (132. - (99. - 140. / z2) / z2) / z2) / z2) / z / 166320.
                            + (13860. - (462. - (132. - (99. - 140. / x2) / x2) / x2) / x2) / x1 / 166320.
                            + (13860. - (462. - (132. - (99. - 140. / w2) / w2) / w2) / w2) / w / 166320.)
                        continue;
                    return y;
                }
            } else { /* Step 5.1 */
                int i;
                double s = p / q;
                double aa = s * (n + 1);
                double f = 1.0;
                for (i = m; i < y; f *= (aa / (++i) - s))
                    ;
                for (i = y; i < m; f /= (aa / (++i) - s))
                    ;
                if (v > f)
                    continue;
                return y;
            }
        }
    }
}

From source file:gaffer.serialisation.implementation.raw.CompactRawLongSerialiserTest.java

@Test
public void canSerialiseAllOrdersOfMagnitude() throws SerialisationException {
    for (int i = 0; i < 64; i++) {
        long value = (long) Math.pow(2, i);
        test(value);//from ww  w  .  j  a v a2  s .  co  m
        test(-value);
    }
}

From source file:it.uniroma2.sag.kelp.kernel.standard.PolynomialKernel.java

@Override
protected float kernelComputation(Example exA, Example exB) {
    float dotProduct = this.baseKernel.innerProduct(exA, exB);

    if (this.degree == (int) this.degree) {
        return it.uniroma2.sag.kelp.utils.Math.pow((this.a * dotProduct + this.b), (int) degree);
    }//from w  ww.ja  v a 2 s . com
    return (float) Math.pow((this.a * dotProduct + this.b), degree);
}

From source file:za.org.opengov.common.service.impl.IssueServiceImpl.java

@Override
public int calculatePriority(int severity, int occurance, int duration, int sevMin, int occMin, int durMin,
        int sevMax, int occMax, int durMax) {

    // normalize/*from   www.j a  v  a  2  s.  c o  m*/
    double normSev = (double) (severity - sevMin) / (double) ((sevMax - sevMin) == 0 ? 1 : sevMax - sevMin);
    double normOcc = (double) (occurance - occMin) / (double) ((occMax - occMin) == 0 ? 1 : occMax - occMin);
    double normDur = (double) (duration - durMin) / (double) ((durMax - durMin) == 0 ? 1 : durMax - durMin);
    ;

    double factor = Math.sqrt(Math.pow(normSev, 2) + Math.pow(normOcc, 2) + Math.pow(normDur, 2));

    return (int) ((factor / Math.sqrt(3)) * 100);
}

From source file:com.cloudera.hts.utils.math.MyFunc2.java

public double[] gradient(double t, double... parameters) {

    final double a = parameters[0];
    final double b = parameters[1];
    final double c = parameters[2];

    return new double[] { Math.exp(-c * t) * Math.pow(t, b),
            a * Math.exp(-c * t) * Math.pow(t, b) * Math.log(t), a * (-Math.exp(-c * t)) * Math.pow(t, b + 1) };
}

From source file:net.liuxuan.temp.mathtest.java

public static double compute(double[] s, double in) {
    double y = 0;
    for (int i = 0; i < s.length; i++) {
        y += s[i] * Math.pow(in, i);
    }/*  w ww  .  j  a  va  2  s .c  o  m*/
    return y;
}