List of usage examples for java.lang Double isNaN
public static boolean isNaN(double v)
From source file:gedi.util.MathUtils.java
public static double saveMin(double a, double b) { if (Double.isNaN(a)) return b; if (Double.isNaN(b)) return a; if (Double.isInfinite(a)) return b; if (Double.isInfinite(b)) return a; return Math.min(a, b); }
From source file:de.thkwalter.et.schlupfbezifferung.BetriebspunktTest.java
/** * Test der Methode {@link Betriebspunkt#getI_1y()}. * /*from w ww.j a va 2 s.c o m*/ * @throws SecurityException * @throws NoSuchFieldException * @throws IllegalAccessException * @throws IllegalArgumentException */ @Test public void testGetI_1y() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { // Die in diesem Test verwendete komplexe Stnderstromstrke (in A) wird erzeugt. Complex testI_1 = new Complex(4.0, 2.0); // Die in diesem Test verwendete komplexe Stnderstromstrke (in A) wird im Prfling gespeichert. Field i_1Feld = Betriebspunkt.class.getDeclaredField("i_1"); i_1Feld.setAccessible(true); i_1Feld.set(this.betriebspunkt, testI_1); // Es wird berprft, ob die x-Komponente der komplexen Stnderstromstrke (in A) korrekt zurckgegeben wird. assertEquals(4.0, this.betriebspunkt.getI_1y(), 0.0); // Es wird berprft, ob der Schlupf korrekt initialisiert worden ist. assertTrue(Double.isNaN(this.betriebspunkt.getS())); }
From source file:ffx.xray.SigmaAMinimize.java
private void setWEstimate() { // generate initial w estimate ReflectionSpline spline = new ReflectionSpline(reflectionList, refinementData.nbins); int nmean[] = new int[refinementData.nbins]; for (int i = 0; i < refinementData.nbins; i++) { nmean[i] = 0;/*ww w . j a v a 2 s.c o m*/ } double mean = 0.0, tot = 0.0; double fc[][] = refinementData.fctot; double fo[][] = refinementData.fsigf; for (HKL ih : reflectionList.hkllist) { int i = ih.index(); if (ih.allowed() == 0.0 || Double.isNaN(fc[i][0]) || Double.isNaN(fo[i][0])) { continue; } double s2 = Crystal.invressq(crystal, ih); double epsc = ih.epsilonc(); ComplexNumber fct = new ComplexNumber(fc[i][0], fc[i][1]); double ecscale = spline.f(s2, refinementData.fcesq); double eoscale = spline.f(s2, refinementData.foesq); double ec = fct.times(sqrt(ecscale)).abs(); double eo = fo[i][0] * sqrt(eoscale); double wi = pow(eo - ec, 2.0) / epsc; nmean[spline.i1()]++; tot++; x[spline.i1() + refinementData.nbins] += (wi - x[spline.i1() + refinementData.nbins]) / nmean[spline.i1()]; mean += (wi - mean) / tot; } logger.info(String.format(" Starting mean w: %8.3f", mean)); logger.info(String.format(" Starting w scaling: %8.3f", 1.0 / mean)); for (int i = 0; i < refinementData.nbins; i++) { x[i] -= x[i + refinementData.nbins]; x[i] *= scaling[i]; scaling[i + refinementData.nbins] = 1.0 / mean; x[i + refinementData.nbins] *= scaling[i + refinementData.nbins]; } sigmaAEnergy.setScaling(scaling); }
From source file:com.twitter.hbc.httpclient.ClientBase.java
@Override public void run() { // establish the initial connection // if connection fails due to auth or some other 400, stop immediately // if connection fails due to a 500, back off and retry // if no response or other code, stop immediately // begin reading from the stream // while the stop signal hasn't been sent, and no IOException from processor, keep processing // if IOException, time to restart the connection: // handle http connection cleanup // do some backoff, set backfill // if stop signal set, time to kill/clean the connection, and end this thread. try {/*from w ww. j a va2s .c o m*/ if (client instanceof RestartableHttpClient) { ((RestartableHttpClient) client).setup(); } rateTracker.start(); while (!isDone()) { String host = hosts.nextHost(); if (host == null) { setExitStatus(new Event(EventType.STOPPED_BY_ERROR, "No hosts available")); break; } double rate = rateTracker.getCurrentRateSeconds(); if (!Double.isNaN(rate)) { endpoint.setBackfillCount(reconnectionManager.estimateBackfill(rate)); } HttpUriRequest request = HttpConstants.constructRequest(host, endpoint, auth); if (request != null) { String postContent = null; if (endpoint.getHttpMethod().equalsIgnoreCase(HttpConstants.HTTP_POST)) { postContent = endpoint.getPostParamString(); } auth.signRequest(request, postContent); Connection conn = new Connection(client, processor); StatusLine status = establishConnection(conn, request); if (handleConnectionResult(status)) { rateTracker.resume(); processConnectionData(conn); rateTracker.pause(); } logger.info("{} Done processing, preparing to close connection", name); conn.close(); } else { addEvent(new Event(EventType.CONNECTION_ERROR, String.format("Error creating request: %s, %s, %s", endpoint.getHttpMethod(), host, endpoint.getURI()))); } } } catch (Throwable e) { logger.warn(name + " Uncaught exception", e); Exception laundered = (e instanceof Exception) ? (Exception) e : new RuntimeException(e); setExitStatus(new Event(EventType.STOPPED_BY_ERROR, laundered)); } finally { rateTracker.stop(); logger.info("{} Shutting down httpclient connection manager", name); client.getConnectionManager().shutdown(); isRunning.countDown(); } }
From source file:com.sonicle.webtop.core.io.input.XlsRecordsProcessor.java
@Override public void processRecord(Record record) { int thisRow = -1; int thisCol = -1; cellValue = null;/* w w w .j av a 2s. c o m*/ switch (record.getSid()) { case BoundSheetRecord.sid: BoundSheetRecord bsr = (BoundSheetRecord) record; if (!sheetFound) { if (StringUtils.equals(bsr.getSheetname(), sheetName)) { sheetFound = true; columnNames = new LinkedHashMap<>(); columnIndexes = new HashMap<>(); } } else { close(); } break; case SSTRecord.sid: sstRecord = (SSTRecord) record; break; case BlankRecord.sid: BlankRecord br = (BlankRecord) record; thisRow = br.getRow(); thisCol = br.getColumn(); cellValue = ""; break; case BoolErrRecord.sid: BoolErrRecord ber = (BoolErrRecord) record; thisRow = ber.getRow(); thisCol = ber.getColumn(); cellValue = ""; break; case FormulaRecord.sid: FormulaRecord fr = (FormulaRecord) record; thisRow = fr.getRow(); thisCol = fr.getColumn(); if (Double.isNaN(fr.getValue())) { // Formula result is a string that is stored in the next record! findNextStringRecord = true; nextRow = fr.getRow(); nextCol = fr.getColumn(); cellValue = null; } else { cellValue = formatTrackingListener.formatNumberDateCell(fr); } break; case StringRecord.sid: if (findNextStringRecord) { // String for formula StringRecord sr = (StringRecord) record; cellValue = sr.getString(); thisRow = nextRow; thisCol = nextCol; // Resets markers... findNextStringRecord = false; nextRow = -1; nextCol = -1; } break; case LabelRecord.sid: LabelRecord lr = (LabelRecord) record; thisRow = lr.getRow(); thisCol = lr.getColumn(); cellValue = lr.getValue(); break; case LabelSSTRecord.sid: LabelSSTRecord lsstr = (LabelSSTRecord) record; thisRow = lsstr.getRow(); thisCol = lsstr.getColumn(); if (sstRecord == null) { cellValue = "#ERROR(undefined string)"; } else { cellValue = sstRecord.getString(lsstr.getSSTIndex()).toString(); } break; case NoteRecord.sid: NoteRecord nr = (NoteRecord) record; thisRow = nr.getRow(); thisCol = nr.getColumn(); // TODO: Find object to match nrec.getShapeId() cellValue = "#ERROR(TODO)"; break; case NumberRecord.sid: NumberRecord rn = (NumberRecord) record; thisRow = rn.getRow(); thisCol = rn.getColumn(); cellValue = formatTrackingListener.formatNumberDateCell(rn); break; case RKRecord.sid: RKRecord rkr = (RKRecord) record; thisRow = rkr.getRow(); thisCol = rkr.getColumn(); cellValue = "#ERROR(TODO)"; break; default: cellValue = null; } // Handle new row if ((thisRow != -1) && (thisRow != row)) { row = -1; isNewRow = true; } else { isNewRow = false; } if (thisRow > -1) row = thisRow; if (thisCol > -1) col = thisCol; isInRange = ((row >= firstDataRow) && ((lastDataRow == -1) || (row <= lastDataRow))); // Handle end of row if (record instanceof LastCellOfRowDummyRecord) { isDummyEndRow = true; col = -1; // We're nearly onto a new row } else { isDummyEndRow = false; } if (!isDummyEndRow && (row == headersRow)) { String cellReference = CellReference.convertNumToColString(col); String name = (headersRow == firstDataRow) ? cellReference : StringUtils.defaultIfBlank(cellValue, cellReference); columnNames.put(name.toLowerCase(), name); columnIndexes.put(name, col); } }
From source file:edu.cmu.tetrad.search.Cci.java
/** * Returns true just in the case the x and y vectors are independent, * once undefined values have been removed. Left public so it can be * accessed separately./*ww w. j a v a2 s . c o m*/ */ public boolean independent(double[] x, double[] y) { int both = 0; for (int i = 0; i < x.length; i++) { if (!Double.isNaN(x[i]) && !Double.isNaN(y[i])) { both++; } } // Get rid of NaN's. double[] _rXZ = new double[both]; double[] _rYZ = new double[both]; if (both != x.length) { int index = -1; for (int i = 0; i < x.length; i++) { if (!Double.isNaN(x[i]) && !Double.isNaN(y[i])) { ++index; _rXZ[index] = x[i]; _rYZ[index] = y[i]; } } x = _rXZ; y = _rYZ; } if (x.length < 10) { minP = Double.NaN; return false; // For PC, should not remove the edge for this reason. } double[] _x = new double[x.length]; double[] _y = new double[x.length]; List<Double> p = new ArrayList<Double>(); for (int m = 0; m < getNumFunctions(); m++) { for (int n = 0; n < getNumFunctions(); n++) { for (int i = 0; i < x.length; i++) { _x[i] = function(m, x[i]); _y[i] = function(n, y[i]); } double sigmaXY = covariance(_x, _y); double sigmaXX = covariance(_x, _x); double sigmaYY = covariance(_y, _y); double r = sigmaXY / sqrt(sigmaXX * sigmaYY); if (r > 1) r = 1; if (r < -1) r = -1; // Non-parametric Fisher Z test. double _z = 0.5 * (log(1.0 + r) - log(1.0 - r)); double w = sqrt(x.length) * _z; // Testing the hypothesis that _x and _y are uncorrelated and assuming that 4th moments of _x and _y // are finite and that the sample is large. standardize(_x); standardize(_y); double t2 = moment22(_x, _y); double t = sqrt(t2); double _p = 2.0 * (1.0 - normalCdf(0.0, t, abs(w))); if (!Double.isNaN(_p)) { p.add(_p); } } } Collections.sort(p); double cutoff = fdr(alpha, p, true); double min = p.size() == 0 ? Double.NaN : p.get(0); this.minP = min; this.p = p; if (Double.isNaN(min)) { this.minP = Double.NaN; return true; // No basis on which to remove an edge for PC. } return minP > cutoff; // return getQ(p) > alpha; }
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerXYDatasetTest.java
/** * Some basic checks for the constructor. */// w ww . j a v a 2 s .c om @Test public void testConstructor() { DefaultBoxAndWhiskerXYDataset dataset = new DefaultBoxAndWhiskerXYDataset("S1"); assertEquals(1, dataset.getSeriesCount()); assertEquals(0, dataset.getItemCount(0)); assertTrue(Double.isNaN(dataset.getRangeLowerBound(false))); assertTrue(Double.isNaN(dataset.getRangeUpperBound(false))); }
From source file:Clip.java
/** * Union this clip with another region. As a result, this clip * will become a bounding box around the two original regions. * @param r the rectangle to union with//from w ww . j av a 2s. c o m */ public void union(Rectangle2D r) { if (status == INVALID) return; double minx = r.getMinX(); double miny = r.getMinY(); double maxx = r.getMaxX(); double maxy = r.getMaxY(); if (Double.isNaN(minx) || Double.isNaN(miny) || Double.isNaN(maxx) || Double.isNaN(maxy)) { Logger.getLogger(getClass().getName()).warning("Union with invalid clip region: " + r); return; } if (status == EMPTY) { setClip(r); status = INUSE; return; } clip[0] = Math.min(clip[0], minx); clip[1] = Math.min(clip[1], miny); clip[6] = Math.max(clip[6], maxx); clip[7] = Math.max(clip[7], maxy); }
From source file:com.newatlanta.bluedragon.XYItemLabelGenerator.java
protected Object[] createItemArray(XYDataset dataset, int series, int item) { Object[] result = new Object[5]; result[0] = dataset.getSeriesKey(series).toString(); double x = dataset.getXValue(series, item); if (Double.isNaN(x) && dataset.getX(series, item) == null) { result[1] = "null"; //this.nullXString; } else {//from w w w . java 2 s. c o m if (this.getXDateFormat() != null) { result[1] = this.getXDateFormat().format(new Date((long) x)); } else { result[1] = this.getXFormat().format(x); } } double y = dataset.getYValue(series, item); if (Double.isNaN(y) && dataset.getY(series, item) == null) { result[2] = "null"; //this.nullYString; } else { if (this.getYDateFormat() != null) { result[2] = this.getYDateFormat().format(new Date((long) y)); } else { result[2] = this.getYFormat().format(y); } double total = calculateYTotal(dataset, series); double percent = y / total; result[3] = NumberFormat.getPercentInstance().format(percent); if (this.getYFormat() != null) { result[4] = this.getYFormat().format(total); } else if (this.getYDateFormat() != null) { //result[4] = this.getDateFormat().format(total); } } return result; }
From source file:net.semanticmetadata.lire.filter.LsaFilter.java
/** * @param results// w w w . j a va2s. co m * @param query * @return the filtered results or null if error occurs. */ public ImageSearchHits filter(ImageSearchHits results, Document query) { // create a double[items][histogram] tempFeature = null; LinkedList<double[]> features = new LinkedList<double[]>(); try { tempFeature = (LireFeature) featureClass.newInstance(); } catch (Exception e) { logger.severe("Could not create feature " + featureClass.getName() + " (" + e.getMessage() + ")."); return null; } // get all features from the result set, take care of those that do not have the respective field. for (int i = 0; i < results.length(); i++) { Document d = results.doc(i); if (d.getField(fieldName) != null) { tempFeature.setByteArrayRepresentation(d.getField(fieldName).binaryValue().bytes, d.getField(fieldName).binaryValue().offset, d.getField(fieldName).binaryValue().length); features.add(tempFeature.getDoubleHistogram()); } } // now go for the query if (query.getField(fieldName) != null) { tempFeature.setByteArrayRepresentation(query.getField(fieldName).binaryValue().bytes, query.getField(fieldName).binaryValue().offset, query.getField(fieldName).binaryValue().length); } else { logger.severe("Query document is missing the given feature " + featureClass.getName() + "."); return null; } double[][] matrixData = new double[features.size() + 1][tempFeature.getDoubleHistogram().length]; System.arraycopy(tempFeature.getDoubleHistogram(), 0, matrixData[0], 0, tempFeature.getDoubleHistogram().length); int count = 1; for (Iterator<double[]> iterator = features.iterator(); iterator.hasNext();) { double[] next = iterator.next(); System.arraycopy(next, 0, matrixData[count], 0, next.length); count++; } for (int i = 0; i < matrixData.length; i++) { double[] doubles = matrixData[i]; for (int j = 0; j < doubles.length; j++) { if (Double.isNaN(doubles[j])) System.err.println("Value is NaN"); ; } } // create a matrix object and do the magic Array2DRowRealMatrix m = new Array2DRowRealMatrix(matrixData); long ms = System.currentTimeMillis(); SingularValueDecomposition svd = new SingularValueDecomposition(m); ms = System.currentTimeMillis() - ms; double[] singularValues = svd.getSingularValues(); RealMatrix s = svd.getS(); // if no number of dimensions is given reduce to a tenth. if (numberOfDimensions < 1) numberOfDimensions = singularValues.length / 10; for (int i = numberOfDimensions; i < singularValues.length; i++) { s.setEntry(i, i, 0); } RealMatrix mNew = svd.getU().multiply(s).multiply(svd.getVT()); double[][] data = mNew.getData(); // create the new result set TreeSet<SimpleResult> result = new TreeSet<SimpleResult>(); double maxDistance = 0; double[] queryData = data[0]; for (int i = 1; i < data.length; i++) { double[] doubles = data[i]; double distance = MetricsUtils.distL1(doubles, queryData); result.add(new SimpleResult((float) distance, results.doc(i - 1), i - 1)); maxDistance = Math.max(maxDistance, distance); } ImageSearchHits hits; hits = new SimpleImageSearchHits(result, (float) maxDistance); return hits; }