List of usage examples for java.lang Float isInfinite
public static boolean isInfinite(float v)
From source file:org.caleydo.core.util.impute.KNNImpute.java
@Override protected Table<Integer, Integer, Float> compute() { // data/*from w w w. jav a 2s. c o m*/ // An expression matrix with genes in the rows, samples in the columns // k // Number of neighbors to be used in the imputation (default=10) // rowmax // The maximum percent missing data allowed in any row (default 50%). For any // rows with more than rowmax% missing are imputed using the overall mean per // sample. // colmax // The maximum percent missing data allowed in any column (default 80%). If // any column has more than colmax% missing data, the program halts and reports // an error. // maxp // The largest block of genes imputed using the knn algorithm inside impute.knn // (default 1500); larger blocks are divided by two-means clustering (recursively) // prior to imputation. If maxp=p, only knn imputation is done. // rng.seed // The seed used for the random number generator (default 362436069) for repro- // ducibility. // impute.knn uses k-nearest neighbors in the space of genes to impute missing expression values. // For each gene with missing values, we find the k nearest neighbors using a Euclidean metric, con- // fined to the columns for which that gene is NOT missing. Each candidate neighbor might be missing // some of the coordinates used to calculate the distance. In this case we average the distance from // the non-missing coordinates. Having found the k nearest neighbors for a gene, we impute the miss- // ing elements by averaging those (non-missing) elements of its neighbors. This can fail if ALL the // neighbors are missing in a particular element. In this case we use the overall column mean for that // block of genes. // Since nearest neighbor imputation costs O(plog(p)) operations per gene, where p is the number // of rows, the computational time can be excessive for large p and a large number of missing rows. // Our strategy is to break blocks with more than maxp genes into two smaller blocks using two-mean // clustering. This is done recursively till all blocks have less than maxp genes. For each block, k- // nearest neighbor imputation is done separately. We have set the default value of maxp to 1500. // Depending on the speed of the machine, and number of samples, this number might be increased. // Making it too small is counter-productive, because the number of two-mean clustering algorithms // will increase. if (toomanyNaNsInAColumn()) throw new IllegalStateException(); final float rowMax = desc.getRowmax(); final boolean validRowMax = !Float.isInfinite(rowMax) && !Float.isNaN(rowMax); final int max = validRowMax ? Math.round(desc.getRowmax() * samples) : 0; //list of possible List<Gene> neighborhood; int withMissing = 0; Collection<ForkJoinTask<Void>> tasks = new ArrayList<>(); if (!validRowMax) { neighborhood = genes;// all genes } else { neighborhood = new ArrayList<>(genes.size()); for (Gene gene : genes) { if (gene.getNaNs() == 0) {// nothing to impute neighborhood.add(gene); } else if (validRowMax && gene.getNaNs() > max) { // too many nans use the sample mean tasks.add(new ImputeSampleMean(gene)); //not a good neighbor } else { // neighbor but something needs to be done neighborhood.add(gene); withMissing++; } } } if (withMissing > 0) tasks.add(new ImputeKNNMean(neighborhood)); invokeAll(tasks); ImmutableTable.Builder<Integer, Integer, Float> b = ImmutableTable.builder(); for (Gene gene : genes) { if (gene.isAnySet()) { gene.fillImpute(b); } } return b.build(); }
From source file:MutableFloat.java
/** * Checks whether the float value is infinite. * * @return true if infinite */ public boolean isInfinite() { return Float.isInfinite(value); }
From source file:gov.nasa.ensemble.common.CommonUtils.java
/** * Check whether two floats are equal concerning a delta. If either value is infinity then the delta value is ignored. * /* w w w. ja va 2s. c o m*/ * @param f1 * @param f2 * @param delta * @return boolean */ public static final boolean equals(float f1, float f2, float delta) { // handle infinity specially since subtracting two infinite values gives NaN if (Float.isInfinite(f1) || Float.isInfinite(f2)) return f1 == f2; return Math.abs(f1 - f2) <= delta; }
From source file:Vector3f.java
/** * Returns <code>true</code> if vector is {@link Float#NEGATIVE_INFINITY}, * {@link Float#POSITIVE_INFINITY} or {@link Float#NaN} * @return <code>true</code> if vector is {@link Float#NEGATIVE_INFINITY}, * {@link Float#POSITIVE_INFINITY} or {@link Float#NaN}. *//* w w w. ja va2 s .c om*/ public boolean isInvalid() { return Float.isInfinite(x) || Float.isInfinite(y) || Float.isInfinite(z) || Float.isNaN(x) || Float.isNaN(y) || Float.isNaN(z); }
From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java
public static float[] findMinAndMax(float[] buffer, int pixelStride, int numBands) { float min = Float.MAX_VALUE; float max = -Float.MAX_VALUE; for (int i = 0; i < buffer.length; i += numBands) { for (int j = 0; j < pixelStride; ++j) { float value = buffer[i + j]; if (!Float.isInfinite(value)) { if (value < min) min = value;//from ww w . j a va 2 s . c om if (value > max) max = value; } } } return new float[] { min, max }; }
From source file:ExposedFloat.java
void updateNumberFields() { int intBits = Float.floatToIntBits(value); if (Float.isNaN(value)) { base10Field.setText(notANumberString); } else if (Float.isInfinite(value)) { if ((intBits >>> 31) == 1) { // This is a negative infinity base10Field.setText(negativeInfinityString); } else {// w w w . j ava 2 s . c om // This is a positive infinity base10Field.setText(positiveInfinityString); } } else if (intBits == (int) 0x80000000) { base10Field.setText("-0"); } else { base10Field.setText(Float.toString(value)); } int v = intBits; StringBuffer buf = new StringBuffer(); for (int i = 0; i < 8; ++i) { // Get lowest bit int remainder = v & 0xf; // Convert bit to a character and insert it into the beginning of the string switch (remainder) { case 0: buf.insert(0, "0"); break; case 1: buf.insert(0, "1"); break; case 2: buf.insert(0, "2"); break; case 3: buf.insert(0, "3"); break; case 4: buf.insert(0, "4"); break; case 5: buf.insert(0, "5"); break; case 6: buf.insert(0, "6"); break; case 7: buf.insert(0, "7"); break; case 8: buf.insert(0, "8"); break; case 9: buf.insert(0, "9"); break; case 10: buf.insert(0, "a"); break; case 11: buf.insert(0, "b"); break; case 12: buf.insert(0, "c"); break; case 13: buf.insert(0, "d"); break; case 14: buf.insert(0, "e"); break; case 15: buf.insert(0, "f"); break; } // Shift the int to the right one bit v >>>= 4; } hexField.setText(buf.toString()); v = intBits; buf.setLength(0); for (int i = 0; i < 32; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } binaryField.setText(buf.toString()); if (intBits < 0) { signField.setText("1"); } else { signField.setText("0"); } v = intBits >> 23; buf.setLength(0); for (int i = 0; i < 8; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } exponentField.setText(buf.toString()); // Do the mantissa v = intBits; buf.setLength(0); for (int i = 0; i < 23; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } if (((intBits >> 23) & 0xff) == 0) { // This is a denormalized number, first bit is 0 buf.insert(0, "0"); } else { // This is a normalized number, first bit is 1 buf.insert(0, "1"); } mantissaField.setText(buf.toString()); // Print out a denormalized base 2 version. buf.setLength(0); if (Float.isNaN(value)) { buf.append(notANumberString); } else if (Float.isInfinite(value)) { if ((intBits >>> 31) == 1) { // This is a negative infinity buf.append(negativeInfinityString); } else { // This is a positive infinity buf.append(positiveInfinityString); } } else { if ((intBits >>> 31) == 1) { // This is a negative number buf.append("-"); } // Convert mantissa to int. v = (intBits & 0x007fffff); if (((intBits >> 23) & 0xff) != 0) { // Set bit 23 if the number is normalized v |= 0x00800000; } buf.append(v); // print out the exponent v = (intBits >> 23) & 0xff; if (v != 150 && intBits != 0 && intBits != (int) 0x80000000) { if (v != 0) { // regular normalized number buf.append("e" + (v - 150)); } else { // denormalized number buf.append("e-149"); } } } base2Field.setText(buf.toString()); }
From source file:com.larvalabs.svgandroid.SVGParser.java
private static SVG parse(InputStream in, Integer searchColor, Integer replaceColor, boolean whiteMode) throws SVGParseException { // Util.debug("Parsing SVG..."); SVGHandler svgHandler = null;//from w ww . j a va 2s .com try { // long start = System.currentTimeMillis(); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); final Picture picture = new Picture(); svgHandler = new SVGHandler(picture); svgHandler.setColorSwap(searchColor, replaceColor); svgHandler.setWhiteMode(whiteMode); CopyInputStream cin = new CopyInputStream(in); IDHandler idHandler = new IDHandler(); xr.setContentHandler(idHandler); xr.parse(new InputSource(cin.getCopy())); svgHandler.idXml = idHandler.idXml; xr.setContentHandler(svgHandler); xr.parse(new InputSource(cin.getCopy())); // Util.debug("Parsing complete in " + (System.currentTimeMillis() - start) + " millis."); SVG result = new SVG(picture, svgHandler.bounds); // Skip bounds if it was an empty pic if (!Float.isInfinite(svgHandler.limits.top)) { result.setLimits(svgHandler.limits); } return result; } catch (Exception e) { //for (String s : handler.parsed.toString().replace(">", ">\n").split("\n")) // Log.d(TAG, "Parsed: " + s); throw new SVGParseException(e); } }
From source file:org.apache.tajo.worker.TaskAttemptContext.java
public void setProgress(float progress) { float previousProgress = this.progress; if (Float.isNaN(progress) || Float.isInfinite(progress)) { this.progress = 0.0f; } else {//from ww w .j av a 2 s.c om this.progress = progress; } this.progressChanged = previousProgress != progress; }
From source file:org.apache.tajo.worker.TaskAttemptContext.java
public void setExecutorProgress(float executorProgress) { if (Float.isNaN(executorProgress) || Float.isInfinite(executorProgress)) { executorProgress = 0.0f;/*from ww w.j av a 2 s. c o m*/ } if (hasFetchPhase()) { setProgress(fetcherProgress + (executorProgress * 0.5f)); } else { setProgress(executorProgress); } }
From source file:org.apache.tajo.worker.TaskAttemptContext.java
public void setFetcherProgress(float fetcherProgress) { if (Float.isNaN(fetcherProgress) || Float.isInfinite(fetcherProgress)) { fetcherProgress = 0.0f;/*from w w w. j av a2 s . co m*/ } float previousProgress = this.fetcherProgress; this.fetcherProgress = fetcherProgress; this.progressChanged = previousProgress != fetcherProgress; }