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:cc.kave.commons.pointsto.evaluation.cv.CVEvaluator.java

public double evaluate(SetProvider setProvider) {
    List<Future<Pair<Integer, Double>>> futures = new ArrayList<>(numFolds);
    double[] evaluationResults = new double[numFolds];

    for (int i = 0; i < numFolds; ++i) {
        futures.add(executorService.submit(new FoldEvaluation(i, setProvider)));
    }//w  ww.ja v a  2  s  .  co m

    for (int i = 0; i < evaluationResults.length; ++i) {
        try {
            Pair<Integer, Double> result = futures.get(i).get();
            evaluationResults[i] = result.getValue();
            log("\tFold %d: %.3f\n", i + 1, evaluationResults[i]);
        } catch (ExecutionException e) {
            throw new RuntimeException(e.getCause());
        } catch (InterruptedException e) {
            e.printStackTrace();
            return Double.NaN;
        }

    }

    return StatUtils.mean(evaluationResults);
}

From source file:net.relet.freimap.LinkInfo.java

public void setLinkProfile(LinkedList<LinkData> lp) {

    XYSeries data = new XYSeries("etx");
    XYSeries avail = new XYSeries("avail");
    XYSeriesCollection datac = new XYSeriesCollection(data);
    datac.addSeries(avail);/*from w ww . j  a v a2s .c  o  m*/
    linkChart = ChartFactory.createXYLineChart("average link etx\r\naverage link availability", "time", "etx",
            datac, PlotOrientation.VERTICAL, false, false, false);
    sexupLayout(linkChart);

    long first = lp.getFirst().time, last = lp.getLast().time, lastClock = first, count = 0, //number of samplis in aggregation timespan
            maxCount = 0; //max idem
    long aggregate = (last - first) / CHART_WIDTH; //calculate aggregation timespan: divide available timespan in CHART_WIDTH equal chunks
    double sum = 0;

    /* ok, this ain't effective, we do it just to pre-calculate maxCount */
    ListIterator<LinkData> li = lp.listIterator();
    while (li.hasNext()) {
        LinkData ld = li.next();
        count++;
        if (ld.time - lastClock > aggregate) {
            if (maxCount < count)
                maxCount = count;
            lastClock = ld.time;
            count = 0;
        }
    }

    //reset for second iteration
    count = 0;
    lastClock = first;

    //iterate again
    li = lp.listIterator();
    while (li.hasNext()) {
        LinkData ld = li.next();

        sum += ld.quality;
        count++;

        if (aggregate == 0)
            aggregate = 1000;//dirty hack
        if (ld.time - lastClock > aggregate) {
            for (long i = lastClock; i < ld.time - aggregate; i += aggregate) {
                data.add(i * 1000, (i == lastClock) ? sum / count : Double.NaN);
                avail.add(i * 1000, (i == lastClock) ? ((double) count / maxCount) : 0);
            }

            count = 0;
            sum = 0;
            lastClock = ld.time;
        }
    }

    status = STATUS_AVAILABLE;
}

From source file:de.betterform.xml.xforms.action.SetIndexAction.java

/**
 * Performs the <code>setindex</code> action.
 *
 * @throws XFormsException if an error occurred during <code>setindex</code>
 * processing.// www.  java  2s . com
 */
public void perform() throws XFormsException {
    // check repeat idref
    Object repeatObject = this.container.lookup(this.repeatAttribute);
    if (repeatObject == null || !(repeatObject instanceof Repeat)) {
        throw new XFormsBindingException("invalid repeat id at " + DOMUtil.getCanonicalPath(this.getElement()),
                this.target, this.repeatAttribute);
    }
    Repeat repeat = (Repeat) repeatObject;

    List resultNodeset = evalInScopeContext();
    final String relativeExpr = this.indexAttribute;
    //todo:fix this hack - last() function does not evaluate correctly thus we take the size of the nodeset
    String result;
    if (relativeExpr.equals("last()")) {
        result = resultNodeset.size() + "";
    } else {
        result = XPathCache.getInstance().evaluateAsString(resultNodeset, getPosition(), relativeExpr,
                getPrefixMapping(), xpathFunctionContext);
    }

    double value = Double.NaN;
    if (result != null)
        value = Double.valueOf(result);

    if (Double.isNaN(value)) {
        getLogger().warn(
                this + " perform: expression '" + this.indexAttribute + "' does not evaluate to an integer");
        return;
    }

    // check boundaries
    long index = Math.round(value);
    if (index < 1) {
        repeat.setIndex(1);
        this.container.dispatch(repeat.getTarget(), XFormsEventNames.SCROLL_FIRST, null);
    } else if (index > repeat.getContextSize()) {
        index = repeat.getContextSize();
        repeat.setIndex((int) index);
        this.container.dispatch(repeat.getTarget(), XFormsEventNames.SCROLL_LAST, null);
    } else {
        // set repeat index
        repeat.setIndex((int) index);
    }

    // update behaviour
    doRebuild(true);
    doRecalculate(true);
    doRevalidate(true);
    doRefresh(true);
}

From source file:com.fay.statics.SummaryStat.java

public double variance() {
    if (numObs < 2)
        return Double.NaN;
    return (weightSum * sumSquare - valSum * valSum) / (weightSum * (weightSum - 1));
}

From source file:marytts.tools.voiceimport.HalfPhoneUnitLabelComputer.java

@Override
protected List<Double> getMidTimes(List<String> labels, List<Double> endTimes) {
    assert labels.size() == endTimes.size();

    List<Double> midTimes = new ArrayList<Double>(endTimes.size());
    double startTime = 0;
    for (int i = 0; i < labels.size(); i++) {
        String label = labels.get(i);
        double endTime = endTimes.get(i);

        boolean isTransient = false;
        double peakTime = Double.NaN;
        if (energyBasedTransientSplitting) {
            try {
                Allophone allophone = db.getAllophoneSet().getAllophone(label);
                isTransient = allophone.isPlosive() || allophone.isAffricate();
                if (isTransient) {
                    peakTime = getEnergyPeak(startTime, endTime);
                }/*  w ww  .j  a  v  a2  s  .  com*/
            } catch (NullPointerException e) {
                // ignore for now
            } catch (IOException e) {
                // ignore for now
            }
        }

        double midTime;
        if (isTransient && !Double.isNaN(peakTime)) {
            midTime = peakTime;
        } else {
            midTime = (startTime + endTime) / 2;
        }
        midTimes.add(midTime);
        startTime = endTime;
    }
    return midTimes;
}

From source file:net.sf.maltcms.chromaui.charts.renderer.XYNoBlockRenderer.java

/**
 * Draws the block representing the specified item.
 *
 * @param g2 the graphics device.// w  w w .  j a  v a2  s .  co m
 * @param state the state.
 * @param dataArea the data area.
 * @param info the plot rendering info.
 * @param plot the plot.
 * @param domainAxis the x-axis.
 * @param rangeAxis the y-axis.
 * @param dataset the dataset.
 * @param series the series index.
 * @param item the item index.
 * @param crosshairState the crosshair state.
 * @param pass the pass index.
 */
@Override
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) {
    //        return;
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = 0.0;
    if (dataset instanceof XYZDataset) {
        z = ((XYZDataset) dataset).getZValue(series, item);
        if (entityThreshold != Double.NaN && z < entityThreshold) {
            return;
        }
    }

    //}
    Paint p = getPaintScale().getPaint(z);
    //        if(p.equals(getPaintScale().getPaint(getPaintScale().getLowerBound()))) {
    //            return;
    //        }
    //        double xx0 = domainAxis.valueToJava2D(x + xOffset, dataArea,
    //                plot.getDomainAxisEdge());
    //        double yy0 = rangeAxis.valueToJava2D(y + yOffset, dataArea,
    //                plot.getRangeAxisEdge());
    //        double xx1 = domainAxis.valueToJava2D(x + blockWidth
    //                + xOffset, dataArea, plot.getDomainAxisEdge());
    //        double yy1 = rangeAxis.valueToJava2D(y + blockHeight
    //                + yOffset, dataArea, plot.getRangeAxisEdge());
    double xx0 = domainAxis.valueToJava2D(x - getBlockWidth() / 2, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y - getBlockHeight() / 2, dataArea, plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + getBlockWidth() / 2, dataArea, plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + getBlockHeight() / 2, dataArea, plot.getRangeAxisEdge());

    Rectangle2D block;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        if (dataArea.contains(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                Math.abs(xx0 - xx1))) {
            block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                    Math.abs(xx0 - xx1));
        } else {
            return;
        }
    } else {
        if (dataArea.contains(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                Math.abs(yy0 - yy1))) {
            block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                    Math.abs(yy0 - yy1));
        } else {
            return;
        }
    }

    g2.setPaint(p);
    g2.fill(block);
    g2.setStroke(new BasicStroke(1.0f));
    g2.draw(block);
    EntityCollection entities = state.getEntityCollection();
    //        System.out.println("Entity collection is of type: "+entities.getClass());
    if (entities != null) {
        //System.out.println("Adding entity");
        addEntity(entities, block, dataset, series, item, block.getCenterX(), block.getCenterY());
    }

}

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

@Test
public void testEmptyLatitude() {
    CoordinateValidator cv = new CoordinateValidator();
    Coordinate c = new Coordinate();
    c.setLatitude(Double.NaN);
    Errors errors = new BeanPropertyBindingResult(c, "coordinate");
    cv.validate(c, errors);//  w w  w  .  j  a  va2  s.  c o m
    assertTrue(errors.hasErrors());
    assertEquals(COORDINATE.EMPTY_LATITUDE, errors.getFieldError("latitude").getCode());
}

From source file:org.jfree.data.time.ohlc.OHLCItem.java

/**
 * Returns the low value./*from   w  ww  .  ja  v  a  2  s  .  c  om*/
 *
 * @return The low value.
 */
public double getLowValue() {
    OHLC ohlc = (OHLC) getObject();
    if (ohlc != null) {
        return ohlc.getLow();
    } else {
        return Double.NaN;
    }
}

From source file:cpcc.core.utils.RealVehicleUtils.java

/**
 * @param rvList the list of real vehicles.
 * @return the bounding box of all areas of operation.
 *//*from w w w  .ja  v a2s. c  om*/
public static double[] findBoundingBox(List<RealVehicle> rvList) {
    double[] bbox = new double[] { Double.NaN, Double.NaN, Double.NaN, Double.NaN };

    for (RealVehicle rv : rvList) {
        if (StringUtils.isBlank(rv.getAreaOfOperation())) {
            continue;
        }

        try {
            FeatureCollection collection = new ObjectMapper().readValue(rv.getAreaOfOperation(),
                    FeatureCollection.class);

            for (Feature feature : collection) {
                double[] b = GeoJsonUtils.findBoundingBox(feature.getGeometry());
                GeoJsonUtils.mergeBoundingBoxes(bbox, b);
            }

        } catch (IOException e) {
            continue;
        }
    }

    return bbox;
}

From source file:org.pentaho.platform.uifoundation.chart.BubbleRenderer.java

/**
 * Draws the visual representation of a single data item.
 * /*from w w w  .  ja  v a2s .  com*/
 * @param g2
 *          the graphics device.
 * @param state
 *          the renderer state.
 * @param dataArea
 *          the area within which the data is being drawn.
 * @param info
 *          collects information about the drawing.
 * @param plot
 *          the plot (can be used to obtain standard color information etc).
 * @param domainAxis
 *          the domain (horizontal) axis.
 * @param rangeAxis
 *          the range (vertical) axis.
 * @param dataset
 *          the dataset (an {@link XYZDataset} is expected).
 * @param series
 *          the series index (zero-based).
 * @param item
 *          the item index (zero-based).
 * @param crosshairState
 *          crosshair information for the plot (<code>null</code> permitted).
 * @param pass
 *          the pass index.
 */
@Override
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    PlotOrientation orientation = plot.getOrientation();

    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = Double.NaN;
    if (dataset instanceof XYZDataset) {
        XYZDataset xyzData = (XYZDataset) dataset;
        z = xyzData.getZValue(series, item);
    }
    if (!Double.isNaN(z)) {
        RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
        double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);

        double circleSize;

        circleSize = maxSize * (z / maxZ);

        circleSize = Math.abs(circleSize);

        Ellipse2D circle = null;
        if (orientation == PlotOrientation.VERTICAL) {
            circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize,
                    circleSize);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize,
                    circleSize);
        }
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);

        if (isItemLabelVisible(series, item)) {
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
            }
        }

        // setup for collecting optional entity info...
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }

        // add an entity for the item...
        if (entities != null) {
            String tip = null;
            XYToolTipGenerator generator = getToolTipGenerator(series, item);
            if (generator != null) {
                tip = generator.generateToolTip(dataset, series, item);
            }
            String url = null;
            if (getURLGenerator() != null) {
                url = getURLGenerator().generateURL(dataset, series, item);
            }
            XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url);
            entities.add(entity);
        }

        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);
    }

}