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: * RandomizableMultipleClassifiersCombiner.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 multiple classifiers based
035: * on a given random number seed.
036: *
037: * @author Eibe Frank (eibe@cs.waikato.ac.nz)
038: * @version $Revision: 1.4 $
039: */
040: public abstract class RandomizableMultipleClassifiersCombiner extends
041: MultipleClassifiersCombiner implements Randomizable {
042:
043: /** for serialization */
044: private static final long serialVersionUID = 5057936555724785679L;
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: * -B classifierstring <br>
072: * Classifierstring should contain the full class name of a scheme
073: * included for selection followed by options to the classifier
074: * (required, option should be used once for each classifier).<p>
075: *
076: * -S num <br>
077: * Set the random number seed (default 1). <p>
078: *
079: * @param options the list of options as an array of strings
080: * @exception Exception if an option is not supported
081: */
082: public void setOptions(String[] options) throws Exception {
083:
084: String seed = Utils.getOption('S', options);
085: if (seed.length() != 0) {
086: setSeed(Integer.parseInt(seed));
087: } else {
088: setSeed(1);
089: }
090:
091: super .setOptions(options);
092: }
093:
094: /**
095: * Gets the current settings of the classifier.
096: *
097: * @return an array of strings suitable for passing to setOptions
098: */
099: public String[] getOptions() {
100:
101: String[] super Options = super .getOptions();
102: String[] options = new String[super Options.length + 2];
103:
104: int current = 0;
105: options[current++] = "-S";
106: options[current++] = "" + getSeed();
107:
108: System.arraycopy(super Options, 0, options, current,
109: super Options.length);
110:
111: return options;
112: }
113:
114: /**
115: * Returns the tip text for this property
116: * @return tip text for this property suitable for
117: * displaying in the explorer/experimenter gui
118: */
119: public String seedTipText() {
120: return "The random number seed to be used.";
121: }
122:
123: /**
124: * Set the seed for random number generation.
125: *
126: * @param seed the seed
127: */
128: public void setSeed(int seed) {
129:
130: m_Seed = seed;
131: }
132:
133: /**
134: * Gets the seed for the random number generations
135: *
136: * @return the seed for the random number generation
137: */
138: public int getSeed() {
139:
140: return m_Seed;
141: }
142: }
|