📄 checkscheme.java
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* * CheckScheme.java * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand * */package weka.core;import java.util.Enumeration;import java.util.Random;import java.util.StringTokenizer;import java.util.Vector;/** * Abstract general class for testing schemes in Weka. Derived classes are * also used for JUnit tests. * * @author FracPete (fracpete at waikato dot ac dot nz) * @version $Revision: 1.3 $ * @see TestInstances */public abstract class CheckScheme extends Check { /** a class for postprocessing the test-data */ public static class PostProcessor { /** * Provides a hook for derived classes to further modify the data. Currently, * the data is just passed through. * * @param data the data to process * @return the processed data */ public Instances process(Instances data) { return data; } } /** The number of instances in the datasets */ protected int m_NumInstances = 20; /** the number of nominal attributes */ protected int m_NumNominal = 2; /** the number of numeric attributes */ protected int m_NumNumeric = 1; /** the number of string attributes */ protected int m_NumString = 1; /** the number of date attributes */ protected int m_NumDate = 1; /** the number of relational attributes */ protected int m_NumRelational = 1; /** the number of instances in relational attributes (applies also for bags * in multi-instance) */ protected int m_NumInstancesRelational = 10; /** for generating String attributes/classes */ protected String[] m_Words = TestInstances.DEFAULT_WORDS; /** for generating String attributes/classes */ protected String m_WordSeparators = TestInstances.DEFAULT_SEPARATORS; /** for post-processing the data even further */ protected PostProcessor m_PostProcessor = null; /** whether classpath problems occurred */ protected boolean m_ClasspathProblems = false; /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { Vector result = new Vector(); Enumeration en = super.listOptions(); while (en.hasMoreElements()) result.addElement(en.nextElement()); result.addElement(new Option( "\tThe number of instances in the datasets (default 20).", "N", 1, "-N <num>")); result.addElement(new Option( "\tThe number of nominal attributes (default 2).", "nominal", 1, "-nominal <num>")); result.addElement(new Option( "\tThe number of values for nominal attributes (default 1).", "nominal-values", 1, "-nominal-values <num>")); result.addElement(new Option( "\tThe number of numeric attributes (default 1).", "numeric", 1, "-numeric <num>")); result.addElement(new Option( "\tThe number of string attributes (default 1).", "string", 1, "-string <num>")); result.addElement(new Option( "\tThe number of date attributes (default 1).", "date", 1, "-date <num>")); result.addElement(new Option( "\tThe number of relational attributes (default 1).", "relational", 1, "-relational <num>")); result.addElement(new Option( "\tThe number of instances in relational/bag attributes (default 10).", "num-instances-relational", 1, "-num-instances-relational <num>")); result.addElement(new Option( "\tThe words to use in string attributes.", "words", 1, "-words <comma-separated-list>")); result.addElement(new Option( "\tThe word separators to use in string attributes.", "word-separators", 1, "-word-separators <chars>")); return result.elements(); } /** * Parses a given list of options. * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { String tmpStr; super.setOptions(options); tmpStr = Utils.getOption('N', options); if (tmpStr.length() != 0) setNumInstances(Integer.parseInt(tmpStr)); else setNumInstances(20); tmpStr = Utils.getOption("nominal", options); if (tmpStr.length() != 0) setNumNominal(Integer.parseInt(tmpStr)); else setNumNominal(2); tmpStr = Utils.getOption("numeric", options); if (tmpStr.length() != 0) setNumNumeric(Integer.parseInt(tmpStr)); else setNumNumeric(1); tmpStr = Utils.getOption("string", options); if (tmpStr.length() != 0) setNumString(Integer.parseInt(tmpStr)); else setNumString(1); tmpStr = Utils.getOption("date", options); if (tmpStr.length() != 0) setNumDate(Integer.parseInt(tmpStr)); else setNumDate(1); tmpStr = Utils.getOption("relational", options); if (tmpStr.length() != 0) setNumRelational(Integer.parseInt(tmpStr)); else setNumRelational(1); tmpStr = Utils.getOption("num-instances-relational", options); if (tmpStr.length() != 0) setNumInstancesRelational(Integer.parseInt(tmpStr)); else setNumInstancesRelational(10); tmpStr = Utils.getOption("words", options); if (tmpStr.length() != 0) setWords(tmpStr); else setWords(new TestInstances().getWords()); if (Utils.getOptionPos("word-separators", options) > -1) { tmpStr = Utils.getOption("word-separators", options); setWordSeparators(tmpStr); } else { setWordSeparators(TestInstances.DEFAULT_SEPARATORS); } } /** * Gets the current settings of the CheckClassifier. * * @return an array of strings suitable for passing to setOptions */ public String[] getOptions() { Vector result; String[] options; int i; result = new Vector(); options = super.getOptions(); for (i = 0; i < options.length; i++) result.add(options[i]); result.add("-N"); result.add("" + getNumInstances()); result.add("-nominal"); result.add("" + getNumNominal()); result.add("-numeric"); result.add("" + getNumNumeric()); result.add("-string"); result.add("" + getNumString()); result.add("-date"); result.add("" + getNumDate()); result.add("-relational"); result.add("" + getNumRelational()); result.add("-words"); result.add("" + getWords()); result.add("-word-separators"); result.add("" + getWordSeparators()); return (String[]) result.toArray(new String[result.size()]); } /** * sets the PostProcessor to use * * @param value the new PostProcessor * @see #m_PostProcessor */ public void setPostProcessor(PostProcessor value) { m_PostProcessor = value; } /** * returns the current PostProcessor, can be null * * @return the current PostProcessor */ public PostProcessor getPostProcessor() { return m_PostProcessor; } /** * returns TRUE if the classifier returned a "not in classpath" Exception * * @return true if CLASSPATH problems occurred */ public boolean hasClasspathProblems() { return m_ClasspathProblems; } /** * Begin the tests, reporting results to System.out */ public abstract void doTests(); /** * Sets the number of instances to use in the datasets (some classifiers * might require more instances). * * @param value the number of instances to use */ public void setNumInstances(int value) { m_NumInstances = value; } /** * Gets the current number of instances to use for the datasets. * * @return the number of instances */ public int getNumInstances() { return m_NumInstances;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -