📄 gridsearch.java
字号:
* expression: * <ul> * <li>BASE</li> * <li>FROM (= min)</li> * <li>TO (= max)</li> * <li>STEP</li> * <li>I - the current value (from 'from' to 'to' with stepsize 'step')</li> * </ul> * * @see MathematicalExpression * @see MathExpression */ protected String m_Y_Expression = "pow(BASE,I)"; /** the X option to work on (without leading dash, preceding 'classifier.' * means to set the option for the classifier 'filter.' for the filter) */ protected String m_X_Property = PREFIX_FILTER + "numComponents"; /** the minimum of X */ protected double m_X_Min = +5; /** the maximum of X */ protected double m_X_Max = +20; /** the step size of */ protected double m_X_Step = 1; /** the base for */ protected double m_X_Base = 10; /** * The expression for the X property. Available parameters for the * expression: * <ul> * <li>BASE</li> * <li>FROM (= min)</li> * <li>TO (= max)</li> * <li>STEP</li> * <li>I - the current value (from 'from' to 'to' with stepsize 'step')</li> * </ul> * * @see MathematicalExpression * @see MathExpression */ protected String m_X_Expression = "I"; /** whether the grid can be extended */ protected boolean m_GridIsExtendable = false; /** maximum number of grid extensions (-1 means unlimited) */ protected int m_MaxGridExtensions = 3; /** the number of extensions performed */ protected int m_GridExtensionsPerformed = 0; /** the sample size to search the initial grid with */ protected double m_SampleSize = 100; /** the traversal */ protected int m_Traversal = TRAVERSAL_BY_COLUMN; /** the log file to use */ protected File m_LogFile = new File(System.getProperty("user.dir")); /** the value-pairs grid */ protected Grid m_Grid; /** the training data */ protected Instances m_Data; /** the cache for points in the grid that got calculated */ protected PerformanceCache m_Cache; /** whether all performances in the grid are the same */ protected boolean m_UniformPerformance = false; /** * the default constructor */ public GridSearch() { super(); // classifier m_Classifier = new LinearRegression(); ((LinearRegression) m_Classifier).setAttributeSelectionMethod(new SelectedTag(LinearRegression.SELECTION_NONE, LinearRegression.TAGS_SELECTION)); ((LinearRegression) m_Classifier).setEliminateColinearAttributes(false); // filter m_Filter = new PLSFilter(); PLSFilter filter = new PLSFilter(); filter.setPreprocessing(new SelectedTag(PLSFilter.PREPROCESSING_STANDARDIZE, PLSFilter.TAGS_PREPROCESSING)); filter.setReplaceMissing(true); try { m_BestClassifier = Classifier.makeCopy(m_Classifier); } catch (Exception e) { e.printStackTrace(); } try { m_BestFilter = Filter.makeCopy(filter); } catch (Exception e) { e.printStackTrace(); } } /** * Returns a string describing classifier * * @return a description suitable for displaying in the * explorer/experimenter gui */ public String globalInfo() { return "Performs a grid search of parameter pairs for the a classifier " + "(Y-axis, default is LinearRegression with the \"Ridge\" parameter) " + "and the PLSFilter (X-axis, \"# of Components\") and chooses the best " + "pair found for the actual predicting.\n\n" + "The initial grid is worked on with 2-fold CV to determine the values " + "of the parameter pairs for the selected type of evaluation (e.g., " + "accuracy). The best point in the grid is then taken and a 10-fold CV " + "is performed with the adjacent parameter pairs. If a better pair is " + "found, then this will act as new center and another 10-fold CV will " + "be performed (kind of hill-climbing). This process is repeated until " + "no better pair is found or the best pair is on the border of the grid.\n" + "In case the best pair is on the border, one can let GridSearch " + "automatically extend the grid and continue the search. Check out the " + "properties 'gridIsExtendable' (option '-extend-grid') and " + "'maxGridExtensions' (option '-max-grid-extensions <num>').\n\n" + "GridSearch can handle doubles, integers (values are just cast to int) " + "and booleans (0 is false, otherwise true). float, char and long are " + "supported as well.\n\n" + "The best filter/classifier setup can be accessed after the buildClassifier " + "call via the getBestFilter/getBestClassifier methods.\n" + "Note on the implementation: after the data has been passed through " + "the filter, a default NumericCleaner filter is applied to the data in " + "order to avoid numbers that are getting too small and might produce " + "NaNs in other schemes."; } /** * String describing default classifier. * * @return the classname of the default classifier */ protected String defaultClassifierString() { return LinearRegression.class.getName(); } /** * Gets an enumeration describing the available options. * * @return an enumeration of all the available options. */ public Enumeration listOptions(){ Vector result; Enumeration en; String desc; SelectedTag tag; int i; result = new Vector(); desc = ""; for (i = 0; i < TAGS_EVALUATION.length; i++) { tag = new SelectedTag(TAGS_EVALUATION[i].getID(), TAGS_EVALUATION); desc += "\t" + tag.getSelectedTag().getIDStr() + " = " + tag.getSelectedTag().getReadable() + "\n"; } result.addElement(new Option( "\tDetermines the parameter used for evaluation:\n" + desc + "\t(default: " + new SelectedTag(EVALUATION_CC, TAGS_EVALUATION) + ")", "E", 1, "-E " + Tag.toOptionList(TAGS_EVALUATION))); result.addElement(new Option( "\tThe Y option to test (without leading dash).\n" + "\t(default: " + PREFIX_CLASSIFIER + "ridge)", "y-property", 1, "-y-property <option>")); result.addElement(new Option( "\tThe minimum for Y.\n" + "\t(default: -10)", "y-min", 1, "-y-min <num>")); result.addElement(new Option( "\tThe maximum for Y.\n" + "\t(default: +5)", "y-max", 1, "-y-max <num>")); result.addElement(new Option( "\tThe step size for Y.\n" + "\t(default: 1)", "y-step", 1, "-y-step <num>")); result.addElement(new Option( "\tThe base for Y.\n" + "\t(default: 10)", "y-base", 1, "-y-base <num>")); result.addElement(new Option( "\tThe expression for Y.\n" + "\tAvailable parameters:\n" + "\t\tBASE\n" + "\t\tFROM\n" + "\t\tTO\n" + "\t\tSTEP\n" + "\t\tI - the current iteration value\n" + "\t\t(from 'FROM' to 'TO' with stepsize 'STEP')\n" + "\t(default: 'pow(BASE,I)')", "y-expression", 1, "-y-expression <expr>")); result.addElement(new Option( "\tThe filter to use (on X axis). Full classname of filter to include, \n" + "\tfollowed by scheme options.\n" + "\t(default: weka.filters.supervised.attribute.PLSFilter)", "filter", 1, "-filter <filter specification>")); result.addElement(new Option( "\tThe X option to test (without leading dash).\n" + "\t(default: " + PREFIX_FILTER + "numComponents)", "x-property", 1, "-x-property <option>")); result.addElement(new Option( "\tThe minimum for X.\n" + "\t(default: +5)", "x-min", 1, "-x-min <num>")); result.addElement(new Option( "\tThe maximum for X.\n" + "\t(default: +20)", "x-max", 1, "-x-max <num>")); result.addElement(new Option( "\tThe step size for X.\n" + "\t(default: 1)", "x-step", 1, "-x-step <num>")); result.addElement(new Option( "\tThe base for X.\n" + "\t(default: 10)", "x-base", 1, "-x-base <num>")); result.addElement(new Option( "\tThe expression for the X value.\n" + "\tAvailable parameters:\n" + "\t\tBASE\n" + "\t\tMIN\n" + "\t\tMAX\n" + "\t\tSTEP\n" + "\t\tI - the current iteration value\n" + "\t\t(from 'FROM' to 'TO' with stepsize 'STEP')\n" + "\t(default: 'pow(BASE,I)')", "x-expression", 1, "-x-expression <expr>")); result.addElement(new Option( "\tWhether the grid can be extended.\n" + "\t(default: no)", "extend-grid", 0, "-extend-grid")); result.addElement(new Option( "\tThe maximum number of grid extensions (-1 is unlimited).\n" + "\t(default: 3)", "max-grid-extensions", 1, "-max-grid-extensions <num>")); result.addElement(new Option( "\tThe size (in percent) of the sample to search the inital grid with.\n" + "\t(default: 100)", "sample-size", 1, "-sample-size <num>")); result.addElement(new Option( "\tThe type of traversal for the grid.\n" + "\t(default: " + new SelectedTag(TRAVERSAL_BY_COLUMN, TAGS_TRAVERSAL) + ")", "traversal", 1, "-traversal " + Tag.toOptionList(TAGS_TRAVERSAL))); result.addElement(new Option( "\tThe log file to log the messages to.\n" + "\t(default: none)", "log-file", 1, "-log-file <filename>")); en = super.listOptions(); while (en.hasMoreElements()) result.addElement(en.nextElement()); if (getFilter() instanceof OptionHandler) { result.addElement(new Option( "", "", 0, "\nOptions specific to filter " + getFilter().getClass().getName() + " ('-filter'):")); en = ((OptionHandler) getFilter()).listOptions(); while (en.hasMoreElements()) result.addElement(en.nextElement()); } return result.elements(); } /** * returns the options of the current setup * * @return the current options */ public String[] getOptions(){ int i; Vector result; String[] options; result = new Vector(); result.add("-E"); result.add("" + getEvaluation()); result.add("-y-property"); result.add("" + getYProperty()); result.add("-y-min"); result.add("" + getYMin()); result.add("-y-max"); result.add("" + getYMax()); result.add("-y-step"); result.add("" + getYStep()); result.add("-y-base"); result.add("" + getYBase()); result.add("-y-expression"); result.add("" + getYExpression()); result.add("-filter"); if (getFilter() instanceof OptionHandler) result.add( getFilter().getClass().getName() + " " + Utils.joinOptions(((OptionHandler) getFilter()).getOptions())); else result.add( getFilter().getClass().getName()); result.add("-x-property"); result.add("" + getXProperty()); result.add("-x-min"); result.add("" + getXMin()); result.add("-x-max"); result.add("" + getXMax()); result.add("-x-step"); result.add("" + getXStep()); result.add("-x-base"); result.add("" + getXBase()); result.add("-x-expression"); result.add("" + getXExpression()); if (getGridIsExtendable()) { result.add("-extend-grid"); result.add("-max-grid-extensions"); result.add("" + getMaxGridExtensions()); } result.add("-sample-size"); result.add("" + getSampleSizePercent()); result.add("-traversal"); result.add("" + getTraversal()); result.add("-log-file"); result.add("" + getLogFile()); options = super.getOptions(); for (i = 0; i < options.length; i++) result.add(options[i]); return (String[]) result.toArray(new String[result.size()]); } /** * Parses the options for this object. <p/> * <!-- options-start --> * Valid options are: <p/> * * <pre> -E <CC|RMSE|RRSE|MAE|RAE|COMB|ACC> * Determines the parameter used for evaluation: * CC = Correlation coefficient * RMSE = Root mean squared error * RRSE = Root relative squared error * MAE = Mean absolute error * RAE = Root absolute error * COMB = Combined = (1-abs(CC)) + RRSE + RAE * ACC = Accuracy * (default: CC)</pre> * * <pre> -y-property <option> * The Y option to test (without leading dash). * (default: classifier.ridge)</pre> * * <pre> -y-min <num> * The minimum for Y. * (default: -10)</pre> * * <pre> -y-max <num> * The maximum for Y. * (default: +5)</pre> * * <pre> -y-step <num> * The step size for Y. * (default: 1)</pre> * * <pre> -y-base <num> * The base for Y. * (default: 10)</pre> * * <pre> -y-expression <expr> * The expression for Y. * Available parameters: * BASE * FROM * TO * STEP * I - the current iteration value * (from 'FROM' to 'TO' with stepsize 'STEP') * (default: 'pow(BASE,I)')</pre> * * <pre> -filter <filter specification> * The filter to use (on X axis). Full classname of filter to include, * followed by scheme options. * (default: weka.filters.supervised.attribute.PLSFilter)</pre> * * <pre> -x-property <option> * The X option to test (without leading dash). * (default: filter.numComponents)</pre> * * <pre> -x-min <num> * The minimum for X. * (default: +5)</pre> * * <pre> -x-max <num> * The maximum for X. * (default: +20)</pre> * * <pre> -x-step <num> * The step size for X. * (default: 1)</pre> * * <pre> -x-base <num> * The base for X. * (default: 10)</pre> * * <pre> -x-expression <expr> * The expression for the X value.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -