예제 #1
0
  /**
   * Generating the header of the output file @ param p PrintStream
   *
   * @return Nothing
   */
  private void CopyHeaderTest(PrintStream p) {

    // Header of the output file
    p.println("@relation " + Attributes.getRelationName());
    p.print(Attributes.getInputAttributesHeader());
    p.print(Attributes.getOutputAttributesHeader());
    p.println(Attributes.getInputHeader());
    p.println(Attributes.getOutputHeader());
    p.println("@data");
  }
예제 #2
0
 /**
  * It copies the header of the dataset
  *
  * @return String A string containing all the data-set information
  */
 public String copyHeader() {
   String p = new String("");
   p = "@relation " + Attributes.getRelationName() + "\n";
   p += Attributes.getInputAttributesHeader();
   p += Attributes.getOutputAttributesHeader();
   p += Attributes.getInputHeader() + "\n";
   p += Attributes.getOutputHeader() + "\n";
   p += "@data\n";
   return p;
 }
예제 #3
0
  /**
   * Save data in output file
   *
   * @param file_name File name
   * @param data Data to be saved
   * @param n No of patterns
   * @param problem Type of problem (CLASSIFICATION | REGRESSION)
   * @throws IOException
   */
  public void SaveOutputFile(
      String file_name, double data[][], int n, String problem, double[] a, double[] b) {
    String line;
    double outputs[] = new double[Noutputs];

    try {
      // Result file
      FileOutputStream file = new FileOutputStream(file_name);
      BufferedWriter f = new BufferedWriter(new OutputStreamWriter(file));

      // File header
      f.write("@relation " + Attributes.getRelationName() + "\n");
      f.write(Attributes.getInputAttributesHeader());
      f.write(Attributes.getOutputAttributesHeader());
      f.write(Attributes.getInputHeader() + "\n");
      f.write(Attributes.getOutputHeader() + "\n");
      f.write("@data\n");

      // For all patterns
      for (int i = 0; i < n; i++) {

        // Classification
        if (problem.compareToIgnoreCase("Classification") == 0) {
          // Obtain class
          int Class = 0;
          for (int j = 1; j < Noutputs; j++) {
            if (data[i][Class + Ninputs] < data[i][j + Ninputs]) {
              Class = j;
            }
          }
          /*
          f.write(Integer.toString(Class) + " ");
          f.write(Integer.toString(EnsembleGetClassOfPattern(data[i])));
                              f.newLine();
          */
          f.write(Attributes.getOutputAttributes()[0].getNominalValue(Class) + " ");
          f.write(
              Attributes.getOutputAttributes()[0].getNominalValue(
                  EnsembleGetClassOfPattern(data[i])));
          f.newLine();
          f.flush();

        }
        // Regression
        else {
          if (a != null && b != null) {
            for (int j = 0; j < Noutputs; j++) {
              f.write(Double.toString((data[i][Ninputs + j] - b[j]) / a[j]) + " ");
            }
            EnsembleOutput(data[i], outputs);
            for (int j = 0; j < Noutputs; j++) {
              f.write(Double.toString((outputs[j] - b[j]) / a[j]) + " ");
            }
            f.newLine();
          } else {
            for (int j = 0; j < Noutputs; j++) {
              f.write(Double.toString(data[i][Ninputs + j]) + " ");
            }
            EnsembleOutput(data[i], outputs);
            for (int j = 0; j < Noutputs; j++) {
              f.write(Double.toString(outputs[j]) + " ");
            }
            f.newLine();
          }
        }
      }
      f.close();
      file.close();
    } catch (FileNotFoundException e) {
      System.err.println("Training file does not exist");
      System.exit(1);
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }