List of usage examples for java.util Scanner hasNextDouble
public boolean hasNextDouble()
From source file:picard.analysis.TheoreticalSensitivityTest.java
@Test public void testHetSensDistributions() throws Exception { //Expect theoretical sens to be close to .9617 for Solexa-332667 final double tolerance = 0.02; final double expectedResult = .9617; final int maxDepth = 500; final double[] depthDistribution = new double[maxDepth + 1]; final double[] qualityDistribution = new double[50]; final Scanner scanDepth = new Scanner(DEPTH); for (int i = 0; scanDepth.hasNextDouble(); i++) { depthDistribution[i] = scanDepth.nextDouble(); }//from w w w .j a v a 2s.c o m final Scanner scanBaseQ = new Scanner(BASEQ); for (int j = 0; scanBaseQ.hasNextDouble(); j++) { qualityDistribution[j] = scanBaseQ.nextDouble(); } final int sampleSize = 1_000; final double logOddsThreshold = 3.0; final double result = TheoreticalSensitivity.hetSNPSensitivity(depthDistribution, qualityDistribution, sampleSize, logOddsThreshold); Assert.assertEquals(result, expectedResult, tolerance); }
From source file:ro.hasna.ts.math.ml.distance.DynamicTimeWarpingDistanceTest.java
@Test public void testResultLarge() throws Exception { DynamicTimeWarpingDistance dtw = new DynamicTimeWarpingDistance(0.05, null); int m = 128;/*from w w w . ja va 2s .c o m*/ ZNormalizer normalizer = new ZNormalizer(); Scanner dataScanner = new Scanner(getClass().getResourceAsStream("data-1m.txt")).useLocale(Locale.ENGLISH); double[] data = new double[m]; double[] copy = new double[m]; for (int i = 0; i < m && dataScanner.hasNextDouble(); i++) { data[i] = dataScanner.nextDouble(); } Scanner queryScanner = new Scanner(getClass().getResourceAsStream("query-128.txt")) .useLocale(Locale.ENGLISH); double[] query = new double[m]; for (int i = 0; i < m && queryScanner.hasNextDouble(); i++) { query[i] = queryScanner.nextDouble(); } query = normalizer.normalize(query); double min = Double.POSITIVE_INFINITY; int posMin = 0; int n = 0; // long duration = 0; while (dataScanner.hasNextDouble()) { System.arraycopy(data, 1, copy, 0, m - 1); copy[m - 1] = dataScanner.nextDouble(); double[] normalizedCopy = normalizer.normalize(copy); // long start = System.currentTimeMillis(); double d = dtw.compute(normalizedCopy, query, min); // duration += System.currentTimeMillis() - start; if (d < min) { min = d; posMin = n; } data = copy; n++; } // System.out.println("duration=" + duration); Assert.assertEquals(756561, posMin); Assert.assertEquals(3.775620905705185, min, TimeSeriesPrecision.EPSILON); }
From source file:ro.hasna.ts.math.ml.distance.LongestCommonSubsequenceDistanceTest.java
@Test public void testResultLarge() throws Exception { LongestCommonSubsequenceDistance lcss = new LongestCommonSubsequenceDistance(0.1, 0.05); int m = 128;// w ww.j a v a 2 s .c om ZNormalizer normalizer = new ZNormalizer(); Scanner dataScanner = new Scanner(getClass().getResourceAsStream("data-100k.txt")) .useLocale(Locale.ENGLISH); double[] data = new double[m]; double[] copy = new double[m]; for (int i = 0; i < m && dataScanner.hasNextDouble(); i++) { data[i] = dataScanner.nextDouble(); } Scanner queryScanner = new Scanner(getClass().getResourceAsStream("query-128.txt")) .useLocale(Locale.ENGLISH); double[] query = new double[m]; for (int i = 0; i < m && queryScanner.hasNextDouble(); i++) { query[i] = queryScanner.nextDouble(); } query = normalizer.normalize(query); double min = Double.POSITIVE_INFINITY; int posMin = 0; int n = 0; // long duration = 0; while (dataScanner.hasNextDouble()) { System.arraycopy(data, 1, copy, 0, m - 1); copy[m - 1] = dataScanner.nextDouble(); double[] normalizedCopy = normalizer.normalize(copy); // long start = System.currentTimeMillis(); double d = lcss.compute(normalizedCopy, query, min); // duration += System.currentTimeMillis() - start; if (d < min) { min = d; posMin = n; } data = copy; n++; } // System.out.println("duration=" + duration); Assert.assertEquals(93728, posMin); Assert.assertEquals(0.5625, min, TimeSeriesPrecision.EPSILON); }
From source file:testing.test.java
private static List getPointParts(String points, int indexSize) { List pointParts = new ArrayList(); String test[] = points.split(" "); System.out.println(test.length); Scanner scannedPoints = new Scanner(points).useDelimiter(" "); int totalPointIndex = 3 * (indexSize + 1); System.out.println("totalPointIndex: 3 * (" + indexSize + " + 1) = " + totalPointIndex); int index = 0; double[] floats = new double[totalPointIndex]; while ((scannedPoints.hasNextDouble()) && (index < floats.length)) { double fl = scannedPoints.nextDouble(); floats[index] = fl;//www. j a va 2 s . c om index++; } for (int i = 0; i < floats.length; i += 3) { String nextPart = Double.toString(floats[i]) + " " + Double.toString(floats[i + 1]) + " " + Double.toString(floats[i + 2]); pointParts.add(nextPart); } return pointParts; }