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 | * RandomizableRangedGenerator.java |
---|
19 | * Copyright (C) 2008 University of Waikato, Hamilton, New Zealand |
---|
20 | */ |
---|
21 | |
---|
22 | package weka.classifiers.meta.generators; |
---|
23 | |
---|
24 | import weka.core.Option; |
---|
25 | import weka.core.Utils; |
---|
26 | |
---|
27 | import java.util.Enumeration; |
---|
28 | import java.util.Vector; |
---|
29 | |
---|
30 | /** |
---|
31 | * Abstract superclass for generators that take ranges and use a seeded random |
---|
32 | * number generator internally |
---|
33 | * |
---|
34 | * @author fracpete (fracpete at waikato dot ac dot nz) |
---|
35 | * @version $Revision: 5793 $ |
---|
36 | */ |
---|
37 | public abstract class RandomizableRangedGenerator |
---|
38 | extends RandomizableGenerator |
---|
39 | implements Ranged { |
---|
40 | |
---|
41 | /** for serialization. */ |
---|
42 | private static final long serialVersionUID = -5766761200929361752L; |
---|
43 | |
---|
44 | /** The lower range of this generator. */ |
---|
45 | protected double m_LowerRange = 0.0; |
---|
46 | |
---|
47 | /** The upper range of this generator. */ |
---|
48 | protected double m_UpperRange = 1.0; |
---|
49 | |
---|
50 | /** |
---|
51 | * Returns an enumeration describing the available options. |
---|
52 | * |
---|
53 | * @return an enumeration of all the available options. |
---|
54 | */ |
---|
55 | public Enumeration listOptions() { |
---|
56 | Vector result = new Vector(); |
---|
57 | |
---|
58 | Enumeration enu = super.listOptions(); |
---|
59 | while (enu.hasMoreElements()) |
---|
60 | result.addElement(enu.nextElement()); |
---|
61 | |
---|
62 | result.addElement(new Option( |
---|
63 | "\tSets the lower range of the generator\n" |
---|
64 | + "\t(default: 0)", |
---|
65 | "L", 1, "-L <num>")); |
---|
66 | |
---|
67 | result.addElement(new Option( |
---|
68 | "\tSets the upper range of the generator\n" |
---|
69 | + "\t(default: 1)", |
---|
70 | "U", 1, "-U <num>")); |
---|
71 | |
---|
72 | return result.elements(); |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * Parses a given list of options. |
---|
77 | * |
---|
78 | * @param options the list of options as an array of strings |
---|
79 | * @throws Exception if an option is not supported |
---|
80 | */ |
---|
81 | public void setOptions(String[] options) throws Exception { |
---|
82 | String tmpStr; |
---|
83 | |
---|
84 | super.setOptions(options); |
---|
85 | |
---|
86 | tmpStr = Utils.getOption("L", options); |
---|
87 | if (tmpStr.length() != 0) |
---|
88 | setLowerRange(Double.parseDouble(tmpStr)); |
---|
89 | else |
---|
90 | setLowerRange(0.0); |
---|
91 | |
---|
92 | tmpStr = Utils.getOption("U", options); |
---|
93 | if (tmpStr.length() != 0) |
---|
94 | setUpperRange(Double.parseDouble(tmpStr)); |
---|
95 | else |
---|
96 | setUpperRange(1.0); |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | * Gets the current settings of the Classifier. |
---|
101 | * |
---|
102 | * @return an array of strings suitable for passing to setOptions |
---|
103 | */ |
---|
104 | public String [] getOptions() { |
---|
105 | Vector<String> result; |
---|
106 | String[] options; |
---|
107 | int i; |
---|
108 | |
---|
109 | result = new Vector<String>(); |
---|
110 | |
---|
111 | options = super.getOptions(); |
---|
112 | for (i = 0; i < options.length; i++) |
---|
113 | result.add(options[i]); |
---|
114 | |
---|
115 | result.add("-L"); |
---|
116 | result.add("" + m_LowerRange); |
---|
117 | |
---|
118 | result.add("-U"); |
---|
119 | result.add("" + m_UpperRange); |
---|
120 | |
---|
121 | return result.toArray(new String[result.size()]); |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | * Gets the lower range of the generator. |
---|
126 | * |
---|
127 | * @return The lower range of this generator. |
---|
128 | */ |
---|
129 | public double getLowerRange() { |
---|
130 | return m_LowerRange; |
---|
131 | } |
---|
132 | |
---|
133 | /** |
---|
134 | * Sets the lower range. |
---|
135 | * |
---|
136 | * @param value The lower range of the generator. |
---|
137 | */ |
---|
138 | public void setLowerRange(double value) { |
---|
139 | m_LowerRange = value; |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | * Returns the tip text for this property. |
---|
144 | * |
---|
145 | * @return tip text for this property suitable for |
---|
146 | * displaying in the explorer/experimenter gui |
---|
147 | */ |
---|
148 | public String lowerRangeTipText() { |
---|
149 | return "The lower range."; |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | * Gets the upper range of the generator. |
---|
154 | * |
---|
155 | * @return The upper range of this generator. |
---|
156 | */ |
---|
157 | public double getUpperRange() { |
---|
158 | return m_UpperRange; |
---|
159 | } |
---|
160 | |
---|
161 | /** |
---|
162 | * Sets the upper range. |
---|
163 | * |
---|
164 | * @param value The upper range of the generator. |
---|
165 | */ |
---|
166 | public void setUpperRange(double value) { |
---|
167 | m_UpperRange = value; |
---|
168 | } |
---|
169 | |
---|
170 | /** |
---|
171 | * Returns the tip text for this property. |
---|
172 | * |
---|
173 | * @return tip text for this property suitable for |
---|
174 | * displaying in the explorer/experimenter gui |
---|
175 | */ |
---|
176 | public String upperRangeTipText() { |
---|
177 | return "The upper range."; |
---|
178 | } |
---|
179 | } |
---|