Exemplo n.º 1
0
  /**
   * Returns an enumeration describing the available options.
   *
   * @return an enumeration of all the available options.
   */
  public Enumeration listOptions() {
    Vector newVector = new Vector(4);

    newVector.addElement(
        new Option(
            "\tclass name of attribute evaluator to use for ranking. Place any\n"
                + "\tevaluator options LAST on the command line following a \"--\".\n"
                + "\teg.:\n"
                + "\t\t-A weka.attributeSelection.GainRatioAttributeEval ... -- -M\n"
                + "\t(default: weka.attributeSelection.GainRatioAttributeEval)",
            "A",
            1,
            "-A <attribute evaluator>"));

    newVector.addElement(
        new Option(
            "\tnumber of attributes to be added from the"
                + "\n\tranking in each iteration (default = 1).",
            "S",
            1,
            "-S <step size>"));

    newVector.addElement(
        new Option(
            "\tpoint in the ranking to start evaluating from. "
                + "\n\t(default = 0, ie. the head of the ranking).",
            "R",
            1,
            "-R <start point>"));

    if ((m_ASEval != null) && (m_ASEval instanceof OptionHandler)) {
      newVector.addElement(
          new Option(
              "",
              "",
              0,
              "\nOptions specific to " + "evaluator " + m_ASEval.getClass().getName() + ":"));
      Enumeration enu = ((OptionHandler) m_ASEval).listOptions();

      while (enu.hasMoreElements()) {
        newVector.addElement(enu.nextElement());
      }
    }

    return newVector.elements();
  }
Exemplo n.º 2
0
  /**
   * Ranks attributes using the specified attribute evaluator and then searches the ranking using
   * the supplied subset evaluator.
   *
   * @param ASEval the subset evaluator to guide the search
   * @param data the training instances.
   * @return an array (not necessarily ordered) of selected attribute indexes
   * @throws Exception if the search can't be completed
   */
  public int[] search(ASEvaluation ASEval, Instances data) throws Exception {

    double best_merit = -Double.MAX_VALUE;
    double temp_merit;
    BitSet temp_group, best_group = null;

    if (!(ASEval instanceof SubsetEvaluator)) {
      throw new Exception(ASEval.getClass().getName() + " is not a " + "Subset evaluator!");
    }

    m_SubsetEval = ASEval;
    m_Instances = data;
    m_numAttribs = m_Instances.numAttributes();

    /*    if (m_ASEval instanceof AttributeTransformer) {
    throw new Exception("Can't use an attribute transformer "
                        +"with RankSearch");
                        } */
    if (m_ASEval instanceof UnsupervisedAttributeEvaluator
        || m_ASEval instanceof UnsupervisedSubsetEvaluator) {
      m_hasClass = false;
      /*      if (!(m_SubsetEval instanceof UnsupervisedSubsetEvaluator)) {
      throw new Exception("Must use an unsupervised subset evaluator.");
      } */
    } else {
      m_hasClass = true;
      m_classIndex = m_Instances.classIndex();
    }

    if (m_ASEval instanceof AttributeEvaluator) {
      // generate the attribute ranking first
      Ranker ranker = new Ranker();
      m_ASEval.buildEvaluator(m_Instances);
      if (m_ASEval instanceof AttributeTransformer) {
        // get the transformed data a rebuild the subset evaluator
        m_Instances = ((AttributeTransformer) m_ASEval).transformedData(m_Instances);
        ((ASEvaluation) m_SubsetEval).buildEvaluator(m_Instances);
      }
      m_Ranking = ranker.search(m_ASEval, m_Instances);
    } else {
      GreedyStepwise fs = new GreedyStepwise();
      double[][] rankres;
      fs.setGenerateRanking(true);
      ((ASEvaluation) m_ASEval).buildEvaluator(m_Instances);
      fs.search(m_ASEval, m_Instances);
      rankres = fs.rankedAttributes();
      m_Ranking = new int[rankres.length];
      for (int i = 0; i < rankres.length; i++) {
        m_Ranking[i] = (int) rankres[i][0];
      }
    }

    // now evaluate the attribute ranking
    for (int i = m_startPoint; i < m_Ranking.length; i += m_add) {
      temp_group = new BitSet(m_numAttribs);
      for (int j = 0; j <= i; j++) {
        temp_group.set(m_Ranking[j]);
      }
      temp_merit = ((SubsetEvaluator) m_SubsetEval).evaluateSubset(temp_group);

      if (temp_merit > best_merit) {
        best_merit = temp_merit;
        ;
        best_group = temp_group;
      }
    }
    m_bestMerit = best_merit;
    return attributeList(best_group);
  }