| 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 | * RandomizableSingleClustererEnhancer.java |
|---|
| 19 | * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | package weka.clusterers; |
|---|
| 24 | |
|---|
| 25 | import weka.core.Option; |
|---|
| 26 | import weka.core.OptionHandler; |
|---|
| 27 | import weka.core.Randomizable; |
|---|
| 28 | import weka.core.Utils; |
|---|
| 29 | |
|---|
| 30 | import java.util.Enumeration; |
|---|
| 31 | import java.util.Vector; |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * Abstract utility class for handling settings common to randomizable |
|---|
| 35 | * clusterers. |
|---|
| 36 | * |
|---|
| 37 | * @author FracPete (fracpete at waikato dot ac dot nz) |
|---|
| 38 | * @version $Revision: 1.3 $ |
|---|
| 39 | */ |
|---|
| 40 | public abstract class RandomizableSingleClustererEnhancer |
|---|
| 41 | extends AbstractClusterer |
|---|
| 42 | implements OptionHandler, Randomizable { |
|---|
| 43 | |
|---|
| 44 | /** for serialization */ |
|---|
| 45 | private static final long serialVersionUID = -644847037106316249L; |
|---|
| 46 | |
|---|
| 47 | /** the default seed value */ |
|---|
| 48 | protected int m_SeedDefault = 1; |
|---|
| 49 | |
|---|
| 50 | /** The random number seed. */ |
|---|
| 51 | protected int m_Seed = m_SeedDefault; |
|---|
| 52 | |
|---|
| 53 | /** |
|---|
| 54 | * Returns an enumeration describing the available options. |
|---|
| 55 | * |
|---|
| 56 | * @return an enumeration of all the available options. |
|---|
| 57 | */ |
|---|
| 58 | public Enumeration listOptions() { |
|---|
| 59 | Vector result = new Vector(); |
|---|
| 60 | |
|---|
| 61 | result.addElement(new Option( |
|---|
| 62 | "\tRandom number seed.\n" |
|---|
| 63 | + "\t(default " + m_SeedDefault + ")", |
|---|
| 64 | "S", 1, "-S <num>")); |
|---|
| 65 | |
|---|
| 66 | return result.elements(); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | /** |
|---|
| 70 | * Parses a given list of options. Valid options are:<p> |
|---|
| 71 | * |
|---|
| 72 | * @param options the list of options as an array of strings |
|---|
| 73 | * @throws Exception if an option is not supported |
|---|
| 74 | */ |
|---|
| 75 | public void setOptions(String[] options) throws Exception { |
|---|
| 76 | String tmpStr; |
|---|
| 77 | |
|---|
| 78 | tmpStr = Utils.getOption('S', options); |
|---|
| 79 | if (tmpStr.length() != 0) |
|---|
| 80 | setSeed(Integer.parseInt(tmpStr)); |
|---|
| 81 | else |
|---|
| 82 | setSeed(m_SeedDefault); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | /** |
|---|
| 86 | * Gets the current settings of the classifier. |
|---|
| 87 | * |
|---|
| 88 | * @return an array of strings suitable for passing to setOptions |
|---|
| 89 | */ |
|---|
| 90 | public String[] getOptions() { |
|---|
| 91 | Vector result; |
|---|
| 92 | |
|---|
| 93 | result = new Vector(); |
|---|
| 94 | |
|---|
| 95 | result.add("-S"); |
|---|
| 96 | result.add("" + getSeed()); |
|---|
| 97 | |
|---|
| 98 | return (String[]) result.toArray(new String[result.size()]); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | /** |
|---|
| 102 | * Returns the tip text for this property |
|---|
| 103 | * |
|---|
| 104 | * @return tip text for this property suitable for |
|---|
| 105 | * displaying in the explorer/experimenter gui |
|---|
| 106 | */ |
|---|
| 107 | public String seedTipText() { |
|---|
| 108 | return "The random number seed to be used."; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * Set the seed for random number generation. |
|---|
| 113 | * |
|---|
| 114 | * @param value the seed to use |
|---|
| 115 | */ |
|---|
| 116 | public void setSeed(int value) { |
|---|
| 117 | m_Seed = value; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | /** |
|---|
| 121 | * Gets the seed for the random number generations |
|---|
| 122 | * |
|---|
| 123 | * @return the seed for the random number generation |
|---|
| 124 | */ |
|---|
| 125 | public int getSeed() { |
|---|
| 126 | return m_Seed; |
|---|
| 127 | } |
|---|
| 128 | } |
|---|