[4] | 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 | * RandomizableParallelIteratedSingleClassifierEnhancer.java |
---|
| 19 | * Copyright (C) 2009 University of Waikato, Hamilton, New Zealand |
---|
| 20 | * |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | package weka.classifiers; |
---|
| 24 | |
---|
| 25 | import java.util.Enumeration; |
---|
| 26 | import java.util.Vector; |
---|
| 27 | |
---|
| 28 | import weka.core.Option; |
---|
| 29 | import weka.core.Utils; |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * Abstract utility class for handling settings common to randomizable |
---|
| 33 | * meta classifiers that build an ensemble in parallel from a single base |
---|
| 34 | * learner. |
---|
| 35 | * |
---|
| 36 | * @author Mark Hall (mhall{[at]}pentaho{[dot]}com) |
---|
| 37 | * @version $Revision: 6041 $ |
---|
| 38 | */ |
---|
| 39 | public abstract class RandomizableParallelIteratedSingleClassifierEnhancer |
---|
| 40 | extends ParallelIteratedSingleClassifierEnhancer { |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * For serialization |
---|
| 44 | */ |
---|
| 45 | private static final long serialVersionUID = 1298141000373615374L; |
---|
| 46 | |
---|
| 47 | /** The random number seed. */ |
---|
| 48 | protected int m_Seed = 1; |
---|
| 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 | |
---|
| 57 | Vector newVector = new Vector(2); |
---|
| 58 | |
---|
| 59 | newVector.addElement(new Option( |
---|
| 60 | "\tRandom number seed.\n" |
---|
| 61 | + "\t(default 1)", |
---|
| 62 | "S", 1, "-S <num>")); |
---|
| 63 | |
---|
| 64 | Enumeration enu = super.listOptions(); |
---|
| 65 | while (enu.hasMoreElements()) { |
---|
| 66 | newVector.addElement(enu.nextElement()); |
---|
| 67 | } |
---|
| 68 | return newVector.elements(); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /** |
---|
| 72 | * Parses a given list of options. Valid options are:<p> |
---|
| 73 | * |
---|
| 74 | * -W classname <br> |
---|
| 75 | * Specify the full class name of the base learner.<p> |
---|
| 76 | * |
---|
| 77 | * -I num <br> |
---|
| 78 | * Set the number of iterations (default 10). <p> |
---|
| 79 | * |
---|
| 80 | * -S num <br> |
---|
| 81 | * Set the random number seed (default 1). <p> |
---|
| 82 | * |
---|
| 83 | * Options after -- are passed to the designated classifier.<p> |
---|
| 84 | * |
---|
| 85 | * @param options the list of options as an array of strings |
---|
| 86 | * @exception Exception if an option is not supported |
---|
| 87 | */ |
---|
| 88 | public void setOptions(String[] options) throws Exception { |
---|
| 89 | |
---|
| 90 | String seed = Utils.getOption('S', options); |
---|
| 91 | if (seed.length() != 0) { |
---|
| 92 | setSeed(Integer.parseInt(seed)); |
---|
| 93 | } else { |
---|
| 94 | setSeed(1); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | super.setOptions(options); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | * Gets the current settings of the classifier. |
---|
| 102 | * |
---|
| 103 | * @return an array of strings suitable for passing to setOptions |
---|
| 104 | */ |
---|
| 105 | public String [] getOptions() { |
---|
| 106 | |
---|
| 107 | String [] superOptions = super.getOptions(); |
---|
| 108 | String [] options = new String [superOptions.length + 2]; |
---|
| 109 | |
---|
| 110 | int current = 0; |
---|
| 111 | options[current++] = "-S"; |
---|
| 112 | options[current++] = "" + getSeed(); |
---|
| 113 | |
---|
| 114 | System.arraycopy(superOptions, 0, options, current, |
---|
| 115 | superOptions.length); |
---|
| 116 | |
---|
| 117 | return options; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /** |
---|
| 121 | * Returns the tip text for this property |
---|
| 122 | * @return tip text for this property suitable for |
---|
| 123 | * displaying in the explorer/experimenter gui |
---|
| 124 | */ |
---|
| 125 | public String seedTipText() { |
---|
| 126 | return "The random number seed to be used."; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | * Set the seed for random number generation. |
---|
| 131 | * |
---|
| 132 | * @param seed the seed |
---|
| 133 | */ |
---|
| 134 | public void setSeed(int seed) { |
---|
| 135 | |
---|
| 136 | m_Seed = seed; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | * Gets the seed for the random number generations |
---|
| 141 | * |
---|
| 142 | * @return the seed for the random number generation |
---|
| 143 | */ |
---|
| 144 | public int getSeed() { |
---|
| 145 | |
---|
| 146 | return m_Seed; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | } |
---|