001: /*
002: * This program is free software; you can redistribute it and/or modify
003: * it under the terms of the GNU General Public License as published by
004: * the Free Software Foundation; either version 2 of the License, or
005: * (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU General Public License for more details.
011: *
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
015: */
016:
017: /*
018: * RandomizableSingleClassifierEnhancer.java
019: * Copyright (C) 2004 University of Waikato, Hamilton, New Zealand
020: *
021: */
022:
023: package weka.classifiers;
024:
025: import weka.core.Option;
026: import weka.core.Randomizable;
027: import weka.core.Utils;
028:
029: import java.util.Enumeration;
030: import java.util.Vector;
031:
032: /**
033: * Abstract utility class for handling settings common to randomizable
034: * meta classifiers that build an ensemble from a single base learner.
035: *
036: * @author Eibe Frank (eibe@cs.waikato.ac.nz)
037: * @version $Revision: 1.4 $
038: */
039: public abstract class RandomizableSingleClassifierEnhancer extends
040: SingleClassifierEnhancer implements Randomizable {
041:
042: /** for serialization */
043: private static final long serialVersionUID = 558286687096157160L;
044:
045: /** The random number seed. */
046: protected int m_Seed = 1;
047:
048: /**
049: * Returns an enumeration describing the available options.
050: *
051: * @return an enumeration of all the available options.
052: */
053: public Enumeration listOptions() {
054:
055: Vector newVector = new Vector(2);
056:
057: newVector.addElement(new Option("\tRandom number seed.\n"
058: + "\t(default 1)", "S", 1, "-S <num>"));
059:
060: Enumeration enu = super .listOptions();
061: while (enu.hasMoreElements()) {
062: newVector.addElement(enu.nextElement());
063: }
064: return newVector.elements();
065: }
066:
067: /**
068: * Parses a given list of options. Valid options are:<p>
069: *
070: * -W classname <br>
071: * Specify the full class name of the base learner.<p>
072: *
073: * -I num <br>
074: * Set the number of iterations (default 10). <p>
075: *
076: * -S num <br>
077: * Set the random number seed (default 1). <p>
078: *
079: * Options after -- are passed to the designated classifier.<p>
080: *
081: * @param options the list of options as an array of strings
082: * @exception Exception if an option is not supported
083: */
084: public void setOptions(String[] options) throws Exception {
085:
086: String seed = Utils.getOption('S', options);
087: if (seed.length() != 0) {
088: setSeed(Integer.parseInt(seed));
089: } else {
090: setSeed(1);
091: }
092:
093: super .setOptions(options);
094: }
095:
096: /**
097: * Gets the current settings of the classifier.
098: *
099: * @return an array of strings suitable for passing to setOptions
100: */
101: public String[] getOptions() {
102:
103: String[] super Options = super .getOptions();
104: String[] options = new String[super Options.length + 2];
105:
106: int current = 0;
107: options[current++] = "-S";
108: options[current++] = "" + getSeed();
109:
110: System.arraycopy(super Options, 0, options, current,
111: super Options.length);
112:
113: return options;
114: }
115:
116: /**
117: * Returns the tip text for this property
118: * @return tip text for this property suitable for
119: * displaying in the explorer/experimenter gui
120: */
121: public String seedTipText() {
122: return "The random number seed to be used.";
123: }
124:
125: /**
126: * Set the seed for random number generation.
127: *
128: * @param seed the seed
129: */
130: public void setSeed(int seed) {
131:
132: m_Seed = seed;
133: }
134:
135: /**
136: * Gets the seed for the random number generations
137: *
138: * @return the seed for the random number generation
139: */
140: public int getSeed() {
141:
142: return m_Seed;
143: }
144: }
|