2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
* ResultMatrixHTML.java
19
* Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
23
package weka.experiment;
25
import weka.core.Utils;
28
* This matrix is a container for the datasets and classifier setups and
29
* their statistics. It outputs the matrix in HTML.
32
* @author FracPete (fracpete at waikato dot ac dot nz)
33
* @version $Revision: 1.3 $
35
public class ResultMatrixHTML
36
extends ResultMatrix {
38
/** for serialization */
39
private static final long serialVersionUID = 6672380422544799990L;
42
* initializes the matrix as 1x1 matrix
44
public ResultMatrixHTML() {
49
* initializes the matrix with the given dimensions
51
public ResultMatrixHTML(int cols, int rows) {
56
* initializes the matrix with the values from the given matrix
57
* @param matrix the matrix to get the values from
59
public ResultMatrixHTML(ResultMatrix matrix) {
64
* returns the name of the output format
66
public String getDisplayName() {
71
* removes the stored data but retains the dimensions of the matrix
76
setPrintColNames(false);
77
setEnumerateColNames(true);
81
* returns the header of the matrix as a string
83
* @see #m_HeaderValues
85
public String toStringHeader() {
86
return new ResultMatrixPlainText(this).toStringHeader();
90
* returns the matrix in an HTML table
92
public String toStringMatrix() {
99
result = new StringBuffer();
102
result.append("<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n");
105
result.append(" <tr>");
106
for (n = 0; n < cells[0].length; n++) {
108
result.append("<td><b>" + cells[0][n] + "</b></td>");
110
else if (isMean(n)) {
117
result.append("<td align=\"center\" colspan=\"" + cols + "\">");
118
result.append("<b>" + cells[0][n] + "</b>");
119
result.append("</td>");
122
result.append("</tr>\n");
125
for (i = 1; i < cells.length; i++) {
126
result.append(" <tr>");
127
for (n = 0; n < cells[i].length; n++) {
129
result.append("<td>");
130
else if (isMean(n) || isStdDev(n))
131
result.append("<td align=\"right\">");
132
else if (isSignificance(n))
133
result.append("<td align=\"center\">");
135
result.append("<td>");
138
if (cells[i][n].trim().equals(""))
139
result.append(" ");
140
else if (isStdDev(n))
141
result.append("± " + cells[i][n]);
143
result.append(cells[i][n]);
145
result.append("</td>");
147
result.append("</tr>\n");
149
result.append("</table>\n");
151
return result.toString();
155
* returns returns a key for all the col names, for better readability if
156
* the names got cut off
158
public String toStringKey() {
162
result = "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n"
163
+ " <tr><td colspan=\"2\"><b>Key</b></td></tr>\n";
164
for (i = 0; i < getColCount(); i++) {
169
+ "<td><b>(" + (i+1) + ")</b></td>"
170
+ "<td>" + removeFilterName(m_ColNames[i]) + "</td>"
174
result += "</table>\n";
180
* returns the summary as string
182
public String toStringSummary() {
190
if (m_NonSigWins == null)
191
return "-summary data not set-";
193
result = "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n";
195
resultsetLength = 1 + Math.max((int)(Math.log(getColCount())/Math.log(10)),
196
(int)(Math.log(getRowCount())/Math.log(10)));
198
for (i = 0; i < getColCount(); i++) {
201
titles += "<td align=\"center\"><b>" + getSummaryTitle(i) + "</b></td>";
204
+ "<td><b>(No. of datasets where [col] >> [row])</b></td></tr>\n";
206
for (i = 0; i < getColCount(); i++) {
212
for (j = 0; j < getColCount(); j++) {
217
content = Utils.padLeft("-", resultsetLength * 2 + 3);
219
content = Utils.padLeft("" + m_NonSigWins[i][j]
220
+ " (" + m_Wins[i][j] + ")",
221
resultsetLength * 2 + 3);
222
result += "<td>" + content.replaceAll(" ", " ") + "</td>";
225
result += "<td><b>" + getSummaryTitle(i) + "</b> = " + removeFilterName(m_ColNames[i]) + "</td></tr>\n";
228
result += "</table>\n";
234
* returns the ranking in a string representation
236
public String toStringRanking() {
244
if (m_RankingWins == null)
245
return "-ranking data not set-";
247
biggest = Math.max(m_RankingWins[Utils.maxIndex(m_RankingWins)],
248
m_RankingLosses[Utils.maxIndex(m_RankingLosses)]);
249
width = Math.max(2 + (int)(Math.log(biggest) / Math.log(10)),
251
result = "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n";
253
+ "<td align=\"center\"><b>>-<</b></td>"
254
+ "<td align=\"center\"><b>></b></td>"
255
+ "<td align=\"center\"><b><</b></td>"
256
+ "<td><b>Resultset</b></td>"
259
ranking = Utils.sort(m_RankingDiff);
261
for (i = getColCount() - 1; i >= 0; i--) {
264
if (getColHidden(curr))
268
+ "<td align=\"right\">" + m_RankingDiff[curr] + "</td>"
269
+ "<td align=\"right\">" + m_RankingWins[curr] + "</td>"
270
+ "<td align=\"right\">" + m_RankingLosses[curr] + "</td>"
271
+ "<td>" + removeFilterName(m_ColNames[curr]) + "</td>"
275
result += "</table>\n";
283
public static void main(String[] args) {
288
matrix = new ResultMatrixHTML(3, 3);
291
matrix.addHeader("header1", "value1");
292
matrix.addHeader("header2", "value2");
293
matrix.addHeader("header2", "value3");
296
for (i = 0; i < matrix.getRowCount(); i++) {
297
for (n = 0; n < matrix.getColCount(); n++) {
298
matrix.setMean(n, i, (i+1)*n);
299
matrix.setStdDev(n, i, ((double) (i+1)*n) / 100);
302
matrix.setSignificance(n, i, SIGNIFICANCE_WIN);
304
matrix.setSignificance(n, i, SIGNIFICANCE_LOSS);
309
System.out.println("\n\n--> " + matrix.getDisplayName());
311
System.out.println("\n1. complete\n");
312
System.out.println(matrix.toStringHeader() + "\n");
313
System.out.println(matrix.toStringMatrix() + "\n");
314
System.out.println(matrix.toStringKey());
316
System.out.println("\n2. complete with std deviations\n");
317
matrix.setShowStdDev(true);
318
System.out.println(matrix.toStringMatrix());
320
System.out.println("\n3. cols numbered\n");
321
matrix.setPrintColNames(false);
322
System.out.println(matrix.toStringMatrix());
324
System.out.println("\n4. second col missing\n");
325
matrix.setColHidden(1, true);
326
System.out.println(matrix.toStringMatrix());
328
System.out.println("\n5. last row missing, rows numbered too\n");
329
matrix.setRowHidden(2, true);
330
matrix.setPrintRowNames(false);
331
System.out.println(matrix.toStringMatrix());
333
System.out.println("\n6. mean prec to 3\n");
334
matrix.setMeanPrec(3);
335
matrix.setPrintRowNames(false);
336
System.out.println(matrix.toStringMatrix());