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: * RandomizableIteratedSingleClassifierEnhancer.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 RandomizableIteratedSingleClassifierEnhancer
040: extends IteratedSingleClassifierEnhancer implements
041: Randomizable {
042:
043: /** for serialization */
044: private static final long serialVersionUID = 5063351391524938557L;
045:
046: /** The random number seed. */
047: protected int m_Seed = 1;
048:
049: /**
050: * Returns an enumeration describing the available options.
051: *
052: * @return an enumeration of all the available options.
053: */
054: public Enumeration listOptions() {
055:
056: Vector newVector = new Vector(2);
057:
058: newVector.addElement(new Option("\tRandom number seed.\n"
059: + "\t(default 1)", "S", 1, "-S <num>"));
060:
061: Enumeration enu = super .listOptions();
062: while (enu.hasMoreElements()) {
063: newVector.addElement(enu.nextElement());
064: }
065: return newVector.elements();
066: }
067:
068: /**
069: * Parses a given list of options. Valid options are:<p>
070: *
071: * -W classname <br>
072: * Specify the full class name of the base learner.<p>
073: *
074: * -I num <br>
075: * Set the number of iterations (default 10). <p>
076: *
077: * -S num <br>
078: * Set the random number seed (default 1). <p>
079: *
080: * Options after -- are passed to the designated classifier.<p>
081: *
082: * @param options the list of options as an array of strings
083: * @exception Exception if an option is not supported
084: */
085: public void setOptions(String[] options) throws Exception {
086:
087: String seed = Utils.getOption('S', options);
088: if (seed.length() != 0) {
089: setSeed(Integer.parseInt(seed));
090: } else {
091: setSeed(1);
092: }
093:
094: super .setOptions(options);
095: }
096:
097: /**
098: * Gets the current settings of the classifier.
099: *
100: * @return an array of strings suitable for passing to setOptions
101: */
102: public String[] getOptions() {
103:
104: String[] super Options = super .getOptions();
105: String[] options = new String[super Options.length + 2];
106:
107: int current = 0;
108: options[current++] = "-S";
109: options[current++] = "" + getSeed();
110:
111: System.arraycopy(super Options, 0, options, current,
112: super Options.length);
113:
114: return options;
115: }
116:
117: /**
118: * Returns the tip text for this property
119: * @return tip text for this property suitable for
120: * displaying in the explorer/experimenter gui
121: */
122: public String seedTipText() {
123: return "The random number seed to be used.";
124: }
125:
126: /**
127: * Set the seed for random number generation.
128: *
129: * @param seed the seed
130: */
131: public void setSeed(int seed) {
132:
133: m_Seed = seed;
134: }
135:
136: /**
137: * Gets the seed for the random number generations
138: *
139: * @return the seed for the random number generation
140: */
141: public int getSeed() {
142:
143: return m_Seed;
144: }
145: }
|