private boolean einlesen() { int eingabefaktor; // Faktor try { eingabefaktor = Integer.parseInt(feldFaktor.getText()); if (eingabefaktor < 0) { System.out.println("Faktor < 0"); feldFaktor.selectAll(); return false; } } catch (NumberFormatException e) { System.out.println(e.toString()); feldFaktor.selectAll(); return false; } faktor = eingabefaktor; // Ist die Checkbox angekreuzt? NUREINSCHRITT = checkbox_nureinSchritt.isSelected(); AUCHSTRAGEGIE2 = checkbox_auchStrategie2.isSelected(); return true; }
private void feldFaktorActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_feldFaktorActionPerformed try { int eingabefaktor = Integer.parseInt(feldFaktor.getText()); if (eingabefaktor < 0) { System.out.println("Faktor < 0"); feldFaktor.setSelectionStart(0); feldFaktor.setSelectionEnd(feldFaktor.getText().length()); } } catch (NumberFormatException e) { System.out.println(e.toString()); feldFaktor.setSelectionStart(0); feldFaktor.setSelectionEnd(feldFaktor.getText().length()); } } // GEN-LAST:event_feldFaktorActionPerformed
public void message(String s) { if (firstLine == null) firstLine = s; else { StringTokenizer st = new StringTokenizer(s, " "); try { st.nextToken(); st.nextToken(); st.nextToken(); size = (new Integer(st.nextToken().trim())).longValue(); } catch (NoSuchElementException e) { exception = new RunnerException(e.toString()); } catch (NumberFormatException e) { exception = new RunnerException(e.toString()); } } }
/** * If we know in advance that the table is numeric, can optimize a lot... For example, on 9803 x * 294 table, TableFileLoader.readNumeric takes 6s compared to 12s for WekaMine readFromTable. */ public static Instances readNumeric(String fileName, String relationName, String delimiter) throws Exception { int numAttributes = FileUtils.fastCountLines(fileName) - 1; // -1 exclude heading. String[] attrNames = new String[numAttributes]; // Read the col headings and figure out the number of columns in the table.. BufferedReader reader = new BufferedReader(new FileReader(fileName), 4194304); String line = reader.readLine(); String[] instanceNames = parseColNames(line, delimiter); int numInstances = instanceNames.length; System.err.print("reading " + numAttributes + " x " + numInstances + " table.."); // Create an array to hold the data as we read it in... double dataArray[][] = new double[numAttributes][numInstances]; // Populate the matrix with values... String valToken = ""; try { int rowIdx = 0; while ((line = reader.readLine()) != null) { String[] tokens = line.split(delimiter, -1); attrNames[rowIdx] = tokens[0].trim(); for (int colIdx = 0; colIdx < (tokens.length - 1); colIdx++) { valToken = tokens[colIdx + 1]; double value; if (valToken.equals("null")) { value = Instance.missingValue(); } else if (valToken.equals("?")) { value = Instance.missingValue(); } else if (valToken.equals("NA")) { value = Instance.missingValue(); } else if (valToken.equals("")) { value = Instance.missingValue(); // }else value = DoubleParser.lightningParse(valToken); // faster double parser with // MANY assumptions } else value = Double.parseDouble(valToken); dataArray[rowIdx][colIdx] = value; } rowIdx++; } } catch (NumberFormatException e) { System.err.println(e.toString()); System.err.println("Parsing line: " + line); System.err.println("Parsing token: " + valToken); } // Set up attributes, which for colInstances will be the rowNames... FastVector atts = new FastVector(); for (int a = 0; a < numAttributes; a++) { atts.addElement(new Attribute(attrNames[a])); } // Create Instances object.. Instances data = new Instances(relationName, atts, 0); data.setRelationName(relationName); System.err.print("creating instances.."); // System.err.println("DEBUG: numAttributes "+numAttributes); /** ***** CREATE INSTANCES ************* */ // Fill the instances with data... // For each instance... for (int c = 0; c < numInstances; c++) { double[] vals = new double[data.numAttributes()]; // Even nominal values are stored as double pointers. for (int r = 0; r < numAttributes; r++) { double val = dataArray[r][c]; vals[r] = val; } // Add the a newly minted instance with those attribute values... data.add(new Instance(1.0, vals)); } // System.err.println("DEBUG: data.numInstances: "+data.numInstances()); // System.err.println("DEBUG: data.numAttributes: "+data.numAttributes()); // System.err.println("DEBUG: data.relationNAme"+data.relationName()); System.err.print("add feature names.."); /** ***** ADD FEATURE NAMES ************* */ // takes basically zero time... all time is in previous 2 chunks. Instances newData = new Instances(data); newData.insertAttributeAt(new Attribute("ID", (FastVector) null), 0); int attrIdx = newData.attribute("ID").index(); // Paranoid... should be 0 for (int c = 0; c < numInstances; c++) { newData.instance(c).setValue(attrIdx, instanceNames[c]); } data = newData; // System.err.println("DEBUG: data.numInstances: "+data.numInstances()); // System.err.println("DEBUG: data.numAttributes: "+data.numAttributes()); return (data); }