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

📄 mioptimalball.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. *//* * MIOptimalBall.java * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand * */package weka.classifiers.mi;import weka.classifiers.Classifier;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.WeightedInstancesHandler;import weka.core.Capabilities.Capability;import weka.core.TechnicalInformation.Field;import weka.core.TechnicalInformation.Type;import weka.core.matrix.DoubleVector;import weka.filters.Filter;import weka.filters.unsupervised.attribute.MultiInstanceToPropositional;import weka.filters.unsupervised.attribute.Normalize;import weka.filters.unsupervised.attribute.PropositionalToMultiInstance;import weka.filters.unsupervised.attribute.Standardize;import java.util.Enumeration;import java.util.Vector;/** <!-- globalinfo-start --> * This classifier tries to find a suitable ball in the multiple-instance space, with a certain data point in the instance space as a ball center. The possible ball center is a certain instance in a positive bag. The possible radiuses are those which can achieve the highest classification accuracy. The model selects the maximum radius as the radius of the optimal ball.<br/> * <br/> * For more information about this algorithm, see:<br/> * <br/> * Peter Auer, Ronald Ortner: A Boosting Approach to Multiple Instance Learning. In: 15th European Conference on Machine Learning, 63-74, 2004. * <p/> <!-- globalinfo-end --> * <!-- technical-bibtex-start --> * BibTeX: * <pre> * &#64;inproceedings{Auer2004, *    author = {Peter Auer and Ronald Ortner}, *    booktitle = {15th European Conference on Machine Learning}, *    note = {LNAI 3201}, *    pages = {63-74}, *    publisher = {Springer}, *    title = {A Boosting Approach to Multiple Instance Learning}, *    year = {2004} * } * </pre> * <p/> <!-- technical-bibtex-end --> *  <!-- options-start --> * Valid options are: <p/> *  * <pre> -N &lt;num&gt; *  Whether to 0=normalize/1=standardize/2=neither.  *  (default 0=normalize)</pre> *  <!-- options-end --> *  * @author Lin Dong (ld21@cs.waikato.ac.nz) * @version $Revision: 1.4 $  */public class MIOptimalBall   extends Classifier   implements OptionHandler, WeightedInstancesHandler,              MultiInstanceCapabilitiesHandler, TechnicalInformationHandler {    /** for serialization */  static final long serialVersionUID = -6465750129576777254L;    /** center of the optimal ball */  protected double[] m_Center;  /** radius of the optimal ball */  protected double m_Radius;  /** the distances from each instance in a positive bag to each bag*/  protected double [][][]m_Distance;  /** The filter used to standardize/normalize all values. */  protected Filter m_Filter = null;  /** Whether to normalize/standardize/neither */  protected int m_filterType = FILTER_NORMALIZE;  /** Normalize training data */  public static final int FILTER_NORMALIZE = 0;  /** Standardize training data */  public static final int FILTER_STANDARDIZE = 1;  /** No normalization/standardization */  public static final int FILTER_NONE = 2;  /** The filter to apply to the training data */  public static final Tag [] TAGS_FILTER = {    new Tag(FILTER_NORMALIZE, "Normalize training data"),    new Tag(FILTER_STANDARDIZE, "Standardize training data"),    new Tag(FILTER_NONE, "No normalization/standardization"),  };  /** filter used to convert the MI dataset into single-instance dataset */  protected MultiInstanceToPropositional m_ConvertToSI = new MultiInstanceToPropositional();  /** filter used to convert the single-instance dataset into MI dataset */  protected PropositionalToMultiInstance m_ConvertToMI = new PropositionalToMultiInstance();  /**   * Returns a string describing this filter   *   * @return a description of the filter suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {    return         "This classifier tries to find a suitable ball in the "       + "multiple-instance space, with a certain data point in the instance "       + "space as a ball center. The possible ball center is a certain "       + "instance in a positive bag. The possible radiuses are those which can "       + "achieve the highest classification accuracy. The model selects the "       + "maximum radius as the radius of the optimal ball.\n\n"       + "For more information about this algorithm, 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.INPROCEEDINGS);    result.setValue(Field.AUTHOR, "Peter Auer and Ronald Ortner");    result.setValue(Field.TITLE, "A Boosting Approach to Multiple Instance Learning");    result.setValue(Field.BOOKTITLE, "15th European Conference on Machine Learning");    result.setValue(Field.YEAR, "2004");    result.setValue(Field.PAGES, "63-74");    result.setValue(Field.PUBLISHER, "Springer");    result.setValue(Field.NOTE, "LNAI 3201");        return result;  }  /**   * Returns default capabilities of the classifier.   *   * @return      the capabilities of this classifier   */  public Capabilities getCapabilities() {    Capabilities result = super.getCapabilities();    // attributes    result.enable(Capability.NOMINAL_ATTRIBUTES);    result.enable(Capability.RELATIONAL_ATTRIBUTES);    result.enable(Capability.MISSING_VALUES);    // class    result.enable(Capability.BINARY_CLASS);    result.enable(Capability.MISSING_CLASS_VALUES);        // other    result.enable(Capability.ONLY_MULTIINSTANCE);        return result;  }  /**   * Returns the capabilities of this multi-instance classifier for the   * relational data.   *   * @return            the capabilities of this object   * @see               Capabilities   */  public Capabilities getMultiInstanceCapabilities() {    Capabilities result = super.getCapabilities();        // attributes    result.enable(Capability.NOMINAL_ATTRIBUTES);    result.enable(Capability.NUMERIC_ATTRIBUTES);    result.enable(Capability.DATE_ATTRIBUTES);    result.enable(Capability.MISSING_VALUES);    // class    result.disableAllClasses();    result.enable(Capability.NO_CLASS);        return result;  }  /**   * Builds the classifier   *   * @param data the training data to be used for generating the   * boosted classifier.   * @throws Exception if the classifier could not be built successfully   */  public void buildClassifier(Instances data) throws Exception {    // can classifier handle the data?    getCapabilities().testWithFail(data);    // remove instances with missing class    Instances train = new Instances(data);    train.deleteWithMissingClass();        int numAttributes = train.attribute(1).relation().numAttributes();	    m_Center = new double[numAttributes];    if (getDebug())      System.out.println("Start training ...");     // convert the training dataset into single-instance dataset    m_ConvertToSI.setInputFormat(train);	    train = Filter.useFilter( train, m_ConvertToSI);    if (m_filterType == FILTER_STANDARDIZE)       m_Filter = new Standardize();    else if (m_filterType == FILTER_NORMALIZE)      m_Filter = new Normalize();    else       m_Filter = null;    if (m_Filter!=null) {      // normalize/standardize the converted training dataset      m_Filter.setInputFormat(train);      train = Filter.useFilter(train, m_Filter);    }    // convert the single-instance dataset into multi-instance dataset    m_ConvertToMI.setInputFormat(train);    train = Filter.useFilter(train, m_ConvertToMI);    /*calculate all the distances (and store them in m_Distance[][][]), which      are from each instance in all positive bags to all bags */    calculateDistance(train);    /*find the suitable ball center (m_Center) and the corresponding radius (m_Radius)*/    findRadius(train);     if (getDebug())      System.out.println("Finish building optimal ball model");  }		  /** 

⌨️ 快捷键说明

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