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
* RandomizableClassifier.java
19
* Copyright (C) 2004 University of Waikato, Hamilton, New Zealand
23
package weka.classifiers;
25
import weka.core.Option;
26
import weka.core.Randomizable;
27
import weka.core.Utils;
29
import java.util.Enumeration;
30
import java.util.Vector;
33
* Abstract utility class for handling settings common to randomizable
36
* @author Eibe Frank (eibe@cs.waikato.ac.nz)
37
* @version $Revision: 1.4 $
39
public abstract class RandomizableClassifier
40
extends Classifier implements Randomizable {
42
/** for serialization */
43
private static final long serialVersionUID = -8816375798262351903L;
45
/** The random number seed. */
46
protected int m_Seed = 1;
49
* Returns an enumeration describing the available options.
51
* @return an enumeration of all the available options.
53
public Enumeration listOptions() {
55
Vector newVector = new Vector(2);
57
newVector.addElement(new Option(
58
"\tRandom number seed.\n"
62
Enumeration enu = super.listOptions();
63
while (enu.hasMoreElements()) {
64
newVector.addElement(enu.nextElement());
66
return newVector.elements();
70
* Parses a given list of options. Valid options are:<p>
73
* Specify the full class name of the base learner.<p>
76
* Set the number of iterations (default 10). <p>
79
* Set the random number seed (default 1). <p>
81
* Options after -- are passed to the designated classifier.<p>
83
* @param options the list of options as an array of strings
84
* @exception Exception if an option is not supported
86
public void setOptions(String[] options) throws Exception {
88
String seed = Utils.getOption('S', options);
89
if (seed.length() != 0) {
90
setSeed(Integer.parseInt(seed));
95
super.setOptions(options);
99
* Gets the current settings of the classifier.
101
* @return an array of strings suitable for passing to setOptions
103
public String [] getOptions() {
105
String [] superOptions = super.getOptions();
106
String [] options = new String [superOptions.length + 2];
109
options[current++] = "-S";
110
options[current++] = "" + getSeed();
112
System.arraycopy(superOptions, 0, options, current,
113
superOptions.length);
119
* Returns the tip text for this property
120
* @return tip text for this property suitable for
121
* displaying in the explorer/experimenter gui
123
public String seedTipText() {
124
return "The random number seed to be used.";
128
* Set the seed for random number generation.
130
* @param seed the seed
132
public void setSeed(int seed) {
138
* Gets the seed for the random number generations
140
* @return the seed for the random number generation
142
public int getSeed() {