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:com.thesmartweb.swebrank.TFIDF.java

/**
 * Method to calculate TF score/*  www  .ja v a  2  s  . c  om*/
 * @param Doc the document to analyze
 * @param termToCheck the term to calculate tf for
 * @return th TF score
 */
public double tfCalculator(String Doc, String termToCheck) {
    double count = 0; //to count the overall occurrence of the term termToCheck
    String[] tokenizedTerms = Doc.toString().replaceAll("[\\W&&[^\\s]]", "").split("\\W+"); //to get individual terms
    for (String s : tokenizedTerms) {
        if (s.equalsIgnoreCase(termToCheck)) {
            count++;
        }
    }
    double tfvalue = Math.pow((count / tokenizedTerms.length), 0.5);

    return tfvalue;
}

From source file:org.wallerlab.yoink.density.service.densityProperties.ReducedDensityGradientComputer.java

private double calculateRdg(double density, double gradient) {
    double rdg = Math.sqrt(gradient) / (Math.pow(density, 4.0 / 3));
    rdg = rdg / Constants.RDG_COEFFICIENT;
    return rdg;// w w w  . j  av a 2 s.co m
}

From source file:edu.umd.umiacs.clip.tools.math.CorrelationUtils.java

public static double pr(final double[] xUnsorted, final double[] yUnsorted) {
    Pair<double[], double[]> pairs = sort(xUnsorted, yUnsorted);
    double[] x = minMaxScale(pairs.getLeft());
    double[] y = minMaxScale(pairs.getRight());
    return range(1, x.length).parallel()
            .mapToDouble(i -> x[i] * (range(0, i).mapToDouble(j -> (x[j] - x[i]) * (y[j] - y[i])).sum())
                    / (Math.sqrt((range(0, i).mapToDouble(j -> Math.pow(x[j] - x[i], 2)).sum())
                            * (range(0, i).mapToDouble(j -> Math.pow(y[j] - y[i], 2)).sum()))))
            .sum() / range(1, x.length).mapToDouble(i -> x[i]).sum();

}

From source file:com.opengamma.analytics.financial.timeseries.analysis.JarqueBeraIIDHypothesis.java

@Override
public boolean testIID(final DoubleTimeSeries<?> ts) {
    Validate.notNull(ts);/*from  ww w.j a v a2  s.co  m*/
    if (ts.size() < 1000) {
        s_logger.warn(
                "Use of this test is discouraged for time series with fewer than 1000 elements; the result will be inaccurate");
    }
    final int n = ts.size();
    final double skew = Math.pow(_skewCalculator.evaluate(ts), 2);
    final double kurtosis = Math.pow(_kurtosisCalculator.evaluate(ts), 2);
    final double stat = n * (skew + kurtosis / 4) / 6;
    return stat < _criticalValue;
}

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

public double bandWidth(double variance, int dimensions, DescriptiveStatistics data) {

    double q1 = data.getPercentile(q1_);
    double q3 = data.getPercentile(q3_);
    return 0.9 * Math.min(variance, (q3 - q1) / 1.34) * Math.pow(data.getN(), -(1.0 / 5.0));
}

From source file:Main.java

/**
 * Calculate the position of the point by using the passed points position
 * and strength of signal./* w  w  w. j av  a  2 s  . c  o  m*/
 *
 * The actual calculation is called trilateration:
 * https://en.wikipedia.org/wiki/Trilateration
 * 
 * Also few parts from:
 * http://stackoverflow.com/questions/2813615/trilateration-using-3-latitude-and-longitude-points-and-3-distances
 *
 * @return the resulting point calculated.
 */
public static double[] triangulation(double lat0, double lon0, double r0, double lat1, double lon1, double r1,
        double lat2, double lon2, double r2) {
    // Convert to cartesian
    double[] p0 = latlon2cartesian(lat0, lon0);
    double[] p1 = latlon2cartesian(lat1, lon1);
    double[] p2 = latlon2cartesian(lat2, lon2);

    // Convert so that p0 sits at (0,0)
    double[] p0a = new double[] { 0, 0, 0 };
    double[] p1a = new double[] { p1[X] - p0[X], p1[Y] - p0[Y], p1[Z] - p0[Z] };
    double[] p2a = new double[] { p2[X] - p0[X], p2[Y] - p0[Y], p2[Z] - p0[Z] };

    // All distances refers to p0, the origin
    Double p1distance = distance(p0a, p1a);
    if (p1distance == null)
        return null;
    Double p2distance = distance(p0a, p2a);
    if (p2distance == null)
        return null;

    // unit vector of p1a
    double[] p1a_ev = new double[] { p1a[X] / p1distance, p1a[Y] / p1distance, p1a[X] / p1distance };
    // dot product of p1a_ev with p2a
    double p2b_x = p1a_ev[X] * p2a[X] + p1a_ev[Y] * p2a[Y] + p1a_ev[Z] * p2a[Z];
    // finding the y of p2b (for same distance of p2a from p0a)
    double p2b_y = Math.sqrt(Math.abs(Math.pow(p2distance, 2) - Math.pow(p2b_x, 2)));

    // Convert so that p1 stays on the x line (rotates the plane)
    double[] p0b = new double[] { 0, 0, 0 };
    double[] p1b = new double[] { p1distance, 0, 0 };
    double[] p2b = new double[] { p2b_x, p2b_y, 0 };

    double d = p1distance, i = p2b_x, j = p2b_y;

    double x = (Math.pow(r0, 2) - Math.pow(r1, 2) + Math.pow(d, 2)) / (2 * d);
    double y = (Math.pow(r0, 2) - Math.pow(r2, 2) + Math.pow(i, 2) + Math.pow(j, 2)) / (2 * j) - (i / j) * x;

    double[] pb = new double[] { x, y, 0 };
    Double pbdistance = distance(p0b, pb);
    if (pbdistance == null)
        return null;

    // Opposite operation done for converting points from coordinate system a to b
    double pax = pb[X] / p1a_ev[X] + pb[Y] / p1a_ev[Y] + pb[Z] / p1a_ev[Z];
    double[] pa = new double[] { pax, Math.sqrt(Math.abs(Math.pow(pbdistance, 2) - Math.pow(pax, 2))), 0 };

    // Opposite operation done for converting points from coordinate system to a
    double p[] = new double[] { pa[X] + p0[X], pa[Y] + p0[Y], pa[Z] + p0[Z] };

    // Reconvert to lat/lon
    return cartesian2latlon(p[X], p[Y], p[Z]);
}

From source file:cn.hxh.springside.utils.EncodeUtils.java

private static long alphabetDecode(String str, int base) {
    AssertUtils.hasText(str);/*from  www  .  java  2 s  .c  o m*/

    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:com.wormsim.tracking.ConstantDoubleInstance.java

@Override
public double getSquareMean() {
    return Math.pow(((ConstantDouble) parent).value, 2);
}

From source file:gr.eap.LSHDB.HammingKey.java

@Override
public int optimizeL() {
    L = (int) Math.ceil(Math.log(delta) / Math.log(1 - Math.pow((1.0 - (t * 1.0 / this.size)), k)));
    return L;/*from   www  .  j  a  va2  s  .  c om*/
}

From source file:org.wallerlab.yoink.adaptive.smooth.smoothfunction.MorokumaSmoothFunction.java

/**
 * this smooth function is used in ONIOM-XS method. for details please see:
 * "ONIOM-XS: An extension of the ONIOM method for molecular simulation in condensed phase"
 * Chemical Physics Letters, Volume 355, Number 3, 2 April 2002, pp.
 * 257-262(6).//w ww .  ja v a2 s  .  c o m
 * 
 * @param currentValue
 *            , currentValue(variable) in smooth function
 * @param min
 *            , minimum value in smooth function
 * @param max
 *            , maximum value in smooth function
 * @return smooth factor
 */
public double evaluate(double currentValue, double min, double max) {
    double smoothFactor;
    if (currentValue > max) {
        smoothFactor = 1;
    } else if (currentValue < min) {
        smoothFactor = 0;
    } else {
        double x = (currentValue - min) / (max - min);
        smoothFactor = 6 * (Math.pow((x - 0.5), 5)) - 5 * (Math.pow((x - 0.5), 3)) + 15.0 / 8 * (x - 0.5) + 0.5;
    }
    return smoothFactor;
}