List of usage examples for java.lang Double isNaN
public static boolean isNaN(double v)
From source file:ch.epfl.lsir.xin.algorithm.core.UserBasedCF.java
/** * This function calculates the similarity matrix for users * *//*from w ww . j ava2 s.c o m*/ public void similarityMatrixCalculation() { for (int i = 0; i < this.ratingMatrix.getRow(); i++) { for (int j = i; j < this.ratingMatrix.getRow(); j++) { if (i == j) //the similarity with herself is 1 { this.similarityMatrix[i][j] = 1; } else { ArrayList<Double> commonRatings1 = new ArrayList<Double>(); ArrayList<Double> commonRatings2 = new ArrayList<Double>(); //find common items for the two users for (Map.Entry<Integer, Double> entry : this.ratingMatrix.getRatingMatrix().get(i).entrySet()) { int itemI = entry.getKey(); if (entry.getValue() != null && this.ratingMatrix.getRatingMatrix().get(j).get(itemI) != null) { commonRatings1.add(this.ratingMatrix.getRatingMatrix().get(i).get(itemI)); commonRatings2.add(this.ratingMatrix.getRatingMatrix().get(j).get(itemI)); } } double similarity = Double.NaN; if (this.similarityCalculation.equals("pcc")) { similarity = SimilarityCalculator.getSimilarityPCC(commonRatings1, commonRatings2, this.config.getInt("SHRINKAGE")); } else if (this.similarityCalculation.equals("cosine")) { similarity = SimilarityCalculator.getSimilarityCosine(commonRatings1, commonRatings2, this.config.getInt("SHRINKAGE")); } else { logger.append("Cannot determine which similarity calculation method is used for. \n"); return; } if (Double.isNaN(similarity)) { similarity = 0; } this.similarityMatrix[i][j] = similarity; this.similarityMatrix[j][i] = similarity; } } } }
From source file:it.units.malelab.ege.benchmark.mapper.MappingPropertiesFitness.java
@Override public MultiObjectiveFitness<Double> compute(Node<String> mapperRawPhenotype) { Map<Property, double[]> propertyValues = new LinkedHashMap<>(); for (Property property : properties) { propertyValues.put(property, new double[problems.size()]); }/*from ww w . j ava 2 s . c om*/ int i = 0; for (Problem<String, NumericFitness> problem : problems.keySet()) { List<Node<String>> phenotypes = new ArrayList<>(); Multiset<Node<String>> groups = LinkedHashMultiset.create(); //build mapper RecursiveMapper<String> mapper = new RecursiveMapper<>(mapperRawPhenotype, maxMappingDepth, EXPRESSIVENESS_DEPTH, problem.getGrammar()); //map for (BitsGenotype genotype : genotypes) { Node<String> phenotype = Node.EMPTY_TREE; try { phenotype = mapper.map(genotype, Collections.EMPTY_MAP); } catch (MappingException ex) { //ignore } phenotypes.add(phenotype); groups.add(phenotype); } //compute properties if (propertyValues.keySet().contains(Property.REDUNDANCY)) { propertyValues.get(Property.REDUNDANCY)[i] = 1d - (double) groups.elementSet().size() / (double) genotypes.size(); } if (propertyValues.keySet().contains(Property.NON_UNIFORMITY)) { double[] groupSizes = new double[groups.elementSet().size()]; int c = 0; for (Node<String> phenotype : groups.elementSet()) { groupSizes[c] = (double) groups.count(phenotype); c = c + 1; } propertyValues.get(Property.NON_UNIFORMITY)[i] = Math.sqrt(StatUtils.variance(groupSizes)) / StatUtils.mean(groupSizes); } if (propertyValues.keySet().contains(Property.NON_LOCALITY)) { double[] phenotypeDistances = computeDistances(phenotypes, problems.get(problem)); double locality = 1d - (1d + (new PearsonsCorrelation().correlation(genotypeDistances, phenotypeDistances))) / 2d; propertyValues.get(Property.NON_LOCALITY)[i] = Double.isNaN(locality) ? 1d : locality; } i = i + 1; } Double[] meanValues = new Double[properties.length]; for (int j = 0; j < properties.length; j++) { meanValues[j] = StatUtils.mean(propertyValues.get(properties[j])); } MultiObjectiveFitness<Double> mof = new MultiObjectiveFitness<Double>(meanValues); return mof; }
From source file:juicebox.track.EigenvectorTrack.java
/** * Render the track in the supplied rectangle. It is the responsibility of the track to draw within the * bounds of the rectangle./*ww w .j a v a 2s. c o m*/ * * @param g2d the graphics context * @param rect the track bounds, relative to the enclosing DataPanel bounds. * @param gridAxis */ @Override public void render(Graphics2D g2d, Context context, Rectangle rect, TrackPanel.Orientation orientation, HiCGridAxis gridAxis) { g2d.setColor(color); int height = orientation == TrackPanel.Orientation.X ? rect.height : rect.width; int width = orientation == TrackPanel.Orientation.X ? rect.width : rect.height; int y = orientation == TrackPanel.Orientation.X ? rect.y : rect.x; int x = orientation == TrackPanel.Orientation.X ? rect.x : rect.y; MatrixZoomData zd; try { zd = hic.getZd(); } catch (Exception e) { return; } int zoom = zd.getZoom().getBinSize(); if (zoom != currentZoom) { clearDataCache(); } int chrIdx = orientation == TrackPanel.Orientation.X ? zd.getChr1Idx() : zd.getChr2Idx(); double[] eigen = dataCache.get(chrIdx); if (eigen == null) { eigen = hic.getEigenvector(chrIdx, 0); currentZoom = zoom; setData(chrIdx, eigen); } if (eigen == null || eigen.length == 0) { Font original = g2d.getFont(); g2d.setFont(FontManager.getFont(12)); if (orientation == TrackPanel.Orientation.X) { GraphicUtils.drawCenteredText("Eigenvector not available at this resolution", rect, g2d); } else { drawRotatedString(g2d, "Eigenvector not available at this resolution", (2 * rect.height) / 3, rect.x + 15); } g2d.setFont(original); return; } double dataMax = dataMaxCache.get(chrIdx); double median = medianCache.get(chrIdx); int h = height / 2; for (int bin = (int) context.getBinOrigin(); bin < eigen.length; bin++) { if (Double.isNaN(eigen[bin])) continue; int xPixelLeft = x + (int) ((bin - context.getBinOrigin()) * hic.getScaleFactor()); int xPixelRight = x + (int) ((bin + 1 - context.getBinOrigin()) * hic.getScaleFactor()); if (xPixelRight < x) { continue; } else if (xPixelLeft > x + width) { break; } double x2 = eigen[bin] - median; double max = dataMax - median; int myh = (int) ((x2 / max) * h); if (x2 > 0) { g2d.fillRect(xPixelLeft, y + h - myh, (xPixelRight - xPixelLeft), myh); } else { g2d.fillRect(xPixelLeft, y + h, (xPixelRight - xPixelLeft), -myh); } } }
From source file:fastcall.FArrayUtils.java
/** * Remove NaN from a double array// w w w . ja va 2 s. c o m * @param value * @return */ public static double[] removeNaN(double[] value) { TDoubleArrayList vList = new TDoubleArrayList(); for (int i = 0; i < value.length; i++) { if (Double.isNaN(value[i])) continue; vList.add(value[i]); } return vList.toArray(); }
From source file:com.ning.metrics.collector.util.Stats.java
/** * 90th percentile/*from w w w. j av a 2 s . c om*/ * * @return 90th percentile */ @Managed @SuppressWarnings("unused") public double getSizeTP90() { double percentile = sizeStats.getPercentile(90); return Double.isNaN(percentile) ? 0.0 : percentile; }
From source file:fr.gael.drb.cortex.topic.sentinel3.jai.operator.QuicklookSlstrRIF.java
private BufferedImage toGrayScale(Raster in, PixelCorrection c, boolean invertColors, boolean ignoreBadStats) { int width = in.getWidth(); int height = in.getHeight(); // compute stats SummaryStatistics stats = new SummaryStatistics(); for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { int pixel = checkAndApplyCorrection(in.getSample(i, j, 0), c); if (pixel != c.nodata) stats.addValue(pixel);/*from w ww . j a v a 2 s . com*/ } } double lowerBound = Math.max(stats.getMin(), stats.getMean() - 3 * stats.getStandardDeviation()); double upperBound = Math.min(stats.getMax(), stats.getMean() + 3 * stats.getStandardDeviation()); if (!ignoreBadStats) if (Double.isNaN(stats.getMean()) || Double.isNaN(stats.getStandardDeviation()) || stats.getStandardDeviation() < 1) throw new IllegalStateException("Ugly band stats. Acquired during night?"); return toGrayScale(in, c, invertColors, lowerBound, upperBound); }
From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java
@Test public void testFloat64DecodeNaN() throws IOException { JsonParser p = f.createParser("\"NaN\""); p.nextToken();//from w w w . ja v a 2s . co m assertTrue(Double.isNaN(JsonValueHandler.FLOAT64.readValue(p))); }
From source file:org.trade.ui.chart.renderer.VolumeBarRenderer.java
/** * Draws the visual representation of a single data item. * //ww w .j av a 2 s. co m * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the plot 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 axis. * @param rangeAxis * the range axis. * @param dataset * the dataset. * @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. * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D, * XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot, * ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int) */ 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) { if (!getItemVisible(series, item)) { return; } VolumeDataset volumeDataset = (VolumeDataset) dataset; VolumeItem volumeItem = (VolumeItem) volumeDataset.getSeries(series).getDataItem(item); if (volumeItem.isSide()) { this.color = Color.GREEN; } else { this.color = Color.RED; } double value0; double value1; if (this.getUseYInterval()) { value0 = volumeDataset.getStartYValue(series, item); value1 = volumeDataset.getEndYValue(series, item); } else { value0 = this.getBase(); value1 = volumeDataset.getYValue(series, item); } if (Double.isNaN(value0) || Double.isNaN(value1)) { return; } if (value0 <= value1) { if (!rangeAxis.getRange().intersects(value0, value1)) { return; } } else { if (!rangeAxis.getRange().intersects(value1, value0)) { return; } } double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge()); double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge()); double bottom = Math.min(translatedValue0, translatedValue1); double top = Math.max(translatedValue0, translatedValue1); double startX = volumeItem.getPeriod().getFirstMillisecond(); if (Double.isNaN(startX)) { return; } double endX = volumeItem.getPeriod().getLastMillisecond(); if (Double.isNaN(endX)) { return; } if (startX <= endX) { if (!domainAxis.getRange().intersects(startX, endX)) { return; } } else { if (!domainAxis.getRange().intersects(endX, startX)) { return; } } // is there an alignment adjustment to be made? if (this.getBarAlignmentFactor() >= 0.0 && this.getBarAlignmentFactor() <= 1.0) { double x = volumeDataset.getXValue(series, item); double interval = endX - startX; startX = x - interval * this.getBarAlignmentFactor(); endX = startX + interval; } RectangleEdge location = plot.getDomainAxisEdge(); double translatedStartX = domainAxis.valueToJava2D(startX, dataArea, location); double translatedEndX = domainAxis.valueToJava2D(endX, dataArea, location); double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX)); RectangleEdge domainEdge = plot.getDomainAxisEdge(); double xx = domainAxis.valueToJava2D(startX, dataArea, domainEdge); if (getMargin() > 0.0) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; } Rectangle2D bar = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { // clip left and right bounds to data area bottom = Math.max(bottom, dataArea.getMinX()); top = Math.min(top, dataArea.getMaxX()); bar = new Rectangle2D.Double(bottom, xx, top - bottom, translatedWidth); } else if (orientation == PlotOrientation.VERTICAL) { // clip top and bottom bounds to data area bottom = Math.max(bottom, dataArea.getMinY()); top = Math.min(top, dataArea.getMaxY()); bar = new Rectangle2D.Double(xx - (translatedWidth / 2), bottom, translatedWidth, top - bottom); } boolean positive = (value1 > 0.0); boolean inverted = rangeAxis.isInverted(); RectangleEdge barBase; if (orientation == PlotOrientation.HORIZONTAL) { if (positive && inverted || !positive && !inverted) { barBase = RectangleEdge.RIGHT; } else { barBase = RectangleEdge.LEFT; } } else { if (positive && !inverted || !positive && inverted) { barBase = RectangleEdge.BOTTOM; } else { barBase = RectangleEdge.TOP; } } if (getShadowsVisible()) { this.getBarPainter().paintBarShadow(g2, this, series, item, bar, barBase, !this.getUseYInterval()); } this.getBarPainter().paintBar(g2, this, series, item, bar, barBase); if (isItemLabelVisible(series, item)) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); drawItemLabel(g2, dataset, series, item, plot, generator, bar, value1 < 0.0); } // update the cross hair point double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, location); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge()); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, plot.getOrientation()); EntityCollection entities = state.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); } XYItemEntity entity = new XYItemEntity(bar, dataset, series, item, tip, null); entities.add(entity); } }
From source file:gr.iit.demokritos.cru.cps.ai.ProfileMerger.java
public ArrayList<Double> CalculateUserTrends(ArrayList<String> users_features, Double start_time) throws ParseException { SimpleDateFormat sdfu = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss"); ArrayList<Double> result = new ArrayList<Double>(); for (int i = 0; i < users_features.size(); i++) { SimpleRegression regression = new SimpleRegression(); String[] features = ((String) users_features.get(i)).split(";"); double average = 0.0; double f = 0.0; for (String s : features) { String[] inside_feature = s.split(","); //make timestamp secs Date udate = sdfu.parse(inside_feature[1]); double sec = udate.getTime(); if (sec > start_time) { continue; }/*ww w .j av a2 s.co m*/ average += Double.parseDouble(inside_feature[0]); //fix mls regr regression.addData(sec, Double.parseDouble(inside_feature[0])); average = average / features.length; f = Math.atan(regression.getSlope());// atan of slope is the angle of the regression in rad if (Double.isNaN(f)) { f = 0; } if (f != 0 && (Math.toDegrees(f) > 90 || Math.toDegrees(f) < -90)) { if ((Math.toDegrees(f) / 90) % 2 == 0) {//make angles in [-90,90] f = Math.toDegrees(f) % Math.toDegrees(Math.PI / 2); } else { f = -Math.toDegrees(f) % Math.toDegrees(Math.PI / 2); } } f = f + Math.PI / 2;//refrain trend=0 } result.add(f); result.add(f * average); } return result; }
From source file:de.hdm.uls.loadtests.ui.XYLineAndAreaRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device./*from www . j a v a2 s. c o m*/ * @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 axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @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. */ 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) { if (!getItemVisible(series, item)) { return; } XYAreaRendererState areaState = (XYAreaRendererState) state; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1)) { y1 = 0.0; } double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge()); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge()); // get the previous point and the next point so we can calculate a // "hot spot" for the area (used by the chart entity)... int itemCount = dataset.getItemCount(series); double x0 = dataset.getXValue(series, Math.max(item - 1, 0)); double y0 = dataset.getYValue(series, Math.max(item - 1, 0)); if (Double.isNaN(y0)) { y0 = 0.0; } double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge()); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge()); double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1)); double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1)); if (Double.isNaN(y2)) { y2 = 0.0; } double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge()); double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge()); double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge()); Polygon hotspot = null; if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { hotspot = new Polygon(); hotspot.addPoint((int) transZero, (int) ((transX0 + transX1) / 2.0)); hotspot.addPoint((int) ((transY0 + transY1) / 2.0), (int) ((transX0 + transX1) / 2.0)); hotspot.addPoint((int) transY1, (int) transX1); hotspot.addPoint((int) ((transY1 + transY2) / 2.0), (int) ((transX1 + transX2) / 2.0)); hotspot.addPoint((int) transZero, (int) ((transX1 + transX2) / 2.0)); } else { // vertical orientation hotspot = new Polygon(); hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) transZero); hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) ((transY0 + transY1) / 2.0)); hotspot.addPoint((int) transX1, (int) transY1); hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) ((transY1 + transY2) / 2.0)); hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) transZero); } if (item == 0) { // create a new area polygon for the series areaState.area = new Polygon(); // the first point is (x, 0) double zero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge()); if (plot.getOrientation() == PlotOrientation.VERTICAL) { areaState.area.addPoint((int) transX1, (int) zero); } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { areaState.area.addPoint((int) zero, (int) transX1); } } // Add each point to Area (x, y) if (plot.getOrientation() == PlotOrientation.VERTICAL) { areaState.area.addPoint((int) transX1, (int) transY1); } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { areaState.area.addPoint((int) transY1, (int) transX1); } PlotOrientation orientation = plot.getOrientation(); Paint paint = getItemPaint(series, item); Stroke stroke = getItemStroke(series, item); g2.setPaint(paint); g2.setStroke(stroke); Shape shape = null; if (getPlotShapes()) { shape = getItemShape(series, item); if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } else if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } g2.draw(shape); } if (getPlotLines()) { if (item > 0) { if (plot.getOrientation() == PlotOrientation.VERTICAL) { areaState.line.setLine(transX0, transY0, transX1, transY1); } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { areaState.line.setLine(transY0, transX0, transY1, transX1); } g2.draw(areaState.line); } } // Check if the item is the last item for the series. // and number of items > 0. We can't draw an area for a single point. if (getPlotArea() && item > 0 && item == (itemCount - 1)) { if (orientation == PlotOrientation.VERTICAL) { // Add the last point (x,0) areaState.area.addPoint((int) transX1, (int) transZero); } else if (orientation == PlotOrientation.HORIZONTAL) { // Add the last point (x,0) areaState.area.addPoint((int) transZero, (int) transX1); } Paint fillPaint = getItemFillPaint(series, item); if (fillPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) fillPaint; GradientPaintTransformer t = new StandardGradientPaintTransformer(); fillPaint = t.transform(gp, areaState.area.getBounds()); } g2.setPaint(fillPaint); g2.fill(areaState.area); // draw an outline around the Area. if (isOutline()) { g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(areaState.area); } } updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation); // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null && hotspot != 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(hotspot, dataset, series, item, tip, url); entities.add(entity); } } }