Ejemplo n.º 1
0
  /**
   * Main method for ABB, that explores the search space by pruning nodes and checking their
   * inconsistency ratio.
   */
  private void runABB() {
    boolean[] root = startSolution();
    System.arraycopy(root, 0, features, 0, root.length);

    abb(root);

    /* checks if a subset satisfies the condition (more than 0 selected features) */
    if (features == null) {
      System.err.println("ERROR: It couldn't be possible to find any solution.");
      System.exit(0);
    }
  }
Ejemplo n.º 2
0
    /**
     * Constructor of the Class Parametros
     *
     * @param nombreFileParametros is the pathname of input parameter file
     */
    Parametros(String nombreFileParametros) {

      try {
        int i;
        String fichero, linea, tok;
        StringTokenizer lineasFile, tokens;

        /* read the parameter file using Files class */
        fichero = Files.readFile(nombreFileParametros);
        fichero += "\n";

        /* remove all \r characters. it is neccesary for a correst use in Windows and UNIX  */
        fichero = fichero.replace('\r', ' ');

        /* extracts the differents tokens of the file */
        lineasFile = new StringTokenizer(fichero, "\n");

        i = 0;
        while (lineasFile.hasMoreTokens()) {

          linea = lineasFile.nextToken();
          i++;
          tokens = new StringTokenizer(linea, " ,\t");
          if (tokens.hasMoreTokens()) {

            tok = tokens.nextToken();
            if (tok.equalsIgnoreCase("algorithm")) nameAlgorithm = getParamString(tokens);
            else if (tok.equalsIgnoreCase("inputdata")) getInputFiles(tokens);
            else if (tok.equalsIgnoreCase("outputdata")) getOutputFiles(tokens);
            else if (tok.equalsIgnoreCase("seed")) seed = getParamLong(tokens);
            else throw new java.io.IOException("Syntax error on line " + i + ": [" + tok + "]\n");
          }
        }

      } catch (java.io.FileNotFoundException e) {
        System.err.println(e + "Parameter file");
      } catch (java.io.IOException e) {
        System.err.println(e + "Aborting program");
        System.exit(-1);
      }

      /** show the read parameter in the standard output */
      String contents = "-- Parameters echo --- \n";
      contents += "Algorithm name: " + nameAlgorithm + "\n";
      contents += "Input Train File: " + trainFileNameInput + "\n";
      contents += "Input Test File: " + testFileNameInput + "\n";
      contents += "Output Train File: " + trainFileNameOutput + "\n";
      contents += "Output Test File: " + testFileNameOutput + "\n";
      System.out.println(contents);
    }
Ejemplo n.º 3
0
  /**
   * Removes one feature at a time, starting from the furthest on the right
   *
   * @param featuresVector solution to generate its neighbor
   * @param which number of the feature to remove starting from the right
   * @return next neighbor of the given solution with one less feature
   */
  private static boolean[] removeOne(boolean featuresVector[], int which) {
    boolean[] fv = new boolean[featuresVector.length];
    System.arraycopy(featuresVector, 0, fv, 0, fv.length);
    boolean stop = false;
    int count = 0;
    for (int i = fv.length - 1; i >= 0 && !stop; i--) {
      if (fv[i]) {
        count++;
        if (count == which) {
          fv[i] = false;
          stop = true;
        }
      }
    }

    return fv;
  }
Ejemplo n.º 4
0
  /** Recursive method for ABB */
  private void abb(boolean feat[]) {
    boolean[] child;
    double measure;

    threshold = data.measureIEP(feat);

    for (int i = 0; i < cardinalidadCto(feat); i++) {
      child = removeOne(feat, i);
      measure = data.measureIEP(child);

      if (legitimate(child) && measure < threshold) {
        if (measure < data.measureIEP(features)) {
          // we keep the best found in 'features'
          System.arraycopy(child, 0, features, 0, child.length);
        }
        abb(child);
      } else { // we prune this node
        pruned.add(child);
      }
    }
  }