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
/** * 99th percentile/*from ww w.j a v a2 s . co m*/ * * @return 99th percentile */ @Managed @SuppressWarnings("unused") public double getSizeTP99() { double percentile = sizeStats.getPercentile(99); return Double.isNaN(percentile) ? 0.0 : percentile; }
From source file:fr.irit.smac.libs.tooling.plot.server.AgentPlotChart.java
@Override public void add(String _serieName, double _y) { double x = getSeries(_serieName).getMaxX(); if (Double.isNaN(x)) { x = 0;//from w ww. j a v a 2 s . co m } x += 1; add(_serieName, x, _y); }
From source file:eu.cloud4soa.frontend.commons.server.services.soa.PaaSOfferingDiscoveryServiceImpl.java
@Override public ListLoadResult<PaaSOfferingModel> searchForMatchingPlatform(String applicationInstanceId) { logger.debug("Invoking searchForMatchingPlatform in SOA PaaSOfferingDiscovery with " + " applicationInstanceId: " + applicationInstanceId); List<PaaSOfferingModel> matchings = new ArrayList<PaaSOfferingModel>(); MatchingPlatform mp = null;/*w ww . j av a2 s.c o m*/ try { mp = paaSOfferingDiscoverySoaService.searchForMatchingPlatform(applicationInstanceId); Map<PaaSInstance, Float> rankedPaaSInstances = mp.getRankedListPaaSInstances(); for (PaaSInstance instance : rankedPaaSInstances.keySet()) { PaaSOfferingModel offer = new PaaSOfferMapper().from(instance.getPaaSOffering()).toModel(); offer.setScore(rankedPaaSInstances.get(instance) * 100); //Score as percentage offer.setProvider(instance.getProviderTitle()); // Average User Rating float averageUserRating = offeringRecommendationSoaService .getAveragePaaSUserExperienceRate(instance.getPaaSOffering().getUriId()); if (Double.isNaN(averageUserRating)) averageUserRating = 0; offer.<Integer>set(PaaSOfferingModel.AVERAGE_USER_RATING, Math.round(averageUserRating)); // Average System Rating (Montly) // TODO: Determine with ASR (Daily, Weekly, Montly) to use float averageSystemRating = offeringRecommendationSoaService .getPaaSBreachesPerMonth(instance.getPaaSOffering().getUriId()); if (Double.isNaN(averageSystemRating)) averageSystemRating = 0; offer.<Integer>set(PaaSOfferingModel.AVERAGE_SYSTEM_RATING, Math.round(averageSystemRating)); SlaTemplate slaTemplate = mp.getListSlaContract().get(instance); if (slaTemplate != null) { SLATemplateModel slaTemplateModel = new SLATemplateMapper().from(slaTemplate).toModel(); offer.setSLATemplate(slaTemplateModel); } matchings.add(offer); } } catch (Exception e) { String msg = "An error occurred while searching for matching platforms."; logger.error(msg, e); throw new RuntimeException(msg, e); } return new BaseListLoadResult<PaaSOfferingModel>(matchings); }
From source file:fr.amap.lidar.format.jleica.LPointShotExtractor.java
public LPointShotExtractor(GriddedPointScan scan) throws Exception { this.scan = scan; scan.computeExtremumsAngles();/* www. ja v a 2s. c o m*/ scan.openScanFile(scan.getFile()); angles = new SimpleSpherCoords[this.scan.getHeader().getNumRows()][this.scan.getHeader().getNumCols()]; azimuts = new boolean[this.scan.getHeader().getNumCols()]; zenithals = new boolean[this.scan.getHeader().getNumRows()]; //azimutsRegression = new SimpleRegression[this.scan.getHeader().getNumCols()]; //zenithalsRegression = new SimpleRegression[this.scan.getHeader().getNumRows()]; //azimuts = new SimpleRegression[this.scan.getHeader().getNumCols()]; //zenithals = new SimpleRegression[this.scan.getHeader().getNumRows()]; Iterator<LPoint> iterator = scan.iterator(); while (iterator.hasNext()) { LPoint point = iterator.next(); if (point.valid) { double x, y, z; if (scan.getHeader().isPointInDoubleFormat()) { x = ((LDoublePoint) point).x; y = ((LDoublePoint) point).y; z = ((LDoublePoint) point).z; } else { x = ((LFloatPoint) point).x; y = ((LFloatPoint) point).y; z = ((LFloatPoint) point).z; } Vector3d dir = new Vector3d(x, y, z); dir.normalize(); SphericalCoordinates sc = new SphericalCoordinates(new Vector3D(dir.x, dir.y, dir.z)); angles[point.rowIndex][point.columnIndex] = new SimpleSpherCoords(); angles[point.rowIndex][point.columnIndex].azimut = sc.getTheta(); angles[point.rowIndex][point.columnIndex].zenith = sc.getPhi(); azimuts[point.columnIndex] = true; zenithals[point.rowIndex] = true; } } int lastValidRowIndex = -1; int lastValidColumnIndex = -1; for (int row = 0; row < angles.length; row++) { for (int column = 0; column < angles[0].length; column++) { if (angles[row][column] == null) { double azimut = Double.NaN; double zenithal = Double.NaN; if (azimuts[column]) { for (int i = row + 1, j = row - 1; i < angles.length || j >= 0; i++, j--) { if (i < angles.length && angles[i][column] != null) { azimut = angles[i][column].azimut; azimuts[column] = true; break; } if (j >= 0 && angles[j][column] != null) { azimut = angles[j][column].azimut; azimuts[column] = true; break; } } } if (azimuts[column]) { for (int i = row + 1, j = row - 1; i < angles.length || j >= 0; i++, j--) { if (i < angles.length && angles[i][column] != null) { zenithal = (angles[i][column].zenith + ((i - row) * scan.getElevationStepAngle())); azimuts[column] = true; break; } if (j >= 0 && angles[j][column] != null) { zenithal = (angles[j][column].zenith - ((row - j) * scan.getElevationStepAngle())); azimuts[column] = true; break; } } } /*if(zenithals[row]){ for(int i=column+1, j=column-1;i<angles[0].length || j>=0;i++, j--){ if(i<angles[0].length && angles[row][i] != null){ zenithal = angles[row][i].zenith; zenithals[row] = true; break; } if(j >=0 && angles[row][j] != null){ zenithal = angles[row][j].zenith; zenithals[row] = true; break; } } }*/ if (Double.isNaN(azimut)) { azimut = (scan.getAzim_min() - ((column - scan.getColIndexAzimMin()) * scan.getAzimutalStepAngle())); } if (Double.isNaN(zenithal)) { if (lastValidRowIndex != -1) { zenithal = (angles[lastValidRowIndex][lastValidColumnIndex].zenith - ((row - lastValidRowIndex) * scan.getElevationStepAngle())); } else { zenithal = (scan.getElev_min() - ((row - scan.getRowIndexElevMin()) * scan.getElevationStepAngle())); } } angles[row][column] = new SimpleSpherCoords(azimut, zenithal); } else { lastValidRowIndex = row; lastValidColumnIndex = column; } } } }
From source file:com.opengamma.analytics.financial.model.volatility.BlackScholesFormulaRepository.java
/** * The spot delta/*from w w w . ja va 2s . c o m*/ * @param spot The spot value of the underlying * @param strike The Strike * @param timeToExpiry The time-to-expiry * @param lognormalVol The log-normal volatility * @param interestRate The interest rate * @param costOfCarry The cost-of-carry rate * @param isCall true for call * @return The spot delta */ @ExternalFunction public static double delta(final double spot, final double strike, final double timeToExpiry, final double lognormalVol, final double interestRate, final double costOfCarry, final boolean isCall) { ArgumentChecker.isTrue(spot >= 0.0, "negative/NaN spot; have {}", spot); ArgumentChecker.isTrue(strike >= 0.0, "negative/NaN strike; have {}", strike); ArgumentChecker.isTrue(timeToExpiry >= 0.0, "negative/NaN timeToExpiry; have {}", timeToExpiry); ArgumentChecker.isTrue(lognormalVol >= 0.0, "negative/NaN lognormalVol; have {}", lognormalVol); ArgumentChecker.isFalse(Double.isNaN(interestRate), "interestRate is NaN"); ArgumentChecker.isFalse(Double.isNaN(costOfCarry), "costOfCarry is NaN"); double coef = 0.; if ((interestRate > LARGE && costOfCarry > LARGE) || (-interestRate > LARGE && -costOfCarry > LARGE) || Math.abs(costOfCarry - interestRate) < SMALL) { coef = 1.; //ref value is returned } else { final double rate = costOfCarry - interestRate; if (rate > LARGE) { return isCall ? Double.POSITIVE_INFINITY : (costOfCarry > LARGE ? 0. : Double.NEGATIVE_INFINITY); } if (-rate > LARGE) { return 0.; } coef = Math.exp(rate * timeToExpiry); } if (spot > LARGE * strike) { return isCall ? coef : 0.; } if (spot < SMALL * strike) { return isCall ? 0. : -coef; } final int sign = isCall ? 1 : -1; final double rootT = Math.sqrt(timeToExpiry); double sigmaRootT = lognormalVol * rootT; if (Double.isNaN(sigmaRootT)) { sigmaRootT = 1.; //ref value is returned } double factor = Math.exp(costOfCarry * timeToExpiry); if (Double.isNaN(factor)) { factor = 1.; //ref value is returned } double rescaledSpot = spot * factor; double d1 = 0.; if (Math.abs(spot - strike) < SMALL || sigmaRootT > LARGE || (spot > LARGE && strike > LARGE)) { final double coefD1 = (costOfCarry / lognormalVol + 0.5 * lognormalVol); final double tmp = coefD1 * rootT; d1 = Double.isNaN(tmp) ? 0. : tmp; } else { if (sigmaRootT < SMALL) { return isCall ? (rescaledSpot > strike ? coef : 0.) : (rescaledSpot < strike ? -coef : 0.); } final double tmp = costOfCarry * rootT / lognormalVol; final double sig = (costOfCarry >= 0.) ? 1. : -1.; final double scnd = Double.isNaN(tmp) ? ((lognormalVol < LARGE && lognormalVol > SMALL) ? sig / lognormalVol : sig * rootT) : tmp; d1 = Math.log(spot / strike) / sigmaRootT + scnd + 0.5 * sigmaRootT; } // if (Double.isNaN(d1)) { // throw new IllegalArgumentException("NaN found"); // } final double norm = NORMAL.getCDF(sign * d1); return norm < SMALL ? 0. : sign * coef * norm; }
From source file:edu.cudenver.bios.power.glmm.GLMMTestUnirepGeisserGreenhouse.java
/** * Calculate the Geisser-Greenhouse epsilon to correct for violations * of sphericity/*w w w . ja v a 2 s . c om*/ */ @Override protected void calculateEpsilon() { super.calculateEpsilon(); if (this.epsilonMethod == UnivariateEpsilonApproximation.MULLER_BARTON_APPROX) { // calculate the expected value of the epsilon estimate // E[f(lambda)] = f(lambda) + g1 / (N - r) // see Muller, Barton (1989) for details double b = rankU; double g1 = 0; for (int i = 0; i < distinctSigmaStarEigenValues.size(); i++) { EigenValueMultiplicityPair evmI = distinctSigmaStarEigenValues.get(i); double firstDerivative = ((2 * sumLambda) / (b * sumLambdaSquared) - (2 * evmI.eigenValue * sumLambda * sumLambda) / (b * sumLambdaSquared * sumLambdaSquared)); double secondDerivative = (2 / (b * sumLambdaSquared) - (8 * evmI.eigenValue * sumLambda) / (b * sumLambdaSquared * sumLambdaSquared) + (8 * evmI.eigenValue * evmI.eigenValue * sumLambda * sumLambda) / (b * sumLambdaSquared * sumLambdaSquared * sumLambdaSquared) - (2 * sumLambda * sumLambda) / (b * sumLambdaSquared * sumLambdaSquared)); // accumulate the first term of g1 (sum over distinct eigen vals of 1st derivative * eigen val ^2 * multiplicity) g1 += secondDerivative * evmI.eigenValue * evmI.eigenValue * evmI.multiplicity; // loop over elements not equal to current for (int j = 0; j < distinctSigmaStarEigenValues.size(); j++) { if (i != j) { EigenValueMultiplicityPair evmJ = distinctSigmaStarEigenValues.get(j); // accumulate second term of g1 g1 += ((firstDerivative * evmI.eigenValue * evmI.multiplicity * evmJ.eigenValue * evmJ.multiplicity) / (evmI.eigenValue - evmJ.eigenValue)); } } } expectedEpsilon = epsilonD + g1 / (totalN - rank); } else { // calculate the expected value of the epsilon estimate // see Muller, Edwards, Taylor (2004) for details // build a vector with each eigen value repeated per its multiplicity ArrayRealVector eigenColumnVector = new ArrayRealVector(); for (EigenValueMultiplicityPair evmp : distinctSigmaStarEigenValues) { // there is probably a more memory-efficient method to do this. eigenColumnVector = eigenColumnVector .append(new ArrayRealVector((int) evmp.multiplicity, evmp.eigenValue)); } RealMatrix outerProduct = eigenColumnVector.outerProduct(eigenColumnVector); double sum = outerProduct.walkInOptimizedOrder(new SummationVisitor()); double nu = (totalN - rank); double expT1 = (2 * nu * sumLambdaSquared) + (nu * nu * sumLambda * sumLambda); double expT2 = (nu * (nu + 1) * sumLambdaSquared) + (nu * sum * sum); expectedEpsilon = (1 / (double) rankU) * (expT1 / expT2); } // ensure that expected value is within bounds 1/b to 1 if (!Double.isNaN(expectedEpsilon)) { if (expectedEpsilon < 1 / rankU) { expectedEpsilon = 1 / rankU; } else if (expectedEpsilon > 1) { expectedEpsilon = 1; } } }
From source file:lirmm.inria.fr.math.OpenLongToDoubleHashMapTest.java
@Test public void testRemoveAbsent() { Map<Long, Double> generated = generateAbsent(); OpenLongToDoubleHashMap map = createFromJavaMap(); int mapSize = map.size(); for (Map.Entry<Long, Double> mapEntry : generated.entrySet()) { map.remove(mapEntry.getKey());/*from w w w. ja v a 2 s .c om*/ Assert.assertEquals(mapSize, map.size()); Assert.assertTrue(Double.isNaN(map.get(mapEntry.getKey()))); } }
From source file:com.ibm.bluej.commonutil.PrecisionRecallThreshold.java
public double pearsonsR() { double[] x = new double[scoredPlusGold.size()]; double[] y = new double[scoredPlusGold.size()]; int ndx = 0;//ww w .ja va 2 s . c o m for (Pair<Double, Boolean> sg : scoredPlusGold) { x[ndx] = sg.first; y[ndx] = sg.second ? 1.0 : -1.0; ++ndx; } double corrValue = new PearsonsCorrelation().correlation(x, y); if (Double.isNaN(corrValue)) corrValue = 0.0; return corrValue; }
From source file:es.uvigo.ei.sing.laimages.core.operations.Interpolator.java
private final static int firstValueIndex(double[] values) { for (int i = 0; i < values.length; i++) { if (!Double.isNaN(values[i])) return i; }/*from w w w. ja v a2s. c om*/ throw new IllegalArgumentException("No value found"); }
From source file:org.trade.ui.chart.renderer.CandleRenderer.java
/** * Method drawItem./* w w w . j av a2 s . com*/ * * @param g2 * Graphics2D * @param state * XYItemRendererState * @param dataArea * Rectangle2D * @param info * PlotRenderingInfo * @param plot * XYPlot * @param domainAxis * ValueAxis * @param rangeAxis * ValueAxis * @param dataset * XYDataset * @param series * int * @param item * int * @param crosshairState * CrosshairState * @param pass * int * @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 (dataset instanceof OHLCVwapDataset) { // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } CandleDataset candleDataset = (CandleDataset) dataset; CandleItem candle = (CandleItem) candleDataset.getSeries(series).getDataItem(item); double startX = candle.getPeriod().getFirstMillisecond(); if (Double.isNaN(startX)) { return; } double endX = candle.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; } } 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)); if (getMargin() > 0.0) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; } double x = candleDataset.getXValue(series, item); double yHigh = candleDataset.getHighValue(series, item); double yLow = candleDataset.getLowValue(series, item); double yOpen = candleDataset.getOpenValue(series, item); double yClose = candleDataset.getCloseValue(series, item); RectangleEdge domainEdge = plot.getDomainAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, domainEdge); RectangleEdge edge = plot.getRangeAxisEdge(); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, edge); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, edge); double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea, edge); double yyClose = rangeAxis.valueToJava2D(yClose, dataArea, edge); Paint outlinePaint = null; outlinePaint = getItemOutlinePaint(series, item); g2.setStroke(getItemStroke(series, item)); g2.setPaint(outlinePaint); double yyMaxOpenClose = Math.max(yyOpen, yyClose); double yyMinOpenClose = Math.min(yyOpen, yyClose); double maxOpenClose = Math.max(yOpen, yClose); double minOpenClose = Math.min(yOpen, yClose); Shape body = null; boolean highlight = highlight(series, item); /********************************** * draw the upper shadow START **********************************/ if (yHigh > maxOpenClose) { if (highlight) { body = new Rectangle2D.Double(xx - (translatedWidth / 2), yyHigh - 10, translatedWidth, (yyMaxOpenClose - yyHigh) + 10); g2.setPaint(Color.YELLOW); g2.fill(body); g2.draw(body); } } if (yHigh > maxOpenClose) { if (nightMode) { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } else { g2.setPaint(Color.black); } g2.draw(new Line2D.Double(xx, yyHigh, xx, yyMaxOpenClose)); } /********************************** * draw the lower shadow START **********************************/ if (yLow < minOpenClose) { if (highlight) { body = new Rectangle2D.Double(xx - (translatedWidth / 2), yyMinOpenClose, translatedWidth, (yyLow - yyMinOpenClose) + 10); g2.setPaint(Color.YELLOW); g2.fill(body); g2.draw(body); } if (yLow < minOpenClose) { if (nightMode) { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } else { g2.setPaint(Color.BLACK); } g2.draw(new Line2D.Double(xx, yyLow, xx, yyMinOpenClose)); } } /********************************** * draw the body **********************************/ body = new Rectangle2D.Double(xx - (translatedWidth / 2), yyMinOpenClose, translatedWidth, yyMaxOpenClose - yyMinOpenClose); if (nightMode) { g2.setPaint(Color.white); } else { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } g2.fill(body); g2.draw(body); if (nightMode) { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } else { g2.setPaint(outlinePaint); } g2.draw(body); // 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(body, dataset, series, item, tip, null); entities.add(entity); } // 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()); } }