pairedttester.java
来自「wekaUT是 university texas austin 开发的基于wek」· Java 代码 · 共 1,963 行 · 第 1/5 页
JAVA
1,963 行
* @return a value of type 'String' */ public String header(String comparisonField) { if (!m_ResultsetsValid) { try { prepareData(); } catch (Exception ex) { ex.printStackTrace(); return ex.getMessage(); } } return "Analysing: " + comparisonField + '\n' + "Datasets: " + getNumDatasets() + '\n' + "Resultsets: " + getNumResultsets() + '\n' + "Confidence: " + getSignificanceLevel() + " (two tailed)\n" + "Date: " + (new SimpleDateFormat()).format(new Date()) + "\n\n"; } /** * Carries out a comparison between all resultsets, counting the number * of datsets where one resultset outperforms the other. * * @param comparisonColumn the index of the comparison column * @return a 2d array where element [i][j] is the number of times resultset * j performed significantly better than resultset i. * @exception Exception if an error occurs */ public int [][] multiResultsetWins(int comparisonColumn) throws Exception { int numResultsets = getNumResultsets(); int [][] win = new int [numResultsets][numResultsets]; for (int i = 0; i < numResultsets; i++) { for (int j = i + 1; j < numResultsets; j++) { System.err.print("Comparing (" + (i + 1) + ") with (" + (j + 1) + ")\r"); System.err.flush(); for (int k = 0; k < getNumDatasets(); k++) { try { PairedStats pairedStats = calculateStatistics(m_DatasetSpecifiers.specifier(k), i, j, comparisonColumn); if (pairedStats.differencesSignificance < 0) { win[i][j]++; } else if (pairedStats.differencesSignificance > 0) { win[j][i]++; } } catch (Exception ex) { ex.printStackTrace(); System.err.println(ex.getMessage()); } } } } return win; } /** * Carries out a comparison between all resultsets, counting the number * of datsets where one resultset outperforms the other. The results * are summarized in a table. * * @param comparisonColumn the index of the comparison column * @return the results in a string * @exception Exception if an error occurs */ public String multiResultsetSummary(int comparisonColumn) throws Exception { int [][] win = multiResultsetWins(comparisonColumn); int numResultsets = getNumResultsets(); int resultsetLength = 1 + Math.max((int)(Math.log(numResultsets) / Math.log(10)), (int)(Math.log(getNumDatasets()) / Math.log(10))); String result = ""; String titles = ""; if (m_latexOutput) { result += "\\begin{table}[thb]\n\\caption{\\label{labelname}" +"Table Caption}\n"; result += "\\footnotesize\n"; result += "{\\centering \\begin{tabular}{l"; } for (int i = 0; i < numResultsets; i++) { if (m_latexOutput) { titles += " &"; result += "c"; } titles += ' ' + Utils.padLeft("" + (char)((int)'a' + i % 26), resultsetLength); } if (m_latexOutput) { result += "}}\\\\\n\\hline\n"; result += titles + " \\\\\n\\hline\n"; } else { result += titles + " (No. of datasets where [col] >> [row])\n"; } for (int i = 0; i < numResultsets; i++) { for (int j = 0; j < numResultsets; j++) { if (m_latexOutput && j == 0) { result += (char)((int)'a' + i % 26); } if (j == i) { if (m_latexOutput) { result += " & - "; } else { result += ' ' + Utils.padLeft("-", resultsetLength); } } else { if (m_latexOutput) { result += "& " + win[i][j] + ' '; } else { result += ' ' + Utils.padLeft("" + win[i][j], resultsetLength); } } } if (!m_latexOutput) { result += " | " + (char)((int)'a' + i % 26) + " = " + getResultsetName(i) + '\n'; } else { result += "\\\\\n"; } } if (m_latexOutput) { result += "\\hline\n\\end{tabular} \\footnotesize \\par}\n\\end{table}"; } return result; } public String multiResultsetRanking(int comparisonColumn) throws Exception { int [][] win = multiResultsetWins(comparisonColumn); int numResultsets = getNumResultsets(); int [] wins = new int [numResultsets]; int [] losses = new int [numResultsets]; int [] diff = new int [numResultsets]; for (int i = 0; i < win.length; i++) { for (int j = 0; j < win[i].length; j++) { wins[j] += win[i][j]; diff[j] += win[i][j]; losses[i] += win[i][j]; diff[i] -= win[i][j]; } } int biggest = Math.max(wins[Utils.maxIndex(wins)], losses[Utils.maxIndex(losses)]); int width = Math.max(2 + (int)(Math.log(biggest) / Math.log(10)), ">-<".length()); String result; if (m_latexOutput) { result = "\\begin{table}[thb]\n\\caption{\\label{labelname}Table Caption" +"}\n\\footnotesize\n{\\centering \\begin{tabular}{rlll}\\\\\n\\hline\n"; result += "Resultset & Wins$-$ & Wins & Losses \\\\\n& Losses & & " +"\\\\\n\\hline\n"; } else { result = Utils.padLeft(">-<", width) + ' ' + Utils.padLeft(">", width) + ' ' + Utils.padLeft("<", width) + " Resultset\n"; } int [] ranking = Utils.sort(diff); for (int i = numResultsets - 1; i >= 0; i--) { int curr = ranking[i]; if (m_latexOutput) { result += "(" + (curr+1) + ") & " + Utils.padLeft("" + diff[curr], width) +" & " + Utils.padLeft("" + wins[curr], width) +" & " + Utils.padLeft("" + losses[curr], width) +"\\\\\n"; } else { result += Utils.padLeft("" + diff[curr], width) + ' ' + Utils.padLeft("" + wins[curr], width) + ' ' + Utils.padLeft("" + losses[curr], width) + ' ' + getResultsetName(curr) + '\n'; } } if (m_latexOutput) { result += "\\hline\n\\end{tabular} \\footnotesize \\par}\n\\end{table}"; } return result; } /** * Generates a comparison table in latex table format * * @param baseResultset the index of the base resultset * @param comparisonColumn the index of the column to compare over * @param maxWidthMean width for the mean * @param maxWidthStdDev width for the standard deviation * @return the comparison table string */ private String multiResultsetFullLatex(int baseResultset, int comparisonColumn, int maxWidthMean, int maxWidthStdDev) { StringBuffer result = new StringBuffer(1000); int numcols = getNumResultsets() * 2; if (m_ShowStdDevs) { numcols += getNumResultsets(); } result.append("\\begin{table}[thb]\n\\caption{\\label{labelname}" +"Table Caption}\n"); if (!m_ShowStdDevs) { result.append("\\footnotesize\n"); } else { result.append("\\scriptsize\n"); } // output the column alignment characters // one for the dataset name and one for the comparison column if (!m_ShowStdDevs) { result.append("{\\centering \\begin{tabular}{ll"); } else { // dataset, mean, std dev result.append("{\\centering \\begin{tabular}{lr@{\\hspace{0cm}}l"); } for (int j = 0; j < getNumResultsets(); j++) { if (j != baseResultset) { if (!m_ShowStdDevs) { result.append("l@{\\hspace{0.1cm}}l"); } else { result.append("r@{\\hspace{0cm}}l@{\\hspace{0cm}}r"); } } } result.append("}\n\\\\\n\\hline\n"); if (!m_ShowStdDevs) { result.append("Data Set & ("+(baseResultset+1)+")"); } else { result.append("Data Set & \\multicolumn{2}{c}{("+(baseResultset+1)+")}"); } // now do the column names (numbers) for (int j = 0; j < getNumResultsets(); j++) { if (j != baseResultset) { if (!m_ShowStdDevs) { result.append("& (" + (j + 1) + ") & "); } else { result.append("& \\multicolumn{3}{c}{(" + (j + 1) + ")} "); } } } result.append("\\\\\n\\hline\n"); int datasetLength = 25; int resultsetLength = maxWidthMean + 7; if (m_ShowStdDevs) { resultsetLength += (maxWidthStdDev + 5); } for (int i = 0; i < getNumDatasets(); i++) { // Print the name of the dataset String datasetName = templateString(m_DatasetSpecifiers.specifier(i)).replace('_','-'); try { PairedStats pairedStats = calculateStatistics(m_DatasetSpecifiers.specifier(i), baseResultset, baseResultset, comparisonColumn); datasetName = Utils.padRight(datasetName, datasetLength); result.append(datasetName); if (!m_ShowStdDevs) { result.append("& "+Utils.doubleToString(pairedStats.xStats.mean, resultsetLength - 2, 2)); } else { result.append("& "+Utils.doubleToString(pairedStats.xStats.mean, (maxWidthMean+5), 2)+"$\\pm$"); if (Double.isNaN(pairedStats.xStats.stdDev)) { result.append("&"+Utils.doubleToString(0.0, (maxWidthStdDev+3),2)+" "); } else { result.append("&"+Utils.doubleToString(pairedStats.xStats.stdDev, (maxWidthStdDev+3),2)+" "); } } // Iterate over the resultsets for (int j = 0; j < getNumResultsets(); j++) { if (j != baseResultset) { try { pairedStats = calculateStatistics(m_DatasetSpecifiers.specifier(i), baseResultset, j, comparisonColumn); String sigString = ""; if (pairedStats.differencesSignificance < 0) { sigString = "$\\circ$"; } else if (pairedStats.differencesSignificance > 0) { sigString = "$\\bullet$"; } if (!m_ShowStdDevs) { result.append(" & "+Utils.doubleToString(pairedStats.yStats.mean, resultsetLength - 2, 2)).append(" & "+sigString); } else { result.append(" & " +Utils.doubleToString(pairedStats.yStats.mean, (maxWidthMean+5), 2)+"$\\pm$"); if (Double.isNaN(pairedStats.yStats.stdDev)) { result.append("&"+Utils.doubleToString(0.0, (maxWidthStdDev+3),2)+" "); } else { result.append("&"+Utils.doubleToString(pairedStats. yStats.stdDev, (maxWidthStdDev+3),2)+" "); } result.append(" & ").append(sigString); } } catch (Exception ex) { ex.printStackTrace(); result.append(Utils.padLeft("", resultsetLength + 1)); } } } result.append("\\\\\n"); } catch (Exception ex) { ex.printStackTrace(); } } result.append("\\hline\n\\multicolumn{"+numcols+"}{c}{$\\circ$, $\\bullet$" +" statistically significant improvement or degradation}" +"\\\\\n\\end{tabular} "); if (!m_ShowStdDevs) { result.append("\\footnotesize "); } else { result.append("\\scriptsize "); } result.append("\\par}\n\\end{table}" +"\n"); System.out.println(result.toString()+"\n\n"); return result.toString(); } /** * Generates a comparison table in latex table format * * @param baseResultset the index of the base resultset * @param comparisonColumn the index of the column to compare over * @param maxWidthMean width for the mean * @param maxWidthStdDev width for the standard deviation * @return the comparison table string */ private String multiResultsetFullPlainText(int baseResultset, int comparisonColumn, int maxWidthMean, int maxWidthStdDev) { StringBuffer result = new StringBuffer(1000); int datasetLength = 25; //=============== BEGIN EDIT melville =============== int meanWidth = maxWidthMean + 2; int meanWidthStdDev = maxWidthStdDev; if(m_Precision>0) {//account for the decimal point and decimal digits meanWidth += (1 + m_Precision); meanWidthStdDev += (1 + m_Precision); } int resultsetLength = meanWidth + 2; if (m_ShowStdDevs) { resultsetLength += (meanWidthStdDev + 2); } //=============== END EDIT melville =============== // Set up the titles StringBuffer titles = new StringBuffer(Utils.padRight("Dataset", datasetLength)); titles.append(' '); StringBuffer label = new StringBuffer(Utils.padLeft("(" + (baseResultset + 1) + ") " + getResultsetName(baseResultset), resultsetLength + 3)); titles.append(label); StringBuffer separator = new StringBuffer(Utils.padRight("", datasetLength)); while (separator.length() < titles.length()) { separator.append('-'); } separator.append("---"); titles.append(" | ");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?