📄 semisupcrossvalidationresultproducer.java
字号:
public void setStepSize(int newStepSize) { m_StepSize = newStepSize; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String plotPointsTipText() { return "A list of specific points to plot as a string of numbers separated by commas or spaces. "+ "Whole numbers indicate a specific number of examples, "+ "decimal fractions indicate a fraction of the total training set. "+ "Specifying plot points overrides step size, lower size, and upper size parameters."; } /** * Get the value of PlotPoints. * * @return Value of PlotPoints. */ public String getPlotPoints() { StringBuffer buf = new StringBuffer(); if (m_PlotPoints != null) for (int i=0; i < m_PlotPoints.length; i++) { buf.append(m_PlotPoints[i]); if (i != (m_PlotPoints.length -1)) buf.append(" "); } return buf.toString(); } /** * Set the value of PlotPoints. * * @param plotPoints Value to assign to * PlotPoints. */ public void setPlotPoints(String plotPoints) { m_PlotPoints = parsePlotPoints(plotPoints); setIsFraction(); } /** * Parse a string of doubles separated by commas or spaces into a sorted array of doubles */ protected double[] parsePlotPoints(String plotPoints) { StringTokenizer tokenizer = new StringTokenizer(plotPoints," ,\t"); double[] result = null; int count = tokenizer.countTokens(); if (count > 0) result = new double[count]; else return null; int i = 0; while(tokenizer.hasMoreTokens()) { result[i] = Double.parseDouble(tokenizer.nextToken()); i++; } Arrays.sort(result); return result; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String rawOutputTipText() { return "Save raw output (useful for debugging). If set, then output is " +"sent to the destination specified by outputFile"; } /** * Get if raw split evaluator output is to be saved * @return true if raw split evalutor output is to be saved */ public boolean getRawOutput() { return m_debugOutput; } /** * Set to true if raw split evaluator output is to be saved * @param d true if output is to be saved */ public void setRawOutput(boolean d) { m_debugOutput = d; } /** * Returns the tip text for this property * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String splitEvaluatorTipText() { return "The evaluator to apply to the cross validation folds. " +"This may be a classifier, regression scheme etc."; } /** * Get the SplitEvaluator. * * @return the SplitEvaluator. */ public SplitEvaluator getSplitEvaluator() { return m_SplitEvaluator; } /** * Set the SplitEvaluator. * * @param newSplitEvaluator new SplitEvaluator to use. */ public void setSplitEvaluator(SplitEvaluator newSplitEvaluator) { m_SplitEvaluator = newSplitEvaluator; m_SplitEvaluator.setAdditionalMeasures(m_AdditionalMeasures); } /** * Returns an enumeration describing the available options.. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { Vector newVector = new Vector(8); newVector.addElement(new Option( "\tThe number of folds to use for the cross-validation.\n" +"\t(default 10)", "X", 1, "-X <number of folds>")); newVector.addElement(new Option( "\tThe number of instances to add at each step on the learning curve.", "S", 1, "-S <step size>")); newVector.addElement(new Option( "\tThe minmum number of instances in a training set. Setting zero" + "\there will actually use <stepSize> number of instances at the first" + "\tstep (since performance at zero instances is predictable)", "L", 1, "-L <lower bound>")); newVector.addElement(new Option( "\tThe maximum number of instances in a training set. Setting -1 " + "\tsets no upper limit (other than the total number of instances " + "\tin the full training set)", "U", 1, "-U <upper bound>")); newVector.addElement(new Option( "\tA list of specific points to plot as a string of numbers\n"+ "separated by commas or spaces.\n"+ "Whole numbers indicate a specific number of examples,\n"+ "decimal fractions indicate a fraction of the total training set.\n"+ "Specifying plot points overrides the S, L, and U parameters", "P", 1, "-P <point list>")); newVector.addElement(new Option( "Save raw split evaluator output.", "D",0,"-D")); newVector.addElement(new Option( "\tThe filename where raw output will be stored.\n" +"\tIf a directory name is specified then then individual\n" +"\toutputs will be gzipped, otherwise all output will be\n" +"\tzipped to the named file. Use in conjuction with -D." +"\t(default splitEvalutorOut.zip)", "O", 1, "-O <file/directory name/path>")); newVector.addElement(new Option( "\tThe full class name of a SplitEvaluator.\n" +"\teg: weka.experiment.ClassifierSplitEvaluator", "W", 1, "-W <class name>")); if ((m_SplitEvaluator != null) && (m_SplitEvaluator instanceof OptionHandler)) { newVector.addElement(new Option( "", "", 0, "\nOptions specific to split evaluator " + m_SplitEvaluator.getClass().getName() + ":")); Enumeration enum = ((OptionHandler)m_SplitEvaluator).listOptions(); while (enum.hasMoreElements()) { newVector.addElement(enum.nextElement()); } } return newVector.elements(); } /** * Parses a given list of options. Valid options are:<p> * * -X num_folds <br> * The number of folds to use for the cross-validation. <p> * * -D <br> * Specify that raw split evaluator output is to be saved. <p> * * -O file/directory name <br> * Specify the file or directory to which raw split evaluator output * is to be saved. If a directory is specified, then each output string * is saved as an individual gzip file. If a file is specified, then * each output string is saved as an entry in a zip file. <p> * * -W classname <br> * Specify the full class name of the split evaluator. <p> * * All option after -- will be passed to the split evaluator. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { setRawOutput(Utils.getFlag('D', options)); String fName = Utils.getOption('O', options); if (fName.length() != 0) { setOutputFile(new File(fName)); } String numFolds = Utils.getOption('X', options); if (numFolds.length() != 0) { setNumFolds(Integer.parseInt(numFolds)); } else { setNumFolds(10); } String stepSize = Utils.getOption('S', options); if (stepSize.length() != 0) { setStepSize(Integer.parseInt(stepSize)); } else { setStepSize(10); } String lowerSize = Utils.getOption('L', options); if (lowerSize.length() != 0) { setLowerSize(Integer.parseInt(lowerSize)); } else { setLowerSize(0); } String upperSize = Utils.getOption('U', options); if (upperSize.length() != 0) { setUpperSize(Integer.parseInt(upperSize)); } else { setUpperSize(-1); } String plotPoints = Utils.getOption('P', options); if (plotPoints.length() != 0) { setPlotPoints(plotPoints); } else { setPlotPoints(""); } String seName = Utils.getOption('W', options); if (seName.length() == 0) { throw new Exception("A SplitEvaluator must be specified with" + " the -W option."); } // Do it first without options, so if an exception is thrown during // the option setting, listOptions will contain options for the actual // SE. setSplitEvaluator((SplitEvaluator)Utils.forName( SplitEvaluator.class, seName, null)); if (getSplitEvaluator() instanceof OptionHandler) { ((OptionHandler) getSplitEvaluator()) .setOptions(Utils.partitionOptions(options)); } } /** * Gets the current settings of the result producer. * * @return an array of strings suitable for passing to setOptions */ public String [] getOptions() { String [] seOptions = new String [0]; if ((m_SplitEvaluator != null) && (m_SplitEvaluator instanceof OptionHandler)) { seOptions = ((OptionHandler)m_SplitEvaluator).getOptions(); } String [] options = new String [seOptions.length + 16]; int current = 0; options[current++] = "-X"; options[current++] = "" + getNumFolds(); if (getRawOutput()) { options[current++] = "-D"; } options[current++] = "-O"; options[current++] = getOutputFile().getName(); options[current++] = "-S"; options[current++] = "" + getStepSize(); options[current++] = "-L"; options[current++] = "" + getLowerSize(); options[current++] = "-U"; options[current++] = "" + getUpperSize(); options[current++] = "-P"; options[current++] = getPlotPoints(); if (getSplitEvaluator() != null) { options[current++] = "-W"; options[current++] = getSplitEvaluator().getClass().getName(); } options[current++] = "--"; System.arraycopy(seOptions, 0, options, current, seOptions.length); current += seOptions.length; while (current < options.length) { options[current++] = ""; } return options; } /** * Gets a text descrption of the result producer. * * @return a text description of the result producer. */ public String toString() { String result = "SemiSupCrossValidationResultProducer: "; result += getCompatibilityState(); if (m_Instances == null) { result += ": <null Instances>"; } else { result += ": " + Utils.backQuoteChars(m_Instances.relationName()); } return result; } // Quick test public static void main(String [] args) { SemiSupCrossValidationResultProducer rp = new SemiSupCrossValidationResultProducer(); rp.setPlotPoints(args[0]); System.out.println(rp.getPlotPoints()); if (rp.m_PlotPoints != null) System.out.println(isInteger(rp.m_PlotPoints[0])); }} // SemiSupCrossValidationResultProducer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -