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

📄 testinstances.java

📁 矩阵的QR分解算法
💻 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. *//* * TestInstances.java * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand */package weka.core;import weka.core.Capabilities.Capability;import java.io.Serializable;import java.util.Enumeration;import java.util.Random;import java.util.StringTokenizer;import java.util.Vector;/** * Generates artificial datasets for testing. In case of Multi-Instance data * the settings for the number of attributes applies to the data inside * the bag. Originally based on code from the CheckClassifier.<p/> * <!-- options-start --> * Valid options are: <p/> *  * <pre> -relation &lt;name&gt; *  The name of the data set.</pre> *  * <pre> -seed &lt;num&gt; *  The seed value.</pre> *  * <pre> -num-instances &lt;num&gt; *  The number of instances in the datasets (default 20).</pre> *  * <pre> -class-type &lt;num&gt; *  The class type, see constants in weka.core.Attribute *  (default 1=nominal).</pre> *  * <pre> -class-values &lt;num&gt; *  The number of classes to generate (for nominal classes only) *  (default 2).</pre> *  * <pre> -class-index &lt;num&gt; *  The class index, with -1=last, (default -1).</pre> *  * <pre> -no-class *  Doesn't include a class attribute in the output.</pre> *  * <pre> -nominal &lt;num&gt; *  The number of nominal attributes (default 1).</pre> *  * <pre> -nominal-values &lt;num&gt; *  The number of values for nominal attributes (default 2).</pre> *  * <pre> -numeric &lt;num&gt; *  The number of numeric attributes (default 0).</pre> *  * <pre> -string &lt;num&gt; *  The number of string attributes (default 0).</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> -date &lt;num&gt; *  The number of date attributes (default 0).</pre> *  * <pre> -relational &lt;num&gt; *  The number of relational attributes (default 0).</pre> *  * <pre> -relational-nominal &lt;num&gt; *  The number of nominal attributes in a rel. attribute (default 1).</pre> *  * <pre> -relational-nominal-values &lt;num&gt; *  The number of values for nominal attributes in a rel. attribute (default 2).</pre> *  * <pre> -relational-numeric &lt;num&gt; *  The number of numeric attributes in a rel. attribute (default 0).</pre> *  * <pre> -relational-string &lt;num&gt; *  The number of string attributes in a rel. attribute (default 0).</pre> *  * <pre> -relational-date &lt;num&gt; *  The number of date attributes in a rel. attribute (default 0).</pre> *  * <pre> -num-instances-relational &lt;num&gt; *  The number of instances in relational/bag attributes (default 10).</pre> *  * <pre> -multi-instance *  Generates multi-instance data.</pre> *  * <pre> -W &lt;classname&gt; *  The Capabilities handler to base the dataset on. *  The other parameters can be used to override the ones *  determined from the handler. Additional parameters for *  handler can be passed on after the '--'.</pre> *  <!-- options-end --> *  * @author FracPete (fracpete at waikato dot ac dot nz) * @version $Revision: 1.9 $ * @see weka.classifiers.CheckClassifier */public class TestInstances   implements Cloneable, Serializable, OptionHandler {  /** for serialization */  private static final long serialVersionUID = -6263968936330390469L;  /** can be used for settting the class attribute index to last    * @see #setClassIndex(int) */  public final static int CLASS_IS_LAST = -1;    /** can be used to avoid generating a class attribute   * @see #setClassIndex(int) */  public final static int NO_CLASS = -2;  /** the default list of words used in strings */  public final static String[] DEFAULT_WORDS = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};  /** the default word separators used in strings */  public final static String DEFAULT_SEPARATORS = " ";    /** for generating String attributes/classes */  protected String[] m_Words = DEFAULT_WORDS;    /** for generating String attributes/classes */  protected String m_WordSeparators = DEFAULT_SEPARATORS;    /** the name of the relation */  protected String m_Relation = "Testdata";    /** the seed value */  protected int m_Seed = 1;    /** the random number generator */  protected Random m_Random = new Random(m_Seed);    /** the number of instances */  protected int m_NumInstances = 20;    /** the class type */  protected int m_ClassType = Attribute.NOMINAL;    /** the number of classes (in case of NOMINAL class) */  protected int m_NumClasses = 2;  /** the class index (-1 is LAST, -2 means no class)    * @see #CLASS_IS_LAST   * @see #NO_CLASS */  protected int m_ClassIndex = CLASS_IS_LAST;    /** the number of nominal attributes */  protected int m_NumNominal = 1;    /** the number of values for nominal attributes */  protected int m_NumNominalValues = 2;    /** the number of numeric attributes */  protected int m_NumNumeric = 0;    /** the number of string attributes */  protected int m_NumString = 0;    /** the number of date attributes */  protected int m_NumDate = 0;    /** the number of relational attributes */  protected int m_NumRelational = 0;    /** the number of nominal attributes in a relational attribute */  protected int m_NumRelationalNominal = 1;    /** the number of values for nominal attributes in relational attributes */  protected int m_NumRelationalNominalValues = 2;    /** the number of numeric attributes in a relational attribute */  protected int m_NumRelationalNumeric = 0;    /** the number of string attributes in a relational attribute */  protected int m_NumRelationalString = 0;    /** the number of date attributes in a relational attribute */  protected int m_NumRelationalDate = 0;    /** whether to generate Multi-Instance data or not */  protected boolean m_MultiInstance = false;    /** the number of instances in relational attributes (applies also for bags   * in multi-instance) */  protected int m_NumInstancesRelational = 10;    /** the format of the multi-instance data */  protected Instances[] m_RelationalFormat = null;    /** the format of the multi-instance data of the class */  protected Instances m_RelationalClassFormat = null;    /** the generated data */  protected Instances m_Data = null;    /** the CapabilitiesHandler to get the Capabilities from */  protected CapabilitiesHandler m_Handler = null;  /**   * the default constructor   */  public TestInstances() {    super();        setRelation("Testdata");    setSeed(1);    setNumInstances(20);    setClassType(Attribute.NOMINAL);    setNumClasses(2);    setClassIndex(CLASS_IS_LAST);    setNumNominal(1);    setNumNominalValues(2);    setNumNumeric(0);    setNumString(0);    setNumDate(0);    setNumRelational(0);    setNumRelationalNominal(1);    setNumRelationalNominalValues(2);    setNumRelationalNumeric(0);    setNumRelationalString(0);    setNumRelationalDate(0);    setNumInstancesRelational(10);    setMultiInstance(false);    setWords(arrayToList(DEFAULT_WORDS));    setWordSeparators(DEFAULT_SEPARATORS);  }    /**   * creates a clone of the current object   *    * @return		a clone of the current object   */  public Object clone() {    TestInstances     result;        result = new TestInstances();    result.assign(this);        return result;  }    /**   * updates itself with all the settings from the given TestInstances   * object   *    * @param t		the object to get the settings from   */  public void assign(TestInstances t) {    setRelation(t.getRelation());    setSeed(t.getSeed());    setNumInstances(t.getNumInstances());    setClassType(t.getClassType());    setNumClasses(t.getNumClasses());    setClassIndex(t.getClassIndex());    setNumNominal(t.getNumNominal());    setNumNominalValues(t.getNumNominalValues());    setNumNumeric(t.getNumNumeric());    setNumString(t.getNumString());    setNumDate(t.getNumDate());    setNumRelational(t.getNumRelational());    setNumRelationalNominal(t.getNumRelationalNominal());    setNumRelationalNominalValues(t.getNumRelationalNominalValues());    setNumRelationalNumeric(t.getNumRelationalNumeric());    setNumRelationalString(t.getNumRelationalString());    setNumRelationalDate(t.getNumRelationalDate());    setMultiInstance(t.getMultiInstance());    for (int i = 0; i < t.getNumRelational(); i++)      setRelationalFormat(i, t.getRelationalFormat(i));    setRelationalClassFormat(t.getRelationalClassFormat());    setNumInstancesRelational(t.getNumInstancesRelational());    setWords(t.getWords());    setWordSeparators(t.getWordSeparators());  }    /**   * 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 name of the data set.",        "relation", 1, "-relation <name>"));        result.addElement(new Option(        "\tThe seed value.",        "seed", 1, "-seed <num>"));        result.addElement(new Option(        "\tThe number of instances in the datasets (default 20).",        "num-instances", 1, "-num-instances <num>"));        result.addElement(new Option(        "\tThe class type, see constants in weka.core.Attribute\n"	+ "\t(default 1=nominal).",        "class-type", 1, "-class-type <num>"));        result.addElement(new Option(        "\tThe number of classes to generate (for nominal classes only)\n"	+ "\t(default 2).",        "class-values", 1, "-class-values <num>"));        result.addElement(new Option(        "\tThe class index, with -1=last, (default -1).",        "class-index", 1, "-class-index <num>"));        result.addElement(new Option(        "\tDoesn't include a class attribute in the output.",        "no-class", 0, "-no-class"));    result.addElement(new Option(        "\tThe number of nominal attributes (default 1).",        "nominal", 1, "-nominal <num>"));        result.addElement(new Option(        "\tThe number of values for nominal attributes (default 2).",        "nominal-values", 1, "-nominal-values <num>"));        result.addElement(new Option(        "\tThe number of numeric attributes (default 0).",        "numeric", 1, "-numeric <num>"));        result.addElement(new Option(        "\tThe number of string attributes (default 0).",        "string", 1, "-string <num>"));        result.addElement(new Option(        "\tThe words to use in string attributes.",        "words", 1, "-words <comma-separated-list>"));        result.addElement(new Option(        "\tThe word separators to use in string attributes.",        "word-separators", 1, "-word-separators <chars>"));        result.addElement(new Option(        "\tThe number of date attributes (default 0).",        "date", 1, "-date <num>"));        result.addElement(new Option(        "\tThe number of relational attributes (default 0).",        "relational", 1, "-relational <num>"));        result.addElement(new Option(        "\tThe number of nominal attributes in a rel. attribute (default 1).",        "relational-nominal", 1, "-relational-nominal <num>"));        result.addElement(new Option(        "\tThe number of values for nominal attributes in a rel. attribute (default 2).",        "relational-nominal-values", 1, "-relational-nominal-values <num>"));        result.addElement(new Option(        "\tThe number of numeric attributes in a rel. attribute (default 0).",        "relational-numeric", 1, "-relational-numeric <num>"));        result.addElement(new Option(        "\tThe number of string attributes in a rel. attribute (default 0).",        "relational-string", 1, "-relational-string <num>"));        result.addElement(new Option(        "\tThe number of date attributes in a rel. attribute (default 0).",        "relational-date", 1, "-relational-date <num>"));        result.addElement(new Option(        "\tThe number of instances in relational/bag attributes (default 10).",        "num-instances-relational", 1, "-num-instances-relational <num>"));        result.addElement(new Option(        "\tGenerates multi-instance data.",        "multi-instance", 0, "-multi-instance"));    result.addElement(new Option(        "\tThe Capabilities handler to base the dataset on.\n"	+ "\tThe other parameters can be used to override the ones\n"	+ "\tdetermined from the handler. Additional parameters for\n"	+ "\thandler can be passed on after the '--'.",        "W", 1, "-W <classname>"));        return result.elements();  }    /**   * Parses a given list of options. <p/>   *   <!-- options-start -->   * Valid options are: <p/>   *    * <pre> -relation &lt;name&gt;   *  The name of the data set.</pre>   *    * <pre> -seed &lt;num&gt;   *  The seed value.</pre>   *    * <pre> -num-instances &lt;num&gt;   *  The number of instances in the datasets (default 20).</pre>   *    * <pre> -class-type &lt;num&gt;   *  The class type, see constants in weka.core.Attribute   *  (default 1=nominal).</pre>   *    * <pre> -class-values &lt;num&gt;   *  The number of classes to generate (for nominal classes only)   *  (default 2).</pre>   *    * <pre> -class-index &lt;num&gt;   *  The class index, with -1=last, (default -1).</pre>   *    * <pre> -no-class   *  Doesn't include a class attribute in the output.</pre>   *    * <pre> -nominal &lt;num&gt;   *  The number of nominal attributes (default 1).</pre>   *    * <pre> -nominal-values &lt;num&gt;   *  The number of values for nominal attributes (default 2).</pre>   *    * <pre> -numeric &lt;num&gt;   *  The number of numeric attributes (default 0).</pre>   *    * <pre> -string &lt;num&gt;   *  The number of string attributes (default 0).</pre>

⌨️ 快捷键说明

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