List of usage examples for java.lang Double NaN
double NaN
To view the source code for java.lang Double NaN.
Click Source Link
From source file:com.fay.statics.SummaryStat.java
public double mean() { if (numObs < 1) return Double.NaN; return valSum / weightSum; }
From source file:com.joptimizer.functions.SDPLogarithmicBarrier.java
/** * @see "S.Boyd and L.Vandenberghe, Convex Optimization, p. 618" *///from w ww . ja va2s. co m public double value(double[] X) { RealMatrix S = buildS(X); try { CholeskyDecomposition cFact = new CholeskyDecomposition(S); double detS = cFact.getDeterminant(); return -Math.log(detS); } catch (NonPositiveDefiniteMatrixException e) { return Double.NaN; } }
From source file:org.jfree.data.statistics.DefaultStatisticalCategoryDatasetTest.java
/** * Some checks for the getRangeBounds() method. *///from w w w . j a v a 2 s . c o m @Test public void testGetRangeBounds() { DefaultStatisticalCategoryDataset d = new DefaultStatisticalCategoryDataset(); // an empty dataset should return null for bounds assertNull(d.getRangeBounds(true)); // try a dataset with a single value d.add(4.5, 1.0, "R1", "C1"); assertEquals(new Range(4.5, 4.5), d.getRangeBounds(false)); assertEquals(new Range(3.5, 5.5), d.getRangeBounds(true)); // try a dataset with two values d.add(0.5, 2.0, "R1", "C2"); assertEquals(new Range(0.5, 4.5), d.getRangeBounds(false)); assertEquals(new Range(-1.5, 5.5), d.getRangeBounds(true)); // try a Double.NaN d.add(Double.NaN, 0.0, "R1", "C3"); assertEquals(new Range(0.5, 4.5), d.getRangeBounds(false)); assertEquals(new Range(-1.5, 5.5), d.getRangeBounds(true)); // try a Double.NEGATIVE_INFINITY d.add(Double.NEGATIVE_INFINITY, 0.0, "R1", "C3"); assertEquals(new Range(Double.NEGATIVE_INFINITY, 4.5), d.getRangeBounds(false)); assertEquals(new Range(Double.NEGATIVE_INFINITY, 5.5), d.getRangeBounds(true)); // try a Double.POSITIVE_INFINITY d.add(Double.POSITIVE_INFINITY, 0.0, "R1", "C3"); assertEquals(new Range(0.5, Double.POSITIVE_INFINITY), d.getRangeBounds(false)); assertEquals(new Range(-1.5, Double.POSITIVE_INFINITY), d.getRangeBounds(true)); }
From source file:edu.cmu.sv.modelinference.eventtool.charting.DataChart.java
private void createChartPanel(JFreeChart chart) { chartPanel = new ChartPanel(chart); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override/*w w w .j a v a 2 s. c o m*/ public void chartMouseClicked(ChartMouseEvent arg0) { //ignore } @Override public void chartMouseMoved(ChartMouseEvent event) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); ValueAxis yAxis = plot.getRangeAxis(); double y = yAxis.java2DToValue(event.getTrigger().getY(), dataArea, RectangleEdge.LEFT); //Alternatively, obtain y for one of the subplots, which would be very neat. //We should find the "nearest" subplot to the cursor -- this is easy //double y = DatasetUtilities.findYValue(plot.getDataset(), 0, x); xCrosshair.setValue(x); yCrosshair.setValue(y); } }); CrosshairOverlay crosshairOverlay = new CrosshairOverlay(); xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); xCrosshair.setLabelVisible(true); yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); yCrosshair.setLabelVisible(true); crosshairOverlay.addDomainCrosshair(xCrosshair); crosshairOverlay.addRangeCrosshair(yCrosshair); chartPanel.addOverlay(crosshairOverlay); chartPanel.setPreferredSize(new java.awt.Dimension(800, 600)); setContentPane(chartPanel); }
From source file:de.betterform.xml.xforms.action.DeleteAction.java
/** * Performs the <code>delete</code> action as specified by XForms 1.1. * * @throws XFormsException if an error occurred during <code>delete</code> * processing.// www .j av a 2s.c o m */ public void perform() throws XFormsException { updateXPathContext(); final int nrOfNodesInNodeset = this.nodeset.size(); if (nrOfNodesInNodeset == 0) { getLogger().warn(this + " perform: nodeset '" + getLocationPath() + "' is empty"); return; } if (this.atAttribute == null) { final Instance instance = this.model.getInstance(getInstanceId()); final String locationPath = getLocationPath(); final String path = locationPath + "[1]"; for (int i = 0; i < this.nodeset.size(); i++) { //evaluate each node and return in case no nodes were deleted if (!(instance.deleteNode( de.betterform.xml.xpath.impl.saxon.XPathUtil.getAsNode(this.nodeset, i + 1), path))) return; } this.container.dispatch(instance.getTarget(), XFormsEventNames.DELETE, constructEventInfo(Double.valueOf(Double.NaN), this.nodeset, locationPath)); } else { final Node target; final String positionInNodeset; final List deleteNodes; if (this.atAttribute.equals("last()")) { deleteNodes = Collections.singletonList(this.nodeset.get(nrOfNodesInNodeset - 1)); target = (Node) de.betterform.xml.xpath.impl.saxon.XPathUtil.getAsNode(this.nodeset, nrOfNodesInNodeset); positionInNodeset = Integer.toString(nrOfNodesInNodeset); } else { Double d; try { d = XPathCache.getInstance().evaluateAsDouble(this.nodeset, this.position, "round(number(" + this.atAttribute + "))", getPrefixMapping(), xpathFunctionContext); } catch (Exception e) { throw new XFormsComputeException("invalid 'at' expression at " + this, e, this.target, this.atAttribute); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("bound to: " + getBindingExpression()); LOGGER.debug("value attribute evaluated to: " + d); } long position = Math.round(d); /* if @at evaluated on the nodeset returns NaN or delete position is bigger than the actual nodeset then new position is equal to the size of the nodeset */ if (Double.isNaN(d) || position > nrOfNodesInNodeset) { position = nrOfNodesInNodeset; } /* if evaluated position is 0 or smaller then new position is 1 */ else if (position < 1) { position = 1; } deleteNodes = Collections.singletonList(this.nodeset.get((int) position - 1)); target = de.betterform.xml.xpath.impl.saxon.XPathUtil.getAsNode(this.nodeset, (int) position); positionInNodeset = Long.toString(position); } // delete specified node and dispatch notification event final Instance instance = this.model.getInstance(getInstanceId()); final String path = getLocationPath() + "[" + positionInNodeset + "]"; if (!(instance.deleteNode(target, path))) return; this.container.dispatch(instance.getTarget(), XFormsEventNames.DELETE, constructEventInfo(Double.valueOf(positionInNodeset), deleteNodes, path)); } // update behaviour doRebuild(true); doRecalculate(true); doRevalidate(true); doRefresh(true); }
From source file:org.elasticsoftware.elasticactors.geoevents.Coordinate.java
public double distance(final double latitude, final double longitude, LengthUnit unit) { double a = 6378137, b = 6356752.3142; // ellipsiod// w w w . j ava2s .c om double L = (longitude - this.longitude) * degToRad; double U1 = Math.atan((1 - f) * Math.tan(this.latitude * degToRad)); double U2 = Math.atan((1 - f) * Math.tan(latitude * degToRad)); double sinU1 = Math.sin(U1), cosU1 = Math.cos(U1); double sinU2 = Math.sin(U2), cosU2 = Math.cos(U2); double cosSqAlpha, sinSigma, cos2SigmaM, cosSigma, sigma; double lambda = L, lambdaP, iterLimit = 20; do { double sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda); sinSigma = Math.sqrt((cosU2 * sinLambda) * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda)); if (sinSigma == 0) return 0; // co-incident points cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda; sigma = Math.atan2(sinSigma, cosSigma); double sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma; cosSqAlpha = 1 - sinAlpha * sinAlpha; cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha; if (cos2SigmaM == Double.NaN) cos2SigmaM = 0; // equatorial line: cosSqAlpha=0 (?6) double C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha)); lambdaP = lambda; lambda = L + (1 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM))); } while (Math.abs(lambda - lambdaP) > EPSILON && --iterLimit > 0); if (iterLimit == 0) return Double.NaN; double uSquared = cosSqAlpha * (a * a - b * b) / (b * b); double A = 1 + uSquared / 16384 * (4096 + uSquared * (-768 + uSquared * (320 - 175 * uSquared))); double B = uSquared / 1024 * (256 + uSquared * (-128 + uSquared * (74 - 47 * uSquared))); double deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM))); double s = b * A * (sigma - deltaSigma); return unit.convert(s, LengthUnit.METRES); }
From source file:geogebra.util.MyMath.java
final public static double betaIncomplete(double a, double b, double x) { try {//from w w w. j ava2 s .c om return Beta.regularizedBeta(x, a, b) * beta(a, b); } catch (MathException e) { return Double.NaN; } }
From source file:com.clust4j.metrics.pairwise.TestDistanceEnums.java
@Test public void testNaN() { final double[] a = new double[] { 0d, 0d, 0d }; final double[] b = new double[] { 3d, 4d, Double.NaN }; assertTrue(Double.isNaN(Distance.MANHATTAN.getDistance(a, b))); assertTrue(Double.isNaN(Distance.EUCLIDEAN.getDistance(a, b))); }
From source file:de.thkwalter.et.schlupfbezifferung.Schlupfresiduum.java
/** * Diese Methode berechnet das Residuum des Schlupfs eines Betriebspunkts in Abhngigkeit vom Steigungswinkel der * Schlupfgeraden./*w w w.j a va2 s. c om*/ * * @param phi Der Steigungswinkel der Schlupfgeraden * * @return Das Residuum des Schlupfs eines Betriebspunkts */ @Override public double value(double phi) { // Die Variable fr das Residuum des Schlupfs eines Betriebspunkts wird deklariert. double residuum = Double.NaN; // Das Residuum des Schlupfs eines Betriebspunkts wird zurckgegeben. return residuum; }
From source file:de.tudarmstadt.ukp.clarin.webanno.brat.curation.AgreementUtils.java
public static AgreementResult getCohenKappaAgreement(DiffResult aDiff, String aType, String aFeature, Map<String, List<JCas>> aCasMap) { if (aCasMap.size() != 2) { throw new IllegalArgumentException("CAS map must contain exactly two CASes"); }//from w w w . j a v a 2 s. com AgreementResult agreementResult = AgreementUtils.makeStudy(aDiff, aType, aFeature, aCasMap); try { IAgreementMeasure agreement = new CohenKappaAgreement(agreementResult.study); if (agreementResult.study.getItemCount() > 0) { agreementResult.setAgreement(agreement.calculateAgreement()); } else { agreementResult.setAgreement(Double.NaN); } return agreementResult; } catch (RuntimeException e) { // FIXME AgreementUtils.dumpAgreementStudy(System.out, agreementResult); throw e; } }