List of usage examples for java.lang Double NEGATIVE_INFINITY
double NEGATIVE_INFINITY
To view the source code for java.lang Double NEGATIVE_INFINITY.
Click Source Link
From source file:Main.java
public static void main(String[] args) { System.out.println(Double.NEGATIVE_INFINITY); }
From source file:Main.java
public static void main(String[] args) { System.out.printf("%.2e %n", Double.NaN); System.out.printf("%.2f %n", Double.POSITIVE_INFINITY); System.out.printf("%.2g %n", Double.NEGATIVE_INFINITY); System.out.printf("%(f %n", Double.POSITIVE_INFINITY); System.out.printf("%(f %n", Double.NEGATIVE_INFINITY); }
From source file:FpError.java
public static void main(String[] args) { double res;/*from ww w .java2 s . c o m*/ double divisor = 0; double dividend, root; // Get user input for numerator System.out.println("Forcing division by zero error"); dividend = 10d; res = dividend / divisor; // Test for negative invifinity if (res == Double.NEGATIVE_INFINITY) System.out.println("result is NEGATIVE_INFINITY"); if (res == Double.POSITIVE_INFINITY) System.out.println("result is POSITIVE_INFINITY"); // Test for either infinity if (Double.isInfinite(res)) System.out.println("result is infinite"); // Get user input for square root System.out.println("\nCalculating square root (try negative)"); root = 10d; res = Math.sqrt(root); if (Double.isNaN(res)) System.out.println("result is Nan"); else System.out.println("Square root = " + res); }
From source file:edu.msu.cme.rdp.graph.utils.ContigMerger.java
public static void main(String[] args) throws IOException { final BufferedReader hmmgsResultReader; final IndexedSeqReader nuclContigReader; final double minBits; final int minProtLength; final Options options = new Options(); final PrintStream out; final ProfileHMM hmm; final FastaWriter protSeqOut; final FastaWriter nuclSeqOut; final boolean prot; final boolean all; final String shortSampleName; options.addOption("a", "all", false, "Generate all combinations for multiple paths, instead of just the best"); options.addOption("b", "min-bits", true, "Minimum bits score"); options.addOption("l", "min-length", true, "Minimum length"); options.addOption("s", "short_samplename", true, "short sample name, to be used as part of contig identifiers. This allow analyzing contigs together from different samples in downstream analysis "); options.addOption("o", "out", true, "Write output to file instead of stdout"); try {/*from w ww .ja va 2 s . c o m*/ CommandLine line = new PosixParser().parse(options, args); if (line.hasOption("min-bits")) { minBits = Double.valueOf(line.getOptionValue("min-bits")); } else { minBits = Double.NEGATIVE_INFINITY; } if (line.hasOption("min-length")) { minProtLength = Integer.valueOf(line.getOptionValue("min-length")); } else { minProtLength = 0; } if (line.hasOption("short_samplename")) { shortSampleName = line.getOptionValue("short_samplename") + "_"; } else { shortSampleName = ""; } if (line.hasOption("out")) { out = new PrintStream(line.getOptionValue("out")); } else { out = System.err; } all = line.hasOption("all"); args = line.getArgs(); if (args.length != 3) { throw new Exception("Unexpected number of arguments"); } hmmgsResultReader = new BufferedReader(new FileReader(new File(args[1]))); nuclContigReader = new IndexedSeqReader(new File(args[2])); hmm = HMMER3bParser.readModel(new File(args[0])); prot = (hmm.getAlphabet() == SequenceType.Protein); if (prot) { protSeqOut = new FastaWriter(new File("prot_merged.fasta")); } else { protSeqOut = null; } nuclSeqOut = new FastaWriter(new File("nucl_merged.fasta")); } catch (Exception e) { new HelpFormatter().printHelp("USAGE: ContigMerger [options] <hmm> <hmmgs_file> <nucl_contig>", options); System.err.println("Error: " + e.getMessage()); System.exit(1); throw new RuntimeException("I hate you javac"); } String line; SearchDirection lastDir = SearchDirection.left; //So this has an assumption built in //It depends on hmmgs always outputting left fragments, then right //We can't just use the kmer to figure out if we've switched to another starting point //because we allow multiple starting model pos, so two different starting //positions can have the same starting kmer Map<String, Sequence> leftContigs = new HashMap(); Map<String, Sequence> rightContigs = new HashMap(); int contigsMerged = 0; int writtenMerges = 0; long startTime = System.currentTimeMillis(); String kmer = null; String geneName = null; while ((line = hmmgsResultReader.readLine()) != null) { if (line.startsWith("#")) { continue; } String[] lexemes = line.trim().split("\t"); if (lexemes.length != 12 || lexemes[0].equals("-")) { System.err.println("Skipping line: " + line); continue; } //contig_53493 nirk 1500:6:35:16409:3561/1 ADV15048 tcggcgctctacacgttcctgcagcccggg 40 210 70 left -44.692 184 0 int index = 0; String seqid = lexemes[0]; geneName = lexemes[1]; String readid = lexemes[2]; String refid = lexemes[3]; kmer = lexemes[4]; int modelStart = Integer.valueOf(lexemes[5]); int nuclLength = Integer.valueOf(lexemes[6]); int protLength = Integer.valueOf(lexemes[7]); SearchDirection dir = SearchDirection.valueOf(lexemes[8]); if (dir != lastDir) { if (dir == SearchDirection.left) { List<MergedContig> mergedContigs = all ? mergeAllContigs(leftContigs, rightContigs, kmer, geneName, hmm) : mergeContigs(leftContigs, rightContigs, kmer, geneName, hmm); contigsMerged++; for (MergedContig mc : mergedContigs) { String mergedId = shortSampleName + geneName + "_" + mc.leftContig + "_" + mc.rightContig; out.println(mergedId + "\t" + mc.length + "\t" + mc.score); if (mc.score > minBits && mc.length > minProtLength) { if (prot) { protSeqOut.writeSeq(mergedId, mc.protSeq); } nuclSeqOut.writeSeq(mergedId, mc.nuclSeq); writtenMerges++; } } leftContigs.clear(); rightContigs.clear(); } lastDir = dir; } Sequence seq = nuclContigReader.readSeq(seqid); if (dir == SearchDirection.left) { leftContigs.put(seqid, seq); } else if (dir == SearchDirection.right) { rightContigs.put(seqid, seq); } else { throw new IOException("Cannot handle search direction " + dir); } } if (!leftContigs.isEmpty() || !rightContigs.isEmpty()) { List<MergedContig> mergedContigs = all ? mergeAllContigs(leftContigs, rightContigs, kmer, geneName, hmm) : mergeContigs(leftContigs, rightContigs, kmer, geneName, hmm); for (MergedContig mc : mergedContigs) { String mergedId = shortSampleName + mc.gene + "_" + mc.leftContig + "_" + mc.rightContig; out.println(mergedId + "\t" + mc.length + "\t" + mc.score); contigsMerged++; if (mc.score > minBits && mc.length > minProtLength) { if (prot) { protSeqOut.writeSeq(mergedId, mc.protSeq); } nuclSeqOut.writeSeq(mergedId, mc.nuclSeq); writtenMerges++; } } } out.close(); if (prot) { protSeqOut.close(); } nuclSeqOut.close(); System.err.println("Read in " + contigsMerged + " contigs, wrote out " + writtenMerges + " merged contigs in " + ((double) (System.currentTimeMillis() - startTime) / 1000) + "s"); }
From source file:Main.java
/** * Returns next smaller float value considering precision of the argument. * /*from w ww . j a va 2 s. c om*/ */ public static double nextDown(double d) { if (Double.isNaN(d) || d == Double.NEGATIVE_INFINITY) { return d; } else { if (d == 0.0f) { return -Float.MIN_VALUE; } else { return Double.longBitsToDouble(Double.doubleToRawLongBits(d) + ((d > 0.0f) ? -1 : +1)); } } }
From source file:Main.java
public static double max(double[] x, int length) { double m = Double.NEGATIVE_INFINITY; for (int i = 0; i < length; i++) if (x[i] > m) m = x[i];// ww w .j a v a 2 s . co m return m; }
From source file:Util.java
public static int argmax(double[] elems) { int bestIdx = -1; double max = Double.NEGATIVE_INFINITY; for (int i = 0; i < elems.length; i++) { double elem = elems[i]; if (elem > max) { max = elem;//from www . jav a 2s . c o m bestIdx = i; } } return bestIdx; }
From source file:mase.mason.world.GeomUtils.java
public static Pair<Double2D, Double2D> computeBB(Double2D[] points) { double xMin = Double.POSITIVE_INFINITY; double yMin = Double.POSITIVE_INFINITY; double xMax = Double.NEGATIVE_INFINITY; double yMax = Double.NEGATIVE_INFINITY; for (Double2D p : points) { xMin = Math.min(xMin, p.x); yMin = Math.min(yMin, p.y); xMax = Math.max(xMax, p.x); yMax = Math.max(yMax, p.y); }// w ww . j a v a 2s . c o m return Pair.of(new Double2D(xMin, yMin), new Double2D(xMax, yMax)); }
From source file:Main.java
/** * Determines the minimum and maximum values in the <tt>array</tt>, ignoring any instances of <tt>noDataValue</tt>. * /*from www.j a v a2 s . co m*/ * @param array * @param noDataValue * @return a <tt>double[]</tt> where [0]==minimum and [1]==maximum */ public static double[] minMax(double[] array, double noDataValue) { double[] ret = null; double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY; double val; for (int i = 0; i < array.length; i++) { val = array[i]; if (val != noDataValue) { min = (val < min) ? val : min; max = (val > max) ? val : max; } } if (!Double.isInfinite(min) & !Double.isInfinite(max)) { ret = new double[] { min, max }; } return ret; }
From source file:com.ibm.bluej.commonutil.DenseVectors.java
public static int maxIndex(double[] v) { int maxNdx = 0; double max = Double.NEGATIVE_INFINITY; for (int i = 0; i < v.length; ++i) { if (v[i] > max) { max = v[i];/*from w w w . jav a 2 s.co m*/ maxNdx = i; } } return maxNdx; }