List of usage examples for java.lang Double isNaN
public static boolean isNaN(double v)
From source file:com.ning.metrics.collector.util.Stats.java
/** * Average./* w w w . ja v a 2s.c o m*/ * * @return average */ @Managed @SuppressWarnings("unused") public double getMillisAvg() { double avg = millisStats.getMean(); return Double.isNaN(avg) ? 0.0 : avg; }
From source file:org.jfree.data.general.DefaultHeatMapDataset.java
/** * Creates a new dataset where all the z-values are initially 0. This is * a fixed size array of z-values./* w w w. j a v a 2s .c o m*/ * * @param xSamples the number of x-values. * @param ySamples the number of y-values * @param minX the minimum x-value in the dataset. * @param maxX the maximum x-value in the dataset. * @param minY the minimum y-value in the dataset. * @param maxY the maximum y-value in the dataset. */ public DefaultHeatMapDataset(int xSamples, int ySamples, double minX, double maxX, double minY, double maxY) { if (xSamples < 1) { throw new IllegalArgumentException("Requires 'xSamples' > 0"); } if (ySamples < 1) { throw new IllegalArgumentException("Requires 'ySamples' > 0"); } if (Double.isInfinite(minX) || Double.isNaN(minX)) { throw new IllegalArgumentException("'minX' cannot be INF or NaN."); } if (Double.isInfinite(maxX) || Double.isNaN(maxX)) { throw new IllegalArgumentException("'maxX' cannot be INF or NaN."); } if (Double.isInfinite(minY) || Double.isNaN(minY)) { throw new IllegalArgumentException("'minY' cannot be INF or NaN."); } if (Double.isInfinite(maxY) || Double.isNaN(maxY)) { throw new IllegalArgumentException("'maxY' cannot be INF or NaN."); } this.xSamples = xSamples; this.ySamples = ySamples; this.minX = minX; this.maxX = maxX; this.minY = minY; this.maxY = maxY; this.zValues = new double[xSamples][]; for (int x = 0; x < xSamples; x++) { this.zValues[x] = new double[ySamples]; } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.BubbleRenderer.java
/** * Draws the visual representation of a single data item. * * @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. *//*from w w w . j a v a2 s .c om*/ 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) { final PlotOrientation orientation = plot.getOrientation(); // get the data point... final double x = dataset.getXValue(series, item); final double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { final XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); final double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); final 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; final 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); } final XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url); entities.add(entity); } final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } }
From source file:com.rapidminer.gui.plotter.charts.ColorizedShapeItemRenderer.java
/** * Draws the block representing the specified item. * /*from w w w.j a va 2 s . c om*/ * @param g2 * the graphics device. * @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) { Shape hotspot = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double colorValue = ((XYZDataset) dataset).getZValue(series, item); double normalized = (colorValue - minColor) / (maxColor - minColor); if (Double.isNaN(x) || Double.isNaN(y)) { // can't draw anything return; } double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); PlotOrientation orientation = plot.getOrientation(); Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY, transX); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX, transY); } hotspot = shape; if (shape.intersects(dataArea)) { g2.setPaint(colorProvider.getPointColor(normalized)); g2.fill(shape); if (getDrawOutlines()) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } // add an entity for the item... if (entities != null) { addEntity(entities, hotspot, dataset, series, item, transX, transY); } }
From source file:dbs_project.util.Utils.java
public static double generateRandomDouble() { double d;//from w w w . java2 s. c om do { d = Double.longBitsToDouble(randomLong()); } while (Double.isNaN(d) || Double.isInfinite(d)); return d; }
From source file:bb.mcmc.analysis.ESSConvergeStat.java
@Override protected double calculateEachStat(String key) { List<Double> listDouble = Arrays.asList(ArrayUtils.toObject(traceValues.get(key))); TraceCorrelation<Double> traceCorrelation = new TraceCorrelation<Double>(listDouble, TRACETYPE, stepSize); double stat = traceCorrelation.getESS(); if (Double.isNaN(stat)) { //Use two separate if to handle other NaN cases later if (traceCorrelation.getVariance() == 0) { stat = Double.NEGATIVE_INFINITY; System.err.println(STATISTIC_NAME + " could not be calculated for variable with id " + key + ". This is due to logged values being unchanged during the run");//. Check log file for details. "); }/* w w w . ja v a 2s .c om*/ } return stat; }
From source file:com.opengamma.analytics.math.rootfinding.BracketRoot.java
public double[] getBracketedPoints(final Function1D<Double, Double> f, final double xLower, final double xUpper, final double minX, final double maxX) { Validate.notNull(f, "f"); Validate.isTrue(xLower >= minX, "xLower < minX"); Validate.isTrue(xUpper <= maxX, "xUpper < maxX"); double x1 = xLower; double x2 = xUpper; double f1 = 0; double f2 = 0; boolean lowerLimitReached = false; boolean upperLimitReached = false; f1 = f.evaluate(x1);/* w ww.j a v a 2 s. c om*/ f2 = f.evaluate(x2); if (Double.isNaN(f1)) { throw new MathException("Failed to bracket root: function invalid at x = " + x1 + " f(x) = " + f1); } if (Double.isNaN(f2)) { throw new MathException("Failed to bracket root: function invalid at x = " + x2 + " f(x) = " + f2); } for (int count = 0; count < MAX_STEPS; count++) { if (f1 * f2 <= 0) { return new double[] { x1, x2 }; } if (lowerLimitReached && upperLimitReached) { throw new MathException("Failed to bracket root: no root found between minX and maxX"); } if (Math.abs(f1) < Math.abs(f2) && !lowerLimitReached) { x1 += RATIO * (x1 - x2); if (x1 < minX) { x1 = minX; lowerLimitReached = true; } f1 = f.evaluate(x1); if (Double.isNaN(f1)) { throw new MathException( "Failed to bracket root: function invalid at x = " + x1 + " f(x) = " + f1); } } else { x2 += RATIO * (x2 - x1); if (x2 > maxX) { x2 = maxX; upperLimitReached = true; } f2 = f.evaluate(x2); if (Double.isNaN(f2)) { throw new MathException( "Failed to bracket root: function invalid at x = " + x2 + " f(x) = " + f2); } } } throw new MathException("Failed to bracket root: max iterations"); }
From source file:com.hp.hpl.jena.sparql.util.Utils.java
static public String stringForm(double d) { if (Double.isInfinite(d)) { if (d < 0) return "-INF"; return "INF"; }/*from www.j a v a 2 s . c o m*/ if (Double.isNaN(d)) return "NaN"; // Otherwise, SPARQL form always has "e0" String x = Double.toString(d); if ((x.indexOf('e') != -1) || (x.indexOf('E') != -1)) return x; // Renormalize? return x + "e0"; }
From source file:eu.amidst.core.utils.Utils.java
/** * Tests if a given value is missing or not. * @param val a {@code double} value./*from w w w . j a va 2s . co m*/ * @return {@code true} is the value is missing, {@code false} otherwise. */ public static boolean isMissingValue(double val) { return Double.isNaN(val); }
From source file:com.itemanalysis.psychometrics.cmh.CochranMantelHaenszel.java
/** * * @param strataScore mathing score i.e. raw score, decile, or quintile * @param groupValue examinees group membership * @param itemScore examinees response to item *//*from ww w.j a va2 s .com*/ public void increment(double strataScore, String groupValue, double itemScore) { if (groupValue == null || "".equals(groupValue.trim()) || Double.isNaN(itemScore)) return; CmhTable temp = strata.get(strataScore); if (temp == null) { temp = new CmhTable(focalCode, referenceCode); strata.put(strataScore, temp); } temp.increment(groupValue, itemScore); combinedGroupsSd.increment(itemScore); if (groupValue.equals(focalCode)) { focalSd.increment(itemScore); } else if (groupValue.equals(referenceCode)) { referenceSd.increment(itemScore); } }