Example usage for java.lang Math sqrt

List of usage examples for java.lang Math sqrt

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double sqrt(double a) 

Source Link

Document

Returns the correctly rounded positive square root of a double value.

Usage

From source file:jcurl.sim.core.SlideStrategy.java

protected static double hypot(final double a, final double b) {
    return Math.sqrt(a * a + b * b);
}

From source file:com.metaos.pricer.volatility.RecentlyRealizedVolatility.java

/**
 * Gets volatility for given instrument.
 *///from w  ww. j  a  v  a  2s  .  c  o  m
public double calculate(final Instrument instrument) {
    final double[] values = this.getValues(instrument);
    return Math.sqrt(this.variance.evaluate(values));
}

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

/**
 * @param x The array of data, not null, must contain at least three data points
 * @return The sample skewness/*  www .  j  a v  a  2 s. c om*/
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length >= 3, "Need at least three points to calculate sample skewness");
    double sum = 0;
    double variance = 0;
    final double mean = MEAN.evaluate(x);
    for (final Double d : x) {
        final double diff = d - mean;
        variance += diff * diff;
        sum += diff * diff * diff;
    }
    final int n = x.length;
    variance /= n - 1;
    return Math.sqrt(n - 1.) * sum / (Math.pow(variance, 1.5) * Math.sqrt(n) * (n - 2));
}

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

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

    for (int i = 0; i < n; i++) {
        sum1 += x[i] * x[i];/*from   w ww.  j a v a  2s.com*/
        sum2 += Math.cos(2 * Math.PI * x[i]);
    }
    double fx = -20 * Math.exp(-0.2 * Math.sqrt(sum1 / n)) - Math.exp(sum2 / n) + 20 + Math.E;
    return fx;
}

From source file:com.anhth12.distributions.Distributions.java

public static RealDistribution uniform(RandomGenerator rng, int nIn, int nOut) {
    double fanIn = -4 * Math.sqrt(6. / (nOut + nIn));
    return uniform(rng, fanIn);
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.fon.Fon_Objective_1.java

@Override
public double evaluate(double[] values) {
    double[] x = new double[values.length];
    double sum = 0;
    double k = 1 / Math.sqrt(values.length);

    for (int i = 0; i < values.length; i++) {
        x[i] = 4 * values[i];/*from   w ww  .  java2s  . c  o  m*/
        sum += (x[i] - k) * (x[i] - k);
    }

    return 1 - Math.exp(-sum);
}

From source file:es.udc.gii.common.eaf.stoptest.cma.CMATolXUpStopTest.java

@Override
public boolean isReach(EvolutionaryAlgorithm algorithm) {

    double sigma, maxstartsigma, maxsqrtdiagC;
    CMAEvolutionaryAlgorithm cma = (CMAEvolutionaryAlgorithm) algorithm;

    maxstartsigma = StatUtils.max(cma.getStartSigma());
    maxsqrtdiagC = Math.sqrt(StatUtils.max(cma.diag(cma.getC())));
    sigma = cma.getSigma();/*from w w  w  . jav a2 s . c  o m*/

    if (sigma * maxsqrtdiagC > this.tol_up_x_factor * maxstartsigma) {
        return true;
    }

    return false;

}

From source file:es.udc.gii.common.eaf.stoptest.cma.CMAXMeanStuckStopTest.java

@Override
public boolean isReach(EvolutionaryAlgorithm algorithm) {

    CMAEvolutionaryAlgorithm cma = (CMAEvolutionaryAlgorithm) algorithm;
    int N = cma.getPopulation().getIndividual(0).getDimension();

    /* Test whether one component of xmean is stuck */
    for (int iKoo = 0; iKoo < N; ++iKoo) {
        if (cma.getxMean()[iKoo] == cma.getxMean()[iKoo]
                + 0.2 * cma.getSigma() * Math.sqrt(cma.getC()[iKoo][iKoo])) {
            return true;
        }/*from   w  w  w.  j a  v a  2 s  . c  o m*/
    } /* for iKoo */

    return false;

}

From source file:de.tud.kom.p2psim.impl.util.stats.ConfidenceInterval.java

/**
 * Returns the delta between the mean and the lower(x1)/upper(x2) bound as
 * positive number. That is, the probabilistic bounds of x1 and x2 are given
 * by x1 <= mean <= x2 <=> mean-delta <= mean <= mean + delta
 * /*w ww  .j a v a2s .co m*/
 * @param sdev
 *            the given standard deviation
 * @param n
 *            the given sample size
 * @param alpha
 *            the given significance level
 * @return the upper/lower bound as positiv number
 */
public static double getDeltaBound(double sdev, int n, double alpha) {
    TDistribution tDist = DistributionFactory.newInstance().createTDistribution(n - 1);
    double errorConfCoeff = 1d - (alpha / 2);
    double delta;
    try {
        double t = Math.abs(tDist.inverseCumulativeProbability(errorConfCoeff));
        delta = t * sdev / Math.sqrt(n);
    } catch (MathException e) {
        throw new IllegalStateException(e);
    }
    return delta;
}

From source file:com.bleedobsidian.datawave.utils.Sinewave.java

/**
 * Calculate the frequency of sine wave from sound data.
 * /*from  w  ww  .  j a  v a 2 s  . c o  m*/
 * @param sampleRate Sample rate.
 * @param samples Samples.
 * 
 * @return Frequency.
 */
public static double calculateFrequency(double sampleRate, double[] samples) {
    FastFourierTransformer transformer = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] complex = transformer.transform(samples, TransformType.FORWARD);

    double real;
    double im;
    double mag[] = new double[complex.length];

    for (int i = 0; i < complex.length; i++) {
        real = complex[i].getReal();
        im = complex[i].getImaginary();
        mag[i] = Math.sqrt((real * real) + (im * im));
    }

    double peak = 0.2;
    int index = -1;
    for (int i = 0; i < complex.length; i++) {
        if (peak < mag[i]) {
            index = i;
            peak = mag[i];
        }
    }

    return ((sampleRate * index) / Audio.SAMPLE_BUFFER_SIZE) * 2;
}