⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forwardselection.java

📁 wekaUT是 university texas austin 开发的基于weka的半指导学习(semi supervised learning)的分类器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *    This program is free software; you can redistribute it and/or modify *    it under the terms of the GNU General Public License as published by *    the Free Software Foundation; either version 2 of the License, or *    (at your option) any later version. * *    This program is distributed in the hope that it will be useful, *    but WITHOUT ANY WARRANTY; without even the implied warranty of *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *    GNU General Public License for more details. * *    You should have received a copy of the GNU General Public License *    along with this program; if not, write to the Free Software *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* *    ForwardSelection.java *    Copyright (C) 1999 Mark Hall * */package  weka.attributeSelection;import  java.io.*;import  java.util.*;import  weka.core.*;/**  * Class for performing a forward selection hill climbing search. <p> * * Valid options are: <p> * * -P <start set> <br> * Specify a starting set of attributes. Eg 1,4,7-9. <p> * * -R <br> * Produce a ranked list of attributes. <p> *  * -T <threshold> <br> * Specify a threshold by which the AttributeSelection module can. <br> * discard attributes. Use in conjunction with -R <p> * * @author Mark Hall (mhall@cs.waikato.ac.nz) * @version $Revision: 1.1.1.1 $ */public class ForwardSelection extends ASSearch   implements RankedOutputSearch, StartSetHandler, OptionHandler { /** does the data have a class */  private boolean m_hasClass;   /** holds the class index */  private int m_classIndex;   /** number of attributes in the data */  private int m_numAttribs;  /** true if the user has requested a ranked list of attributes */  private boolean m_rankingRequested;  /**    * go from one side of the search space to the other in order to generate   * a ranking   */  private boolean m_doRank;  /** used to indicate whether or not ranking has been performed */  private boolean m_doneRanking;  /**   * A threshold by which to discard attributes---used by the   * AttributeSelection module   */  private double m_threshold;  /** The number of attributes to select. -1 indicates that all attributes      are to be retained. Has precedence over m_threshold */  private int m_numToSelect = -1;  private int m_calculatedNumToSelect;  /** the merit of the best subset found */  private double m_bestMerit;  /** a ranked list of attribute indexes */  private double [][] m_rankedAtts;  private int m_rankedSoFar;  /** the best subset found */  private BitSet m_best_group;  private ASEvaluation m_ASEval;  private Instances m_Instances;  /** holds the start set for the search as a Range */  private Range m_startRange;  /** holds an array of starting attributes */  private int [] m_starting;  /**   * Returns a string describing this search method   * @return a description of the search suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {    return "ForwardSelection :\n\nPerforms a greedy forward search through "      +"the space of attribute subsets. May start with no attributes or from "      +"an arbitrary point in the space. Stops when the addition of any "      +"remaining attributes results in a decrease in evaluation. "      +"Can also produce a ranked list of "      +"attributes by traversing the space from one side to the other and "      +"recording the order that attributes are selected.\n";  }  public ForwardSelection () {    m_threshold = -Double.MAX_VALUE;    m_doneRanking = false;    m_startRange = new Range();    m_starting = null;    resetOptions();  }  /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String thresholdTipText() {    return "Set threshold by which attributes can be discarded. Default value "      + "results in no attributes being discarded. Use in conjunction with "      + "generateRanking";  }  /**   * Set the threshold by which the AttributeSelection module can discard   * attributes.   * @param threshold the threshold.   */  public void setThreshold(double threshold) {    m_threshold = threshold;  }  /**   * Returns the threshold so that the AttributeSelection module can   * discard attributes from the ranking.   */  public double getThreshold() {    return m_threshold;  }  /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String numToSelectTipText() {    return "Specify the number of attributes to retain. The default value "      +"(-1) indicates that all attributes are to be retained. Use either "      +"this option or a threshold to reduce the attribute set.";  }  /**   * Specify the number of attributes to select from the ranked list   * (if generating a ranking). -1   * indicates that all attributes are to be retained.   * @param n the number of attributes to retain   */  public void setNumToSelect(int n) {    m_numToSelect = n;  }  /**   * Gets the number of attributes to be retained.   * @return the number of attributes to retain   */  public int getNumToSelect() {    return m_numToSelect;  }  /**   * Gets the calculated number of attributes to retain. This is the   * actual number of attributes to retain. This is the same as   * getNumToSelect if the user specifies a number which is not less   * than zero. Otherwise it should be the number of attributes in the   * (potentially transformed) data.   */  public int getCalculatedNumToSelect() {    if (m_numToSelect >= 0) {      m_calculatedNumToSelect = m_numToSelect;    }    return m_calculatedNumToSelect;  }  /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String generateRankingTipText() {    return "Set to true if a ranked list is required.";  }    /**   * Records whether the user has requested a ranked list of attributes.   * @param doRank true if ranking is requested   */  public void setGenerateRanking(boolean doRank) {    m_rankingRequested = doRank;  }  /**   * Gets whether ranking has been requested. This is used by the   * AttributeSelection module to determine if rankedAttributes()   * should be called.   * @return true if ranking has been requested.   */  public boolean getGenerateRanking() {    return m_rankingRequested;  }  /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String startSetTipText() {    return "Set the start point for the search. This is specified as a comma "      +"seperated list off attribute indexes starting at 1. It can include "      +"ranges. Eg. 1,2,5-9,17.";  }  /**   * Sets a starting set of attributes for the search. It is the   * search method's responsibility to report this start set (if any)   * in its toString() method.   * @param startSet a string containing a list of attributes (and or ranges),   * eg. 1,2,6,10-15.   * @exception Exception if start set can't be set.   */  public void setStartSet (String startSet) throws Exception {    m_startRange.setRanges(startSet);  }  /**   * Returns a list of attributes (and or attribute ranges) as a String   * @return a list of attributes (and or attribute ranges)   */  public String getStartSet () {    return m_startRange.getRanges();  }  /**   * Returns an enumeration describing the available options.   * @return an enumeration of all the available options.   **/  public Enumeration listOptions () {    Vector newVector = new Vector(3);    newVector      .addElement(new Option("\tSpecify a starting set of attributes." 			     + "\n\tEg. 1,3,5-7."			     ,"P",1			     , "-P <start set>"));    newVector.addElement(new Option("\tProduce a ranked list of attributes."				    ,"R",0,"-R"));    newVector      .addElement(new Option("\tSpecify a theshold by which attributes" 			     + "\n\tmay be discarded from the ranking."			     +"\n\tUse in conjuction with -R","T",1			     , "-T <threshold>"));    newVector      .addElement(new Option("\tSpecify number of attributes to select" 			     ,"N",1			     , "-N <num to select>"));    return newVector.elements();  }    /**   * Parses a given list of options.   *   * Valid options are: <p>   *    * -P <start set> <br>   * Specify a starting set of attributes. Eg 1,4,7-9. <p>   *   * -R <br>   * Produce a ranked list of attributes. <p>   *    * -T <threshold> <br>   * Specify a threshold by which the AttributeSelection module can <br>   * discard attributes. Use in conjunction with -R <p>   *   * -N <number to retain> <br>   * Specify the number of attributes to retain. Overides any threshold. <br>   * <p>   *   * @param options the list of options as an array of strings   * @exception Exception if an option is not supported   *   **/  public void setOptions (String[] options)    throws Exception {    String optionString;    resetOptions();    optionString = Utils.getOption('P', options);    if (optionString.length() != 0) {      setStartSet(optionString);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -