List of usage examples for java.util Scanner nextDouble
public double nextDouble()
From source file:IO.java
public static double[] readDoubleVec(File file) { double[] data; try {/*from w w w.ja v a 2s . co m*/ int nData = countLines(file.getAbsolutePath()); data = new double[nData]; Scanner sc = new Scanner(file); sc.useDelimiter(",|\\n"); for (int i = 0; i < nData; i++) { data[i] = sc.nextDouble(); } return data; } catch (IOException e) { e.printStackTrace(); data = new double[0]; return data; } }
From source file:aula1.Aula1.java
public static Double[] lerDados() { Scanner dados = new Scanner(System.in); Double[] vetor = new Double[3]; System.out.println("Isira o valor do inicio do dominio"); vetor[0] = dados.nextDouble(); System.out.println("Insira o valor do fim do dominio"); vetor[1] = dados.nextDouble();/* w w w . j av a2 s . co m*/ System.out.println("Insira o valor da sensibilidade"); vetor[2] = dados.nextDouble(); return vetor; }
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;//from w ww. j a v a 2s. com 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; }
From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java
public static double[][] loadTimeSeries(Path filename) { double[][] series = new double[1][1]; try (InputStream in = Files.newInputStream(filename); BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { Scanner scin = new Scanner(in); int num_frames = scin.nextInt(); int dim = scin.nextInt(); series = new double[num_frames][dim]; for (int i = 0; i < num_frames; i++) { for (int j = 0; j < dim; j++) { series[i][j] = scin.nextDouble(); }// w ww . ja va 2 s . co m } } catch (IOException e) { e.printStackTrace(); } return series; }
From source file:org.pooledtimeseries.PoT.java
public static double[][] loadTimeSeries(Scanner scin) { double[][] series = new double[1][1]; int num_frames = scin.nextInt(); int dim = scin.nextInt(); series = new double[num_frames][dim]; for (int i = 0; i < num_frames; i++) { for (int j = 0; j < dim; j++) { series[i][j] = scin.nextDouble(); }/*from www. j a v a2 s .c om*/ } scin.close(); return series; }
From source file:edu.umn.msi.tropix.proteomics.conversion.impl.MzXMLToDTAConverterStreamingImplTest.java
@Test(groups = "unit") public void readw() { /*/*from w w w . j a v a2 s . co m*/ final Random random = new Random(); int count = 5000; double[] peaks = new double[count]; for(int i =0; i < count; i++) { peaks[i] = random.nextDouble(); } System.out.println(new String(Base64.encodeBase64(ConversionUtils.doubles2bytes(peaks)))); */ final MzXMLToDTAConverterStreamingImpl converter = new MzXMLToDTAConverterStreamingImpl(); DTAList dtaList; InputStream mzxmlStream; mzxmlStream = ProteomicsTests.getResourceAsStream("readw.mzXML"); try { dtaList = converter.mzxmlToDTA(mzxmlStream, null); double[] contents78charge2 = null, contents78charge3 = null; for (DTAList.Entry entry : dtaList) { if (entry.getName().matches(".*0*78\\.0*78\\.2\\.dta$")) { assert contents78charge2 == null; contents78charge2 = DTAUtils.readDtaDoublePairs(entry.getContents()); } if (entry.getName().matches(".*0*78\\.0*78\\.3\\.dta$")) { assert contents78charge3 == null; contents78charge3 = DTAUtils.readDtaDoublePairs(entry.getContents()); } if (entry.getName().matches(".*0*1993\\.0*1993\\.1\\.dta$")) { final double[] values = DTAUtils.readDtaDoublePairs(entry.getContents()); final Scanner scanner = new Scanner(new ByteArrayInputStream(entry.getContents())); assert MathUtils.equals(scanner.nextDouble(), 1515.390000); assert scanner.nextInt() == 1; assert Math.abs(662.267334 - values[0]) < .01 : values[0]; assert Math.abs(4.004042 - values[values.length - 1]) < .01; } } assert contents78charge2 != null; assert contents78charge3 != null; assert contents78charge2.length == contents78charge3.length; for (int i = 2; i < contents78charge2.length; i++) { assert MathUtils.equals(contents78charge2[i], contents78charge3[i]); } } finally { IO_UTILS.closeQuietly(mzxmlStream); } }
From source file:hu.sztaki.incremental.ml.streaming.imsr.MatrixVectorPairSource.java
private void readMatricesSideBySide(Scanner scanner, RealMatrix... matrices) { for (int i = 0; i < matrices[0].getRowDimension(); i++) { if (!scanner.hasNextLine()) { return; //there will be some 0 rows }// www .jav a 2 s . c o m String line = scanner.nextLine(); Scanner lineScanner = initCsvScanner(new Scanner(line)); for (RealMatrix m : matrices) { for (int j = 0; j < m.getColumnDimension(); j++) { double d = lineScanner.nextDouble(); m.setEntry(i, j, d); } } lineScanner.close(); } }
From source file:cz.cuni.mff.ksi.jinfer.autoeditor.BububuEditor.java
/** * Draws automaton and waits until user picks two states and clicks * 'continue' button./*from ww w . ja va 2 s . co m*/ * * @param automaton automaton to be drawn * @return if user picks exactly two states returns Pair of them otherwise null */ @Override public List<State<T>> drawAutomatonToPickStates(final Automaton<T> automaton) { final DirectedSparseMultigraph<State<T>, Step<T>> graph = new DirectedSparseMultigraph<State<T>, Step<T>>(); final Map<State<T>, Set<Step<T>>> automatonDelta = automaton.getDelta(); // Get vertices = states of automaton for (Entry<State<T>, Set<Step<T>>> entry : automatonDelta.entrySet()) { graph.addVertex(entry.getKey()); } // Get edges of automaton for (Entry<State<T>, Set<Step<T>>> entry : automatonDelta.entrySet()) { for (Step<T> step : entry.getValue()) { graph.addEdge(step, step.getSource(), step.getDestination()); } } Map<State<T>, Point2D> positions = new HashMap<State<T>, Point2D>(); ProcessBuilder p = new ProcessBuilder(Arrays.asList("/usr/bin/dot", "-Tplain")); try { Process k = p.start(); k.getOutputStream().write((new AutomatonToDot<T>()).convertToDot(automaton, symbolToString).getBytes()); k.getOutputStream().flush(); BufferedReader b = new BufferedReader(new InputStreamReader(k.getInputStream())); k.getOutputStream().close(); Scanner s = new Scanner(b); s.next(); s.next(); double width = s.nextDouble(); double height = s.nextDouble(); double windowW = 500; double windowH = 300; while (s.hasNext()) { if (s.next().equals("node")) { int nodeName = s.nextInt(); double x = s.nextDouble(); double y = s.nextDouble(); for (State<T> state : automatonDelta.keySet()) { if (state.getName() == nodeName) { positions.put(state, new Point((int) (windowW * x / width), (int) (windowH * y / height))); break; } } } } } catch (IOException ex) { Exceptions.printStackTrace(ex); } Transformer<State<T>, Point2D> trans = TransformerUtils.mapTransformer(positions); // TODO rio find suitable layout final Layout<State<T>, Step<T>> layout = new StaticLayout<State<T>, Step<T>>(graph, trans); //layout.setSize(new Dimension(300,300)); // sets the initial size of the space visualizationViewer = new VisualizationViewer<State<T>, Step<T>>(layout); //visualizationViewer.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size visualizationViewer.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<State<T>>()); visualizationViewer.getRenderContext().setEdgeLabelTransformer(new Transformer<Step<T>, String>() { @Override public String transform(Step<T> i) { return BububuEditor.this.symbolToString.toString(i.getAcceptSymbol()); } }); final PluggableGraphMouse gm = new PluggableGraphMouse(); gm.add(new PickingUnlimitedGraphMousePlugin<State<T>, Step<T>>()); visualizationViewer.setGraphMouse(gm); // Call GUI in a special thread. Required by NB. synchronized (this) { WindowManager.getDefault().invokeWhenUIReady(new Runnable() { @Override public void run() { // Pass this as argument so the thread will be able to wake us up. AutoEditorTopComponent.findInstance().drawAutomatonBasicVisualizationServer(BububuEditor.this, visualizationViewer, "Please select two states to be merged together."); } }); try { // Sleep on this. this.wait(); } catch (InterruptedException e) { return null; } } /* AutoEditorTopComponent wakes us up. Get the result and return it. * VisualizationViewer should give us the information about picked vertices. */ final Set<State<T>> pickedSet = visualizationViewer.getPickedVertexState().getPicked(); List<State<T>> lst = new ArrayList<State<T>>(pickedSet); return lst; }
From source file:uk.ac.gda.dls.client.views.MonitorCompositeFactory.java
void setVal(String newVal) { if (decimalPlaces != null) { Scanner sc = new Scanner(newVal.trim()); if (sc.hasNextDouble()) { NumberFormat format = NumberFormat.getInstance(); format.setMaximumFractionDigits(decimalPlaces.intValue()); newVal = format.format(sc.nextDouble()); }/*from w ww. ja va 2 s . c o m*/ sc.close(); } val = newVal; if (!isDisposed()) display.asyncExec(setTextRunnable); }
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;// w ww .j av a 2s. co 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); }