Example usage for java.lang Double isNaN

List of usage examples for java.lang Double isNaN

Introduction

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

Prototype

public static boolean isNaN(double v) 

Source Link

Document

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Usage

From source file:net.sourceforge.jabm.evolution.FitnessProportionateBreeder.java

public AgentList reproduce(AgentList currentGeneration) {

    int n = currentGeneration.size();
    AgentList nextGeneration = new AgentList(currentGeneration);

    double[] cummulativeFitnesses = cummulativeFitnesses(currentGeneration);

    if (!Double.isNaN(totalFitness) && !Double.isInfinite(totalFitness)) {
        for (int i = 0; i < n; i++) {
            int j = choose(cummulativeFitnesses);
            reproduce(nextGeneration.get(i), currentGeneration.get(j));
        }/*  ww w  .ja va2 s.  c  om*/
    } else {
        logger.warn("Not reproducing because fitness is undefined");
    }

    return nextGeneration;
}

From source file:org.sloth.validation.CoordinateValidator.java

@Override
public void validate(Object t, Errors e) {
    Coordinate c = (Coordinate) t;//from   w w  w .j av a  2 s .co m
    double lon = c.getLongitude(), lat = c.getLatitude();

    if (lon > 180.0 || lon < -180.0) {
        e.rejectValue("longitude", INVALID_LONGITUDE);
    }
    if (lat > 180.0 || lat < -180.0 || lat == Double.NaN) {
        e.rejectValue("latitude", INVALID_LATITUDE);
    }
    if (Double.isNaN(lat)) {
        e.rejectValue("latitude", EMPTY_LATITUDE);
    }
    if (Double.isNaN(lon)) {
        e.rejectValue("longitude", EMPTY_LONGITUDE);
    }
}

From source file:com.proofpoint.units.Duration.java

public Duration(double value, TimeUnit unit) {
    Preconditions.checkArgument(!Double.isInfinite(value), "value is infinite");
    Preconditions.checkArgument(!Double.isNaN(value), "value is not a number");
    Preconditions.checkArgument(value >= 0, "value is negative");
    Preconditions.checkNotNull(unit, "unit is null");

    this.value = value;
    this.unit = unit;
}

From source file:org.spantus.exp.segment.draw.DrawDtw.java

public DrawDtw(DtwInfo info) {
    this.info = info;
    Double[] minMax = new Double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
    for (List<Double> list : info.getDistanceMatrix()) {
        for (Double float1 : list) {
            minMax[0] = Double.isNaN(float1) ? minMax[0] : Math.min(minMax[0], float1);
            minMax[1] = Double.isNaN(float1) ? minMax[1] : Math.max(minMax[1], float1);
        }//from   w w  w  .  j  av a2s .c  o m
    }
    this.min = minMax[0];
    this.max = minMax[1];
    log.debug("min: " + min + "; max: " + max);
}

From source file:agents.firm.sales.prediction.LearningFixedElasticitySalesPredictor.java

@Override
protected void updateRegressorAndUseItToUpdatePredictor() {
    //force a regression
    regressor.updateModel();/*from   w  ww .j  av  a  2 s.c om*/
    //update slope (we need to put the inverse as a sign because the number is subtracted from old price)
    if (!Double.isNaN(regressor.getSlope()))
        predictor.setDecrementDelta(
                (int) Math.round(-regressor.getSlope() * Math.exp(regressor.getLastPriceObserved())
                        / Math.exp(regressor.getLastQuantityConsumedObserved())));
    else
        predictor.setDecrementDelta(0);
}

From source file:net.sf.json.JSONUtils.java

/**
 * Produce a string from a double. The string "null" will be returned if the
 * number is not finite.// w w w.j  a v  a  2 s.c  o m
 *
 * @param d A double.
 * @return A String.
 */
public static String doubleToString(double d) {
    if (Double.isInfinite(d) || Double.isNaN(d)) {
        return "null";
    }

    // Shave off trailing zeros and decimal point, if possible.
    String s = Double.toString(d);

    if ((s.indexOf('.') > 0) && (s.indexOf('e') < 0) && (s.indexOf('E') < 0)) {
        while (s.endsWith("0")) {
            s = s.substring(0, s.length() - 1);
        }

        if (s.endsWith(".")) {
            s = s.substring(0, s.length() - 1);
        }
    }

    return s;
}

From source file:com.clust4j.metrics.scoring.TestMetrics.java

@Test
public void testSilhouetteScoreNaN() {
    Array2DRowRealMatrix X = IRIS.getData();
    final int[] labels = VecUtils.repInt(1, X.getRowDimension());

    assertTrue(Double.isNaN(SILHOUETTE.evaluate(X, labels)));
}

From source file:bide.prior.PriorBeta.java

/**
 * Recompute the normalization factor.//from   ww  w  .j a  v  a 2  s  .co m
 */
private void recomputeZ() {
    if (Double.isNaN(z)) {
        z = Gamma.logGamma(alpha) + Gamma.logGamma(beta) - Gamma.logGamma(alpha + beta);
    }
}

From source file:com.opengamma.analytics.math.interpolation.ShapePreservingCubicSplineInterpolator.java

@Override
public PiecewisePolynomialResult interpolate(final double[] xValues, final double[] yValues) {

    ArgumentChecker.notNull(xValues, "xValues");
    ArgumentChecker.notNull(yValues, "yValues");

    ArgumentChecker.isTrue(xValues.length == yValues.length, "xValues length = yValues length");
    ArgumentChecker.isTrue(xValues.length > 2, "Data points should be more than 1");

    final int nDataPts = xValues.length;

    for (int i = 0; i < nDataPts; ++i) {
        ArgumentChecker.isFalse(Double.isNaN(xValues[i]), "xData containing NaN");
        ArgumentChecker.isFalse(Double.isInfinite(xValues[i]), "xData containing Infinity");
        ArgumentChecker.isFalse(Double.isNaN(yValues[i]), "yData containing NaN");
        ArgumentChecker.isFalse(Double.isInfinite(yValues[i]), "yData containing Infinity");
    }//from   ww w .  j a va 2s.  c o m

    for (int i = 0; i < nDataPts; ++i) {
        for (int j = i + 1; j < nDataPts; ++j) {
            ArgumentChecker.isFalse(xValues[i] == xValues[j], "xValues should be distinct");
        }
    }

    final double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts);
    final double[] yValuesSrt = Arrays.copyOf(yValues, nDataPts);
    ParallelArrayBinarySort.parallelBinarySort(xValuesSrt, yValuesSrt);

    final double[] intervals = intervalsCalculator(xValuesSrt);
    final double[] slopes = slopesCalculator(yValuesSrt, intervals);
    final double[] beta = betaCalculator(slopes);
    double[] first = firstDiffFinder(intervals, slopes);
    double[] rValues = rValuesCalculator(slopes, first);

    boolean correctSign = false;
    int it = 0;

    while (correctSign == false) {
        correctSign = signChecker(beta, rValues);
        if (correctSign == false) {
            first = firstDiffSweep(intervals, slopes, beta, first);
            rValues = rValuesCalculator(slopes, first);
        }
        ++it;
        if (it > 10) {
            throw new IllegalArgumentException("Spline is not found!");
        }
    }

    final double[] second = secondDiffFinder(intervals, beta, rValues);
    final double[] tau = tauFinder(intervals, slopes, beta, first, second);
    final double[] knots = knotsProvider(xValuesSrt, intervals, tau);

    final double[][] coefMatrix = solve(yValuesSrt, intervals, slopes, first, second, tau);

    for (int i = 0; i < coefMatrix.length; ++i) {
        double ref = 0.;
        final double interval = knots[i + 1] - knots[i];
        for (int j = 0; j < 4; ++j) {
            ref += coefMatrix[i][j] * Math.pow(interval, 3 - j);
            ArgumentChecker.isFalse(Double.isNaN(coefMatrix[i][j]), "Too large input");
            ArgumentChecker.isFalse(Double.isInfinite(coefMatrix[i][j]), "Too large input");
        }
        final double yVal = i == coefMatrix.length - 1 ? yValues[nDataPts - 1] : coefMatrix[i + 1][3];
        final double bound = Math.max(Math.abs(ref) + Math.abs(yVal), 1.e-1);
        ArgumentChecker.isTrue(Math.abs(ref - yVal) < ERROR * bound,
                "Input is too large/small or data points are too close");
    }

    return new PiecewisePolynomialResult(new DoubleMatrix1D(knots), new DoubleMatrix2D(coefMatrix), 4, 1);
}

From source file:com.clust4j.kernel.CircularKernel.java

@Override
public double getPartialSimilarity(double[] a, double[] b) {
    final double lp = toHilbertPSpace(a, b);

    // Per corner case condition
    if (lp >= getSigma())
        return 0.0;

    final double twoOverPi = (2d / FastMath.PI);
    final double lpOverSig = lp / getSigma();

    /* Front segment */
    final double front = twoOverPi * FastMath.acos(-lpOverSig);

    /* Back segment */
    final double first = twoOverPi * lpOverSig;
    final double second = FastMath.sqrt(1.0 - FastMath.pow(lpOverSig, 2));
    final double back = first * second;
    final double answer = front - back;

    return Double.isNaN(answer) ? Double.NEGATIVE_INFINITY : answer;
}