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

📄 mexicanhat.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. *//* * MexicanHat.java * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand * */package weka.datagenerators.classifiers.regression;import weka.core.Attribute;import weka.core.FastVector;import weka.core.Instance;import weka.core.Instances;import weka.core.Option;import weka.core.Utils;import weka.datagenerators.RegressionGenerator;import java.util.Enumeration;import java.util.Random;import java.util.Vector;/** <!-- globalinfo-start --> * A data generator for the simple 'Mexian Hat' function:<br/> *    y = sin|x| / |x|<br/> * In addition to this simple function, the amplitude can be changed and gaussian noise can be added. * <p/> <!-- globalinfo-end --> * <!-- options-start --> * Valid options are: <p/> *  * <pre> -h *  Prints this help.</pre> *  * <pre> -o &lt;file&gt; *  The name of the output file, otherwise the generated data is *  printed to stdout.</pre> *  * <pre> -r &lt;name&gt; *  The name of the relation.</pre> *  * <pre> -d *  Whether to print debug informations.</pre> *  * <pre> -S *  The seed for random function (default 1)</pre> *  * <pre> -n &lt;num&gt; *  The number of examples to generate (default 100)</pre> *  * <pre> -A &lt;num&gt; *  The amplitude multiplier (default 1.0).</pre> *  * <pre> -R &lt;num&gt;..&lt;num&gt; *  The range x is randomly drawn from (default -10.0..10.0).</pre> *  * <pre> -N &lt;num&gt; *  The noise rate (default 0.0).</pre> *  * <pre> -V &lt;num&gt; *  The noise variance (default 1.0).</pre> *  <!-- options-end --> * * @author  FracPete (fracpete at waikato dot ac dot nz) * @version $Revision: 1.3 $ */public class MexicanHat  extends RegressionGenerator {  /** for serialization */  static final long serialVersionUID = 4577016375261512975L;    /** the amplitude of y */  protected double m_Amplitude;  /** the lower boundary of the range, x is drawn from */  protected double m_MinRange;  /** the upper boundary of the range, x is drawn from */  protected double m_MaxRange;  /** the rate of the gaussian noise */  protected double m_NoiseRate;  /** the variance of the gaussian noise */  protected double m_NoiseVariance;  /** the random number generator for the noise */  protected Random m_NoiseRandom = null;  /**   * initializes the generator   */  public MexicanHat() {    super();    setAmplitude(defaultAmplitude());    setMinRange(defaultMinRange());    setMaxRange(defaultMaxRange());    setNoiseRate(defaultNoiseRate());    setNoiseVariance(defaultNoiseVariance());  }    /**   * Returns a string describing this data generator.   *   * @return a description of the data generator suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {    return         "A data generator for the simple 'Mexian Hat' function:\n"        + "   y = sin|x| / |x|\n"        + "In addition to this simple function, the amplitude can be changed and "        + "gaussian noise can be added.";  }  /**   * Returns an enumeration describing the available options.   *   * @return an enumeration of all the available options   */  public Enumeration listOptions() {    Vector result = enumToVector(super.listOptions());    result.addElement(new Option(              "\tThe amplitude multiplier (default "               + defaultAmplitude() + ").",              "A", 1, "-A <num>"));    result.addElement(new Option(              "\tThe range x is randomly drawn from (default "               + defaultMinRange() + ".." + defaultMaxRange() + ").",              "R", 1, "-R <num>..<num>"));    result.addElement(new Option(              "\tThe noise rate (default "               + defaultNoiseRate() + ").",              "N", 1, "-N <num>"));    result.addElement(new Option(              "\tThe noise variance (default "              + defaultNoiseVariance() + ").",              "V", 1, "-V <num>"));    return result.elements();  }    /**   * Parses a list of options for this object. <p/>   *   <!-- options-start -->   * Valid options are: <p/>   *    * <pre> -h   *  Prints this help.</pre>   *    * <pre> -o &lt;file&gt;   *  The name of the output file, otherwise the generated data is   *  printed to stdout.</pre>   *    * <pre> -r &lt;name&gt;   *  The name of the relation.</pre>   *    * <pre> -d   *  Whether to print debug informations.</pre>   *    * <pre> -S   *  The seed for random function (default 1)</pre>   *    * <pre> -n &lt;num&gt;   *  The number of examples to generate (default 100)</pre>   *    * <pre> -A &lt;num&gt;   *  The amplitude multiplier (default 1.0).</pre>   *    * <pre> -R &lt;num&gt;..&lt;num&gt;   *  The range x is randomly drawn from (default -10.0..10.0).</pre>   *    * <pre> -N &lt;num&gt;   *  The noise rate (default 0.0).</pre>   *    * <pre> -V &lt;num&gt;   *  The noise variance (default 1.0).</pre>   *    <!-- options-end -->   *   * @param options the list of options as an array of strings   * @exception Exception if an option is not supported   */  public void setOptions(String[] options) throws Exception {    String        tmpStr;       super.setOptions(options);    tmpStr = Utils.getOption('A', options);    if (tmpStr.length() != 0)      setAmplitude(Double.parseDouble(tmpStr));    else      setAmplitude(defaultAmplitude());    tmpStr = Utils.getOption('R', options);    if (tmpStr.length() != 0)      setRange(tmpStr);    else      setRange(defaultMinRange() + ".." + defaultMaxRange());        tmpStr = Utils.getOption('N', options);    if (tmpStr.length() != 0)      setNoiseRate(Double.parseDouble(tmpStr));    else      setNoiseRate(defaultNoiseRate());    tmpStr = Utils.getOption('V', options);    if (tmpStr.length() != 0)      setNoiseVariance(Double.parseDouble(tmpStr));    else      setNoiseVariance(defaultNoiseVariance());  }  /**   * Gets the current settings of the datagenerator BIRCHCluster.   *   * @return an array of strings suitable for passing to setOptions   */  public String[] getOptions() {    Vector        result;    String[]      options;    int           i;        result  = new Vector();    options = removeBlacklist(super.getOptions());    for (i = 0; i < options.length; i++)      result.add(options[i]);    result.add("-A");     result.add("" + getAmplitude());    result.add("-R");     result.add("" + getRange());    result.add("-N");     result.add("" + getNoiseRate());    result.add("-V");     result.add("" + getNoiseVariance());        return (String[]) result.toArray(new String[result.size()]);  }  /**   * returns the default amplitude   *    * @return the default amplitude   */  protected double defaultAmplitude() {    return 1.0;  }  /**   * Gets the amplitude multiplier.   *   * @return the amplitude multiplier   */  public double getAmplitude() {     return m_Amplitude;   }    /**   * Sets the amplitude multiplier.   *   * @param value the amplitude multiplier   */  public void setAmplitude(double value) {    m_Amplitude = value;  }    /**   * Returns the tip text for this property   *    * @return tip text for this property suitable for   *         displaying in the explorer/experimenter gui   */  public String amplitudeTipText() {    return "The amplitude of the mexican hat.";  }  /**   * Sets the upper and lower boundary for the range of x   *   * @param fromTo the string containing the upper and lower boundary for   *               the range of x, separated by ..   */  protected void setRange(String fromTo) {    int i = fromTo.indexOf("..");    String from = fromTo.substring(0, i);    setMinRange(Double.valueOf(from).doubleValue());    String to = fromTo.substring(i + 2, fromTo.length());    setMaxRange(Double.valueOf(to).doubleValue());  }  /**

⌨️ 快捷键说明

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