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

📄 resultmatrix.java

📁 Java 编写的多种数据挖掘算法 包括聚类、分类、预处理等
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   * @param length    the max. length of the string   * @param left      whether to pad left or right   * @return          the padded string   */  protected String padString(String s, int length, boolean left) {    String      result;    int         i;    result = s;    // pad with blanks    for (i = s.length(); i < length; i++) {      if (left)        result = " " + result;      else        result = result + " ";    }          // too long?    if ( (length > 0) && (result.length() > length) )      result = result.substring(0, length);    return result;  }  /**   * returns the length of the longest cell in the given column   * @param data    the data to base the calculation on   * @param col     the column to check   * @return        the maximum length   */  protected int getColSize(String[][] data, int col) {    return getColSize(data, col, false, false);  }  /**   * returns the length of the longest cell in the given column   * @param data        the data to base the calculation on   * @param col         the column to check   * @param skipFirst   whether to skip the first row   * @param skipLast    whether to skip the last row   * @return            the maximum length   */  protected int getColSize( String[][] data, int col,                             boolean skipFirst, boolean skipLast ) {    int       result;    int       i;    result = 0;    if ( (col >= 0) && (col < data[0].length) ) {      for (i = 0; i < data.length; i++) {        // skip first?        if ( (i == 0) && (skipFirst) )          continue;        // skip last?        if ( (i == data.length - 1) && (skipLast) )          continue;                if (data[i][col].length() > result)          result = data[i][col].length();      }    }    return result;  }  /**   * removes the filter classname from the given string if it should be    * removed, otherwise leaves the string alone   * @see     #getRemoveFilterName()   */  protected String removeFilterName(String s) {    if (getRemoveFilterName())      return s.replaceAll("-weka\\.filters\\..*", "")              .replaceAll("-unsupervised\\..*",   "")              .replaceAll("-supervised\\..*",     "");    else      return s;  }  /**   * returns a 2-dimensional array with the prepared data. includes the column   * and row names. hidden cols/rows are already excluded. <br>   * first row: column names<br>   * last  row: wins/ties/losses<br>   * first col: row names<br>   */  protected String[][] toArray() {    int               i;    int               n;    int               ii;    int               nn;    int               x;    int               y;    String[][]        result;    String[][]        tmpResult;    int               cols;    int               rows;    int[]             widths;    boolean           valueExists;    // determine visible cols/rows    rows = getVisibleRowCount();    if (getShowAverage())      rows++;    cols = getVisibleColCount();    if (getShowStdDev())      cols = cols*3;   // mean + stddev + sign.    else      cols = cols*2;   // mean + stddev    result = new String[rows + 2][cols + 1];    // col names    result[0][0] = trimString("Dataset", getRowNameWidth());    x = 1;    for (ii = 0; ii < getColCount(); ii++) {      i = getDisplayCol(ii);      if (getColHidden(i))        continue;            result[0][x] = trimString(          removeFilterName(getColName(i)), getColNameWidth());      x++;      // std dev      if (getShowStdDev()) {        result[0][x] = "";        x++;      }      // sign.      result[0][x] = "";      x++;    }    // row names    y = 1;    for (ii = 0; ii < getRowCount(); ii++) {      i = getDisplayRow(ii);      if (!getRowHidden(i)) {        result[y][0] = trimString(            removeFilterName(getRowName(i)), getRowNameWidth());        y++;      }    }    // fill in mean/std dev    y = 1;    for (ii = 0; ii < getRowCount(); ii++) {      i = getDisplayRow(ii);      if (getRowHidden(i))        continue;      x = 1;      for (nn = 0; nn < getColCount(); nn++) {        n = getDisplayCol(nn);        if (getColHidden(n))          continue;        // do we have a value in the matrix?        valueExists = (!Double.isNaN(getMean(n, i)));        // mean        if (!valueExists)          result[y][x] = "";        else          result[y][x] = doubleToString(getMean(n, i), getMeanPrec());        x++;                // stddev        if (getShowStdDev()) {          if (!valueExists)            result[y][x] = "";          else if (Double.isInfinite(getStdDev(n, i)))            result[y][x] = "Inf";          else            result[y][x] = doubleToString(getStdDev(n, i), getStdDevPrec());          x++;        }                // significance        if (!valueExists) {          result[y][x] = "";        }        else {          switch (getSignificance(n, i)) {            case SIGNIFICANCE_TIE:              result[y][x] = TIE_STRING;              break;            case SIGNIFICANCE_WIN:              result[y][x] = WIN_STRING;              break;            case SIGNIFICANCE_LOSS:              result[y][x] = LOSS_STRING;              break;          }        }        x++;      }      y++;    }    // the average    if (getShowAverage()) {      y = result.length - 2;      x = 0;      result[y][0] = "Average";      x++;      for (ii = 0; ii < getColCount(); ii++) {        i = getDisplayCol(ii);        if (getColHidden(i))          continue;        // mean-average        result[y][x] = doubleToString(getAverage(i), getMeanPrec());        x++;        // std dev.        if (getShowStdDev()) {          result[y][x] = "";          x++;        }        // significance        result[y][x] = "";        x++;      }    }    // wins/ties/losses    y = result.length - 1;    x = 0;    result[y][0] =   LEFT_PARENTHESES                    + WIN_STRING + "/"                    + TIE_STRING + "/"                    + LOSS_STRING                    + RIGHT_PARENTHESES;    x++;    for (ii = 0; ii < getColCount(); ii++) {      i = getDisplayCol(ii);      if (getColHidden(i))        continue;      // mean      result[y][x] = "";      x++;      // std dev.      if (getShowStdDev()) {        result[y][x] = "";        x++;      }      // significance      result[y][x] =   LEFT_PARENTHESES                      + getSignificanceCount(i, SIGNIFICANCE_WIN) + "/"                      + getSignificanceCount(i, SIGNIFICANCE_TIE) + "/"                      + getSignificanceCount(i, SIGNIFICANCE_LOSS)                      + RIGHT_PARENTHESES;      x++;    }    // base column has no significance -> remove these columns    tmpResult = new String[result.length][result[0].length - 1];    x = 0;    for (i = 0; i < result[0].length; i++) {      // significance      if (    ((i == 3) && ( getShowStdDev()))           || ((i == 2) && (!getShowStdDev())) )        continue;            for (n = 0; n < result.length; n++)        tmpResult[n][x] = result[n][i];      x++;    }    result = tmpResult;    return result;  }  /**   * returns true if the index (in the array produced by toArray(boolean))   * is the row name   */  protected boolean isRowName(int index) {    return  (index == 0);  }  /**   * returns true if the index (in the array produced by toArray(boolean))   * contains a mean   */  protected boolean isMean(int index) {    index--;   // dataset    if (index == 0) {      return true;   // base column    }    else {      index--;   // base column      if (index < 0)        return false;            if (getShowStdDev())        return (index % 3 == 1);      else        return (index % 2 == 0);    }  }  /**   * returns true if the row index (in the array produced by toArray(boolean))   * contains the average row   */  protected boolean isAverage(int rowIndex) {    if (getShowAverage())      return (getVisibleRowCount() + 1 == rowIndex);    else      return false;  }  /**   * returns true if the index (in the array produced by toArray(boolean))   * contains a std deviation   */  protected boolean isStdDev(int index) {    index--;   // dataset    index--;   // base column    if (getShowStdDev()) {      if (index == 0) {        return true;   // stddev of base column      }      else {        index--;   // stddev of base column        if (index < 0)          return false;              return (index % 3 == 1);      }    }    else      return false;  }  /**   * returns true if the index (in the array produced by toArray(boolean))   * contains a significance column   */  protected boolean isSignificance(int index) {    index--;   // dataset    index--;   // base column    if (getShowStdDev()) {      index--;   // stddev of base column      if (index < 0)        return false;            return (index % 3 == 2);    }    else {      if (index < 0)        return false;            return (index % 2 == 1);    }  }  /**   * returns the matrix as a string   */  public abstract String toStringMatrix();  /**   * returns the matrix as a string   * @see #toStringMatrix()   */  public String toString() {    return toStringMatrix();  }  /**   * removes all the header information   */  public void clearHeader() {    m_HeaderKeys   = new Vector();    m_HeaderValues = new Vector();  }  /**   * adds the key-value pair to the header   * @param key       the name of the header value   * @param value     the value of the header value   */  public void addHeader(String key, String value) {    int         pos;        pos = m_HeaderKeys.indexOf(key);    if (pos > -1) {      m_HeaderValues.set(pos, value);    }    else {      m_HeaderKeys.add(key);      m_HeaderValues.add(value);    }  }  /**   * returns the value associated with the given key, null if if cannot be   * found   * @param key       the key to retrieve the value for   * @return          the associated value   */  public String getHeader(String key) {    int       pos;    pos = m_HeaderKeys.indexOf(key);    if (pos == 0)      return null;    else      return (String) m_HeaderKeys.get(pos);  }  /**   * returns an enumeration of the header keys   * @return all stored keys   */  public Enumeration headerKeys() {    return m_HeaderKeys.elements();  }    /**   * returns the header of the matrix as a string   * @see #m_HeaderKeys   * @see #m_HeaderValues   */  public abstract String toStringHeader();  /**   * returns returns a key for all the col names, for better readability if   * the names got cut off   */  public abstract String toStringKey();  /**   * clears the current summary data   */  public void clearSummary() {    m_NonSigWins = null;    m_Wins       = null;  }  /**   * sets the non-significant and significant wins of the resultsets   * @param nonSigWins      the non-significant wins   * @param wins         the significant wins   */  public void setSummary(int[][] nonSigWins, int[][] wins) {    int         i;    int         n;        m_NonSigWins = new int[nonSigWins.length][nonSigWins[0].length];    m_Wins       = new int[wins.length][wins[0].length];    for (i = 0; i < m_NonSigWins.length; i++) {      for (n = 0; n < m_NonSigWins[i].length; n++) {        m_NonSigWins[i][n] = nonSigWins[i][n];        m_Wins[i][n]       = wins[i][n];      }    }  }  /**   * returns the character representation of the given column   */  protected String getSummaryTitle(int col) {    return "" + (char) ((int) 'a' + col % 26);  }  /**   * returns the summary as string   */  public abstract String toStringSummary();  /**   * clears the currently stored ranking data   */  public void clearRanking() {    m_RankingWins   = null;    m_RankingLosses = null;    m_RankingDiff   = null;  }  /**   * sets the ranking data based on the wins   * @param wins      the wins    */  public void setRanking(int[][] wins) {    int         i;    int         j;        m_RankingWins   = new int[wins.length];    m_RankingLosses = new int[wins.length];    m_RankingDiff   = new int[wins.length];    for (i = 0; i < wins.length; i++) {      for (j = 0; j < wins[i].length; j++) {	m_RankingWins[j]   += wins[i][j];	m_RankingDiff[j]   += wins[i][j];	m_RankingLosses[i] += wins[i][j];	m_RankingDiff[i]   -= wins[i][j];      }    }  }  /**   * returns the ranking in a string representation   */  public abstract String toStringRanking();}

⌨️ 快捷键说明

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