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:Main.java
/** * Parses the supplied xsd:double string and returns its value. * /*from w w w . j av a 2 s.c o m*/ * @param s * A string representation of an xsd:double value. * @return The <tt>double</tt> value represented by the supplied string argument. * @throws NumberFormatException * If the supplied string is not a valid xsd:double value. */ public static double parseDouble(String s) { if (POSITIVE_INFINITY.equals(s)) { return Double.POSITIVE_INFINITY; } else if (NEGATIVE_INFINITY.equals(s)) { return Double.NEGATIVE_INFINITY; } else if (NaN.equals(s)) { return Double.NaN; } else { s = trimPlusSign(s); return Double.parseDouble(s); } }
From source file:Main.java
public static List<Double> difference(final List<? extends Object> minuend, final List<? extends Object> subtrahend) { final List<Double> result = new ArrayList<Double>(); for (int i = 0; i < minuend.size(); ++i) { final Object o1 = minuend.get(i); final Object o2 = subtrahend.get(i); if (areBothNumbers(o1, o2)) { subtract(result, o1, o2);/* w ww . j av a 2 s. c om*/ } else { result.add(Double.NaN); } } return result; }
From source file:conceptor.chaos.Lyapunov.java
/** Given a DynamicalSystem, returns the maximul lyapunov exponent using the method outline by J.C. Sprott see: http://sprott.physics.wisc.edu/chaos/lyapexp.htm *///w w w. j a v a2 s . c o m public static double computeLargestExponent(DynamicalSystem system) { double d0 = 10e-8; // First, evolve the system such that it's very likely to be on // the attractor (1000 iterations is a decent guess) evolveSystem(system, 10000); // Next, pick a test point a distance d0 away double[] testPoint = getTestPoint(system, d0); double[] x = system.getState(); double d1 = 0.0; double l = 0.0; // Evolve both the test point and the original for (int i = 0; i < 64100; i++) { testPoint = system.evolveOther(testPoint); x = system.evolve(); // Test for unbounded orbits if (isUnbounded(x)) { return Double.NaN; } // Compute distance d1 = MathArrays.distance(testPoint, x); // Compute lyapunov exponent this round if (i > 100) { l = l + Math.log(d1 / d0); } // Renormalize test point for (int j = 0; j < x.length; j++) { testPoint[j] = x[j] + (d0 / d1) * (testPoint[j] - x[j]); } } return l / (63999 * system.getStepSize()); }
From source file:geogebra.util.MyMath.java
final public static double sgn(Kernel kernel, double a) { // bugfix for graph f(x) = sgn(sqrt(1 - x)) if (Double.isNaN(a)) return Double.NaN; if (Kernel.isZero(a)) return 0.0; else if (a > 0.0) return 1.0; else//from ww w.j a v a 2s .c o m return -1.0; }
From source file:Main.java
/** * Returns the <a href="http://mathworld.wolfram.com/Sign.html"> sign</a> * for double precision <code>x</code>. * <p>/* w w w . ja va 2s. co m*/ * For a double value <code>x</code>, this method returns * <code>+1.0</code> if <code>x > 0</code>, <code>0.0</code> if * <code>x = 0.0</code>, and <code>-1.0</code> if <code>x < 0</code>. * Returns <code>NaN</code> if <code>x</code> is <code>NaN</code>.</p> * * @param x the value, a double * @return +1.0, 0.0, or -1.0, depending on the sign of x */ public static double sign(final double x) { if (Double.isNaN(x)) { return Double.NaN; } return (x == 0.0) ? 0.0 : (x > 0.0) ? 1.0 : -1.0; }
From source file:edu.umn.msi.tropix.proteomics.itraqquantitation.impl.Variance.java
private static int indexOf(final double value, final double[] vector) { int index = -1; for (int i = 0; i < vector.length; i++) { if (vector[i] == value) { vector[i] = Double.NaN; index = i;//from w w w . j a v a 2 s . com break; } } return index; }
From source file:Main.java
/** * Round the given value to the specified number of decimal places. The * value is rounded using the given method which is any method defined in * {@link BigDecimal}./*from w ww . ja v a 2 s . c om*/ * * @param x the value to round. * @param scale the number of digits to the right of the decimal point. * @param roundingMethod the rounding method as defined in * {@link BigDecimal}. * @return the rounded value. * @since 1.1 */ public static double round(double x, int scale, int roundingMethod) { try { return (new BigDecimal(Double.toString(x)).setScale(scale, roundingMethod)).doubleValue(); } catch (NumberFormatException ex) { if (Double.isInfinite(x)) { return x; } else { return Double.NaN; } } }
From source file:fr.ens.transcriptome.teolenn.util.MathUtils.java
/** * Calculates the standard deviation of an array of numbers. see * http://davidmlane.com/hyperstat/A16252.html * @param data Numbers to compute the standard deviation of. Array must * contain two or more numbers. * @return standard deviation estimate of population ( to get estimate of * sample, use n instead of n-1 in last line ) *///from w w w .ja va 2 s.c o m public static double sdFast(final double[] data) { if (data == null) return Double.NaN; // sd is sqrt of sum of (values-mean) squared divided by n - 1 // Calculate the mean double mean = 0; final int n = data.length; if (n < 2) return Double.NaN; for (int i = 0; i < n; i++) { mean += data[i]; } mean /= n; // calculate the sum of squares double sum = 0; for (int i = 0; i < n; i++) { final double v = data[i] - mean; sum += v * v; } return java.lang.Math.sqrt(sum / (n - 1)); }
From source file:Main.java
/** * Determines the minimum and maximum values in the two dimensional array <tt>multi</tt>. Calls {@link #minMax(double[], double)} with * <tt>Double.NaN</tt> as the <tt>noDataValue</tt>. * // w ww . j av a 2 s . c om * @param multi * @return a <tt>double[]</tt> where [0]==minimum and [1]==maximum * @see #minMax(double[][], double) */ public static double[] minMax(double[][] multi) { return minMax(multi, Double.NaN); }
From source file:eqtlmappingpipeline.util.ModuleEqtlGeuvadisReplication.java
/** * @param args the command line arguments *//*w w w . j av a 2 s . com*/ public static void main(String[] args) throws IOException, LdCalculatorException { System.out.println(HEADER); System.out.println(); System.out.flush(); //flush to make sure header is before errors try { Thread.sleep(25); //Allows flush to complete } catch (InterruptedException ex) { } CommandLineParser parser = new PosixParser(); final CommandLine commandLine; try { commandLine = parser.parse(OPTIONS, args, true); } catch (ParseException ex) { System.err.println("Invalid command line arguments: " + ex.getMessage()); System.err.println(); new HelpFormatter().printHelp(" ", OPTIONS); System.exit(1); return; } final String[] genotypesBasePaths = commandLine.getOptionValues("g"); final RandomAccessGenotypeDataReaderFormats genotypeDataType; final String replicationQtlFilePath = commandLine.getOptionValue("e"); final String interactionQtlFilePath = commandLine.getOptionValue("i"); final String outputFilePath = commandLine.getOptionValue("o"); final double ldCutoff = Double.parseDouble(commandLine.getOptionValue("ld")); final int window = Integer.parseInt(commandLine.getOptionValue("w")); System.out.println("Genotype: " + Arrays.toString(genotypesBasePaths)); System.out.println("Interaction file: " + interactionQtlFilePath); System.out.println("Replication file: " + replicationQtlFilePath); System.out.println("Output: " + outputFilePath); System.out.println("LD: " + ldCutoff); System.out.println("Window: " + window); try { if (commandLine.hasOption("G")) { genotypeDataType = RandomAccessGenotypeDataReaderFormats .valueOf(commandLine.getOptionValue("G").toUpperCase()); } else { if (genotypesBasePaths[0].endsWith(".vcf")) { System.err.println( "Only vcf.gz is supported. Please see manual on how to do create a vcf.gz file."); System.exit(1); return; } try { genotypeDataType = RandomAccessGenotypeDataReaderFormats .matchFormatToPath(genotypesBasePaths[0]); } catch (GenotypeDataException e) { System.err .println("Unable to determine input 1 type based on specified path. Please specify -G"); System.exit(1); return; } } } catch (IllegalArgumentException e) { System.err.println("Error parsing --genotypesFormat \"" + commandLine.getOptionValue("G") + "\" is not a valid input data format"); System.exit(1); return; } final RandomAccessGenotypeData genotypeData; try { genotypeData = genotypeDataType.createFilteredGenotypeData(genotypesBasePaths, 100, null, null, null, 0.8); } catch (TabixFileNotFoundException e) { LOGGER.fatal("Tabix file not found for input data at: " + e.getPath() + "\n" + "Please see README on how to create a tabix file"); System.exit(1); return; } catch (IOException e) { LOGGER.fatal("Error reading input data: " + e.getMessage(), e); System.exit(1); return; } catch (IncompatibleMultiPartGenotypeDataException e) { LOGGER.fatal("Error combining the impute genotype data files: " + e.getMessage(), e); System.exit(1); return; } catch (GenotypeDataException e) { LOGGER.fatal("Error reading input data: " + e.getMessage(), e); System.exit(1); return; } ChrPosTreeMap<ArrayList<EQTL>> replicationQtls = new QTLTextFile(replicationQtlFilePath, false) .readQtlsAsTreeMap(); int interactionSnpNotInGenotypeData = 0; int noReplicationQtlsInWindow = 0; int noReplicationQtlsInLd = 0; int multipleReplicationQtlsInLd = 0; int replicationTopSnpNotInGenotypeData = 0; final CSVWriter outputWriter = new CSVWriter(new FileWriter(new File(outputFilePath)), '\t', '\0'); final String[] outputLine = new String[14]; int c = 0; outputLine[c++] = "Chr"; outputLine[c++] = "Pos"; outputLine[c++] = "SNP"; outputLine[c++] = "Gene"; outputLine[c++] = "Module"; outputLine[c++] = "DiscoveryZ"; outputLine[c++] = "ReplicationZ"; outputLine[c++] = "DiscoveryZCorrected"; outputLine[c++] = "ReplicationZCorrected"; outputLine[c++] = "DiscoveryAlleleAssessed"; outputLine[c++] = "ReplicationAlleleAssessed"; outputLine[c++] = "bestLd"; outputLine[c++] = "bestLd_dist"; outputLine[c++] = "nextLd"; outputWriter.writeNext(outputLine); HashSet<String> notFound = new HashSet<>(); CSVReader interactionQtlReader = new CSVReader(new FileReader(interactionQtlFilePath), '\t'); interactionQtlReader.readNext();//skip header String[] interactionQtlLine; while ((interactionQtlLine = interactionQtlReader.readNext()) != null) { String snp = interactionQtlLine[1]; String chr = interactionQtlLine[2]; int pos = Integer.parseInt(interactionQtlLine[3]); String gene = interactionQtlLine[4]; String alleleAssessed = interactionQtlLine[9]; String module = interactionQtlLine[12]; double discoveryZ = Double.parseDouble(interactionQtlLine[10]); GeneticVariant interactionQtlVariant = genotypeData.getSnpVariantByPos(chr, pos); if (interactionQtlVariant == null) { System.err.println("Interaction QTL SNP not found in genotype data: " + chr + ":" + pos); ++interactionSnpNotInGenotypeData; continue; } EQTL bestMatch = null; double bestMatchR2 = Double.NaN; Ld bestMatchLd = null; double nextBestR2 = Double.NaN; ArrayList<EQTL> sameSnpQtls = replicationQtls.get(chr, pos); if (sameSnpQtls != null) { for (EQTL sameSnpQtl : sameSnpQtls) { if (sameSnpQtl.getProbe().equals(gene)) { bestMatch = sameSnpQtl; bestMatchR2 = 1; } } } NavigableMap<Integer, ArrayList<EQTL>> potentionalReplicationQtls = replicationQtls.getChrRange(chr, pos - window, true, pos + window, true); for (ArrayList<EQTL> potentialReplicationQtls : potentionalReplicationQtls.values()) { for (EQTL potentialReplicationQtl : potentialReplicationQtls) { if (!potentialReplicationQtl.getProbe().equals(gene)) { continue; } GeneticVariant potentialReplicationQtlVariant = genotypeData.getSnpVariantByPos( potentialReplicationQtl.getRsChr().toString(), potentialReplicationQtl.getRsChrPos()); if (potentialReplicationQtlVariant == null) { notFound.add(potentialReplicationQtl.getRsChr().toString() + ":" + potentialReplicationQtl.getRsChrPos()); ++replicationTopSnpNotInGenotypeData; continue; } Ld ld = interactionQtlVariant.calculateLd(potentialReplicationQtlVariant); double r2 = ld.getR2(); if (r2 > 1) { r2 = 1; } if (bestMatch == null) { bestMatch = potentialReplicationQtl; bestMatchR2 = r2; bestMatchLd = ld; } else if (r2 > bestMatchR2) { bestMatch = potentialReplicationQtl; nextBestR2 = bestMatchR2; bestMatchR2 = r2; bestMatchLd = ld; } } } double replicationZ = Double.NaN; double replicationZCorrected = Double.NaN; double discoveryZCorrected = Double.NaN; String replicationAlleleAssessed = null; if (bestMatch != null) { replicationZ = bestMatch.getZscore(); replicationAlleleAssessed = bestMatch.getAlleleAssessed(); if (pos != bestMatch.getRsChrPos()) { String commonHap = null; double commonHapFreq = -1; for (Map.Entry<String, Double> hapFreq : bestMatchLd.getHaplotypesFreq().entrySet()) { double f = hapFreq.getValue(); if (f > commonHapFreq) { commonHapFreq = f; commonHap = hapFreq.getKey(); } } String[] commonHapAlleles = StringUtils.split(commonHap, '/'); discoveryZCorrected = commonHapAlleles[0].equals(alleleAssessed) ? discoveryZ : discoveryZ * -1; replicationZCorrected = commonHapAlleles[1].equals(replicationAlleleAssessed) ? replicationZ : replicationZ * -1; } else { discoveryZCorrected = discoveryZ; replicationZCorrected = alleleAssessed.equals(replicationAlleleAssessed) ? replicationZ : replicationZ * -1; } } c = 0; outputLine[c++] = chr; outputLine[c++] = String.valueOf(pos); outputLine[c++] = snp; outputLine[c++] = gene; outputLine[c++] = module; outputLine[c++] = String.valueOf(discoveryZ); outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(replicationZ); outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(discoveryZCorrected); outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(replicationZCorrected); outputLine[c++] = alleleAssessed; outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(bestMatch.getAlleleAssessed()); outputLine[c++] = String.valueOf(bestMatchR2); outputLine[c++] = bestMatch == null ? "NA" : String.valueOf(Math.abs(pos - bestMatch.getRsChrPos())); outputLine[c++] = String.valueOf(nextBestR2); outputWriter.writeNext(outputLine); } outputWriter.close(); for (String e : notFound) { System.err.println("Not found: " + e); } System.out.println("interactionSnpNotInGenotypeData: " + interactionSnpNotInGenotypeData); System.out.println("noReplicationQtlsInWindow: " + noReplicationQtlsInWindow); System.out.println("noReplicationQtlsInLd: " + noReplicationQtlsInLd); System.out.println("multipleReplicationQtlsInLd: " + multipleReplicationQtlsInLd); System.out.println("replicationTopSnpNotInGenotypeData: " + replicationTopSnpNotInGenotypeData); }