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:MutableDouble.java

/**
 * Checks whether the double value is the special NaN value.
 * 
 * @return true if NaN
 */
public boolean isNaN() {
    return Double.isNaN(value);
}

From source file:com.rapidminer.operator.postprocessing.SimpleUncertainPredictionsTransformation.java

@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
    // checks//from   w  w  w . ja v  a  2s  .c o m
    Attribute predictedLabel = exampleSet.getAttributes().getPredictedLabel();
    if (predictedLabel == null) {
        throw new UserError(this, 107);
    }
    if (!predictedLabel.isNominal()) {
        throw new UserError(this, 119, predictedLabel, getName());
    }

    switch (getParameterAsInt(PARAMETER_CLASS_HANDLING)) {
    case CLASS_HANDLING_BALANCED:
        double minConfidence = getParameterAsDouble(PARAMETER_MIN_CONFIDENCE);
        for (Example example : exampleSet) {
            double predictionValue = example.getValue(predictedLabel);
            String predictionClass = predictedLabel.getMapping().mapIndex((int) predictionValue);
            double confidence = example.getConfidence(predictionClass);
            if (!Double.isNaN(confidence)) {
                if (confidence < minConfidence) {
                    example.setValue(predictedLabel, Double.NaN);
                }
            }
        }
        break;
    case CLASS_HANDLING_UNBALANCED:
        HashMap<String, Double> thresholdMap = new HashMap<String, Double>();
        for (String[] threshold : getParameterList(PARAMETER_MIN_CONFIDENCES)) {
            thresholdMap.put(threshold[0], Double.valueOf(threshold[1]));
        }

        for (Example example : exampleSet) {
            double predictionValue = example.getValue(predictedLabel);
            String predictionClass = predictedLabel.getMapping().mapIndex((int) predictionValue);
            double confidence = example.getConfidence(predictionClass);
            Double threshold = thresholdMap.get(predictionClass);
            if (!Double.isNaN(confidence) && threshold != null) {
                if (confidence < threshold.doubleValue()) {
                    example.setValue(predictedLabel, Double.NaN);
                }
            }
        }
        break;
    }

    return exampleSet;
}

From source file:com.ning.metrics.collector.util.Stats.java

/**
 * 99th percentile/*from  w ww .  ja v  a  2s  . co  m*/
 *
 * @return 99th percentile
 */
@Managed
public double getMillisTP99() {
    double percentile = millisStats.getPercentile(99);
    return Double.isNaN(percentile) ? 0.0 : percentile;
}

From source file:edu.harvard.iq.dataverse.util.SumStatCalculator.java

/**
 * Returns the number of Double.NaNs in a double-type array
 *
 * TODO: figure out if this is actually necessary - to count NaNs and
 * nulls separately;//from  w  w w.j a  v  a  2 s .  com
 *  -- L.A. 4.0 alpha 1
 */
private static int countNaNs(double[] x) {
    int NaNcounter = 0;
    for (int i = 0; i < x.length; i++) {
        if (Double.isNaN(x[i])) {
            NaNcounter++;
        }
    }
    return NaNcounter;
}

From source file:com.google.blockly.model.FieldNumber.java

/**
 * Sets the constraints on valid number values.
 * <p/>//from ww  w. j a va2s  .  co  m
 * Changing the constraints may trigger a {@link ChangeEvent}, even if the value does not
 * change.
 *
 * @param min The minimum allowed value, inclusive.
 * @param max The maximum allowed value, inclusive.
 * @param precision The precision of allowed values. Valid values are multiples of this number,
 *                  such as 1, 0.1, 100, or 0.125.
 */
public void setConstraints(double min, double max, double precision) {
    if (max == Double.POSITIVE_INFINITY || Double.isNaN(max)) {
        max = NO_CONSTRAINT;
    } else if (max == Double.NEGATIVE_INFINITY) {
        throw new IllegalArgumentException("Max cannot be -Inf. No valid values would exist.");
    }
    if (min == Double.NEGATIVE_INFINITY || Double.isNaN(min)) {
        min = NO_CONSTRAINT;
    } else if (min == Double.POSITIVE_INFINITY) {
        throw new IllegalArgumentException("Min cannot be Inf. No valid values would exist.");
    }
    if (precision == 0 || Double.isNaN(precision)) {
        precision = NO_CONSTRAINT;
    }
    if (Double.isInfinite(precision)) {
        throw new IllegalArgumentException("Precision cannot be infinite.");
    }
    if (!Double.isNaN(min) && !Double.isNaN(max) && min > max) {
        throw new IllegalArgumentException("Minimum value must be less than max. Found " + min + " > " + max);
    }
    if (!Double.isNaN(precision) && precision <= 0) {
        throw new IllegalArgumentException("Precision must be positive. Found " + precision);
    }

    double effectiveMin = Double.isNaN(min) ? -Double.MAX_VALUE : min;
    double effectiveMax = Double.isNaN(max) ? Double.MAX_VALUE : max;
    if (!Double.isNaN(precision)) {
        if (effectiveMin < 0) {
            double multiplier = Math.floor(-effectiveMin / precision);
            effectiveMin = precision * -multiplier;
        } else {
            double multiplier = Math.ceil(effectiveMin / precision);
            effectiveMin = precision * multiplier;
        }
        if (effectiveMax < 0) {
            double multiplier = Math.ceil(-effectiveMax / precision);
            effectiveMax = precision * -multiplier;
        } else {
            double multiplier = Math.floor(effectiveMax / precision);
            effectiveMax = precision * multiplier;

        }
        if (effectiveMin > effectiveMax) {
            throw new IllegalArgumentException("No valid value in range.");
        }
    }

    mMin = min;
    mMax = max;
    mPrecision = precision;
    mEffectiveMin = effectiveMin;
    mEffectiveMax = effectiveMax;
    mIntegerPrecision = (precision == Math.round(precision));
    if (!hasPrecision()) {
        mFormatter = NAIVE_DECIMAL_FORMAT;
    } else if (mIntegerPrecision) {
        mFormatter = INTEGER_DECIMAL_FORMAT;
    } else {
        String precisionStr = NAIVE_DECIMAL_FORMAT.format(precision);
        int decimalChar = precisionStr.indexOf('.');
        if (decimalChar == -1) {
            mFormatter = INTEGER_DECIMAL_FORMAT;
        } else {
            int significantDigits = precisionStr.length() - decimalChar;
            StringBuilder sb = new StringBuilder("0.");
            char[] sigDigitsFormat = new char[significantDigits];
            Arrays.fill(sigDigitsFormat, '#');
            sb.append(sigDigitsFormat);
            mFormatter = new DecimalFormat(sb.toString());
        }
    }

    setValueImpl(mValue, true);
}

From source file:com.newatlanta.bluedragon.CustomXYAreaRenderer.java

public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {
    super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
            crosshairState, pass);//from w  ww. j a v a2s  . co  m

    // The complete area chart is drawn when drawItem() is called for the last
    // item
    // so we need to draw all of the item labels after the last item so they'll
    // be
    // visible if they overlap the area chart.
    int itemCount = dataset.getItemCount(series);
    if (getPlotArea() && item > 0 && item == (itemCount - 1)) {
        // this is the last item so draw the item labels
        PlotOrientation orientation = plot.getOrientation();

        for (int i = 0; i < itemCount; i++) {
            if (isItemLabelVisible(series, i)) {
                double xValue = dataset.getXValue(series, i);
                double yValue = dataset.getYValue(series, i);
                if (Double.isNaN(yValue)) {
                    yValue = 0.0;
                }
                double transXValue = domainAxis.valueToJava2D(xValue, dataArea, plot.getDomainAxisEdge());
                double transYValue = rangeAxis.valueToJava2D(yValue, dataArea, plot.getRangeAxisEdge());

                double xx = transXValue;
                double yy = transYValue;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    xx = transYValue;
                    yy = transXValue;
                }
                drawItemLabel(g2, orientation, dataset, series, i, xx, yy, (yValue < 0.0));
            }
        }
    }
}

From source file:geogebra.common.kernel.algos.AlgoRootNewton.java

public final double calcRoot(Function fun, double start) {
    double root = Double.NaN;
    if (rootFinderBrent == null)
        rootFinderBrent = new BrentSolver(Kernel.STANDARD_PRECISION);

    // try Brent method with borders close to start value
    try {//from w ww .  j a  va  2  s. c o  m

        // arbitrary (used to depend on screen width)
        double step = 1;

        root = rootFinderBrent.solve(MAX_ITERATIONS, new RealRootAdapter(fun), start - step, start + step,
                start);
        if (checkRoot(fun, root)) {
            // System.out.println("1. Brent worked: " + root);
            return root;
        }
    } catch (Exception e) {
        root = Double.NaN;
    }

    // try Brent method on valid interval around start
    double[] borders = getDomain(fun, start);
    try {
        root = rootFinderBrent.solve(MAX_ITERATIONS, new RealRootAdapter(fun), borders[0], borders[1], start);
        if (checkRoot(fun, root)) {
            // System.out.println("2. Brent worked: " + root);
            return root;
        }
    } catch (Exception e) {
        root = Double.NaN;
    }

    // try Newton's method
    RealRootDerivFunction derivFun = fun.getRealRootDerivFunction();
    if (derivFun != null) {
        // check if fun(start) is defined
        double eval = fun.evaluate(start);
        if (Double.isNaN(eval) || Double.isInfinite(eval)) {
            // shift left border slightly right
            borders[0] = 0.9 * borders[0] + 0.1 * borders[1];
            start = (borders[0] + borders[1]) / 2;
        }

        if (rootFinderNewton == null) {
            rootFinderNewton = new NewtonSolver();
        }

        try {
            root = rootFinderNewton.solve(MAX_ITERATIONS, new RealRootDerivAdapter(derivFun), borders[0],
                    borders[1], start);
            if (checkRoot(fun, root)) {
                // System.out.println("Newton worked: " + root);
                return root;
            }
        } catch (Exception e) {
            root = Double.NaN;
        }
    }

    // neither Brent nor Newton worked
    return Double.NaN;
}

From source file:eu.eexcess.diversityasurement.CorrelationTest.java

@Test
public void spearmansRho_givenPosXAxis() {
    CorrelationValues c = newCorrelationValue4();
    SpearmansCorrelation sCorrelation = new SpearmansCorrelation();
    System.out.println("spearman correlation r(x, y)=" + sCorrelation.correlation(c.x, c.y));
    assertTrue(Double.isNaN(sCorrelation.correlation(c.x, c.y)));
}

From source file:net.cit.tetrad.dao.management.impl.SubDaoImpl.java

@SuppressWarnings("unchecked")
public void convertValue(GraphDto graphDto) {
    int interval = Integer.parseInt(TetradRrdConfig.getTetradRrdConfig("default_log_generation_interval"));
    List<HashMap<String, Object>> newStatusList = new ArrayList<HashMap<String, Object>>();
    List<HashMap<String, Object>> statusList = (List<HashMap<String, Object>>) graphDto.getStatusListObj();

    for (HashMap<String, Object> obj : statusList) {
        HashMap<String, Object> status = new HashMap<String, Object>();

        Set<String> keys = obj.keySet();
        Iterator<String> it = keys.iterator();
        while (it.hasNext()) {
            String key = it.next().toString();
            Object value = obj.get(key);
            Object newValue = value;
            if (value instanceof java.lang.Double) {
                double dvalue = (Double) value;
                if (!Double.isNaN(dvalue))
                    newValue = dvalue * interval;
            }//from   w w  w  . ja v  a  2s  . c  o m
            status.put(key, newValue);
        }
        newStatusList.add(status);
    }
    graphDto.setStatusListObj(newStatusList);
}

From source file:com.google.android.glass.sample.compass.model.Landmarks.java

/**
 * Converts a JSON object that represents a place into a {@link Place} object.
 *//*from  www  .  j av a 2 s .  co m*/
private Place jsonObjectToPlace(JSONObject object) {
    String name = object.optString("name");
    double latitude = object.optDouble("latitude", Double.NaN);
    double longitude = object.optDouble("longitude", Double.NaN);

    if (!name.isEmpty() && !Double.isNaN(latitude) && !Double.isNaN(longitude)) {
        return new Place(latitude, longitude, name);
    } else {
        return null;
    }
}