📄 simplemi.java
字号:
/* * 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. *//* * SimpleMI.java * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand */package weka.classifiers.mi;import weka.classifiers.SingleClassifierEnhancer;import weka.classifiers.Evaluation;import weka.core.Attribute;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.Utils;import weka.core.Capabilities.Capability;import java.util.Enumeration;import java.util.Vector;/** <!-- globalinfo-start --> * Reduces MI data into mono-instance data. * <p/> <!-- globalinfo-end --> * <!-- options-start --> * Valid options are: <p/> * * <pre> -M [1|2|3] * The method used in transformation: * 1.arithmatic average; 2.geometric centor; * 3.using minimax combined features of a bag (default: 1) * * Method 3: * Define s to be the vector of the coordinate-wise maxima * and minima of X, ie., * s(X)=(minx1, ..., minxm, maxx1, ...,maxxm), transform * the exemplars into mono-instance which contains attributes * s(X)</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) * @author Lin Dong (ld21@cs.waikato.ac.nz) * @version $Revision: 1.3 $ */public class SimpleMI extends SingleClassifierEnhancer implements OptionHandler, MultiInstanceCapabilitiesHandler { /** for serialization */ static final long serialVersionUID = 9137795893666592662L; /** arithmetic average */ public static final int TRANSFORMMETHOD_ARITHMETIC = 1; /** geometric average */ public static final int TRANSFORMMETHOD_GEOMETRIC = 2; /** using minimax combined features of a bag */ public static final int TRANSFORMMETHOD_MINIMAX = 3; /** the transformation methods */ public static final Tag[] TAGS_TRANSFORMMETHOD = { new Tag(TRANSFORMMETHOD_ARITHMETIC, "arithmetic average"), new Tag(TRANSFORMMETHOD_GEOMETRIC, "geometric average"), new Tag(TRANSFORMMETHOD_MINIMAX, "using minimax combined features of a bag") }; /** the method used in transformation */ protected int m_TransformMethod = TRANSFORMMETHOD_ARITHMETIC; /** * Returns a string describing this filter * * @return a description of the filter suitable for * displaying in the explorer/experimenter gui */ public String globalInfo() { return "Reduces MI data into mono-instance data."; } /** * 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 transformation:\n" + "\t1.arithmatic average; 2.geometric centor;\n" + "\t3.using minimax combined features of a bag (default: 1)\n\n" + "\tMethod 3:\n" + "\tDefine s to be the vector of the coordinate-wise maxima\n" + "\tand minima of X, ie., \n" + "\ts(X)=(minx1, ..., minxm, maxx1, ...,maxxm), transform\n" + "\tthe exemplars into mono-instance which contains attributes\n" + "\ts(X)", "M", 1, "-M [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> -M [1|2|3] * The method used in transformation: * 1.arithmatic average; 2.geometric centor; * 3.using minimax combined features of a bag (default: 1) * * Method 3: * Define s to be the vector of the coordinate-wise maxima * and minima of X, ie., * s(X)=(minx1, ..., minxm, maxx1, ...,maxxm), transform * the exemplars into mono-instance which contains attributes * s(X)</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('M', options); if (methodString.length() != 0) { setTransformMethod( new SelectedTag( Integer.parseInt(methodString), TAGS_TRANSFORMMETHOD)); } else { setTransformMethod( new SelectedTag( TRANSFORMMETHOD_ARITHMETIC, TAGS_TRANSFORMMETHOD)); } super.setOptions(options); } /** * Gets the current settings of the Classifier. * * @return an array of strings suitable for passing to setOptions */ public String[] getOptions() { Vector result; String[] options; int i; result = new Vector(); options = super.getOptions(); for (i = 0; i < options.length; i++) result.add(options[i]); result.add("-M"); result.add("" + m_TransformMethod); return (String[]) result.toArray(new String[result.size()]); } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String transformMethodTipText() { return "The method used in transformation."; } /** * Set the method used in transformation. * * @param newMethod the index of method to use. */ public void setTransformMethod(SelectedTag newMethod) { if (newMethod.getTags() == TAGS_TRANSFORMMETHOD) m_TransformMethod = newMethod.getSelectedTag().getID(); } /** * Get the method used in transformation. * * @return the index of method used. */ public SelectedTag getTransformMethod() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -