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

📄 pairedttester.java

📁 Java 编写的多种数据挖掘算法 包括聚类、分类、预处理等
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    catch (Exception e) {      e.printStackTrace();    }        // append a key so that we can tell the difference between long    // scheme+option names    result.append("\n\n" + m_ResultMatrix.toStringKey());    return result.toString();  }  /**   * Lists options understood by this object.   *   * @return an enumeration of Options.   */  public Enumeration listOptions() {        Vector newVector = new Vector();    newVector.addElement(new Option(             "\tSpecify list of columns that specify a unique\n"	      + "\tdataset.\n"	      + "\tFirst and last are valid indexes. (default none)",              "D", 1, "-D <index,index2-index4,...>"));    newVector.addElement(new Option(	      "\tSet the index of the column containing the run number",              "R", 1, "-R <index>"));    newVector.addElement(new Option(	      "\tSet the index of the column containing the fold number",              "F", 1, "-F <index>"));    newVector.addElement(new Option(              "\tSpecify list of columns that specify a unique\n"	      + "\t'result generator' (eg: classifier name and options).\n"	      + "\tFirst and last are valid indexes. (default none)",              "G", 1, "-G <index1,index2-index4,...>"));    newVector.addElement(new Option(	      "\tSet the significance level for comparisons (default 0.05)",              "S", 1, "-S <significance level>"));    newVector.addElement(new Option(	      "\tShow standard deviations",              "V", 0, "-V"));    newVector.addElement(new Option(	      "\tProduce table comparisons in Latex table format",              "L", 0, "-L"));    newVector.addElement(new Option(         "\tProduce table comparisons in CSV table format",         "csv", 0, "-csv"));    newVector.addElement(new Option(         "\tProduce table comparisons in HTML table format",         "html", 0, "-html"));    newVector.addElement(new Option(         "\tProduce table comparisons with only the significance values",         "significance", 0, "-significance"));    newVector.addElement(new Option(         "\tProduce table comparisons output suitable for GNUPlot",         "gnuplot", 0, "-gnuplot"));    return newVector.elements();  }  /**   * Parses a given list of options. <p/>   *   <!-- options-start -->   * Valid options are: <p/>   *    * <pre> -D &lt;index,index2-index4,...&gt;   *  Specify list of columns that specify a unique   *  dataset.   *  First and last are valid indexes. (default none)</pre>   *    * <pre> -R &lt;index&gt;   *  Set the index of the column containing the run number</pre>   *    * <pre> -F &lt;index&gt;   *  Set the index of the column containing the fold number</pre>   *    * <pre> -G &lt;index1,index2-index4,...&gt;   *  Specify list of columns that specify a unique   *  'result generator' (eg: classifier name and options).   *  First and last are valid indexes. (default none)</pre>   *    * <pre> -S &lt;significance level&gt;   *  Set the significance level for comparisons (default 0.05)</pre>   *    * <pre> -V   *  Show standard deviations</pre>   *    * <pre> -L   *  Produce table comparisons in Latex table format</pre>   *    * <pre> -csv   *  Produce table comparisons in CSV table format</pre>   *    * <pre> -html   *  Produce table comparisons in HTML table format</pre>   *    * <pre> -significance   *  Produce table comparisons with only the significance values</pre>   *    * <pre> -gnuplot   *  Produce table comparisons output suitable for GNUPlot</pre>   *    <!-- options-end -->   *   * @param options an array containing options to set.   * @throws Exception if invalid options are given   */  public void setOptions(String[] options) throws Exception {    setShowStdDevs(Utils.getFlag('V', options));    if (Utils.getFlag('L', options))      setResultMatrix(new ResultMatrixLatex());    if (Utils.getFlag("csv", options))      setResultMatrix(new ResultMatrixCSV());    if (Utils.getFlag("html", options))      setResultMatrix(new ResultMatrixHTML());    if (Utils.getFlag("significance", options))      setResultMatrix(new ResultMatrixSignificance());    String datasetList = Utils.getOption('D', options);    Range datasetRange = new Range();    if (datasetList.length() != 0) {      datasetRange.setRanges(datasetList);    }    setDatasetKeyColumns(datasetRange);    String indexStr = Utils.getOption('R', options);    if (indexStr.length() != 0) {      if (indexStr.equals("first")) {	setRunColumn(0);      } else if (indexStr.equals("last")) {	setRunColumn(-1);      } else {	setRunColumn(Integer.parseInt(indexStr) - 1);      }        } else {      setRunColumn(-1);    }    String foldStr = Utils.getOption('F', options);    if (foldStr.length() != 0) {      setFoldColumn(Integer.parseInt(foldStr) - 1);    } else {      setFoldColumn(-1);    }    String sigStr = Utils.getOption('S', options);    if (sigStr.length() != 0) {      setSignificanceLevel((new Double(sigStr)).doubleValue());    } else {      setSignificanceLevel(0.05);    }        String resultsetList = Utils.getOption('G', options);    Range generatorRange = new Range();    if (resultsetList.length() != 0) {      generatorRange.setRanges(resultsetList);    }    setResultsetKeyColumns(generatorRange);  }    /**   * Gets current settings of the PairedTTester.   *   * @return an array of strings containing current options.   */  public String[] getOptions() {    String [] options = new String [11];    int current = 0;    if (!getResultsetKeyColumns().getRanges().equals("")) {      options[current++] = "-G";      options[current++] = getResultsetKeyColumns().getRanges();    }    if (!getDatasetKeyColumns().getRanges().equals("")) {      options[current++] = "-D";      options[current++] = getDatasetKeyColumns().getRanges();    }    options[current++] = "-R";    options[current++] = "" + (getRunColumn() + 1);    options[current++] = "-S";    options[current++] = "" + getSignificanceLevel();        if (getShowStdDevs()) {      options[current++] = "-V";    }    if (getResultMatrix().equals(ResultMatrixLatex.class))      options[current++] = "-L";    if (getResultMatrix().equals(ResultMatrixCSV.class))      options[current++] = "-csv";       if (getResultMatrix().equals(ResultMatrixHTML.class))      options[current++] = "-html";       if (getResultMatrix().equals(ResultMatrixSignificance.class))      options[current++] = "-significance";       while (current < options.length) {      options[current++] = "";    }    return options;  }  /**   * Get the value of ResultsetKeyColumns.   *   * @return Value of ResultsetKeyColumns.   */  public Range getResultsetKeyColumns() {        return m_ResultsetKeyColumnsRange;  }    /**   * Set the value of ResultsetKeyColumns.   *   * @param newResultsetKeyColumns Value to assign to ResultsetKeyColumns.   */  public void setResultsetKeyColumns(Range newResultsetKeyColumns) {        m_ResultsetKeyColumnsRange = newResultsetKeyColumns;    m_ResultsetsValid = false;  }    /**   * Gets the indices of the the datasets that are displayed (if <code>null</code>   * then all are displayed). The base is always displayed.   *    * @return the indices of the datasets to display   */  public int[] getDisplayedResultsets() {    return m_DisplayedResultsets;  }    /**   * Sets the indicies of the datasets to display (<code>null</code> means all).   * The base is always displayed.   *    * @param cols the indices of the datasets to display   */  public void setDisplayedResultsets(int[] cols) {    m_DisplayedResultsets = cols;  }    /**   * Get the value of SignificanceLevel.   *   * @return Value of SignificanceLevel.   */  public double getSignificanceLevel() {        return m_SignificanceLevel;  }    /**   * Set the value of SignificanceLevel.   *   * @param newSignificanceLevel Value to assign to SignificanceLevel.   */  public void setSignificanceLevel(double newSignificanceLevel) {        m_SignificanceLevel = newSignificanceLevel;  }  /**   * Get the value of DatasetKeyColumns.   *   * @return Value of DatasetKeyColumns.   */  public Range getDatasetKeyColumns() {        return m_DatasetKeyColumnsRange;  }    /**   * Set the value of DatasetKeyColumns.   *   * @param newDatasetKeyColumns Value to assign to DatasetKeyColumns.   */  public void setDatasetKeyColumns(Range newDatasetKeyColumns) {        m_DatasetKeyColumnsRange = newDatasetKeyColumns;    m_ResultsetsValid = false;  }    /**   * Get the value of RunColumn.   *   * @return Value of RunColumn.   */  public int getRunColumn() {        return m_RunColumnSet;  }    /**   * Set the value of RunColumn.   *   * @param newRunColumn Value to assign to RunColumn.   */  public void setRunColumn(int newRunColumn) {        m_RunColumnSet = newRunColumn;    m_ResultsetsValid = false;  }  /**   * Get the value of FoldColumn.   *   * @return Value of FoldColumn.   */  public int getFoldColumn() {        return m_FoldColumn;  }    /**   * Set the value of FoldColumn.   *   * @param newFoldColumn Value to assign to FoldColumn.   */  public void setFoldColumn(int newFoldColumn) {        m_FoldColumn = newFoldColumn;    m_ResultsetsValid = false;  }  /**   * Returns the name of the column to sort on.   *   * @return the name of the column to sort on.   */  public String getSortColumnName() {    if (getSortColumn() == -1)      return "-";    else      return m_Instances.attribute(getSortColumn()).name();  }  /**   * Returns the column to sort on, -1 means the default sorting.   *   * @return the column to sort on.   */  public int getSortColumn() {    return m_SortColumn;  }    /**   * Set the column to sort on, -1 means the default sorting.   *   * @param newSortColumn the new sort column.   */  public void setSortColumn(int newSortColumn) {    if (newSortColumn >= -1)      m_SortColumn = newSortColumn;  }    /**   * Get the value of Instances.   *   * @return Value of Instances.   */  public Instances getInstances() {        return m_Instances;  }    /**   * Set the value of Instances.   *   * @param newInstances Value to assign to Instances.   */  public void setInstances(Instances newInstances) {        m_Instances = newInstances;    m_ResultsetsValid = false;  }  /**   * retrieves all the settings from the given Tester   *   * @param tester      the Tester to get the settings from   */  public void assign(Tester tester) {    setInstances(tester.getInstances());    setResultMatrix(tester.getResultMatrix());    setShowStdDevs(tester.getShowStdDevs());    setResultsetKeyColumns(tester.getResultsetKeyColumns());    setDisplayedResultsets(tester.getDisplayedResultsets());    setSignificanceLevel(tester.getSignificanceLevel());    setDatasetKeyColumns(tester.getDatasetKeyColumns());    setRunColumn(tester.getRunColumn());    setFoldColumn(tester.getFoldColumn());    setSortColumn(tester.getSortColumn());  }  /**   * returns a string that is displayed as tooltip on the "perform test"   * button in the experimenter   *    * @return	the tool tip   */  public String getToolTipText() {    return "Performs test using t-test statistic";  }  /**   * returns the name of the tester   *    * @return	the display name   */  public String getDisplayName() {    return "Paired T-Tester";  }    /**   * Test the class from the command line.   *   * @param args contains options for the instance ttests   */  public static void main(String args[]) {    try {      PairedTTester tt = new PairedTTester();      String datasetName = Utils.getOption('t', args);      String compareColStr = Utils.getOption('c', args);      String baseColStr = Utils.getOption('b', args);      boolean summaryOnly = Utils.getFlag('s', args);      boolean rankingOnly = Utils.getFlag('r', args);      try {	if ((datasetName.length() == 0)	    || (compareColStr.length() == 0)) {	  throw new Exception("-t and -c options are required");	}	tt.setOptions(args);	Utils.checkForRemainingOptions(args);      } catch (Exception ex) {	String result = "";	Enumeration enu = tt.listOptions();	while (enu.hasMoreElements()) {	  Option option = (Option) enu.nextElement();	  result += option.synopsis() + '\n'	    + option.description() + '\n';	}	throw new Exception(	      "Usage:\n\n"	      + "-t <file>\n"	      + "\tSet the dataset containing data to evaluate\n"	      + "-b <index>\n"	      + "\tSet the resultset to base comparisons against (optional)\n"	      + "-c <index>\n"	      + "\tSet the column to perform a comparison on\n"	      + "-s\n"	      + "\tSummarize wins over all resultset pairs\n\n"	      + "-r\n"	      + "\tGenerate a resultset ranking\n\n"	      + result);      }      Instances data = new Instances(new BufferedReader(				  new FileReader(datasetName)));      tt.setInstances(data);      //      tt.prepareData();      int compareCol = Integer.parseInt(compareColStr) - 1;      System.out.println(tt.header(compareCol));      if (rankingOnly) {	System.out.println(tt.multiResultsetRanking(compareCol));      } else if (summaryOnly) {	System.out.println(tt.multiResultsetSummary(compareCol));      } else {	System.out.println(tt.resultsetKey());	if (baseColStr.length() == 0) {	  for (int i = 0; i < tt.getNumResultsets(); i++) {            if (!tt.displayResultset(i))              continue;	    System.out.println(tt.multiResultsetFull(i, compareCol));	  }	} else {	  int baseCol = Integer.parseInt(baseColStr) - 1;	  System.out.println(tt.multiResultsetFull(baseCol, compareCol));	}      }    } catch(Exception e) {      e.printStackTrace();      System.err.println(e.getMessage());    }  }}

⌨️ 快捷键说明

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