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:k_means.Kmeans.java

public void calDist() {

    double distance = 0;
    double minimum = 0;
    int cluster = 0;
    double bignum = Math.pow(10, 10);

    for (int i = 0; i < dataSet.size(); i++) {
        minimum = bignum;/*from w  w w.  j  a v a  2 s.  c  om*/
        for (int j = 0; j < k; j++) {
            distance = Distance.EDistance(dataSet.get(i), centroids.get(j));
            if (distance < minimum) {
                minimum = distance;
                cluster = j;
            }
            dataSet.get(i).setCluster(cluster);
        }
    }

}

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

public double value(double t, double... parameters) {
    return parameters[0] * Math.pow(t, parameters[1]) * Math.exp(-parameters[2] * t);
}

From source file:me.datamining.bandwidth.ScottsRule.java

public double bandWidth(double variance, int dimensions, long number) {
    double pow = -1.0 / (dimensions + 4);
    return variance * Math.pow(number, pow);
}

From source file:de.termininistic.serein.examples.benchmarks.functions.multimodal.StyblinskiTangFunction.java

@Override
public double map(RealVector v) {
    double[] x = v.toArray();
    int n = x.length;
    double sum = 0.0;

    for (int i = 0; i < n; i++) {
        sum += Math.pow(x[i], 4) - 16 * x[i] * x[i] + 5 * x[i];
    }/* ww w .  j a v a  2 s.  c o m*/

    return 0.5 * sum;
}

From source file:es.udc.gii.common.eaf.benchmark.constrained_real_param.g03.G03ObjectiveFunction.java

@Override
public double evaluate(double[] values) {

    double[] norm_values;

    norm_values = G03Function.normalize(values);

    return -Math.pow(Math.sqrt(norm_values.length), norm_values.length) * StatUtils.product(norm_values);

}

From source file:Main.java

/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details./*ww w. j  a v a 2s  . co  m*/
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.LEFT:
        x0 = 1;
        x1 = 0;
        break;
    case Gravity.RIGHT:
        x0 = 0;
        x1 = 1;
        break;
    default:
        x0 = 0;
        x1 = 0;
        break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
        y0 = 1;
        y1 = 0;
        break;
    case Gravity.BOTTOM:
        y0 = 0;
        y1 = 1;
        break;
    default:
        y0 = 0;
        y1 = 0;
        break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null,
                    Shader.TileMode.CLAMP);
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}

From source file:beast.math.distributions.NegativeBinomialDistribution.java

public double logPdf(double x) {
    if (x < 0)
        return Double.NEGATIVE_INFINITY;
    double r = -1 * (mean * mean) / (mean - stdev * stdev);
    double p = mean / (stdev * stdev);
    return Math.log(Math.pow(1 - p, x)) + Math.log(Math.pow(p, r)) + GammaFunction.lnGamma(r + x)
            - GammaFunction.lnGamma(r) - GammaFunction.lnGamma(x + 1);
}

From source file:com.opengamma.analytics.math.statistics.descriptive.SampleCentralMomentCalculator.java

/**
 * @param x The array of data, not null. Must contain at least two data points.
 * @return The sample central moment./*from  ww w .j  av  a2s. co  m*/
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length >= 2, "Need at least 2 data points to calculate central moment");
    if (_n == 0) {
        return 1.;
    }
    final double mu = MEAN.evaluate(x);
    double sum = 0;
    for (final Double d : x) {
        sum += Math.pow(d - mu, _n);
    }
    return sum / (x.length - 1);
}

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

@Override
public RealVector getOptimum(int dimension) {
    double[] optimum = new double[dimension];
    for (int i = 0; i < optimum.length; i++) {
        optimum[i] = Math.pow(2, -((Math.pow(2, i) - 2 / Math.pow(2, i))));
    }/*www .  ja v a2s . c  o m*/
    return new ArrayRealVector(optimum);
}

From source file:net.bither.util.ChartsUtil.java

public static List<IStickEntity> formatJsonArray(MarketType marketType, KlineTimeType klineTimeType,
        JSONArray jsonArray) throws JSONException {
    double rate = ExchangeUtil.getRate(marketType);
    List<IStickEntity> ohlc = new ArrayList<IStickEntity>();
    for (int i = jsonArray.length() - 1; i >= 0; i--) {
        JSONArray tickerArray = jsonArray.getJSONArray(i);
        long time = tickerArray.getLong(0) * 1000;
        Date date = new Date(time);
        String title = DateTimeUtil.getXTitle(klineTimeType, date);
        double open = tickerArray.getDouble(1) / 100 * rate;
        double high = tickerArray.getDouble(2) / 100 * rate;
        double low = tickerArray.getDouble(3) / 100 * rate;
        double close = tickerArray.getDouble(4) / 100 * rate;
        double volume = tickerArray.getDouble(5) / Math.pow(10, 8);
        if (volume == 0) {
            if (i == 0) {
                continue;
            } else {
                BitherOHLCEntity bitherOHLCEntity = (BitherOHLCEntity) ohlc.get(i - 1);
                open = bitherOHLCEntity.getOpen();
                high = bitherOHLCEntity.getHigh();
                low = bitherOHLCEntity.getLow();
                close = bitherOHLCEntity.getClose();
            }//from  www  .j  av  a2 s . com

        }
        BitherOHLCEntity bitherOHLCEntity = new BitherOHLCEntity(open, high, low, close, volume, title, time);

        ohlc.add(bitherOHLCEntity);
    }

    return ohlc;
}