Package org.encog.util.csv

Examples of org.encog.util.csv.ReadCSV


   * Process the file and output to the target file.
   * @param target The target file to write to.
   */
  public final void process(final File target) {
    try {
      ReadCSV csv = new ReadCSV(this.getInputFilename().toString(),
          this.isExpectInputHeaders(), this.getInputFormat());

      PrintWriter tw = new PrintWriter(new FileWriter(target));

      resetStatus();
      while (csv.next() && !this.shouldStop()) {
        StringBuilder line = new StringBuilder();
        updateStatus(false);
        line.append(this.getColumnData(FileData.DATE, csv));
        line.append(" ");
        line.append(this.getColumnData(FileData.TIME, csv));
        line.append(";");
        line.append(getInputFormat().format(
            Double.parseDouble(this.getColumnData(FileData.OPEN,
                csv)), this.getPrecision()));
        line.append(";");
        line.append(getInputFormat().format(
            Double.parseDouble(this.getColumnData(FileData.HIGH,
                csv)), this.getPrecision()));
        line.append(";");
        line.append(getInputFormat().format(
            Double.parseDouble(this
                .getColumnData(FileData.LOW, csv)),
            this.getPrecision()));
        line.append(";");
        line.append(getInputFormat().format(
            Double.parseDouble(this.getColumnData(FileData.CLOSE,
                csv)), this.getPrecision()));
        line.append(";");
        line.append(getInputFormat().format(
            Double.parseDouble(this.getColumnData(FileData.VOLUME,
                csv)), this.getPrecision()));

        tw.println(line.toString());
      }
      reportDone(false);
      csv.close();
      tw.close();
    } catch (IOException ex) {
      throw new QuantError(ex);
    }
  }
View Full Code Here


   * Process the input file and segregate into the output files.
   */
  public final void process() {
    validate();

    final ReadCSV csv = new ReadCSV(getInputFilename().toString(),
        isExpectInputHeaders(), getInputFormat());
    resetStatus();
    for (final SegregateTargetPercent target : this.targets) {
      final PrintWriter tw = prepareOutputFile(target.getFilename());

      while ((target.getNumberRemaining() > 0) && csv.next()
          && !shouldStop()) {
        updateStatus(false);
        final LoadedRow row = new LoadedRow(csv);
        writeRow(tw, row);
        target.setNumberRemaining(target.getNumberRemaining() - 1);
      }

      tw.close();
    }
    reportDone(false);
    csv.close();
  }
View Full Code Here

    try {

      final InputStream is = ResourceInputStream
          .openResourceInputStream("org/encog/data/analyst.csv");
      final ReadCSV csv = new ReadCSV(is, false, CSVFormat.EG_FORMAT);

      while (csv.next()) {
        final String sectionStr = csv.get(0);
        final String nameStr = csv.get(1);
        final String typeStr = csv.get(2);

        // determine type
        PropertyType t = null;
        if ("boolean".equalsIgnoreCase(typeStr)) {
          t = PropertyType.TypeBoolean;
        } else if ("real".equalsIgnoreCase(typeStr)) {
          t = PropertyType.TypeDouble;
        } else if ("format".equalsIgnoreCase(typeStr)) {
          t = PropertyType.typeFormat;
        } else if ("int".equalsIgnoreCase(typeStr)) {
          t = PropertyType.TypeInteger;
        } else if ("list-string".equalsIgnoreCase(typeStr)) {
          t = PropertyType.TypeListString;
        } else if ("string".equalsIgnoreCase(typeStr)) {
          t = PropertyType.TypeString;
        } else {
          throw new AnalystError("Unknown type constraint: "
              + typeStr);
        }

        final PropertyEntry entry = new PropertyEntry(t, nameStr,
            sectionStr);
        List<PropertyEntry> list;

        if (this.data.containsKey(sectionStr)) {
          list = this.data.get(sectionStr);
        } else {
          list = new ArrayList<PropertyEntry>();
          this.data.put(sectionStr, list);
        }

        list.add(entry);
      }

      csv.close();
      is.close();
    } catch (final IOException e) {
      throw new EncogError(e);
    }
  }
View Full Code Here

     
    // read the file
    this.rowCount = 0;
    this.missingCount = 0;
   
    ReadCSV csv = new ReadCSV(sourceFile.toString(),headers,inputFormat);
    while(csv.next()) {
      rowCount++;
      if( csv.hasMissing() )
        missingCount++;
    }
    csv.close();

  }
View Full Code Here

   *
   * @param outputFile
   *            The output file to write to.
   */
  public final void process(final File outputFile) {
    final ReadCSV csv = new ReadCSV(getInputFilename().toString(),
        isExpectInputHeaders(), getInputFormat());

    final PrintWriter tw = prepareOutputFile(outputFile);
    this.filteredCount = 0;

    resetStatus();
    while (csv.next() && !shouldStop()) {
      updateStatus(false);
      final LoadedRow row = new LoadedRow(csv);
      if (shouldProcess(row)) {
        writeRow(tw, row);
        this.filteredCount++;
      }
    }
    reportDone(false);
    tw.close();
    csv.close();
  }
View Full Code Here

            File binFile, int[] input, int[] ideal,
            boolean headers)
   {

       binFile.delete();
       ReadCSV csv = new ReadCSV(csvFile.toString(), headers, format);
      
       BufferedNeuralDataSet buffer = new BufferedNeuralDataSet(binFile);
       buffer.beginLoad(input.length, ideal.length);
       while(csv.next())
       {
         BasicMLData inputData = new BasicMLData(input.length);
         BasicMLData idealData = new BasicMLData(ideal.length);
        
         // handle input data
         for(int i=0;i<input.length;i++) {
           inputData.setData(i, csv.getDouble(input[i]));
         }
        
         // handle input data
         for(int i=0;i<ideal.length;i++) {
           idealData.setData(i, csv.getDouble(ideal[i]));
         }
        
         // add to dataset
        
           buffer.add(inputData,idealData);
View Full Code Here

   * @return A NeuralDataSet that holds the contents of the CSV file.
   */
  public static MLDataSet loadCSVTOMemory(CSVFormat format,
      String filename, boolean headers, int inputSize, int idealSize) {
    MLDataSet result = new BasicMLDataSet();
    ReadCSV csv = new ReadCSV(filename, headers, format);
    while (csv.next()) {
      MLData input = null;
      MLData ideal = null;
      int index = 0;

      input = new BasicMLData(inputSize);
      for (int i = 0; i < inputSize; i++) {
        double d = csv.getDouble(index++);
        input.setData(i, d);
      }

      if (idealSize > 0) {
        ideal = new BasicMLData(idealSize);
        for (int i = 0; i < idealSize; i++) {
          double d = csv.getDouble(index++);
          ideal.setData(i, d);
        }
      }

      MLDataPair pair = new BasicMLDataPair(input, ideal);
View Full Code Here

    if (this.inputCount == 0) {
      throw new BufferedDataError("To import CSV, you must use the "
          + "CSVDataCODEC constructor that specifies input and "
          + "ideal sizes.");
    }
    this.readCSV = new ReadCSV(this.file.toString(), this.headers,
        this.format);
  }
View Full Code Here

    analyst.addAnalystListener(new ConsoleAnalystListener());
    analyst.load(egaFile);

    analyst.executeTask("task-full");
   
    ReadCSV csv = new ReadCSV(outputFile.toString(),true,CSVFormat.ENGLISH);
    while(csv.next()) {
      double diff = Math.abs(csv.getDouble(2) - csv.getDouble(4));
      Assert.assertTrue(diff<1.5);
    }
   
    Assert.assertEquals(4, analyst.getScript().getFields().length );
    Assert.assertEquals(3, analyst.getScript().getFields()[3].getClassMembers().size());
   
    csv.close();
  }
View Full Code Here

    analyst.addAnalystListener(new ConsoleAnalystListener());
    analyst.load(egaFile);

    analyst.executeTask("task-full");
   
    ReadCSV csv = new ReadCSV(outputFile.toString(),true,CSVFormat.ENGLISH);
    while(csv.next()) {
      Assert.assertEquals(csv.get(3), csv.get(4));
    }
   
    Assert.assertEquals(4, analyst.getScript().getFields().length );
    Assert.assertEquals(3, analyst.getScript().getFields()[3].getClassMembers().size());
   
    csv.close();
  }
View Full Code Here

TOP

Related Classes of org.encog.util.csv.ReadCSV

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.