List of usage examples for java.lang Float NaN
float NaN
To view the source code for java.lang Float NaN.
Click Source Link
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Use target tracker to extract draught based on mmsi lookup. * //w ww . java2 s. co m * @param mmsi * @return */ private float getDraught(int mmsi) { float draught = Float.NaN; TargetInfo target = targetTracker.get(mmsi); if (target != null) { AisPacket[] staticPackets = target.getStaticPackets(); if (staticPackets.length > 0 && staticPackets[0].tryGetAisMessage() instanceof AisMessage5) { draught = (float) (((AisMessage5) staticPackets[0].tryGetAisMessage()).getDraught() / 10.0); } } return draught; }
From source file:net.aksingh.java.api.owm.DailyForecastData.java
public boolean hasResponseTime() { return (this.responseTime != Float.NaN); }
From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java
/** * Returns the median value of input array and sorts array in place. If the * array length is even, the value returned is equal to the average of the * middle two values of the sorted array. {@code null} input returns * {@code Double.NaN}. Because no array copying is performed, this may yield * slight performance improvements over {@link #median(float[]) median} if * the input array reordering is unimportant. * * @param a input array; array is sorted in place * @return median value of {@code a} or {@code NaN} if {@code a} is * {@code null}//from ww w . jav a 2s. com */ public static final float medianAndSort(float[] a) { if (a != null) { int n = a.length; if (n > 1) { int halfN = n / 2; Arrays.sort(a); if (n % 2 == 0) { return (0.5f * (a[halfN] + a[halfN - 1])); } else { return a[halfN]; } } else { return a[0]; } } else { return Float.NaN; } }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Use target tracker to extract latitude based on mmsi lookup. * //from w w w . j a va 2 s. c o m * @param mmsi * @return */ private float getLatitude(int mmsi) { float lat = Float.NaN; TargetInfo target = targetTracker.get(mmsi); if (target != null) { AisPacket positionPacket = target.getPositionPacket(); if (positionPacket != null && positionPacket.tryGetAisMessage() instanceof AisPositionMessage) { lat = (float) ((AisPositionMessage) positionPacket.tryGetAisMessage()).getPos().getLatitudeDouble(); } } return lat; }
From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java
/** * Use target tracker to extract latitude based on mmsi lookup. * //from w ww . j a va 2 s. c o m * @param mmsi * @return */ private float getLongitude(int mmsi) { float lon = Float.NaN; TargetInfo target = targetTracker.get(mmsi); if (target != null) { AisPacket positionPacket = target.getPositionPacket(); if (positionPacket != null && positionPacket.tryGetAisMessage() instanceof AisPositionMessage) { lon = (float) ((AisPositionMessage) positionPacket.tryGetAisMessage()).getPos() .getLongitudeDouble(); } } return lon; }
From source file:juicebox.data.MatrixZoomData.java
/** * Dump the O/E or Pearsons matrix to standard out in ascii format. * * @param df Density function (expected values) * @param type will be "oe", "pearsons", or "expected" * @param les output stream/* w ww .jav a 2 s.c o m*/ * @param pw Text output stream * @throws java.io.IOException If fails to write */ public void dumpOE(ExpectedValueFunction df, String type, NormalizationType no, LittleEndianOutputStream les, PrintWriter pw) throws IOException { if (les == null && pw == null) { pw = new PrintWriter(System.out); } if (type.equals("oe")) { int nBins; if (zoom.getUnit() == HiC.Unit.BP) { nBins = chr1.getLength() / zoom.getBinSize() + 1; } else { nBins = ((DatasetReaderV2) reader).getFragCount(chr1) / zoom.getBinSize() + 1; } BasicMatrix matrix = new InMemoryMatrix(nBins); BitSet bitSet = new BitSet(nBins); List<Integer> blockNumbers = reader.getBlockNumbers(this); for (int blockNumber : blockNumbers) { Block b = null; try { b = reader.readNormalizedBlock(blockNumber, this, df.getNormalizationType()); if (b != null) { for (ContactRecord rec : b.getContactRecords()) { int x = rec.getBinX(); int y = rec.getBinY(); int dist = Math.abs(x - y); double expected = 0; try { expected = df.getExpectedValue(chr1.getIndex(), dist); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } double observed = rec.getCounts(); // Observed is already normalized double normCounts = observed / expected; // The apache library doesn't seem to play nice with NaNs if (!Double.isNaN(normCounts)) { matrix.setEntry(x, y, (float) normCounts); if (x != y) { matrix.setEntry(y, x, (float) normCounts); } bitSet.set(x); bitSet.set(y); } } } } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } if (les != null) les.writeInt(nBins); for (int i = 0; i < nBins; i++) { for (int j = 0; j < nBins; j++) { float output; if (!bitSet.get(i) && !bitSet.get(j)) { output = Float.NaN; } else output = matrix.getEntry(i, j); if (les != null) les.writeFloat(output); else pw.print(output + " "); } if (les == null) pw.println(); } if (les == null) { pw.println(); pw.flush(); } } else { BasicMatrix pearsons = getPearsons(df); if (pearsons != null) { int dim = pearsons.getRowDimension(); for (int i = 0; i < dim; i++) { for (int j = 0; j < dim; j++) { float output = pearsons.getEntry(i, j); if (les != null) les.writeFloat(output); else pw.print(output + " "); } if (les == null) pw.println(); } pw.flush(); } else { log.error("Pearson's not available at zoom " + zoom); } } }
From source file:org.eclipse.dataset.ComplexFloatDataset.java
@Override public ComplexFloatDataset idivide(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); boolean useLong = bds.elementClass().equals(Long.class); if (bds.getSize() == 1) { final IndexIterator it = getIterator(); if (useLong) { // note no complex longs final long r2 = bds.getElementLongAbs(0); while (it.hasNext()) { data[it.index] /= r2;/*from ww w .j a v a2 s . c om*/ data[it.index + 1] /= r2; } } else { final double r2 = bds.getElementDoubleAbs(0); if (!bds.isComplex() || bds.getElementDoubleAbs(1) == 0) { while (it.hasNext()) { data[it.index] /= r2; data[it.index + 1] /= r2; } } else { final double i2 = bds.getElementDoubleAbs(1); if (Math.abs(r2) < Math.abs(i2)) { double q = r2 / i2; double den = r2 * q + i2; while (it.hasNext()) { double r1 = data[it.index]; double i1 = data[it.index + 1]; data[it.index] = (float) ((r1 * q + i1) / den); // ADD_CAST data[it.index + 1] = (float) ((i1 * q - r1) / den); // ADD_CAST } } else { double q = i2 / r2; double den = i2 * q + r2; if (den == 0) { while (it.hasNext()) { data[it.index] = Float.NaN; // CLASS_TYPE data[it.index + 1] = Float.NaN; // CLASS_TYPE } } else { while (it.hasNext()) { double r1 = data[it.index]; double i1 = data[it.index + 1]; data[it.index] = (float) ((i1 * q + r1) / den); // ADD_CAST data[it.index + 1] = (float) ((i1 - r1 * q) / den); // ADD_CAST } } } } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(!useLong); if (useLong) { while (it.hasNext()) { data[it.aIndex] /= it.bLong; data[it.aIndex + 1] /= it.bLong; } } else { if (bds.isComplex()) { while (it.hasNext()) { double r1 = it.aDouble; double r2 = it.bDouble; double i1 = data[it.aIndex + 1]; double i2 = bds.getElementDoubleAbs(it.bIndex + 1); if (Math.abs(r2) < Math.abs(i2)) { double q = r2 / i2; double den = r2 * q + i2; data[it.aIndex] = (float) ((r1 * q + i1) / den); // ADD_CAST data[it.aIndex + 1] = (float) ((i1 * q - r1) / den); // ADD_CAST } else { double q = i2 / r2; double den = i2 * q + r2; if (den == 0) { data[it.aIndex] = Float.NaN; // CLASS_TYPE data[it.aIndex + 1] = Float.NaN; // CLASS_TYPE } else { data[it.aIndex] = (float) ((i1 * q + r1) / den); // ADD_CAST data[it.aIndex + 1] = (float) ((i1 - r1 * q) / den); // ADD_CAST } } } } else { while (it.hasNext()) { data[it.aIndex] /= it.bDouble; data[it.aIndex + 1] /= it.bDouble; } } } } setDirty(); return this; }
From source file:org.caleydo.view.bicluster.elem.ClusterElement.java
protected final void updateVisibility() { boolean should = shouldBeVisible(); boolean v = should && !forceHide; final boolean bak = getVisibility() == EVisibility.PICKABLE; if (v == bak) return;/*from w w w . j ava2s . c o m*/ if (v) // reset location if become visible setLocation(Float.NaN, Float.NaN); setVisibility(v ? EVisibility.PICKABLE : EVisibility.NONE); // System.out.println(toString() + " " + v); }
From source file:juicebox.tools.utils.original.Preprocessor.java
/** * Note -- compressed//from w ww. ja v a 2 s. co m * * @param zd Matrix zoom data * @param block Block to write * @param sampledData Array to hold a sample of the data (to compute statistics) * @throws IOException */ private void writeBlock(MatrixZoomDataPP zd, BlockPP block, DownsampledDoubleArrayList sampledData) throws IOException { final Map<Point, ContactCount> records = block.getContactRecordMap();// getContactRecords(); // System.out.println("Write contact records : records count = " + records.size()); // Count records first int nRecords; if (countThreshold > 0) { nRecords = 0; for (ContactCount rec : records.values()) { if (rec.getCounts() >= countThreshold) { nRecords++; } } } else { nRecords = records.size(); } BufferedByteWriter buffer = new BufferedByteWriter(nRecords * 12); buffer.putInt(nRecords); zd.cellCount += nRecords; // Find extents of occupied cells int binXOffset = Integer.MAX_VALUE; int binYOffset = Integer.MAX_VALUE; int binXMax = 0; int binYMax = 0; for (Map.Entry<Point, ContactCount> entry : records.entrySet()) { Point point = entry.getKey(); binXOffset = Math.min(binXOffset, point.x); binYOffset = Math.min(binYOffset, point.y); binXMax = Math.max(binXMax, point.x); binYMax = Math.max(binYMax, point.y); } buffer.putInt(binXOffset); buffer.putInt(binYOffset); // Sort keys in row-major order List<Point> keys = new ArrayList<Point>(records.keySet()); Collections.sort(keys, new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { if (o1.y != o2.y) { return o1.y - o2.y; } else { return o1.x - o2.x; } } }); Point lastPoint = keys.get(keys.size() - 1); final short w = (short) (binXMax - binXOffset + 1); boolean isInteger = true; float maxCounts = 0; LinkedHashMap<Integer, List<ContactRecord>> rows = new LinkedHashMap<Integer, List<ContactRecord>>(); for (Point point : keys) { final ContactCount contactCount = records.get(point); float counts = contactCount.getCounts(); if (counts >= countThreshold) { isInteger = isInteger && (Math.floor(counts) == counts); maxCounts = Math.max(counts, maxCounts); final int px = point.x - binXOffset; final int py = point.y - binYOffset; List<ContactRecord> row = rows.get(py); if (row == null) { row = new ArrayList<ContactRecord>(10); rows.put(py, row); } row.add(new ContactRecord(px, py, counts)); } } // Compute size for each representation and choose smallest boolean useShort = isInteger && (maxCounts < Short.MAX_VALUE); int valueSize = useShort ? 2 : 4; int lorSize = 0; int nDensePts = (lastPoint.y - binYOffset) * w + (lastPoint.x - binXOffset) + 1; int denseSize = nDensePts * valueSize; for (List<ContactRecord> row : rows.values()) { lorSize += 4 + row.size() * valueSize; } buffer.put((byte) (useShort ? 0 : 1)); if (lorSize < denseSize) { buffer.put((byte) 1); // List of rows representation buffer.putShort((short) rows.size()); // # of rows for (Map.Entry<Integer, List<ContactRecord>> entry : rows.entrySet()) { int py = entry.getKey(); List<ContactRecord> row = entry.getValue(); buffer.putShort((short) py); // Row number buffer.putShort((short) row.size()); // size of row for (ContactRecord contactRecord : row) { buffer.putShort((short) (contactRecord.getBinX())); final float counts = contactRecord.getCounts(); if (useShort) { buffer.putShort((short) counts); } else { buffer.putFloat(counts); } sampledData.add(counts); zd.sum += counts; } } } else { buffer.put((byte) 2); // Dense matrix buffer.putInt(nDensePts); buffer.putShort(w); int lastIdx = 0; for (Point p : keys) { int idx = (p.y - binYOffset) * w + (p.x - binXOffset); for (int i = lastIdx; i < idx; i++) { // Filler value if (useShort) { buffer.putShort(Short.MIN_VALUE); } else { buffer.putFloat(Float.NaN); } } float counts = records.get(p).getCounts(); if (useShort) { buffer.putShort((short) counts); } else { buffer.putFloat(counts); } lastIdx = idx + 1; sampledData.add(counts); zd.sum += counts; } } byte[] bytes = buffer.getBytes(); byte[] compressedBytes = compress(bytes); los.write(compressedBytes); }
From source file:net.aksingh.java.api.owm.ForecastWeatherData.java
/** * Parameterized constructor//from ww w . ja va 2s . c om * <p> * Initializes variables from values from the given JSON object. * <p> * @param jsonObj JSON object containing data about clouds */ public ForecastWeatherData(JSONObject jsonObj) { this.responseCode = (jsonObj != null) ? jsonObj.optString(this.JSON_RESPONSE_CODE, null) : null; this.responseTime = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_RESPONSE_TIME, Double.NaN) : Float.NaN; this.responseForecastCount = (jsonObj != null) ? jsonObj.optInt(this.JSON_RESPONSE_FORECAST_COUNT, Integer.MIN_VALUE) : Integer.MIN_VALUE; JSONObject jsonObjCity = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_CITY) : null; this.city = (jsonObjCity != null) ? new City(jsonObjCity) : new City(); JSONArray jsonArrForecast = (jsonObj != null) ? jsonObj.optJSONArray(this.JSON_FORECAST_LIST) : null; this.forecastList = (jsonArrForecast != null) ? new ArrayList<Forecast>(jsonArrForecast.length()) : Collections.EMPTY_LIST; if (this.forecastList != Collections.EMPTY_LIST) { for (int i = 0; i < jsonArrForecast.length(); i++) { JSONObject jsonObjWeather = jsonArrForecast.optJSONObject(i); if (jsonObjWeather != null) { this.forecastList.add(new Forecast(jsonObjWeather)); } } } this.forecastListCount = this.forecastList.size(); }