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

📄 checkkernel.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* *    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. *//* * CheckKernel.java * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand * */package weka.classifiers.functions.supportVector;import weka.core.Attribute;import weka.core.CheckScheme;import weka.core.FastVector;import weka.core.Instances;import weka.core.MultiInstanceCapabilitiesHandler;import weka.core.Option;import weka.core.OptionHandler;import weka.core.TestInstances;import weka.core.Utils;import weka.core.WeightedInstancesHandler;import java.util.Enumeration;import java.util.Random;import java.util.Vector;/** * Class for examining the capabilities and finding problems with  * kernels. If you implement an kernels using the WEKA.libraries, * you should run the checks on it to ensure robustness and correct * operation. Passing all the tests of this object does not mean * bugs in the kernels don't exist, but this will help find some * common ones. <p/> *  * Typical usage: <p/> * <code>java weka.classifiers.functions.supportVector.CheckKernel -W kernel_name  * -- kernel_options </code><p/> *  * CheckKernel reports on the following: * <ul> *    <li> Kernel abilities  *      <ul> *         <li> Possible command line options to the kernels </li> *         <li> Whether the kernels can predict nominal, numeric, string,  *              date or relational class attributes. </li> *         <li> Whether the kernels can handle numeric predictor attributes </li> *         <li> Whether the kernels can handle nominal predictor attributes </li> *         <li> Whether the kernels can handle string predictor attributes </li> *         <li> Whether the kernels can handle date predictor attributes </li> *         <li> Whether the kernels can handle relational predictor attributes </li> *         <li> Whether the kernels can handle multi-instance data </li> *         <li> Whether the kernels can handle missing predictor values </li> *         <li> Whether the kernels can handle missing class values </li> *         <li> Whether a nominal kernels only handles 2 class problems </li> *         <li> Whether the kernels can handle instance weights </li> *      </ul> *    </li> *    <li> Correct functioning  *      <ul> *         <li> Correct initialisation during buildKernel (i.e. no result *              changes when buildKernel called repeatedly) </li> *         <li> Whether the kernels alters the data passed to it  *              (number of instances, instance order, instance weights, etc) </li> *      </ul> *    </li> *    <li> Degenerate cases  *      <ul> *         <li> building kernels with zero training instances </li> *         <li> all but one predictor attribute values missing </li> *         <li> all predictor attribute values missing </li> *         <li> all but one class values missing </li> *         <li> all class values missing </li> *      </ul> *    </li> * </ul> * Running CheckKernel with the debug option set will output the  * training and test datasets for any failed tests.<p/> * * The <code>weka.classifiers.AbstractKernelTest</code> uses this * class to test all the kernels. Any changes here, have to be  * checked in that abstract test class, too. <p/> * <!-- options-start --> * Valid options are: <p/> *  * <pre> -D *  Turn on debugging output.</pre> *  * <pre> -S *  Silent mode - prints nothing to stdout.</pre> *  * <pre> -N &lt;num&gt; *  The number of instances in the datasets (default 20).</pre> *  * <pre> -nominal &lt;num&gt; *  The number of nominal attributes (default 2).</pre> *  * <pre> -nominal-values &lt;num&gt; *  The number of values for nominal attributes (default 1).</pre> *  * <pre> -numeric &lt;num&gt; *  The number of numeric attributes (default 1).</pre> *  * <pre> -string &lt;num&gt; *  The number of string attributes (default 1).</pre> *  * <pre> -date &lt;num&gt; *  The number of date attributes (default 1).</pre> *  * <pre> -relational &lt;num&gt; *  The number of relational attributes (default 1).</pre> *  * <pre> -num-instances-relational &lt;num&gt; *  The number of instances in relational/bag attributes (default 10).</pre> *  * <pre> -words &lt;comma-separated-list&gt; *  The words to use in string attributes.</pre> *  * <pre> -word-separators &lt;chars&gt; *  The word separators to use in string attributes.</pre> *  * <pre> -W *  Full name of the kernel analysed. *  eg: weka.classifiers.functions.supportVector.RBFKernel *  (default weka.classifiers.functions.supportVector.RBFKernel)</pre> *  * <pre>  * Options specific to kernel weka.classifiers.functions.supportVector.RBFKernel: * </pre> *  * <pre> -D *  Enables debugging output (if available) to be printed. *  (default: off)</pre> *  * <pre> -no-checks *  Turns off all checks - use with caution! *  (default: checks on)</pre> *  * <pre> -C &lt;num&gt; *  The size of the cache (a prime number), 0 for full cache and  *  -1 to turn it off. *  (default: 250007)</pre> *  * <pre> -G &lt;num&gt; *  The Gamma parameter. *  (default: 0.01)</pre> *  <!-- options-end --> * * Options after -- are passed to the designated kernel.<p/> * * @author Len Trigg (trigg@cs.waikato.ac.nz) * @author FracPete (fracpete at waikato dot ac dot nz) * @version $Revision: 1.1 $ * @see TestInstances */public class CheckKernel  extends CheckScheme {  /*   * Note about test methods:   * - methods return array of booleans   * - first index: success or not   * - second index: acceptable or not (e.g., Exception is OK)   *   * FracPete (fracpete at waikato dot ac dot nz)   */    /*** The kernel to be examined */  protected Kernel m_Kernel = new weka.classifiers.functions.supportVector.RBFKernel();    /**   * Returns an enumeration describing the available options.   *   * @return an enumeration of all the available options.   */  public Enumeration listOptions() {    Vector result = new Vector();        Enumeration en = super.listOptions();    while (en.hasMoreElements())      result.addElement(en.nextElement());        result.addElement(new Option(        "\tFull name of the kernel analysed.\n"        +"\teg: weka.classifiers.functions.supportVector.RBFKernel\n"        + "\t(default weka.classifiers.functions.supportVector.RBFKernel)",        "W", 1, "-W"));        if ((m_Kernel != null)         && (m_Kernel instanceof OptionHandler)) {      result.addElement(new Option("", "", 0,           "\nOptions specific to kernel "          + m_Kernel.getClass().getName()          + ":"));      Enumeration enu = ((OptionHandler)m_Kernel).listOptions();      while (enu.hasMoreElements())        result.addElement(enu.nextElement());    }        return result.elements();  }    /**   * Parses a given list of options.    *   <!-- options-start -->   * Valid options are: <p/>   *    * <pre> -D   *  Turn on debugging output.</pre>   *    * <pre> -S   *  Silent mode - prints nothing to stdout.</pre>   *    * <pre> -N &lt;num&gt;   *  The number of instances in the datasets (default 20).</pre>   *    * <pre> -nominal &lt;num&gt;   *  The number of nominal attributes (default 2).</pre>   *    * <pre> -nominal-values &lt;num&gt;   *  The number of values for nominal attributes (default 1).</pre>   *    * <pre> -numeric &lt;num&gt;   *  The number of numeric attributes (default 1).</pre>   *    * <pre> -string &lt;num&gt;   *  The number of string attributes (default 1).</pre>   *    * <pre> -date &lt;num&gt;   *  The number of date attributes (default 1).</pre>   *    * <pre> -relational &lt;num&gt;   *  The number of relational attributes (default 1).</pre>   *    * <pre> -num-instances-relational &lt;num&gt;   *  The number of instances in relational/bag attributes (default 10).</pre>   *    * <pre> -words &lt;comma-separated-list&gt;   *  The words to use in string attributes.</pre>   *    * <pre> -word-separators &lt;chars&gt;   *  The word separators to use in string attributes.</pre>   *    * <pre> -W   *  Full name of the kernel analysed.   *  eg: weka.classifiers.functions.supportVector.RBFKernel   *  (default weka.classifiers.functions.supportVector.RBFKernel)</pre>   *    * <pre>    * Options specific to kernel weka.classifiers.functions.supportVector.RBFKernel:   * </pre>   *    * <pre> -D   *  Enables debugging output (if available) to be printed.   *  (default: off)</pre>   *    * <pre> -no-checks   *  Turns off all checks - use with caution!   *  (default: checks on)</pre>   *    * <pre> -C &lt;num&gt;   *  The size of the cache (a prime number), 0 for full cache and    *  -1 to turn it off.   *  (default: 250007)</pre>   *    * <pre> -G &lt;num&gt;   *  The Gamma parameter.   *  (default: 0.01)</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 {    String      tmpStr;        super.setOptions(options);        tmpStr = Utils.getOption('W', options);    if (tmpStr.length() == 0)      tmpStr = weka.classifiers.functions.supportVector.RBFKernel.class.getName();    setKernel(	(Kernel) forName(	    "weka.classifiers.functions.supportVector", 	    Kernel.class, 	    tmpStr, 	    Utils.partitionOptions(options)));  }    /**   * Gets the current settings of the CheckKernel.   *   * @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]);        if (getKernel() != null) {      result.add("-W");      result.add(getKernel().getClass().getName());    }        if ((m_Kernel != null) && (m_Kernel instanceof OptionHandler))      options = ((OptionHandler) m_Kernel).getOptions();    else      options = new String[0];        if (options.length > 0) {      result.add("--");      for (i = 0; i < options.length; i++)        result.add(options[i]);    }        return (String[]) result.toArray(new String[result.size()]);  }    /**   * Begin the tests, reporting results to System.out   */  public void doTests() {        if (getKernel() == null) {      println("\n=== No kernel set ===");      return;    }    println("\n=== Check on kernel: "        + getKernel().getClass().getName()        + " ===\n");        // Start tests

⌨️ 快捷键说明

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