List of usage examples for java.lang Double isNaN
public static boolean isNaN(double v)
From source file:edu.jhuapl.bsp.detector.OpenMath.java
public static double mean(int[] in) { if (in != null && in.length > 0) { double sum = 0; for (int i = 0; i < in.length; i++) { sum += in[i];/*from w ww . ja v a 2 s . c o m*/ } double result = sum / in.length; if (Double.isNaN(result) || Double.isInfinite(result)) { return 0; } else { return result; } } return 0; }
From source file:gr.iit.demokritos.cru.cps.ai.ProfileMerger.java
public ArrayList<Double> CalculateUserTrends(ArrayList<String> users_features) 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(); 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;//from ww w. j av a2s .c o m } 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:com.joptimizer.optimizers.LPOptimizationRequest.java
public void setLb(DoubleMatrix1D lb) { for (int i = 0; i < lb.size(); i++) { double lbi = lb.getQuick(i); if (Double.isNaN(lbi) || Double.isInfinite(lbi)) { throw new IllegalArgumentException( "The lower bounds can not be set to Double.NaN or Double.INFINITY"); }//from w w w . java 2s .c o m } this.lb = lb; }
From source file:gda.plots.SimpleXYItemRenderer.java
/** * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information * stored in the Renderer itself./* w w w . ja v a 2 s. c o m*/ * * @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 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. */ @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) { SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series); if (!sxys.isVisible()) { return; } // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } PlotOrientation orientation = plot.getOrientation(); g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); // get the data point double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); // Test x1 = xValueTransformer.transformValue(x1); if (Double.isNaN(x1) || Double.isNaN(y1)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (sxys.isDrawLines()) { if (item > 0) { // get the previous data point... double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); // Test // System.out.print("tranformed " + x0); x0 = xValueTransformer.transformValue(x0); // Message.debug(" to " + x0); if (!Double.isNaN(x0) && !Double.isNaN(y0)) { boolean drawLine = true; if (getPlotDiscontinuous()) { // only draw a line if the gap between the current and // previous data // point is within the threshold int numX = dataset.getItemCount(series); double minX = dataset.getXValue(series, 0); double maxX = dataset.getXValue(series, numX - 1); drawLine = (x1 - x0) <= ((maxX - minX) / numX * getGapThreshold()); } if (drawLine) { double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } if (state.workingLine.intersects(dataArea)) { g2.draw(state.workingLine); } } } } } if (sxys.isDrawMarkers()) { Shape shape = sxys.getSymbol(); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } if (shape.intersects(dataArea)) { g2.setPaint(sxys.getSymbolPaint()); // Always use full stroke for drawing marker g2.setStroke(new BasicStroke()); if (sxys.getFilled()) { g2.fill(shape); } else { g2.draw(shape); } g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); } entityArea = shape; } if (getPlotImages()) { // use shape scale with transform?? // double scale = getShapeScale(plot, series, item, transX1, // transY1); Image image = getImage(plot, series, item, transX1, transY1); if (image != null) { Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image); g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null); entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(), image.getWidth(null), image.getHeight(null)); } } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, transX1, transY1, (y1 < 0.0)); } updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation); // add an entity for the item... if (entities != null) { addEntity(entities, entityArea, dataset, series, item, transX1, transY1); } }
From source file:net.librec.similarity.AbstractRecommenderSimilarity.java
/** * Build social similarity matrix with trainMatrix * and socialMatrix in dataModel./*from w w w . j a v a 2s. c o m*/ * * @param dataModel * the input data model */ public void buildSocialSimilarityMatrix(DataModel dataModel) { SparseMatrix trainMatrix = dataModel.getDataSplitter().getTrainData(); SparseMatrix socialMatrix = ((SocialDataAppender) dataModel.getDataAppender()).getUserAppender(); int numUsers = trainMatrix.numRows(); similarityMatrix = new SymmMatrix(numUsers); for (int userIdx = 0; userIdx < numUsers; userIdx++) { SparseVector userVector = trainMatrix.row(userIdx); if (userVector.getCount() == 0) { continue; } List<Integer> socialList = socialMatrix.getRows(userIdx); for (int socialIdx : socialList) { SparseVector socialVector = trainMatrix.row(socialIdx); if (socialVector.getCount() == 0) { continue; } double sim = getCorrelation(userVector, socialVector); if (!Double.isNaN(sim)) { similarityMatrix.set(userIdx, socialIdx, sim); } } } }
From source file:com.ning.metrics.collector.util.Stats.java
/** * 99.9th percentile//from w w w . j a va 2s . co m * * @return 99.9th percentile */ @Managed @SuppressWarnings("unused") public double getMillisTP999() { double percentile = millisStats.getPercentile(99.9); return Double.isNaN(percentile) ? 0.0 : percentile; }
From source file:net.rptools.tokentool.client.TokenTool.java
@Override public void start(Stage primaryStage) throws IOException { stage = primaryStage;/*from ww w . ja va2 s .co m*/ setUserAgentStylesheet(STYLESHEET_MODENA); // Setting the style back to the new Modena FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(AppConstants.TOKEN_TOOL_FXML), ResourceBundle.getBundle(AppConstants.TOKEN_TOOL_BUNDLE)); root = fxmlLoader.load(); tokentool_Controller = (TokenTool_Controller) fxmlLoader.getController(); Scene scene = new Scene(root); primaryStage.setTitle(I18N.getString("TokenTool.stage.title")); primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(AppConstants.TOKEN_TOOL_ICON))); primaryStage.setScene(scene); primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> { if (Double.isNaN(oldVal.doubleValue())) return; deltaX += newVal.doubleValue() - oldVal.doubleValue(); // Only adjust on even width adjustments if (deltaX > 1 || deltaX < -1) { if (deltaX % 2 == 0) { tokentool_Controller.updatePortraitLocation(deltaX, 0); deltaX = 0; } else { tokentool_Controller.updatePortraitLocation(deltaX - 1, 0); deltaX = 1; } } }); primaryStage.heightProperty().addListener((obs, oldVal, newVal) -> { if (Double.isNaN(oldVal.doubleValue())) return; deltaY += newVal.doubleValue() - oldVal.doubleValue(); // Only adjust on even width adjustments if (deltaY > 1 || deltaY < -1) { if (deltaY % 2 == 0) { tokentool_Controller.updatePortraitLocation(0, deltaY); deltaY = 0; } else { tokentool_Controller.updatePortraitLocation(0, deltaY - 1); deltaY = 1; } } }); primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { tokentool_Controller.exitApplication(); } }); // Load all the overlays into the treeview tokentool_Controller.updateOverlayTreeview(overlayTreeItems); // Restore saved settings AppPreferences.restorePreferences(tokentool_Controller); // Add recent list to treeview tokentool_Controller.updateOverlayTreeViewRecentFolder(true); // Set the Overlay Options accordion to be default open view tokentool_Controller.expandOverlayOptionsPane(true); primaryStage.show(); // Finally, update token preview image after everything is done loading Platform.runLater(() -> tokentool_Controller.updateTokenPreviewImageView()); }
From source file:it.geosolutions.geobatch.geotiff.retile.GeotiffRetiler.java
public static void reTile(File inFile, File tiledTiffFile, double compressionRatio, String compressionType, int tileW, int tileH, boolean forceBigTiff) throws IOException { ///*www . j a va 2 s .c o m*/ // look for a valid file that we can read // AbstractGridFormat format = null; AbstractGridCoverage2DReader reader = null; GridCoverage2D inCoverage = null; AbstractGridCoverageWriter writer = null; final Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); // getting a format for the given input format = (AbstractGridFormat) GridFormatFinder.findFormat(inFile, hints); if (format == null || (format instanceof UnknownFormat)) { throw new IllegalArgumentException("Unable to find the GridFormat for the provided file: " + inFile); } try { // // ACQUIRING A READER // if (LOGGER.isInfoEnabled()) { LOGGER.info("Acquiring a reader for the provided file..."); } // can throw UnsupportedOperationsException reader = (AbstractGridCoverage2DReader) format.getReader(inFile, hints); if (reader == null) { final IOException ioe = new IOException("Unable to find a reader for the provided file: " + inFile); throw ioe; } // // ACQUIRING A COVERAGE // if (LOGGER.isInfoEnabled()) { LOGGER.info("Acquiring a coverage provided file..."); } inCoverage = (GridCoverage2D) reader.read(null); if (inCoverage == null) { final IOException ioe = new IOException("inCoverage == null"); throw ioe; } // // PREPARING A WRITE // if (LOGGER.isInfoEnabled()) { LOGGER.info("Writing down the file in the decoded directory..."); } final GeoTiffFormat wformat = new GeoTiffFormat(); final GeoTiffWriteParams wp = new GeoTiffWriteParams(); if (!Double.isNaN(compressionRatio) && compressionType != null) { wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT); wp.setCompressionType(compressionType); wp.setCompressionQuality((float) compressionRatio); } wp.setForceToBigTIFF(forceBigTiff); wp.setTilingMode(GeoToolsWriteParams.MODE_EXPLICIT); wp.setTiling(tileW, tileH); final ParameterValueGroup wparams = wformat.getWriteParameters(); wparams.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp); // // ACQUIRING A WRITER AND PERFORMING A WRITE // writer = (AbstractGridCoverageWriter) new GeoTiffWriter(tiledTiffFile); writer.write(inCoverage, (GeneralParameterValue[]) wparams.values().toArray(new GeneralParameterValue[1])); } finally { // // PERFORMING FINAL CLEAN UP AFTER THE WRITE PROCESS // if (reader != null) { try { reader.dispose(); } catch (Exception e) { if (LOGGER.isWarnEnabled()) LOGGER.warn(e.getLocalizedMessage(), e); } } if (writer != null) { try { writer.dispose(); } catch (Exception e) { if (LOGGER.isWarnEnabled()) LOGGER.warn(e.getLocalizedMessage(), e); } } if (inCoverage != null) { final RenderedImage initImage = inCoverage.getRenderedImage(); ImageReader r = (ImageReader) initImage.getProperty(ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER); try { r.dispose(); } catch (Exception e) { if (LOGGER.isWarnEnabled()) LOGGER.warn("GeotiffRetiler::reTile(): " + e.getLocalizedMessage(), e); } // dispose ImageUtilities.disposePlanarImageChain(PlanarImage.wrapRenderedImage(initImage)); } } }
From source file:com.bmwcarit.barefoot.matcher.MatcherSample.java
@Override public JSONObject toJSON() throws JSONException { JSONObject json = super.toJSON(); json.put("id", id); json.put("point", GeometryEngine.geometryToWkt(point, WktExportFlags.wktExportPoint)); if (!Double.isNaN(azimuth)) { json.put("azimuth", azimuth); }/*from w w w. j a v a 2 s . co m*/ return json; }
From source file:org.jfree.data.statistics.Statistics.java
/** * Returns the mean of a collection of {@code Number} objects. * * @param values the values ({@code null} not permitted). * @param includeNullAndNaN a flag that controls whether or not * {@code null} and {@code Double.NaN} values are included * in the calculation (if either is present in the array, the result is * {@link Double#NaN}).//from www . java2s . com * * @return The mean. * * @since 1.0.3 */ public static double calculateMean(Collection values, boolean includeNullAndNaN) { ParamChecks.nullNotPermitted(values, "values"); int count = 0; double total = 0.0; Iterator iterator = values.iterator(); while (iterator.hasNext()) { Object object = iterator.next(); if (object == null) { if (includeNullAndNaN) { return Double.NaN; } } else { if (object instanceof Number) { Number number = (Number) object; double value = number.doubleValue(); if (Double.isNaN(value)) { if (includeNullAndNaN) { return Double.NaN; } } else { total = total + number.doubleValue(); count = count + 1; } } } } return total / count; }