📄 randomrbf.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. *//* * RandomRBF.java * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand * */package weka.datagenerators.classifiers.classification;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.ClassificationGenerator;import java.util.Enumeration;import java.util.Random;import java.util.Vector;/** <!-- globalinfo-start --> * RandomRBF data is generated by first creating a random set of centers for each class. Each center is randomly assigned a weight, a central point per attribute, and a standard deviation. To generate new instances, a center is chosen at random taking the weights of each center into consideration. Attribute values are randomly generated and offset from the center, where the overall vector has been scaled so that its length equals a value sampled randomly from the Gaussian distribution of the center. The particular center chosen determines the class of the instance.<br/> * RandomRBF data contains only numeric attributes as it is non-trivial to include nominal values. * <p/> <!-- globalinfo-end --> * <!-- options-start --> * Valid options are: <p/> * * <pre> -h * Prints this help.</pre> * * <pre> -o <file> * The name of the output file, otherwise the generated data is * printed to stdout.</pre> * * <pre> -r <name> * 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 <num> * The number of examples to generate (default 100)</pre> * * <pre> -a <num> * The number of attributes (default 10).</pre> * * <pre> -c <num> * The number of classes (default 2)</pre> * * <pre> -C <num> * The number of centroids to use. (default 50)</pre> * <!-- options-end --> * * @author Richard Kirkby (rkirkby at cs dot waikato dot ac dot nz) * @author FracPete (fracpete at waikato dot ac dot nz) * @version $Revision: 1.3 $ */public class RandomRBF extends ClassificationGenerator { /** for serialization */ static final long serialVersionUID = 6069033710635728720L; /** Number of attribute the dataset should have */ protected int m_NumAttributes; /** Number of Classes the dataset should have */ protected int m_NumClasses; /** the number of centroids to use for generation */ protected int m_NumCentroids; /** the centroids */ protected double[][] m_centroids; /** the classes of the centroids */ protected int[] m_centroidClasses; /** the weights of the centroids */ protected double[] m_centroidWeights; /** the stddevs of the centroids */ protected double[] m_centroidStdDevs; /** * initializes the generator with default values */ public RandomRBF() { super(); setNumAttributes(defaultNumAttributes()); setNumClasses(defaultNumClasses()); setNumCentroids(defaultNumCentroids()); } /** * 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 "RandomRBF data is generated by first creating a random set of " + "centers for each class. Each center is randomly assigned a weight, " + "a central point per attribute, and a standard deviation. To " + "generate new instances, a center is chosen at random taking the " + "weights of each center into consideration. Attribute values are " + "randomly generated and offset from the center, where the overall " + "vector has been scaled so that its length equals a value sampled " + "randomly from the Gaussian distribution of the center. The " + "particular center chosen determines the class of the instance.\n " + "RandomRBF data contains only numeric attributes as it is " + "non-trivial to include nominal values."; } /** * 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 number of attributes (default " + defaultNumAttributes() + ").", "a", 1, "-a <num>")); result.addElement(new Option( "\tThe number of classes (default " + defaultNumClasses() + ")", "c", 1, "-c <num>")); result.add(new Option( "\tThe number of centroids to use. (default " + defaultNumCentroids() + ")", "C", 1, "-C <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 <file> * The name of the output file, otherwise the generated data is * printed to stdout.</pre> * * <pre> -r <name> * 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 <num> * The number of examples to generate (default 100)</pre> * * <pre> -a <num> * The number of attributes (default 10).</pre> * * <pre> -c <num> * The number of classes (default 2)</pre> * * <pre> -C <num> * The number of centroids to use. (default 50)</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('a', options); if (tmpStr.length() != 0) setNumAttributes(Integer.parseInt(tmpStr)); else setNumAttributes(defaultNumAttributes()); tmpStr = Utils.getOption('c', options); if (tmpStr.length() != 0) setNumClasses(Integer.parseInt(tmpStr)); else setNumClasses(defaultNumClasses()); tmpStr = Utils.getOption('C', options); if (tmpStr.length() != 0) setNumCentroids(Integer.parseInt(tmpStr)); else setNumCentroids(defaultNumCentroids()); } /** * Gets the current settings of the datagenerator. * * @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("-a"); result.add("" + getNumAttributes()); result.add("-c"); result.add("" + getNumClasses()); result.add("-C"); result.add("" + getNumCentroids()); return (String[]) result.toArray(new String[result.size()]); } /** * returns the default number of attributes * * @return the default number of attributes */ protected int defaultNumAttributes() { return 10; } /** * Sets the number of attributes the dataset should have. * @param numAttributes the new number of attributes */ public void setNumAttributes(int numAttributes) { m_NumAttributes = numAttributes; } /** * Gets the number of attributes that should be produced. * @return the number of attributes that should be produced */ public int getNumAttributes() { return m_NumAttributes; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String numAttributesTipText() { return "The number of attributes the generated data will contain."; } /** * returns the default number of classes *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -