[29] | 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 | * RandomizableParallelMultipleClassifiersCombiner.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 |
---|
| 33 | * meta classifiers that build an ensemble in parallel using multiple |
---|
| 34 | * classifiers based on a given random number seed. |
---|
| 35 | * |
---|
| 36 | * @author Mark Hall (mhall{[at]}pentaho{[dot]}com) |
---|
| 37 | * @version $Revision: 6041 $ |
---|
| 38 | */ |
---|
| 39 | public abstract class RandomizableParallelMultipleClassifiersCombiner extends |
---|
| 40 | ParallelMultipleClassifiersCombiner { |
---|
| 41 | |
---|
| 42 | /** For serialization */ |
---|
| 43 | private static final long serialVersionUID = 8274061943448676943L; |
---|
| 44 | |
---|
| 45 | /** The random number seed. */ |
---|
| 46 | protected int m_Seed = 1; |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * Returns an enumeration describing the available options. |
---|
| 50 | * |
---|
| 51 | * @return an enumeration of all the available options. |
---|
| 52 | */ |
---|
| 53 | public Enumeration listOptions() { |
---|
| 54 | |
---|
| 55 | Vector newVector = new Vector(2); |
---|
| 56 | |
---|
| 57 | newVector.addElement(new Option( |
---|
| 58 | "\tRandom number seed.\n" |
---|
| 59 | + "\t(default 1)", |
---|
| 60 | "S", 1, "-S <num>")); |
---|
| 61 | |
---|
| 62 | Enumeration enu = super.listOptions(); |
---|
| 63 | while (enu.hasMoreElements()) { |
---|
| 64 | newVector.addElement(enu.nextElement()); |
---|
| 65 | } |
---|
| 66 | return newVector.elements(); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * Parses a given list of options. Valid options are:<p> |
---|
| 71 | * |
---|
| 72 | * -B classifierstring <br> |
---|
| 73 | * Classifierstring should contain the full class name of a scheme |
---|
| 74 | * included for selection followed by options to the classifier |
---|
| 75 | * (required, option should be used once for each classifier).<p> |
---|
| 76 | * |
---|
| 77 | * -S num <br> |
---|
| 78 | * Set the random number seed (default 1). <p> |
---|
| 79 | * |
---|
| 80 | * @param options the list of options as an array of strings |
---|
| 81 | * @exception Exception if an option is not supported |
---|
| 82 | */ |
---|
| 83 | public void setOptions(String[] options) throws Exception { |
---|
| 84 | |
---|
| 85 | String seed = Utils.getOption('S', options); |
---|
| 86 | if (seed.length() != 0) { |
---|
| 87 | setSeed(Integer.parseInt(seed)); |
---|
| 88 | } else { |
---|
| 89 | setSeed(1); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | super.setOptions(options); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * Gets the current settings of the classifier. |
---|
| 97 | * |
---|
| 98 | * @return an array of strings suitable for passing to setOptions |
---|
| 99 | */ |
---|
| 100 | public String [] getOptions() { |
---|
| 101 | |
---|
| 102 | String [] superOptions = super.getOptions(); |
---|
| 103 | String [] options = new String [superOptions.length + 2]; |
---|
| 104 | |
---|
| 105 | int current = 0; |
---|
| 106 | options[current++] = "-S"; |
---|
| 107 | options[current++] = "" + getSeed(); |
---|
| 108 | |
---|
| 109 | System.arraycopy(superOptions, 0, options, current, |
---|
| 110 | superOptions.length); |
---|
| 111 | |
---|
| 112 | return options; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * Returns the tip text for this property |
---|
| 117 | * @return tip text for this property suitable for |
---|
| 118 | * displaying in the explorer/experimenter gui |
---|
| 119 | */ |
---|
| 120 | public String seedTipText() { |
---|
| 121 | return "The random number seed to be used."; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | /** |
---|
| 125 | * Set the seed for random number generation. |
---|
| 126 | * |
---|
| 127 | * @param seed the seed |
---|
| 128 | */ |
---|
| 129 | public void setSeed(int seed) { |
---|
| 130 | |
---|
| 131 | m_Seed = seed; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | * Gets the seed for the random number generations |
---|
| 136 | * |
---|
| 137 | * @return the seed for the random number generation |
---|
| 138 | */ |
---|
| 139 | public int getSeed() { |
---|
| 140 | |
---|
| 141 | return m_Seed; |
---|
| 142 | } |
---|
| 143 | } |
---|