Example #1
0
  /**
   * Adds new row element to this data set
   *
   * @param row data set row to add
   */
  public void addRow(DataSetRow row) throws VectorSizeMismatchException {

    if (row == null) {
      throw new NeurophException("Training dta row cannot be null!");
    }

    // check input vector size if it is predefined
    if ((this.inputSize != 0) && (row.getInput().length != this.inputSize)) {
      throw new VectorSizeMismatchException(
          "Input vector size does not match data set input size!");
    }

    if ((this.outputSize != 0) && (row.getDesiredOutput().length != this.outputSize)) {
      throw new VectorSizeMismatchException(
          "Output vector size does not match data set output size!");
    }

    // if everything went ok add training element
    this.rows.add(row);
  }
Example #2
0
  public void saveAsTxt(String filePath, String delimiter) {
    if ((delimiter == null) || delimiter.equals("")) {
      delimiter = " ";
    }

    PrintWriter out = null;

    try {
      out = new PrintWriter(new FileWriter(new File(filePath)));

      for (DataSetRow element : this.rows) {
        double[] input = element.getInput();
        for (int i = 0; i < input.length; i++) {
          out.print(input[i] + delimiter);
        }

        if (element instanceof DataSetRow) {
          double[] output = ((DataSetRow) element).getDesiredOutput();
          for (int j = 0; j < output.length; j++) {
            out.print(output[j] + delimiter);
          }
        }
        out.println();
      }

      out.flush();

    } catch (Exception e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
    } finally {
      if (out != null) {
        out.close();
      }
    }
  }