Example usage for java.lang Double NaN

List of usage examples for java.lang Double NaN

Introduction

In this page you can find the example usage for java.lang Double NaN.

Prototype

double NaN

To view the source code for java.lang Double NaN.

Click Source Link

Document

A constant holding a Not-a-Number (NaN) value of type double .

Usage

From source file:de.qaware.chronix.solr.type.metric.functions.aggregations.Difference.java

/**
 * Calculate the difference between the first and the last value of a given time series
 *
 * @param timeSeries the time series/*  w ww .  jav a2  s.c  o m*/
 * @return the average or 0 if the list is empty
 */
@Override
public void execute(MetricTimeSeries timeSeries, FunctionValueMap functionValueMap) {
    //If it is empty, we return NaN
    if (timeSeries.size() <= 0) {
        functionValueMap.add(this, Double.NaN);
        return;
    }

    //we need to sort the time series
    timeSeries.sort();
    //get the first and the last value
    double firstValue = timeSeries.getValue(0);
    double lastValue = timeSeries.getValue(timeSeries.size() - 1);

    functionValueMap.add(this, Math.abs(firstValue - lastValue));

}

From source file:Main.java

/**
 * Fills the array with random doubles.  Values will be between min (inclusive) and
 * max (inclusive).//  www .j a  va  2s  .co m
 */
public static void genRandomDoubles(long seed, double min, double max, double array[],
        boolean includeExtremes) {
    Random r = new Random(seed);
    int minExponent = Math.min(Math.getExponent(min), 0);
    int maxExponent = Math.max(Math.getExponent(max), 0);
    if (minExponent < -6 || maxExponent > 6) {
        // Use an exponential distribution
        int exponentDiff = maxExponent - minExponent;
        for (int i = 0; i < array.length; i++) {
            double mantissa = r.nextDouble();
            int exponent = minExponent + r.nextInt(maxExponent - minExponent);
            int sign = (min >= 0) ? 1 : 1 - r.nextInt(2) * 2; // -1 or 1
            double rand = sign * mantissa * Math.pow(2.0, exponent);
            if (rand < min || rand > max) {
                continue;
            }
            array[i] = rand;
        }
    } else {
        // Use a linear distribution
        for (int i = 0; i < array.length; i++) {
            double rand = r.nextDouble();
            array[i] = min + rand * (max - min);
        }
    }
    // Seed a few special numbers we want to be sure to test.
    for (int i = 0; i < sInterestingDoubles.length; i++) {
        double d = sInterestingDoubles[i];
        if (min <= d && d <= max) {
            array[r.nextInt(array.length)] = d;
        }
    }
    array[r.nextInt(array.length)] = min;
    array[r.nextInt(array.length)] = max;
    if (includeExtremes) {
        array[r.nextInt(array.length)] = Double.NaN;
        array[r.nextInt(array.length)] = Double.POSITIVE_INFINITY;
        array[r.nextInt(array.length)] = Double.NEGATIVE_INFINITY;
        array[r.nextInt(array.length)] = Double.MIN_VALUE;
        array[r.nextInt(array.length)] = Double.MIN_NORMAL;
        array[r.nextInt(array.length)] = Double.MAX_VALUE;
        array[r.nextInt(array.length)] = -Double.MIN_VALUE;
        array[r.nextInt(array.length)] = -Double.MIN_NORMAL;
        array[r.nextInt(array.length)] = -Double.MAX_VALUE;
    }
}

From source file:de.qaware.chronix.solr.type.metric.functions.aggregations.Range.java

/**
 * Gets difference between the maximum and the minimum value.
 * It is always a positive value./*  w  w w  .j  a  va  2  s . com*/
 *
 * @param timeSeries the time series
 * @return the average or 0 if the list is empty
 */
@Override
public void execute(MetricTimeSeries timeSeries, FunctionValueMap functionValueMap) {
    //If it is empty, we return NaN
    if (timeSeries.size() <= 0) {
        functionValueMap.add(this, Double.NaN);
        return;
    }

    //the values to iterate
    double[] values = timeSeries.getValuesAsArray();
    //Initialize the values with the first element
    double min = values[0];
    double max = values[0];

    for (int i = 1; i < values.length; i++) {
        double current = values[i];

        //check for min
        if (current < min) {
            min = current;
        }
        //check of max
        if (current > max) {
            max = current;
        }
    }
    //return the absolute difference
    functionValueMap.add(this, Math.abs(max - min));
}

From source file:MathUtil.java

/** Arcus sin */
static public double asin(double x) {
    if (x < -1. || x > 1.) {
        return Double.NaN;
    }/*from   ww  w .j  av a 2s  .c o  m*/
    if (x == -1.) {
        return -Math.PI / 2;
    }
    if (x == 1) {
        return Math.PI / 2;
    }
    return atan(x / Math.sqrt(1 - x * x));
}

From source file:gis.proj.drivers.Snyder.java

protected static double parseDatumVal(String dVal) {
    double value = Double.NaN;

    try {// ww w. j  a v  a 2  s.c  o m
        String valueStr = dVal.trim();
        boolean doRadians = !(valueStr.lastIndexOf("r") < 0);
        double scalar = 1.0;

        //
        // Assume all values should be passed in as is, unless they
        // end with an 'r' which means the following:
        //         * Convert to radians
        //
        // All values are parsed using DMS to DD
        if (doRadians) {
            scalar = SnyderMath.DEG_TO_RAD;
            valueStr = valueStr.substring(0, valueStr.length() - 1);
        }

        value = toDD(valueStr) * scalar;
    } catch (Exception e) {
    }

    return value;
}

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

@Override
public double map(RealVector v) {
    double fx = Double.NaN;
    double[] x = v.toArray();
    int n = x.length;
    fx = 10 * n;//  w w w .  j a  v a  2 s .co  m
    for (int i = 0; i < n; i++) {
        fx += x[i] * x[i] - 10 * Math.cos(2 * Math.PI * x[i]);
    }
    return fx;
}

From source file:net.myrrix.common.stats.IntWeightedMean.java

@Override
public void clear() {
    totalWeight = 0;
    mean = Double.NaN;
}

From source file:bide.prior.PriorBeta.java

/**
 * Build a new instance./*w  ww  . j  ava2s .com*/
 * 
 * @param alpha
 *            first shape parameter (must be positive)
 * @param beta
 *            second shape parameter (must be positive)
 */

public PriorBeta(double alpha, double beta) {
    this.alpha = alpha;
    this.beta = beta;
    z = Double.NaN;
    bDist = new BetaDistribution(alpha, beta);

}

From source file:net.myrrix.common.stats.DoubleWeightedMean.java

@Override
public void clear() {
    totalWeight = 0.0;
    mean = Double.NaN;
}

From source file:de.qaware.chronix.solr.query.analysis.functions.aggregations.Integral.java

/**
 * Calculates the integral of the given time series using the simpson integrator of commons math lib
 *
 * @param timeSeries       the time series as argument for the chronix function
 * @param functionValueMap the analysis and values result map
 *///from w w  w  .  ja  v  a  2  s  .co m
@Override
public void execute(MetricTimeSeries timeSeries, FunctionValueMap functionValueMap) {

    if (timeSeries.isEmpty()) {
        functionValueMap.add(this, Double.NaN);
        return;
    }

    SimpsonIntegrator simpsonIntegrator = new SimpsonIntegrator();
    double integral = simpsonIntegrator.integrate(Integer.MAX_VALUE, x -> timeSeries.getValue((int) x), 0,
            timeSeries.size() - 1);

    functionValueMap.add(this, integral);
}