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.
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.
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.
18
* RegressionGenerator.java
19
* Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
23
package weka.datagenerators;
25
import weka.core.Option;
26
import weka.core.Utils;
27
import weka.datagenerators.DataGenerator;
29
import java.util.Enumeration;
30
import java.util.Vector;
33
* Abstract class for data generators for regression classifiers. <p/>
35
* Example usage as the main of a datagenerator called RandomGenerator:
37
* public static void main(String[] args) {
39
* DataGenerator.makeData(new RandomGenerator(), args);
41
* catch (Exception e) {
42
* e.printStackTrace();
43
* System.err.println(e.getMessage());
48
* @author FracPete (fracpete at waikato dot ac dot nz)
49
* @version $Revision: 1.3 $
51
public abstract class RegressionGenerator
52
extends DataGenerator {
54
/** for serialization */
55
private static final long serialVersionUID = 3073254041275658221L;
57
/** Number of instances*/
58
protected int m_NumExamples;
61
* initializes the generator with default values
63
public RegressionGenerator() {
66
setNumExamples(defaultNumExamples());
70
* Returns an enumeration describing the available options.
72
* @return an enumeration of all the available options.
74
public Enumeration listOptions() {
75
Vector result = enumToVector(super.listOptions());
77
result.addElement(new Option(
78
"\tThe number of examples to generate (default "
79
+ defaultNumExamples() + ")",
82
return result.elements();
88
* @param options the options
89
* @throws Exception if invalid option
91
public void setOptions(String[] options) throws Exception {
94
super.setOptions(options);
96
tmpStr = Utils.getOption('n', options);
97
if (tmpStr.length() != 0)
98
setNumExamples(Integer.parseInt(tmpStr));
100
setNumExamples(defaultNumExamples());
104
* Gets the current settings of the classifier.
106
* @return an array of strings suitable for passing to setOptions
108
public String[] getOptions() {
113
result = new Vector();
114
options = super.getOptions();
115
for (i = 0; i < options.length; i++)
116
result.add(options[i]);
119
result.add("" + getNumExamples());
121
return (String[]) result.toArray(new String[result.size()]);
125
* returns the default number of examples
127
* @return the default number of examples
129
protected int defaultNumExamples() {
134
* Sets the number of examples, given by option.
135
* @param numExamples the new number of examples
137
public void setNumExamples(int numExamples) {
138
m_NumExamples = numExamples;
142
* Gets the number of examples, given by option.
143
* @return the number of examples, given by option
145
public int getNumExamples() {
146
return m_NumExamples;
150
* Returns the tip text for this property
152
* @return tip text for this property suitable for
153
* displaying in the explorer/experimenter gui
155
public String numExamplesTipText() {
156
return "The number of examples to generate.";