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

📄 miwrapper.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 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. *//* * MIWrapper.java * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand *  */package weka.classifiers.mi;import weka.classifiers.SingleClassifierEnhancer;import weka.core.Capabilities;import weka.core.Instance;import weka.core.Instances;import weka.core.MultiInstanceCapabilitiesHandler;import weka.core.Option;import weka.core.OptionHandler;import weka.core.SelectedTag;import weka.core.Tag;import weka.core.TechnicalInformation;import weka.core.TechnicalInformationHandler;import weka.core.Utils;import weka.core.Capabilities.Capability;import weka.core.TechnicalInformation.Field;import weka.core.TechnicalInformation.Type;import weka.filters.Filter;import weka.filters.unsupervised.attribute.MultiInstanceToPropositional;import java.util.Enumeration;import java.util.Vector;/** <!-- globalinfo-start --> * A simple Wrapper method for applying standard propositional learners to multi-instance data.<br/> * <br/> * For more information see:<br/> * <br/> * E. T. Frank, X. Xu (2003). Applying propositional learning algorithms to multi-instance data. Department of Computer Science, University of Waikato, Hamilton, NZ. * <p/> <!-- globalinfo-end --> *  <!-- technical-bibtex-start --> * BibTeX: * <pre> * &#64;techreport{Frank2003, *    address = {Department of Computer Science, University of Waikato, Hamilton, NZ}, *    author = {E. T. Frank and X. Xu}, *    institution = {University of Waikato}, *    month = {06}, *    title = {Applying propositional learning algorithms to multi-instance data}, *    year = {2003} * } * </pre> * <p/> <!-- technical-bibtex-end --> * <!-- options-start --> * Valid options are: <p/> *  * <pre> -P [1|2|3] *  The method used in testing: *  1.arithmetic average *  2.geometric average *  3.max probability of positive bag. *  (default: 1)</pre> *  * <pre> -A [0|1|2|3] *  The type of weight setting for each single-instance: *  0.keep the weight to be the same as the original value; *  1.weight = 1.0 *  2.weight = 1.0/Total number of single-instance in the *   corresponding bag *  3. weight = Total number of single-instance / (Total *   number of bags * Total number of single-instance  *   in the corresponding bag). *  (default: 3)</pre> *  * <pre> -D *  If set, classifier is run in debug mode and *  may output additional info to the console</pre> *  * <pre> -W *  Full name of base classifier. *  (default: weka.classifiers.rules.ZeroR)</pre> *  * <pre>  * Options specific to classifier weka.classifiers.rules.ZeroR: * </pre> *  * <pre> -D *  If set, classifier is run in debug mode and *  may output additional info to the console</pre> *  <!-- options-end --> *  * @author Eibe Frank (eibe@cs.waikato.ac.nz) * @author Xin Xu (xx5@cs.waikato.ac.nz) * @version $Revision: 1.4 $  */public class MIWrapper   extends SingleClassifierEnhancer  implements MultiInstanceCapabilitiesHandler, OptionHandler,             TechnicalInformationHandler {    /** for serialization */  static final long serialVersionUID = -7707766152904315910L;    /** The number of the class labels */  protected int m_NumClasses;  /** arithmetic average */  public static final int TESTMETHOD_ARITHMETIC = 1;  /** geometric average */  public static final int TESTMETHOD_GEOMETRIC = 2;  /** max probability of positive bag */  public static final int TESTMETHOD_MAXPROB = 3;  /** the test methods */  public static final Tag[] TAGS_TESTMETHOD = {    new Tag(TESTMETHOD_ARITHMETIC, "arithmetic average"),    new Tag(TESTMETHOD_GEOMETRIC, "geometric average"),    new Tag(TESTMETHOD_MAXPROB, "max probability of positive bag")  };  /** the test method  */  protected int m_Method = TESTMETHOD_GEOMETRIC;  /** Filter used to convert MI dataset into single-instance dataset */  protected MultiInstanceToPropositional m_ConvertToProp = new MultiInstanceToPropositional();  /** the single-instance weight setting method */  protected int m_WeightMethod = MultiInstanceToPropositional.WEIGHTMETHOD_INVERSE2;  /**   * Returns a string describing this filter   *   * @return a description of the filter suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {    return          "A simple Wrapper method for applying standard propositional learners "       + "to multi-instance data.\n\n"       + "For more information see:\n\n"       + getTechnicalInformation().toString();  }  /**   * Returns an instance of a TechnicalInformation object, containing    * detailed information about the technical background of this class,   * e.g., paper reference or book this class is based on.   *    * @return the technical information about this class   */  public TechnicalInformation getTechnicalInformation() {    TechnicalInformation 	result;        result = new TechnicalInformation(Type.TECHREPORT);    result.setValue(Field.AUTHOR, "E. T. Frank and X. Xu");    result.setValue(Field.TITLE, "Applying propositional learning algorithms to multi-instance data");    result.setValue(Field.YEAR, "2003");    result.setValue(Field.MONTH, "06");    result.setValue(Field.INSTITUTION, "University of Waikato");    result.setValue(Field.ADDRESS, "Department of Computer Science, University of Waikato, Hamilton, NZ");        return result;  }  /**   * Returns an enumeration describing the available options.   *   * @return an enumeration of all the available options.   */  public Enumeration listOptions() {    Vector result = new Vector();    result.addElement(new Option(          "\tThe method used in testing:\n"          + "\t1.arithmetic average\n"          + "\t2.geometric average\n"          + "\t3.max probability of positive bag.\n"          + "\t(default: 1)",          "P", 1, "-P [1|2|3]"));        result.addElement(new Option(          "\tThe type of weight setting for each single-instance:\n"          + "\t0.keep the weight to be the same as the original value;\n"          + "\t1.weight = 1.0\n"          + "\t2.weight = 1.0/Total number of single-instance in the\n"          + "\t\tcorresponding bag\n"          + "\t3. weight = Total number of single-instance / (Total\n"          + "\t\tnumber of bags * Total number of single-instance \n"          + "\t\tin the corresponding bag).\n"          + "\t(default: 3)",          "A", 1, "-A [0|1|2|3]"));	    Enumeration enu = super.listOptions();    while (enu.hasMoreElements()) {      result.addElement(enu.nextElement());    }    return result.elements();  }  /**   * Parses a given list of options. <p/>   *    <!-- options-start -->   * Valid options are: <p/>   *    * <pre> -P [1|2|3]   *  The method used in testing:   *  1.arithmetic average   *  2.geometric average   *  3.max probability of positive bag.   *  (default: 1)</pre>   *    * <pre> -A [0|1|2|3]   *  The type of weight setting for each single-instance:   *  0.keep the weight to be the same as the original value;   *  1.weight = 1.0   *  2.weight = 1.0/Total number of single-instance in the   *   corresponding bag   *  3. weight = Total number of single-instance / (Total   *   number of bags * Total number of single-instance    *   in the corresponding bag).   *  (default: 3)</pre>   *    * <pre> -D   *  If set, classifier is run in debug mode and   *  may output additional info to the console</pre>   *    * <pre> -W   *  Full name of base classifier.   *  (default: weka.classifiers.rules.ZeroR)</pre>   *    * <pre>    * Options specific to classifier weka.classifiers.rules.ZeroR:   * </pre>   *    * <pre> -D   *  If set, classifier is run in debug mode and   *  may output additional info to the console</pre>   *    <!-- options-end -->   *   * @param options the list of options as an array of strings   * @throws Exception if an option is not supported   */  public void setOptions(String[] options) throws Exception {    setDebug(Utils.getFlag('D', options));    String methodString = Utils.getOption('P', options);    if (methodString.length() != 0) {      setMethod(          new SelectedTag(Integer.parseInt(methodString), TAGS_TESTMETHOD));

⌨️ 快捷键说明

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