⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 experiment.java

📁 Java 编写的多种数据挖掘算法 包括聚类、分类、预处理等
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }    return newVector.elements();  }  /**   * Parses a given list of options. <p/>   *   <!-- options-start -->   * Valid options are: <p/>   *    * <pre> -L &lt;num&gt;   *  The lower run number to start the experiment from.   *  (default 1)</pre>   *    * <pre> -U &lt;num&gt;   *  The upper run number to end the experiment at (inclusive).   *  (default 10)</pre>   *    * <pre> -T &lt;arff file&gt;   *  The dataset to run the experiment on.   *  (required, may be specified multiple times)</pre>   *    * <pre> -P &lt;class name&gt;   *  The full class name of a ResultProducer (required).   *  eg: weka.experiment.RandomSplitResultProducer</pre>   *    * <pre> -D &lt;class name&gt;   *  The full class name of a ResultListener (required).   *  eg: weka.experiment.CSVResultListener</pre>   *    * <pre> -N &lt;string&gt;   *  A string containing any notes about the experiment.   *  (default none)</pre>   *    * <pre>    * Options specific to result producer weka.experiment.RandomSplitResultProducer:   * </pre>   *    * <pre> -P &lt;percent&gt;   *  The percentage of instances to use for training.   *  (default 66)</pre>   *    * <pre> -D   * Save raw split evaluator output.</pre>   *    * <pre> -O &lt;file/directory name/path&gt;   *  The filename where raw output will be stored.   *  If a directory name is specified then then individual   *  outputs will be gzipped, otherwise all output will be   *  zipped to the named file. Use in conjuction with -D. (default splitEvalutorOut.zip)</pre>   *    * <pre> -W &lt;class name&gt;   *  The full class name of a SplitEvaluator.   *  eg: weka.experiment.ClassifierSplitEvaluator</pre>   *    * <pre> -R   *  Set when data is not to be randomized and the data sets' size.   *  Is not to be determined via probabilistic rounding.</pre>   *    * <pre>    * Options specific to split evaluator weka.experiment.ClassifierSplitEvaluator:   * </pre>   *    * <pre> -W &lt;class name&gt;   *  The full class name of the classifier.   *  eg: weka.classifiers.bayes.NaiveBayes</pre>   *    * <pre> -C &lt;index&gt;   *  The index of the class for which IR statistics   *  are to be output. (default 1)</pre>   *    * <pre> -I &lt;index&gt;   *  The index of an attribute to output in the   *  results. This attribute should identify an   *  instance in order to know which instances are   *  in the test set of a cross validation. if 0   *  no output (default 0).</pre>   *    * <pre> -P   *  Add target and prediction columns to the result   *  for each fold.</pre>   *    * <pre>    * Options specific to classifier weka.classifiers.rules.ZeroR:   * </pre>   *    * <pre> -D   *  If set, classifier is run in debug mode and   *  may output additional info to the console</pre>   *    <!-- options-end -->   *   * All options after -- will be passed to the result producer. <p>   *   * @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 lowerString = Utils.getOption('L', options);    if (lowerString.length() != 0) {      setRunLower(Integer.parseInt(lowerString));    } else {      setRunLower(1);    }    String upperString = Utils.getOption('U', options);    if (upperString.length() != 0) {      setRunUpper(Integer.parseInt(upperString));    } else {      setRunUpper(10);    }    if (getRunLower() > getRunUpper()) {      throw new Exception("Lower (" + getRunLower() 			  + ") is greater than upper (" 			  + getRunUpper() + ")");    }        setNotes(Utils.getOption('N', options));        getDatasets().removeAllElements();    String dataName;    do {      dataName = Utils.getOption('T', options);      if (dataName.length() != 0) {	File dataset = new File(dataName);	getDatasets().addElement(dataset);      }    } while (dataName.length() != 0);    if (getDatasets().size() == 0) {      throw new Exception("Required: -T <arff file name>");    }    String rlName = Utils.getOption('D', options);    if (rlName.length() == 0) {      throw new Exception("Required: -D <ResultListener class name>");    }    rlName = rlName.trim();    // split off any options    int breakLoc = rlName.indexOf(' ');    String clName = rlName;    String rlOptionsString = "";    String [] rlOptions = null;    if (breakLoc != -1) {      clName = rlName.substring(0, breakLoc);      rlOptionsString = rlName.substring(breakLoc).trim();      rlOptions = Utils.splitOptions(rlOptionsString);    }    setResultListener((ResultListener)Utils.forName(ResultListener.class,						    clName, rlOptions));    String rpName = Utils.getOption('P', options);    if (rpName.length() == 0) {      throw new Exception("Required: -P <ResultProducer class name>");    }    // Do it first without options, so if an exception is thrown during    // the option setting, listOptions will contain options for the actual    // RP.    //GHF -- nice idea, but it prevents you from using result producers that    //       have *required* parameters    setResultProducer((ResultProducer)Utils.forName(		      ResultProducer.class,		      rpName,		      Utils.partitionOptions(options) )); //GHF    //GHF if (getResultProducer() instanceof OptionHandler) {    //GHF  ((OptionHandler) getResultProducer())    //GHF  .setOptions(Utils.partitionOptions(options));    //GHF }  }  /**   * Gets the current settings of the experiment iterator.   *   * @return an array of strings suitable for passing to setOptions   */  public String [] getOptions() {    // Currently no way to set custompropertyiterators from the command line    m_UsePropertyIterator = false;    m_PropertyPath = null;    m_PropertyArray = null;        String [] rpOptions = new String [0];    if ((m_ResultProducer != null) && 	(m_ResultProducer instanceof OptionHandler)) {      rpOptions = ((OptionHandler)m_ResultProducer).getOptions();    }        String [] options = new String [rpOptions.length 				   + getDatasets().size() * 2				   + 11];    int current = 0;    options[current++] = "-L"; options[current++] = "" + getRunLower();    options[current++] = "-U"; options[current++] = "" + getRunUpper();    if (getDatasets().size() != 0) {      for (int i = 0; i < getDatasets().size(); i++) {	options[current++] = "-T";	options[current++] = getDatasets().elementAt(i).toString();      }    }    if (getResultListener() != null) {      options[current++] = "-D";      options[current++] = getResultListener().getClass().getName();    }    if (getResultProducer() != null) {      options[current++] = "-P";      options[current++] = getResultProducer().getClass().getName();    }    if (!getNotes().equals("")) {      options[current++] = "-N"; options[current++] = getNotes();    }    options[current++] = "--";    System.arraycopy(rpOptions, 0, options, current, 		     rpOptions.length);    current += rpOptions.length;    while (current < options.length) {      options[current++] = "";    }    return options;  }  /**   * Gets a string representation of the experiment configuration.   *   * @return a value of type 'String'   */  public String toString() {    String result = "Runs from: " + m_RunLower + " to: " + m_RunUpper + '\n';    result += "Datasets:";    for (int i = 0; i < m_Datasets.size(); i ++) {      result += " " + m_Datasets.elementAt(i);    }    result += '\n';    result += "Custom property iterator: "      + (m_UsePropertyIterator ? "on" : "off")      + "\n";    if (m_UsePropertyIterator) {      if (m_PropertyPath == null) {	throw new Error("*** null propertyPath ***");      }      if (m_PropertyArray == null) {	throw new Error("*** null propertyArray ***");      }      if (m_PropertyPath.length > 1) {	result += "Custom property path:\n";	for (int i = 0; i < m_PropertyPath.length - 1; i++) {	  PropertyNode pn = m_PropertyPath[i];	  result += "" + (i + 1) + "  " + pn.parentClass.getName()	    + "::" + pn.toString()	    + ' ' + pn.value.toString() + '\n';	}      }      result += "Custom property name:"	+ m_PropertyPath[m_PropertyPath.length - 1].toString() + '\n';      result += "Custom property values:\n";      for (int i = 0; i < Array.getLength(m_PropertyArray); i++) {	Object current = Array.get(m_PropertyArray, i);	result += " " + (i + 1)	  + " " + current.getClass().getName()	  + " " + current.toString() + '\n';      }    }    result += "ResultProducer: " + m_ResultProducer + '\n';    result += "ResultListener: " + m_ResultListener + '\n';    if (!getNotes().equals("")) {      result += "Notes: " + getNotes();    }    return result;  }  /**   * Configures/Runs the Experiment from the command line.   *   * @param args command line arguments to the Experiment.   */  public static void main(String[] args) {    try {      Experiment exp = null;      // get options from XML?      String xmlOption = Utils.getOption("xml", args);      if (!xmlOption.equals(""))         args = new XMLOptions(xmlOption).toArray();            String expFile = Utils.getOption('l', args);      String saveFile = Utils.getOption('s', args);      boolean runExp = Utils.getFlag('r', args);      if (expFile.length() == 0) {	exp = new Experiment();	try {	  exp.setOptions(args);	  Utils.checkForRemainingOptions(args);	} catch (Exception ex) {	  ex.printStackTrace();	  String result = "Usage:\n\n"	    + "-l <exp|xml file>\n"	    + "\tLoad experiment from file (default use cli options).\n"      + "\tThe type is determined, based on the extension ("         + FILE_EXTENSION + " or .xml)\n"	    + "-s <exp|xml file>\n"	    + "\tSave experiment to file after setting other options.\n"      + "\tThe type is determined, based on the extension ("         + FILE_EXTENSION + " or .xml)\n"	    + "\t(default don't save)\n"	    + "-r\n"	    + "\tRun experiment (default don't run)\n"	    + "-xml <filename | xml-string>\n"	    + "\tget options from XML-Data instead from parameters\n"            + "\n";	  Enumeration enm = ((OptionHandler)exp).listOptions();	  while (enm.hasMoreElements()) {	    Option option = (Option) enm.nextElement();	    result += option.synopsis() + "\n";	    result += option.description() + "\n";	  }	  throw new Exception(result + "\n" + ex.getMessage());	}      } else {         // KOML?         if ( (KOML.isPresent()) && (expFile.toLowerCase().endsWith(KOML.FILE_EXTENSION)) ) {            exp = (Experiment) KOML.read(expFile);         }         else         // XML?         if (expFile.toLowerCase().endsWith(".xml")) {            XMLExperiment xml = new XMLExperiment();             exp = (Experiment) xml.read(expFile);         }         // binary         else {            FileInputStream fi = new FileInputStream(expFile);            ObjectInputStream oi = new ObjectInputStream(                                   new BufferedInputStream(fi));            exp = (Experiment)oi.readObject();            oi.close();         }	// allow extra datasets to be added to pre-loaded experiment from command line	String dataName;	do {	  dataName = Utils.getOption('T', args);	  if (dataName.length() != 0) {	    File dataset = new File(dataName);	    exp.getDatasets().addElement(dataset);	  }	} while (dataName.length() != 0);	      }      System.err.println("Experiment:\n" + exp.toString());      if (saveFile.length() != 0) {         // KOML?         if ( (KOML.isPresent()) && (saveFile.toLowerCase().endsWith(KOML.FILE_EXTENSION)) ) {            KOML.write(saveFile, exp);         }         else         // XML?         if (saveFile.toLowerCase().endsWith(".xml")) {            XMLExperiment xml = new XMLExperiment();             xml.write(saveFile, exp);         }         // binary         else {            FileOutputStream fo = new FileOutputStream(saveFile);            ObjectOutputStream oo = new ObjectOutputStream(                                    new BufferedOutputStream(fo));            oo.writeObject(exp);            oo.close();         }      }            if (runExp) {	System.err.println("Initializing...");	exp.initialize();	System.err.println("Iterating...");	exp.runExperiment();	System.err.println("Postprocessing...");	exp.postProcess();      }          } catch (Exception ex) {      System.err.println(ex.getMessage());    }  }} // Experiment

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -