Exemplo n.º 1
0
  /**
   * Obtains the parameters used in the execution of the algorithm and stores them in the private
   * variables of the class
   *
   * @param ficheroScript Name of the configuration script that indicates the parameters that are
   *     going to be used during the execution of the algorithm
   */
  public void leerConfiguracion(String ficheroScript) {

    String fichero, linea, token;
    StringTokenizer lineasFichero, tokens;
    byte line[];
    int i, j;

    ficheroSalida = new String[2];

    fichero = Fichero.leeFichero(ficheroScript);
    lineasFichero = new StringTokenizer(fichero, "\n\r");

    lineasFichero.nextToken();
    linea = lineasFichero.nextToken();

    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    token = tokens.nextToken();

    /*Getting the names of the training and test files*/
    line = token.getBytes();
    for (i = 0; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroTraining = new String(line, i, j - i);
    for (i = j + 1; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroTest = new String(line, i, j - i);

    /*Getting the path and base name of the results files*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    token = tokens.nextToken();

    /*Getting the names of output files*/
    line = token.getBytes();
    for (i = 0; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroSalida[0] = new String(line, i, j - i);
    for (i = j + 1; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroSalida[1] = new String(line, i, j - i);

    /*Getting the seed*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    semilla = Long.parseLong(tokens.nextToken().substring(1));

    /*Getting the number of neighbors*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    k = Integer.parseInt(tokens.nextToken().substring(1));
  }
Exemplo n.º 2
0
  /**
   * It obtains all the necesary information from the configuration file.<br>
   * First of all it reads the name of the input data-sets, training, validation and test.<br>
   * Then it reads the name of the output files, where the training (validation) and test outputs
   * will be stored<br>
   * Finally it read the parameters of the algorithm, such as the random seed.<br>
   *
   * @param fileName Name of the configuration file
   */
  public void parseConfigurationFile(String fileName) {
    StringTokenizer line;
    String file = Fichero.leeFichero(fileName); // file is an string containing the whole file

    line = new StringTokenizer(file, "\n\r");
    readName(line); // We read the algorithm name
    readInputFiles(line); // We read all the input files
    readOutputFiles(line); // We read all the output files
    readAllParameters(line); // We read all the possible parameters
  };
Exemplo n.º 3
0
  public static void main(String[] args) {
    String cadena = "";
    StringTokenizer lineas, tokens, tokensT;
    String linea, dato1, dato2, token, timesplit[];
    boolean algorithms = true;
    Vector<String> algoritmos;
    Vector<String> datasets;

    Vector<Integer> saltos;
    int i, j, k, l, m, n;
    double accuracyAv[][];
    double accuracySD[][];
    double reductionAv[][];
    double reductionSD[][];
    double kappaAv[][];
    double kappaSD[][];
    double accredAv[][];
    double kapredAv[][];
    double time[][];
    int runs[][];
    String alAct, alAnterior;
    int configAct;
    String datAct;
    int salAct;
    double acc, red, kappa;
    int aciertos, total;
    double accV[], redV[], kappaV[];
    Vector<String> valoresClase;
    int confusionMatrix[][];
    int sumKappa, sumi, sumj;
    double accSD, redSD, kapSD;
    String tiempos;
    int postime;

    if (args.length != 1) {
      System.err.println("Error. Hace falta un parámetro: Fichero de algoritmos y datasets.");
      System.exit(1);
    }

    algoritmos = new Vector<String>();
    datasets = new Vector<String>();

    saltos = new Vector<Integer>();

    /*Lectura del fichero de configuración*/
    cadena = Fichero.leeFichero(args[0]);
    lineas = new StringTokenizer(cadena, "\n\r");
    while (lineas.hasMoreTokens()) {
      linea = lineas.nextToken();
      if (linea.equalsIgnoreCase("----")) algorithms = false;
      else {
        if (algorithms) {
          algoritmos.addElement(new String(linea));
        } else {
          tokens = new StringTokenizer(linea, " ");
          token = tokens.nextToken();
          datasets.addElement(new String(token));
          token = tokens.nextToken();
          saltos.addElement(new Integer(token));
        }
      }
    }

    accuracyAv = new double[datasets.size()][algoritmos.size()];
    accuracySD = new double[datasets.size()][algoritmos.size()];
    reductionAv = new double[datasets.size()][algoritmos.size()];
    reductionSD = new double[datasets.size()][algoritmos.size()];
    kappaAv = new double[datasets.size()][algoritmos.size()];
    kappaSD = new double[datasets.size()][algoritmos.size()];
    accredAv = new double[datasets.size()][algoritmos.size()];
    kapredAv = new double[datasets.size()][algoritmos.size()];
    time = new double[datasets.size()][algoritmos.size()];
    runs = new int[datasets.size()][algoritmos.size()];
    accV = new double[10];
    redV = new double[10];
    kappaV = new double[10];

    // tiempos = Fichero.leeFichero("tiempos.txt");

    tiempos = Fichero.leeFichero("tiempos.txt");

    tokensT = new StringTokenizer(tiempos, "=\n\r");

    System.out.println("Numbero de algoritmos " + algoritmos.size());
    System.out.println("Dataset Size = " + datasets.size());
    /*Cálculo del accuracy, kappa y reducción en KNN (TRAIN)*/
    configAct = 0;
    for (j = 0; j < datasets.size(); j++) {
      System.out.println("Processing dataset: " + datasets.elementAt(j));

      for (i = 0; i < algoritmos.size(); i++) {
        alAct = (String) algoritmos.elementAt(i);

        configAct = i;

        datAct = (String) datasets.elementAt(j);
        salAct = ((Integer) saltos.elementAt(j)).intValue();
        acc = red = kappa = 0.0;
        for (k = 0; k < 10; k++) {
          /*Accuracy Computation*/
          int result =
              (j + salAct) * algoritmos.size() * 10
                  + i * 10
                  + k; // Calculo el result correspondiente.

          // System.out.println("results//Clas-KNN//"+alAct+"//result"+Integer.toString((j+salAct)*datasets.size()+i*10+k)+".tra");
          cadena =
              Fichero.leeFichero(
                  "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + ".tra");

          lineas = new StringTokenizer(cadena, "\n\r");
          aciertos = total = 0;
          while (lineas.hasMoreTokens()) {
            linea = lineas.nextToken();
            if (!(linea.startsWith("@"))) {
              tokens = new StringTokenizer(linea, " ");
              dato1 = tokens.nextToken();
              dato2 = tokens.nextToken();
              if (dato1.equalsIgnoreCase(dato2)) {
                aciertos++;
                total++;
              } else {
                total++;
              }
            }
          }
          accV[k] = (double) aciertos / (double) total;
          //	System.out.println(accV[k]);
          /*Reduction Computation*/

          cadena =
              Fichero.leeFichero(
                  "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + "e0.txt");

          tokens = new StringTokenizer(cadena, "=\n\r");
          tokens.nextToken();
          dato1 = tokens.nextToken();
          redV[k] = Double.parseDouble(dato1.substring(1)) / 100.0;

          /*Kappa Computation*/
          cadena =
              Fichero.leeFichero(
                  "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + ".tra");

          System.out.println("Result" + result);
          ;

          lineas = new StringTokenizer(cadena, "\n\r");
          aciertos = total = 0;
          valoresClase = new Vector<String>();
          while (lineas.hasMoreTokens()) {
            linea = lineas.nextToken();
            if (!(linea.startsWith("@"))) {
              tokens = new StringTokenizer(linea, " ");
              dato1 = tokens.nextToken();
              if (!valoresClase.contains(dato1)) {
                valoresClase.addElement(dato1);
              }
            }
          }
          confusionMatrix = new int[valoresClase.size()][valoresClase.size()];

          lineas = new StringTokenizer(cadena, "\n\r");

          total = 0;

          while (lineas.hasMoreTokens()) {

            linea = lineas.nextToken();

            if (!(linea.startsWith("@"))) {

              tokens = new StringTokenizer(linea, " ");

              dato1 = tokens.nextToken();

              dato2 = tokens.nextToken();

              try {

                confusionMatrix[valoresClase.indexOf(dato1)][valoresClase.indexOf(dato2)]++;

              } catch (ArrayIndexOutOfBoundsException e) {

                confusionMatrix[valoresClase.indexOf(dato1)][0]++;
              }

              total++;
            }
          }

          sumKappa = 0;

          for (l = 0; l < valoresClase.size(); l++) {

            sumKappa += confusionMatrix[l][l];
          }

          kappa = total * sumKappa;

          sumKappa = 0;

          for (l = 0; l < valoresClase.size(); l++) {

            sumi = 0;

            for (m = 0; m < valoresClase.size(); m++) {

              sumi += confusionMatrix[l][m];
            }

            sumj = 0;

            for (m = 0; m < valoresClase.size(); m++) {

              sumj += confusionMatrix[m][l];
            }

            sumKappa += sumi * sumj;
          }

          kappaV[k] = (double) (kappa - sumKappa) / (double) (total * total - sumKappa);

          // System.out.println(accV[k]);
        }

        acc = 0;

        for (l = 0; l < accV.length; l++) {

          acc += accV[l];
        }

        acc /= (double) accV.length;

        red = 0;

        for (l = 0; l < redV.length; l++) {

          red += redV[l];
        }

        red /= (double) redV.length;

        kappa = 0;

        for (l = 0; l < kappaV.length; l++) {

          kappa += kappaV[l];
        }

        kappa /= (double) kappaV.length;

        accSD = redSD = kapSD = 0;

        for (l = 0; l < accV.length; l++) {

          accSD += (acc - accV[l]) * (acc - accV[l]);
        }

        accSD = Math.sqrt(accSD / (double) accV.length);

        for (l = 0; l < redV.length; l++) {

          redSD += (red - redV[l]) * (red - redV[l]);
        }

        redSD = Math.sqrt(redSD / (double) redV.length);

        for (l = 0; l < kappaV.length; l++) {

          kapSD += (kappa - kappaV[l]) * (kappa - kappaV[l]);
        }

        kapSD = Math.sqrt(kapSD / (double) kappaV.length);

        /*Store the values in the main matrixes*/

        accuracyAv[j][i] = acc;
        accuracySD[j][i] = accSD;
        reductionAv[j][i] = red;
        reductionSD[j][i] = redSD;
        kappaAv[j][i] = kappa;
        kappaSD[j][i] = kapSD;
        accredAv[j][i] = acc * red;
        kapredAv[j][i] = kappa * red;

        // System.out.println("Acc =" +acc);

        /*Time processing*/

        /*
        for( k=0; k< 10 ;k++){
        	dato1 = tokensT.nextToken();
        	time[j][i] += Double.parseDouble(dato1) ;
        	runs[j][i]++;
        	//System.out.println(dato1);
        }*/
      }
    }

    /*Print the results*/
    cadena = "Datasets\t\t";
    for (i = 0; i < algoritmos.size(); i++) {
      cadena += algoritmos.elementAt(i) + "\t\t";
    }
    cadena += "\n";
    Fichero.escribeFichero("tablaAccuracyTRA.txt", cadena);
    for (i = 0; i < datasets.size(); i++) {
      cadena = datasets.elementAt(i) + "\t\t";
      for (j = 0; j < algoritmos.size(); j++) {
        cadena +=
            String.format("%6.4f", accuracyAv[i][j])
                + "\t"
                + String.format("%6.4f", accuracySD[i][j])
                + "\t";
      }
      cadena += "\n";
      Fichero.AnadirtoFichero("tablaAccuracyTRA.txt", cadena);
    }

    /*Print the results*/
    cadena = "Datasets\t\t";
    for (i = 0; i < algoritmos.size(); i++) {
      cadena += algoritmos.elementAt(i) + "\t\t";
    }
    cadena += "\n";
    Fichero.escribeFichero("tablaReduction.txt", cadena);
    for (i = 0; i < datasets.size(); i++) {
      cadena = datasets.elementAt(i) + "\t\t";
      for (j = 0; j < algoritmos.size(); j++) {
        cadena +=
            String.format("%6.4f", reductionAv[i][j])
                + "\t"
                + String.format("%6.4f", reductionSD[i][j])
                + "\t";
      }
      cadena += "\n";
      Fichero.AnadirtoFichero("tablaReduction.txt", cadena);
    }

    /*Print the results*/
    cadena = "Datasets\t\t";
    for (i = 0; i < algoritmos.size(); i++) {
      cadena += algoritmos.elementAt(i) + "\t";
    }
    cadena += "\n";
    Fichero.escribeFichero("tablaTime.txt", cadena);
    for (i = 0; i < datasets.size(); i++) {
      cadena = datasets.elementAt(i) + "\t\t";
      for (j = 0; j < algoritmos.size(); j++) {
        cadena += String.format("%6.4f", time[i][j] / (double) runs[i][j]) + "\t";
      }
      cadena += "\n";
      Fichero.AnadirtoFichero("tablaTime.txt", cadena);
    }

    /*Print the results*/
    cadena = "Datasets\t\t";
    for (i = 0; i < algoritmos.size(); i++) {
      cadena += algoritmos.elementAt(i) + "\t\t";
    }
    cadena += "\n";
    Fichero.escribeFichero("tablaKappaTRA.txt", cadena);
    for (i = 0; i < datasets.size(); i++) {
      cadena = datasets.elementAt(i) + "\t\t";
      for (j = 0; j < algoritmos.size(); j++) {
        cadena +=
            String.format("%6.4f", kappaAv[i][j])
                + "\t"
                + String.format("%6.4f", kappaSD[i][j])
                + "\t";
      }
      cadena += "\n";
      Fichero.AnadirtoFichero("tablaKappaTRA.txt", cadena);
    }

    /*Print the results*/
    cadena = "Datasets\t\t";
    for (i = 0; i < algoritmos.size(); i++) {
      cadena += algoritmos.elementAt(i) + "\t\t";
    }
    cadena += "\n";
    Fichero.escribeFichero("tablaAccRedTRA.txt", cadena);
    for (i = 0; i < datasets.size(); i++) {
      cadena = datasets.elementAt(i) + "\t\t";
      for (j = 0; j < algoritmos.size(); j++) {
        cadena += String.format("%6.4f", accredAv[i][j]) + "\t";
      }
      cadena += "\n";
      Fichero.AnadirtoFichero("tablaAccRedTRA.txt", cadena);
    }

    /*Print the results*/
    cadena = "Datasets\t\t";
    for (i = 0; i < algoritmos.size(); i++) {
      cadena += algoritmos.elementAt(i) + "\t\t";
    }
    cadena += "\n";
    Fichero.escribeFichero("tablaKappaRedTRA.txt", cadena);
    for (i = 0; i < datasets.size(); i++) {
      cadena = datasets.elementAt(i) + "\t\t";
      for (j = 0; j < algoritmos.size(); j++) {
        cadena += String.format("%6.4f", kapredAv[i][j]) + "\t";
      }
      cadena += "\n";
      Fichero.AnadirtoFichero("tablaKappaRedTRA.txt", cadena);
    }

    configAct = 0;
    /*Cálculo del accuracy, kappa y reducción en KNN (TST)*/
    for (j = 0; j < datasets.size(); j++) {

      for (i = 0; i < algoritmos.size(); i++) {
        alAct = (String) algoritmos.elementAt(i);
        // System.out.println("Processing algorithm: " + alAct);

        salAct = ((Integer) saltos.elementAt(j)).intValue();
        acc = red = kappa = 0.0;
        for (k = 0; k < 10; k++) {
          /*Accuracy Computation*/
          int result =
              (j + salAct) * algoritmos.size() * 10
                  + i * 10
                  + k; // Calculo el result correspondiente.
          cadena =
              Fichero.leeFichero(
                  "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + ".tst");

          lineas = new StringTokenizer(cadena, "\n\r");
          aciertos = total = 0;
          while (lineas.hasMoreTokens()) {
            linea = lineas.nextToken();
            if (!(linea.startsWith("@"))) {
              tokens = new StringTokenizer(linea, " ");
              dato1 = tokens.nextToken();
              dato2 = tokens.nextToken();
              if (dato1.equalsIgnoreCase(dato2)) {
                aciertos++;
                total++;
              } else {
                total++;
              }
            }
          }
          accV[k] = (double) aciertos / (double) total;

          /*Reduction Computation*/
          cadena =
              Fichero.leeFichero(
                  "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + "e0.txt");

          tokens = new StringTokenizer(cadena, "=\n\r");
          tokens.nextToken();
          dato1 = tokens.nextToken();
          redV[k] = Double.parseDouble(dato1.substring(1)) / 100.0;

          /*Kappa Computation*/
          cadena =
              Fichero.leeFichero(
                  "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + ".tst");
          lineas = new StringTokenizer(cadena, "\n\r");
          aciertos = total = 0;
          valoresClase = new Vector<String>();
          while (lineas.hasMoreTokens()) {
            linea = lineas.nextToken();
            if (!(linea.startsWith("@"))) {
              tokens = new StringTokenizer(linea, " ");
              dato1 = tokens.nextToken();
              if (!valoresClase.contains(dato1)) {
                valoresClase.addElement(dato1);
              }
            }
          }
          confusionMatrix = new int[valoresClase.size()][valoresClase.size()];
          lineas = new StringTokenizer(cadena, "\n\r");
          total = 0;
          while (lineas.hasMoreTokens()) {
            linea = lineas.nextToken();
            if (!(linea.startsWith("@"))) {
              tokens = new StringTokenizer(linea, " ");
              dato1 = tokens.nextToken();
              dato2 = tokens.nextToken();
              try {
                confusionMatrix[valoresClase.indexOf(dato1)][valoresClase.indexOf(dato2)]++;
              } catch (ArrayIndexOutOfBoundsException e) {
                confusionMatrix[valoresClase.indexOf(dato1)][0]++;
              }
              total++;
            }
          }
          sumKappa = 0;
          for (l = 0; l < valoresClase.size(); l++) {
            sumKappa += confusionMatrix[l][l];
          }
          kappa = total * sumKappa;
          sumKappa = 0;
          for (l = 0; l < valoresClase.size(); l++) {
            sumi = 0;
            for (m = 0; m < valoresClase.size(); m++) {
              sumi += confusionMatrix[l][m];
            }
            sumj = 0;
            for (m = 0; m < valoresClase.size(); m++) {
              sumj += confusionMatrix[m][l];
            }
            sumKappa += sumi * sumj;
          }
          kappaV[k] = (double) (kappa - sumKappa) / (double) (total * total - sumKappa);
        }

        acc = 0;
        for (l = 0; l < accV.length; l++) {
          acc += accV[l];
        }
        acc /= (double) accV.length;
        red = 0;
        for (l = 0; l < redV.length; l++) {
          red += redV[l];
        }
        red /= (double) redV.length;
        kappa = 0;
        for (l = 0; l < kappaV.length; l++) {
          kappa += kappaV[l];
        }
        kappa /= (double) kappaV.length;

        accSD = redSD = kapSD = 0;
        for (l = 0; l < accV.length; l++) {
          accSD += (acc - accV[l]) * (acc - accV[l]);
        }
        accSD = Math.sqrt(accSD / (double) accV.length);
        for (l = 0; l < redV.length; l++) {
          redSD += (red - redV[l]) * (red - redV[l]);
        }
        redSD = Math.sqrt(redSD / (double) redV.length);
        for (l = 0; l < kappaV.length; l++) {
          kapSD += (kappa - kappaV[l]) * (kappa - kappaV[l]);
        }
        kapSD = Math.sqrt(kapSD / (double) kappaV.length);

        /*Store the values in the main matrixes*/
        accuracyAv[j][i] = acc;
        accuracySD[j][i] = accSD;
        reductionAv[j][i] = red;
        reductionSD[j][i] = redSD;
        kappaAv[j][i] = kappa;
        kappaSD[j][i] = kapSD;
        accredAv[j][i] = acc * red;
        kapredAv[j][i] = kappa * red;
      }
    }

    /*Print the results*/
    cadena = "Datasets\t\t";
    for (i = 0; i < algoritmos.size(); i++) {
      cadena += algoritmos.elementAt(i) + "\t\t";
    }
    cadena += "\n";
    Fichero.escribeFichero("tablaAccuracyTST.txt", cadena);
    for (i = 0; i < datasets.size(); i++) {
      cadena = datasets.elementAt(i) + "\t\t";
      for (j = 0; j < algoritmos.size(); j++) {
        cadena +=
            String.format("%6.4f", accuracyAv[i][j])
                + "\t"
                + String.format("%6.4f", accuracySD[i][j])
                + "\t";
      }
      cadena += "\n";
      Fichero.AnadirtoFichero("tablaAccuracyTST.txt", cadena);
    }

    /*Print the results*/
    cadena = "Datasets\t\t";
    for (i = 0; i < algoritmos.size(); i++) {
      cadena += algoritmos.elementAt(i) + "\t\t";
    }
    cadena += "\n";
    Fichero.escribeFichero("tablaKappaTST.txt", cadena);
    for (i = 0; i < datasets.size(); i++) {
      cadena = datasets.elementAt(i) + "\t\t";
      for (j = 0; j < algoritmos.size(); j++) {
        cadena +=
            String.format("%6.4f", kappaAv[i][j])
                + "\t"
                + String.format("%6.4f", kappaSD[i][j])
                + "\t";
      }
      cadena += "\n";
      Fichero.AnadirtoFichero("tablaKappaTST.txt", cadena);
    }

    /*Print the results*/
    cadena = "Datasets\t\t";
    for (i = 0; i < algoritmos.size(); i++) {
      cadena += algoritmos.elementAt(i) + "\t\t";
    }
    cadena += "\n";
    Fichero.escribeFichero("tablaAccRedTST.txt", cadena);
    for (i = 0; i < datasets.size(); i++) {
      cadena = datasets.elementAt(i) + "\t\t";
      for (j = 0; j < algoritmos.size(); j++) {
        cadena += String.format("%6.4f", accredAv[i][j]) + "\t";
      }
      cadena += "\n";
      Fichero.AnadirtoFichero("tablaAccRedTST.txt", cadena);
    }

    /*Print the results*/
    cadena = "Datasets\t\t";
    for (i = 0; i < algoritmos.size(); i++) {
      cadena += algoritmos.elementAt(i) + "\t\t";
    }
    cadena += "\n";
    Fichero.escribeFichero("tablaKappaRedTST.txt", cadena);
    for (i = 0; i < datasets.size(); i++) {
      cadena = datasets.elementAt(i) + "\t\t";
      for (j = 0; j < algoritmos.size(); j++) {
        cadena += String.format("%6.4f", kapredAv[i][j]) + "\t";
      }
      cadena += "\n";
      Fichero.AnadirtoFichero("tablaKappaRedTST.txt", cadena);
    }

    System.out.println("FIN");
  }
Exemplo n.º 4
0
  /** Reads the data of the configuration file */
  public void leer_conf() {
    int i, j;
    String cadenaEntrada, valor;
    double cruce, mutacion, a, b, tau;
    int long_poblacion, tipo_fitness;

    // we read the file in a String
    cadenaEntrada = Fichero.leeFichero(fichero_conf);
    StringTokenizer sT = new StringTokenizer(cadenaEntrada, "\n\r=", false);

    // we read the algorithm's name
    sT.nextToken();
    sT.nextToken();

    // we read the name of the training and test files
    sT.nextToken();
    valor = sT.nextToken();

    StringTokenizer ficheros = new StringTokenizer(valor, "\t ", false);
    ficheros.nextToken();
    fich_datos_chequeo = ((ficheros.nextToken()).replace('\"', ' ')).trim();
    fich_datos_tst = ((ficheros.nextToken()).replace('\"', ' ')).trim();
    fichero_br = ((ficheros.nextToken()).replace('\"', ' ')).trim();

    // we read the name of the output files
    sT.nextToken();
    valor = sT.nextToken();

    ficheros = new StringTokenizer(valor, "\t ", false);
    fich_tra_obli = ((ficheros.nextToken()).replace('\"', ' ')).trim();
    fich_tst_obli = ((ficheros.nextToken()).replace('\"', ' ')).trim();
    fichero_reglas = ((ficheros.nextToken()).replace('\"', ' ')).trim();
    ruta_salida = fich_tst_obli.substring(0, fich_tst_obli.lastIndexOf('/') + 1);

    // we read the seed of the random generator
    sT.nextToken();
    valor = sT.nextToken();
    semilla = Double.parseDouble(Quita_blancos(valor));
    Randomize.setSeed((long) semilla);
    ;

    // we read the Number of Iterations
    sT.nextToken();
    valor = sT.nextToken();
    n_generaciones = Long.parseLong(Quita_blancos(valor));

    // we read the Population Size
    sT.nextToken();
    valor = sT.nextToken();
    long_poblacion = Integer.parseInt(Quita_blancos(valor));

    // we read the Tau parameter for the minimun maching degree required to the KB
    sT.nextToken();
    valor = sT.nextToken();
    tau = Double.parseDouble(Quita_blancos(valor));

    // we read the Parameter a
    sT.nextToken();
    valor = sT.nextToken();
    a = Double.parseDouble(Quita_blancos(valor));

    // we read the Parameter b
    sT.nextToken();
    valor = sT.nextToken();
    b = Double.parseDouble(Quita_blancos(valor));

    // we read the Type of Fitness Function
    sT.nextToken();
    valor = sT.nextToken();
    tipo_fitness = Integer.parseInt(Quita_blancos(valor));

    // we read the Cross Probability
    sT.nextToken();
    valor = sT.nextToken();
    cruce = Double.parseDouble(Quita_blancos(valor));

    // we read the Mutation Probability
    sT.nextToken();
    valor = sT.nextToken();
    mutacion = Double.parseDouble(Quita_blancos(valor));

    // we create all the objects
    tipoc = 1;
    tabla = new MiDataset(fich_datos_chequeo, true);
    if (tabla.salir == false) {
      base_reglas = new BaseR(fichero_br, tabla);
      fun_adap = new Adap(tabla, base_reglas, tau, tipo_fitness);
      alg_gen = new AG(long_poblacion, base_reglas.n_reglas, cruce, mutacion, a, b, fun_adap);
    }
  }
Exemplo n.º 5
0
  /**
   * Reads configuration script, and extracts its contents.
   *
   * @param ficheroScript Name of the configuration script
   */
  public void leerConfiguracion(String ficheroScript) {

    String fichero, linea, token;
    StringTokenizer lineasFichero, tokens;
    byte line[];
    int i, j;

    ficheroSalida = new String[2];

    fichero = Fichero.leeFichero(ficheroScript);
    lineasFichero = new StringTokenizer(fichero, "\n\r");

    lineasFichero.nextToken();
    linea = lineasFichero.nextToken();

    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    token = tokens.nextToken();

    /*Getting the names of training and test files*/
    line = token.getBytes();
    for (i = 0; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroTraining = new String(line, i, j - i);
    for (i = j + 1; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroTest = new String(line, i, j - i);

    /*Getting the path and base name of the results files*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    token = tokens.nextToken();

    /*Getting the names of output files*/
    line = token.getBytes();
    for (i = 0; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroSalida[0] = new String(line, i, j - i);
    for (i = j + 1; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroSalida[1] = new String(line, i, j - i);

    /*Getting the seed*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    semilla = Long.parseLong(tokens.nextToken().substring(1));

    /*Getting the mutation and cross probability*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    pMutacion1to0 = Double.parseDouble(tokens.nextToken().substring(1));
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    pMutacion0to1 = Double.parseDouble(tokens.nextToken().substring(1));
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    pCruce = Double.parseDouble(tokens.nextToken().substring(1));

    /*Getting the size of the population and number of evaluations*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    tamPoblacion = Integer.parseInt(tokens.nextToken().substring(1));
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    nEval = Integer.parseInt(tokens.nextToken().substring(1));

    /*Getting the alfa equilibrate factor*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    alfa = Double.parseDouble(tokens.nextToken().substring(1));

    /*Getting the type of selection*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    token = tokens.nextToken();
    token = token.substring(1);
    if (token.equalsIgnoreCase("binary_tournament")) torneo = true;
    else torneo = false;

    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    kNeigh = Integer.parseInt(tokens.nextToken().substring(1));

    /*Getting the type of distance function*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    distanceEu = tokens.nextToken().substring(1).equalsIgnoreCase("Euclidean") ? true : false;
  } // end-method
Exemplo n.º 6
0
  public void leerConfiguracion(String ficheroScript) {

    String fichero, linea, token;
    StringTokenizer lineasFichero, tokens;
    byte line[];
    int i, j;

    ficheroSalida = new String[2];

    fichero = Fichero.leeFichero(ficheroScript);
    lineasFichero = new StringTokenizer(fichero, "\n\r");

    lineasFichero.nextToken();
    linea = lineasFichero.nextToken();

    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    token = tokens.nextToken();

    /*Getting the names of the training and test files*/
    line = token.getBytes();
    for (i = 0; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroTraining = new String(line, i, j - i);
    for (i = j + 1; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroTest = new String(line, i, j - i);

    /*Getting the path and base name of the results files*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    token = tokens.nextToken();

    /*Getting the names of output files*/
    line = token.getBytes();
    for (i = 0; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroSalida[0] = new String(line, i, j - i);
    for (i = j + 1; line[i] != '\"'; i++) ;
    i++;
    for (j = i; line[j] != '\"'; j++) ;
    ficheroSalida[1] = new String(line, i, j - i);

    /*Getting the number of neighbours*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    k = Integer.parseInt(tokens.nextToken().substring(1));

    /*Getting the k' */
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    k2 = Integer.parseInt(tokens.nextToken().substring(1));

    /*Getting the type of distance function*/
    linea = lineasFichero.nextToken();
    tokens = new StringTokenizer(linea, "=");
    tokens.nextToken();
    distanceEu = tokens.nextToken().substring(1).equalsIgnoreCase("Euclidean") ? true : false;
  }
Exemplo n.º 7
0
  /** Reads the data of the configuration file */
  public void leer_conf() {
    int i, n_etiquetas;
    String cadenaEntrada, valor;

    // we read the file in a String
    cadenaEntrada = Fichero.leeFichero(fichero_conf);
    StringTokenizer sT = new StringTokenizer(cadenaEntrada, "\n\r=", false);

    // we read the algorithm's name
    sT.nextToken();
    sT.nextToken();

    // we read the name of the training and test files
    sT.nextToken();
    valor = sT.nextToken();

    StringTokenizer ficheros = new StringTokenizer(valor, "\t ", false);
    ficheros.nextToken();
    fich_datos_chequeo = ((ficheros.nextToken()).replace('\"', ' ')).trim();
    fich_datos_tst = ((ficheros.nextToken()).replace('\"', ' ')).trim();

    // we read the name of the output files
    sT.nextToken();
    valor = sT.nextToken();

    ficheros = new StringTokenizer(valor, "\t ", false);
    fich_tra_obli = ((ficheros.nextToken()).replace('\"', ' ')).trim();
    fich_tst_obli = ((ficheros.nextToken()).replace('\"', ' ')).trim();
    fichero_reglas = ((ficheros.nextToken()).replace('\"', ' ')).trim();
    fichero_inf = ((ficheros.nextToken()).replace('\"', ' ')).trim();
    ruta_salida = fichero_reglas.substring(0, fichero_reglas.lastIndexOf('/') + 1);

    // we read the Number of labels
    sT.nextToken();
    valor = sT.nextToken();
    n_etiquetas = Integer.parseInt(valor.trim());

    // we read the KB Output File Format with Weight values to 1 (0/1)
    peso = 0;

    // we create all the objects
    tabla = new MiDataset(fich_datos_chequeo, true);
    tabla_tst = new MiDataset(fich_datos_tst, false);
    base_datos = new BaseD(n_etiquetas, tabla.n_variables);

    for (i = 0; i < tabla.n_variables; i++) {
      base_datos.n_etiquetas[i] = n_etiquetas;
      base_datos.extremos[i].min = tabla.extremos[i].min;
      base_datos.extremos[i].max = tabla.extremos[i].max;
    }

    MaxReglas = tabla.long_tabla; // MaxReglas == #Ejemplos
    base_reglas = new BaseR(MaxReglas, base_datos, tabla);
    fun_adap = new Adap(tabla, tabla_tst, base_reglas);
    Regla_act = new int[tabla.n_variables];
    grado_pertenencia = new double[tabla.n_variables];
    Conjunto_Reglas = new TipoRegla[tabla.long_tabla];

    for (i = 0; i < tabla.long_tabla; i++) {
      Conjunto_Reglas[i] = new TipoRegla(tabla.n_variables);
    }
  }