source: src/main/java/weka/gui/experiment/ExperimenterDefaults.java @ 14

Last change on this file since 14 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 9.6 KB
RevLine 
[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 * ExperimenterDefaults.java
19 * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.gui.experiment;
24
25import weka.core.Utils;
26import weka.experiment.PairedCorrectedTTester;
27import weka.experiment.ResultMatrix;
28import weka.experiment.ResultMatrixPlainText;
29import weka.experiment.Tester;
30
31import java.io.File;
32import java.io.Serializable;
33import java.util.Collections;
34import java.util.Enumeration;
35import java.util.Properties;
36import java.util.Vector;
37
38/**
39 * This class offers get methods for the default Experimenter settings in
40 * the props file <code>weka/gui/experiment/Experimenter.props</code>.
41 *
42 * @author  FracPete (fracpete at waikato dot ac dot nz)
43 * @version $Revision: 5367 $
44 * @see #PROPERTY_FILE
45 */
46public class ExperimenterDefaults
47  implements Serializable {
48 
49  /** for serialization. */
50  static final long serialVersionUID = -2835933184632147981L;
51 
52  /** The name of the properties file. */
53  public final static String PROPERTY_FILE = "weka/gui/experiment/Experimenter.props";
54
55  /** Properties associated with the experimenter options. */
56  protected static Properties PROPERTIES;
57  static {
58    try {
59      PROPERTIES = Utils.readProperties(PROPERTY_FILE);
60    }
61    catch (Exception e) {
62      System.err.println("Problem reading properties. Fix before continuing.");
63      e.printStackTrace();
64      PROPERTIES = new Properties();
65    }
66  }
67
68  /**
69   * returns the value for the specified property, if non-existent then the
70   * default value.
71   *
72   * @param property      the property to retrieve the value for
73   * @param defaultValue  the default value for the property
74   * @return              the value of the specified property
75   */
76  public static String get(String property, String defaultValue) {
77    return PROPERTIES.getProperty(property, defaultValue);
78  }
79
80  /**
81   * returns the associated properties file.
82   *
83   * @return              the props file
84   */
85  public final static Properties getProperties() {
86    return PROPERTIES;
87  }
88
89  /**
90   * returns the default experiment extension.
91   *
92   * @return              the extension (incl. dot)
93   */
94  public final static String getExtension() {
95    return get("Extension", ".exp");
96  }
97
98  /**
99   * returns the default destination.
100   *
101   * @return              the destination
102   */
103  public final static String getDestination() {
104    return get("Destination", "ARFF file");
105  }
106
107  /**
108   * returns the default experiment type.
109   *
110   * @return              the type
111   */
112  public final static String getExperimentType() {
113    return get("ExperimentType", "Cross-validation");
114  }
115
116  /**
117   * whether classification or regression is used.
118   *
119   * @return              true if classification
120   */
121  public final static boolean getUseClassification() {
122    return Boolean.valueOf(get("UseClassification", "true")).booleanValue();
123  }
124
125  /**
126   * returns the number of folds used for cross-validation.
127   *
128   * @return              the number of folds
129   */
130  public final static int getFolds() {
131    return Integer.parseInt(get("Folds", "10"));
132  }
133
134  /**
135   * returns the training percentage in case of splits.
136   *
137   * @return              the percentage (0-100)
138   */
139  public final static double getTrainPercentage() {
140    return Integer.parseInt(get("TrainPercentage", "66"));
141  }
142
143  /**
144   * returns the number of repetitions to use.
145   *
146   * @return              the repetitions/runs
147   */
148  public final static int getRepetitions() {
149    return Integer.parseInt(get("Repetitions", "10"));
150  }
151
152  /**
153   * whether datasets or algorithms are iterated first.
154   *
155   * @return              true if datasets are iterated first
156   */
157  public final static boolean getDatasetsFirst() {
158    return Boolean.valueOf(get("DatasetsFirst", "true")).booleanValue();
159  }
160
161  /**
162   * returns the initial directory for the datasets (if empty, it returns
163   * the user's home directory).
164   *
165   * @return              the directory
166   */
167  public final static File getInitialDatasetsDirectory() {
168    String    dir;
169   
170    dir = get("InitialDatasetsDirectory", "");
171    if (dir.equals(""))
172      dir = System.getProperty("user.dir");
173
174    return new File(dir);
175  }
176
177  /**
178   * whether relative paths are used by default.
179   *
180   * @return              true if relative paths are used
181   */
182  public final static boolean getUseRelativePaths() {
183    return Boolean.valueOf(get("UseRelativePaths", "false")).booleanValue();
184  }
185
186  /**
187   * returns the display name of the preferred Tester algorithm.
188   *
189   * @return              the display name
190   * @see Tester
191   * @see PairedCorrectedTTester
192   */
193  public final static String getTester() {
194    return get("Tester", new PairedCorrectedTTester().getDisplayName());
195  }
196
197  /**
198   * the comma-separated list of attribute names that identify a row.
199   *
200   * @return              the attribute list
201   */
202  public final static String getRow() {
203    return get("Row", "Key_Dataset");
204  }
205
206  /**
207   * the comma-separated list of attribute names that identify a column.
208   *
209   * @return              the attribute list
210   */
211  public final static String getColumn() {
212    return get("Column", "Key_Scheme,Key_Scheme_options,Key_Scheme_version_ID");
213  }
214
215  /**
216   * returns the name of the field used for comparison.
217   *
218   * @return              the comparison field
219   */
220  public final static String getComparisonField() {
221    return get("ComparisonField", "percent_correct");
222  }
223
224  /**
225   * returns the default significance.
226   *
227   * @return              the significance (0.0-1.0)
228   */
229  public final static double getSignificance() {
230    return Double.parseDouble(get("Significance", "0.05"));
231  }
232
233  /**
234   * returns the default sorting (empty string means none).
235   *
236   * @return              the sorting field
237   */
238  public final static String getSorting() {
239    return get("Sorting", "");
240  }
241
242  /**
243   * returns whether StdDevs are shown by default.
244   *
245   * @return              true if stddevs are shown
246   */
247  public final static boolean getShowStdDevs() {
248    return Boolean.valueOf(get("ShowStdDev", "false")).booleanValue();
249  }
250
251  /**
252   * returns whether the Average is shown by default.
253   *
254   * @return              true if the average is shown
255   */
256  public final static boolean getShowAverage() {
257    return Boolean.valueOf(get("ShowAverage", "false")).booleanValue();
258  }
259
260  /**
261   * returns the default precision for the mean.
262   *
263   * @return              the decimals of the mean
264   */
265  public final static int getMeanPrecision() {
266    return Integer.parseInt(get("MeanPrecision", "2"));
267  }
268
269  /**
270   * returns the default precision for the stddevs.
271   *
272   * @return              the decimals of the stddevs
273   */
274  public final static int getStdDevPrecision() {
275    return Integer.parseInt(get("StdDevPrecision", "2"));
276  }
277
278  /**
279   * returns the classname (and optional options) of the ResultMatrix class,
280   * responsible for the output format.
281   *
282   * @return              the classname and options
283   * @see ResultMatrix
284   * @see ResultMatrixPlainText
285   */
286  public final static ResultMatrix getOutputFormat() {
287    ResultMatrix        result;
288   
289    try {
290      String[] options = Utils.splitOptions(get("OutputFormat", ResultMatrix.class.getName() + " -col-name-width 0 -row-name-width 25 -mean-width 0 -stddev-width 0 -sig-width 0 -count-width 5 -print-col-names -print-row-names -enum-col-names"));
291      String classname = options[0];
292      options[0]       = "";
293      result           = (ResultMatrix) Utils.forName(ResultMatrix.class, classname, options);
294    }
295    catch (Exception e) {
296      e.printStackTrace();
297      result = new ResultMatrixPlainText();
298    }
299   
300    // override with other default properties
301    result.setMeanPrec(getMeanPrecision());
302    result.setStdDevPrec(getStdDevPrecision());
303    result.setShowAverage(getShowAverage());
304    result.setShowStdDev(getShowStdDevs());
305    result.setRemoveFilterName(getRemoveFilterClassnames());
306
307    return result;
308  }
309
310  /**
311   * whether the filter classnames in the dataset names are removed by default.
312   *
313   * @return              true if filter names are removed
314   */
315  public final static boolean getRemoveFilterClassnames() {
316    return Boolean.valueOf(get("RemoveFilterClassnames", "false")).booleanValue();
317  }
318 
319  /**
320   * only for testing - prints the content of the props file.
321   *
322   * @param args        commandline parameters - ignored
323   */
324  public static void main(String[] args) {
325    Enumeration         names;
326    String              name;
327    Vector              sorted;
328   
329    System.out.println("\nExperimenter defaults:");
330    names = PROPERTIES.propertyNames();
331
332    // sort names
333    sorted = new Vector();
334    while (names.hasMoreElements())
335      sorted.add(names.nextElement());
336    Collections.sort(sorted);
337    names = sorted.elements();
338   
339    // output
340    while (names.hasMoreElements()) {
341      name = names.nextElement().toString();
342      System.out.println("- " + name + ": " + PROPERTIES.getProperty(name, ""));
343    }
344    System.out.println();
345  }
346}
347
Note: See TracBrowser for help on using the repository browser.