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

📄 citationknn.java

📁 用于快速分类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* *    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. *//* * CitationKNN.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.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 java.io.Serializable;import java.util.Enumeration;import java.util.Vector;/** <!-- globalinfo-start --> * Modified version of the Citation kNN multi instance classifier.<br/> * <br/> * For more information see:<br/> * <br/> * Jun Wang, Zucker, Jean-Daniel: Solving Multiple-Instance Problem: A Lazy Learning Approach. In: 17th International Conference on Machine Learning, 1119-1125, 2000. * <p/> <!-- globalinfo-end --> *  <!-- technical-bibtex-start --> * BibTeX: * <pre> * &#64;inproceedings{Wang2000, *    author = {Jun Wang and Zucker and Jean-Daniel}, *    booktitle = {17th International Conference on Machine Learning}, *    editor = {Pat Langley}, *    pages = {1119-1125}, *    title = {Solving Multiple-Instance Problem: A Lazy Learning Approach}, *    year = {2000} * } * </pre> * <p/> <!-- technical-bibtex-end --> *  <!-- options-start --> * Valid options are: <p/> *  * <pre> -R &lt;number of references&gt; *  Number of Nearest References (default 1)</pre> *  * <pre> -C &lt;number of citers&gt; *  Number of Nearest Citers (default 1)</pre> *  * <pre> -H &lt;rank&gt; *  Rank of the Hausdorff Distance (default 1)</pre> *  <!-- options-end --> * * @author Miguel Garcia Torres (mgarciat@ull.es) * @version $Revision: 1.5 $  */public class CitationKNN   extends Classifier   implements OptionHandler, MultiInstanceCapabilitiesHandler,             TechnicalInformationHandler {  /** for serialization */  static final long serialVersionUID = -8435377743874094852L;    /** The index of the class attribute */  protected int m_ClassIndex;  /** The number of the class labels */  protected int m_NumClasses;  /** */  protected int m_IdIndex;      /** Debugging output */  protected boolean m_Debug;  /** Class labels for each bag */  protected int[] m_Classes;  /** attribute name structure of the relational attribute*/  protected Instances m_Attributes;  /** Number of references */  protected int m_NumReferences = 1;  /** Number of citers*/  protected int m_NumCiters = 1;  /** Training bags*/  protected Instances m_TrainBags;  /** Different debugging output */  protected boolean m_CNNDebug = false;  protected boolean m_CitersDebug = false;  protected boolean m_ReferencesDebug = false;  protected boolean m_HDistanceDebug = false;  protected boolean m_NeighborListDebug = false;  /** C nearest neighbors considering all the bags*/  protected NeighborList[] m_CNN;  /** C nearest citers */  protected int[] m_Citers;  /** R nearest references */  protected int[] m_References;  /** Rank associated to the Hausdorff distance*/  protected int m_HDRank = 1;  /** Normalization of the euclidean distance */  private double[] m_Diffs;  private double[] m_Min;  private double m_MinNorm = 0.95;  private double[] m_Max;  private double m_MaxNorm = 1.05;  /**   * Returns a string describing this filter   *   * @return a description of the filter suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {    return         "Modified version of the Citation kNN multi instance classifier.\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.INPROCEEDINGS);    result.setValue(Field.AUTHOR, "Jun Wang and Zucker and Jean-Daniel");    result.setValue(Field.TITLE, "Solving Multiple-Instance Problem: A Lazy Learning Approach");    result.setValue(Field.BOOKTITLE, "17th International Conference on Machine Learning");    result.setValue(Field.EDITOR, "Pat Langley");    result.setValue(Field.YEAR, "2000");    result.setValue(Field.PAGES, "1119-1125");        return result;  }  /**    * Calculates the normalization of each attribute.   */  public void preprocessData(){    int i,j, k;    double min, max;    Instances instances;    Instance instance;    // compute the min/max of each feature    for (i=0;i<m_Attributes.numAttributes();i++) {      min=Double.POSITIVE_INFINITY ;      max=Double.NEGATIVE_INFINITY ;      for(j = 0; j < m_TrainBags.numInstances(); j++){        instances = m_TrainBags.instance(j).relationalValue(1);        for (k=0;k<instances.numInstances();k++) {          instance = instances.instance(k);          if(instance.value(i) < min)            min= instance.value(i);          if(instance.value(i) > max)            max= instance.value(i);        }      }      m_Min[i] = min * m_MinNorm;      m_Max[i] = max * m_MaxNorm;      m_Diffs[i]= max * m_MaxNorm - min * m_MinNorm;    }	      }  /**   * Returns the tip text for this property   *   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String HDRankTipText() {    return "The rank associated to the Hausdorff distance.";  }  /**   * Sets the rank associated to the Hausdorff distance   * @param hDRank the rank of the Hausdorff distance   */  public void setHDRank(int hDRank){    m_HDRank = hDRank;  }  /**   * Returns the rank associated to the Hausdorff distance   * @return the rank number   */  public int getHDRank(){    return m_HDRank;  }  /**   * Returns the tip text for this property   *   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String numReferencesTipText() {    return         "The number of references considered to estimate the class "      + "prediction of tests bags.";  }  /**   * Sets the number of references considered to estimate   * the class prediction of tests bags   * @param numReferences the number of references   */  public void setNumReferences(int numReferences){    m_NumReferences = numReferences;  }  /**   * Returns the number of references considered to estimate   * the class prediction of tests bags   * @return the number of references   */  public int getNumReferences(){    return m_NumReferences;  }  /**   * Returns the tip text for this property   *   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String numCitersTipText() {    return         "The number of citers considered to estimate the class "      + "prediction of test bags.";  }  /**   * Sets the number of citers considered to estimate   * the class prediction of tests bags   * @param numCiters the number of citers   */  public void setNumCiters(int numCiters){    m_NumCiters = numCiters;  }  /**   * Returns the number of citers considered to estimate   * the class prediction of tests bags   * @return the number of citers   */  public int getNumCiters(){    return m_NumCiters;  }  /**   * 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.NUMERIC_ATTRIBUTES);    result.enable(Capability.DATE_ATTRIBUTES);    result.enable(Capability.RELATIONAL_ATTRIBUTES);    result.enable(Capability.MISSING_VALUES);    // class    result.enable(Capability.NOMINAL_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 train 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 train) throws Exception {    // can classifier handle the data?    getCapabilities().testWithFail(train);    // remove instances with missing class

⌨️ 快捷键说明

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