source: branches/MetisMQI/src/main/java/weka/datagenerators/RegressionGenerator.java

Last change on this file was 29, checked in by gnappo, 15 years ago

Taggata versione per la demo e aggiunto branch.

File size: 4.0 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 * RegressionGenerator.java
19 * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.datagenerators;
24
25import weka.core.Option;
26import weka.core.Utils;
27import weka.datagenerators.DataGenerator;
28
29import java.util.Enumeration;
30import java.util.Vector;
31
32/**
33 * Abstract class for data generators for regression classifiers. <p/>
34 *
35 * Example usage as the main of a datagenerator called RandomGenerator:
36 * <pre>
37 * public static void main(String[] args) {
38 *   try {
39 *     DataGenerator.makeData(new RandomGenerator(), args);
40 *   }
41 *   catch (Exception e) {
42 *     e.printStackTrace();
43 *     System.err.println(e.getMessage());
44 *   }
45 * }
46 * </pre>
47 *
48 * @author FracPete (fracpete at waikato dot ac dot nz)
49 * @version $Revision: 1.3 $
50 */
51public abstract class RegressionGenerator 
52  extends DataGenerator {
53
54  /** for serialization */
55  private static final long serialVersionUID = 3073254041275658221L;
56
57  /** Number of instances*/
58  protected int m_NumExamples;
59
60  /**
61   * initializes the generator with default values
62   */
63  public RegressionGenerator() {
64    super();
65
66    setNumExamples(defaultNumExamples());
67  }
68 
69  /**
70   * Returns an enumeration describing the available options.
71   *
72   * @return an enumeration of all the available options.
73   */
74  public Enumeration listOptions() {
75    Vector result = enumToVector(super.listOptions());
76
77    result.addElement(new Option(
78        "\tThe number of examples to generate (default " 
79        + defaultNumExamples() + ")",
80        "n", 1, "-n <num>"));
81   
82    return result.elements();
83  }
84
85  /**
86   * Sets the options.
87   *
88   * @param options the options
89   * @throws Exception if invalid option
90   */
91  public void setOptions(String[] options) throws Exception { 
92    String        tmpStr;
93   
94    super.setOptions(options);
95
96    tmpStr = Utils.getOption('n', options);
97    if (tmpStr.length() != 0)
98      setNumExamples(Integer.parseInt(tmpStr));
99    else
100      setNumExamples(defaultNumExamples());
101  }
102 
103  /**
104   * Gets the current settings of the classifier.
105   *
106   * @return an array of strings suitable for passing to setOptions
107   */
108  public String[] getOptions() {
109    Vector        result;
110    String[]      options;
111    int           i;
112   
113    result  = new Vector();
114    options = super.getOptions();
115    for (i = 0; i < options.length; i++)
116      result.add(options[i]);
117   
118    result.add("-n");
119    result.add("" + getNumExamples());
120   
121    return (String[]) result.toArray(new String[result.size()]);
122  }
123
124  /**
125   * returns the default number of examples
126   *
127   * @return the default number of examples
128   */
129  protected int defaultNumExamples() {
130    return 100;
131  }
132
133  /**
134   * Sets the number of examples, given by option.
135   * @param numExamples the new number of examples
136   */
137  public void setNumExamples(int numExamples) { 
138    m_NumExamples = numExamples; 
139  }
140
141  /**
142   * Gets the number of examples, given by option.
143   * @return the number of examples, given by option
144   */
145  public int getNumExamples() { 
146    return m_NumExamples; 
147  }
148 
149  /**
150   * Returns the tip text for this property
151   *
152   * @return tip text for this property suitable for
153   *         displaying in the explorer/experimenter gui
154   */
155  public String numExamplesTipText() {
156    return "The number of examples to generate.";
157  }
158}
Note: See TracBrowser for help on using the repository browser.