Esempio n. 1
0
  /**
   * Process a old format dataset file for a modelling problem.
   *
   * @param nfejemplos Name of the dataset file
   */
  public void oldClassificationProcess(String nfejemplos) {

    // Dataset reading for modelling problems
    try {

      String line;

      BufferedReader in = new BufferedReader(new FileReader(nfejemplos));
      line = in.readLine();
      nData = Integer.parseInt(line);
      line = in.readLine();
      nVariables = Integer.parseInt(line);
      nInputs = nVariables - 1;

      X = new double[nData][nInputs];
      Y = new double[nData];
      iMaximum = new double[nInputs];
      iMinimum = new double[nInputs];

      oMaximum = 0; // Maximum and minimum for output data
      oMinimum = 0;

      for (int i = 0; i < nData; i++) {

        line = in.readLine();
        StringTokenizer tokens = new StringTokenizer(line, " ,\t");
        for (int j = 0; j < nInputs; j++) {
          String tmp = tokens.nextToken();
          X[i][j] = Double.parseDouble(tmp);
          if (X[i][j] > iMaximum[j] || i == 0) {
            iMaximum[j] = X[i][j];
          }
          if (X[i][j] < iMinimum[j] || i == 0) {
            iMinimum[j] = X[i][j];
          }
        }
        Y[i] = Double.parseDouble(tokens.nextToken());
        if (Y[i] > oMaximum || i == 0) {
          oMaximum = Y[i];
        }
        if (Y[i] < oMinimum || i == 0) {
          oMinimum = Y[i];
        }
      }

    } catch (FileNotFoundException e) {
      System.err.println(e + " Fichero de ejemplos no encontrado");
    } catch (IOException e) {
      System.err.println(e + " Error lectura");
    }
  }
  // Read the patron file, and parse data into strings
  private void config_read(String fileParam) {
    File inputFile = new File(fileParam);

    if (inputFile == null || !inputFile.exists()) {
      System.out.println("parameter " + fileParam + " file doesn't exists!");
      System.exit(-1);
    }
    // begin the configuration read from file
    try {
      FileReader file_reader = new FileReader(inputFile);
      BufferedReader buf_reader = new BufferedReader(file_reader);
      // FileWriter file_write = new FileWriter(outputFile);

      String line;

      do {
        line = buf_reader.readLine();
      } while (line.length() == 0); // avoid empty lines for processing -> produce exec failure
      String out[] = line.split("algorithm = ");
      // alg_name = new String(out[1]); //catch the algorithm name
      // input & output filenames
      do {
        line = buf_reader.readLine();
      } while (line.length() == 0);
      out = line.split("inputData = ");
      out = out[1].split("\\s\"");
      input_train_name = new String(out[0].substring(1, out[0].length() - 1));
      input_test_name = new String(out[1].substring(0, out[1].length() - 1));
      if (input_test_name.charAt(input_test_name.length() - 1) == '"')
        input_test_name = input_test_name.substring(0, input_test_name.length() - 1);

      do {
        line = buf_reader.readLine();
      } while (line.length() == 0);
      out = line.split("outputData = ");
      out = out[1].split("\\s\"");
      output_train_name = new String(out[0].substring(1, out[0].length() - 1));
      output_test_name = new String(out[1].substring(0, out[1].length() - 1));
      if (output_test_name.charAt(output_test_name.length() - 1) == '"')
        output_test_name = output_test_name.substring(0, output_test_name.length() - 1);

      file_reader.close();

    } catch (IOException e) {
      System.out.println("IO exception = " + e);
      e.printStackTrace();
      System.exit(-1);
    }
  }
Esempio n. 3
0
  /**
   * Process an old format dataset file for a clustering problem.
   *
   * @param nfejemplos Name of the dataset file.
   */
  public void procesa_clustering_old(String nfejemplos) {
    // Dataset reading for clustering problems

    try {

      String line;

      BufferedReader in = new BufferedReader(new FileReader(nfejemplos));
      line = in.readLine();
      nData = Integer.parseInt(line);
      line = in.readLine();
      nVariables = Integer.parseInt(line);
      nInputs = nVariables;

      X = new double[nData][nInputs];
      iMaximum = new double[nInputs];
      iMinimum = new double[nInputs];

      for (int i = 0; i < nData; i++) {

        line = in.readLine();
        StringTokenizer tokens = new StringTokenizer(line, " ,\t");
        for (int j = 0; j < nInputs; j++) {
          String tmp = tokens.nextToken();
          X[i][j] = Double.parseDouble(tmp);
          if (X[i][j] > iMaximum[j] || i == 0) {
            iMaximum[j] = X[i][j];
          }
          if (X[i][j] < iMinimum[j] || i == 0) {
            iMinimum[j] = X[i][j];
          }
        }
      }

    } catch (FileNotFoundException e) {
      System.err.println(e + " Fichero de ejemplos no encontrado");
    } catch (IOException e) {
      System.err.println(e + " Error lectura");
    }
  }
Esempio n. 4
0
  /**
   * Process an old format dataset file for a classification problem.
   *
   * @param nfejemplos Name of the dataset file.
   */
  public void oldClusteringProcess(String nfejemplos) {

    // Dataset reading for modelling problems

    try {

      String line;

      BufferedReader in = new BufferedReader(new FileReader(nfejemplos));
      line = in.readLine();
      nData = Integer.parseInt(line);
      line = in.readLine();
      nVariables = Integer.parseInt(line);
      nInputs = nVariables - 1;

      X = new double[nData][nInputs];
      C = new int[nData];
      iMaximum = new double[nInputs];
      iMinimum = new double[nInputs];

      int cMaximum = 0; // Maximum and minimum for output data
      int cMinimum = 0;

      for (int i = 0; i < nData; i++) {

        line = in.readLine();
        StringTokenizer tokens = new StringTokenizer(line, " ,\t");
        for (int j = 0; j < nInputs; j++) {
          String tmp = tokens.nextToken();
          X[i][j] = Double.parseDouble(tmp);
          if (X[i][j] > iMaximum[j] || i == 0) {
            iMaximum[j] = X[i][j];
          }
          if (X[i][j] < iMinimum[j] || i == 0) {
            iMinimum[j] = X[i][j];
          }
        }
        C[i] = Integer.parseInt(tokens.nextToken());
        if (C[i] > cMaximum || i == 0) {
          cMaximum = C[i];
        }
        if (C[i] < cMinimum || i == 0) {
          cMinimum = C[i];
        }
      }

      if (cMaximum == cMinimum) {
        throw new IOException("0 clases");
      }

      nClasses = cMaximum - cMinimum + 1;

      // It enumerates classes from 0
      for (int i = 0; i < nData; i++) {
        C[i] = (C[i] - cMinimum) / (cMaximum - cMinimum);
      }

    } catch (FileNotFoundException e) {
      System.err.println(e + " Fichero de ejemplos no encontrado");
    } catch (IOException e) {
      System.err.println(e + " Error lectura");
    }
  }