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 | * ClassificationGenerator.java |
---|
19 | * Copyright (C) 2000 University of Waikato, Hamilton, New Zealand |
---|
20 | * |
---|
21 | */ |
---|
22 | |
---|
23 | package weka.datagenerators; |
---|
24 | |
---|
25 | import weka.core.Option; |
---|
26 | import weka.core.Utils; |
---|
27 | |
---|
28 | import java.util.Enumeration; |
---|
29 | import java.util.Vector; |
---|
30 | |
---|
31 | /** |
---|
32 | * Abstract class for data generators for classifiers. <p/> |
---|
33 | * |
---|
34 | * @author Gabi Schmidberger (gabi@cs.waikato.ac.nz) |
---|
35 | * @author FracPete (fracpete at waikato dot ac dot nz) |
---|
36 | * @version $Revision: 1.4 $ |
---|
37 | */ |
---|
38 | public abstract class ClassificationGenerator |
---|
39 | extends DataGenerator { |
---|
40 | |
---|
41 | /** for serialization */ |
---|
42 | private static final long serialVersionUID = -5261662546673517844L; |
---|
43 | |
---|
44 | /** Number of instances*/ |
---|
45 | protected int m_NumExamples; |
---|
46 | |
---|
47 | /** |
---|
48 | * initializes with default values |
---|
49 | */ |
---|
50 | public ClassificationGenerator() { |
---|
51 | super(); |
---|
52 | |
---|
53 | setNumExamples(defaultNumExamples()); |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * Returns an enumeration describing the available options. |
---|
58 | * |
---|
59 | * @return an enumeration of all the available options. |
---|
60 | */ |
---|
61 | public Enumeration listOptions() { |
---|
62 | Vector result = enumToVector(super.listOptions()); |
---|
63 | |
---|
64 | result.addElement(new Option( |
---|
65 | "\tThe number of examples to generate (default " |
---|
66 | + defaultNumExamples() + ")", |
---|
67 | "n", 1, "-n <num>")); |
---|
68 | |
---|
69 | return result.elements(); |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * Sets the options. |
---|
74 | * |
---|
75 | * @param options the options |
---|
76 | * @throws Exception if invalid option |
---|
77 | */ |
---|
78 | public void setOptions(String[] options) throws Exception { |
---|
79 | String tmpStr; |
---|
80 | |
---|
81 | super.setOptions(options); |
---|
82 | |
---|
83 | tmpStr = Utils.getOption('n', options); |
---|
84 | if (tmpStr.length() != 0) |
---|
85 | setNumExamples(Integer.parseInt(tmpStr)); |
---|
86 | else |
---|
87 | setNumExamples(defaultNumExamples()); |
---|
88 | } |
---|
89 | |
---|
90 | /** |
---|
91 | * Gets the current settings of the classifier. |
---|
92 | * |
---|
93 | * @return an array of strings suitable for passing to setOptions |
---|
94 | */ |
---|
95 | public String[] getOptions() { |
---|
96 | Vector result; |
---|
97 | String[] options; |
---|
98 | int i; |
---|
99 | |
---|
100 | result = new Vector(); |
---|
101 | options = super.getOptions(); |
---|
102 | for (i = 0; i < options.length; i++) |
---|
103 | result.add(options[i]); |
---|
104 | |
---|
105 | result.add("-n"); |
---|
106 | result.add("" + getNumExamples()); |
---|
107 | |
---|
108 | return (String[]) result.toArray(new String[result.size()]); |
---|
109 | } |
---|
110 | |
---|
111 | /** |
---|
112 | * returns the default number of examples |
---|
113 | * |
---|
114 | * @return the default number of examples |
---|
115 | */ |
---|
116 | protected int defaultNumExamples() { |
---|
117 | return 100; |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | * Sets the number of examples, given by option. |
---|
122 | * @param numExamples the new number of examples |
---|
123 | */ |
---|
124 | public void setNumExamples(int numExamples) { |
---|
125 | m_NumExamples = numExamples; |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * Gets the number of examples, given by option. |
---|
130 | * @return the number of examples, given by option |
---|
131 | */ |
---|
132 | public int getNumExamples() { |
---|
133 | return m_NumExamples; |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * Returns the tip text for this property |
---|
138 | * |
---|
139 | * @return tip text for this property suitable for |
---|
140 | * displaying in the explorer/experimenter gui |
---|
141 | */ |
---|
142 | public String numExamplesTipText() { |
---|
143 | return "The number of examples to generate."; |
---|
144 | } |
---|
145 | } |
---|