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.
19
* Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
23
package weka.experiment;
25
import weka.core.Utils;
27
import java.io.Serializable;
28
import java.util.Enumeration;
29
import java.util.Vector;
32
* This matrix is a container for the datasets and classifier setups and
33
* their statistics. Derived classes output the data in different formats.
34
* Derived classes need to implement the following methods:
36
* <li><code>toStringMatrix()</code></li>
37
* <li><code>toStringKey()</code></li>
38
* <li><code>toStringHeader()</code></li>
39
* <li><code>toStringSummary()</code></li>
40
* <li><code>toStringRanking()</code></li>
44
* @author FracPete (fracpete at waikato dot ac dot nz)
45
* @version $Revision: 1.8 $
46
* @see #toStringMatrix()
48
* @see #toStringHeader()
49
* @see #toStringSummary()
50
* @see #toStringRanking()
52
public abstract class ResultMatrix
53
implements Serializable {
55
/** for serialization */
56
private static final long serialVersionUID = 4487179306428209739L;
59
public final static int SIGNIFICANCE_TIE = 0;
62
public final static int SIGNIFICANCE_WIN = 1;
65
public final static int SIGNIFICANCE_LOSS = 2;
68
public String TIE_STRING = " ";
71
public String WIN_STRING = "v";
74
public String LOSS_STRING = "*";
76
/** the left parentheses for enumerating cols/rows */
77
public String LEFT_PARENTHESES = "(";
79
/** the right parentheses for enumerating cols/rows */
80
public String RIGHT_PARENTHESES = ")";
82
/** the column names */
83
protected String[] m_ColNames = null;
86
protected String[] m_RowNames = null;
88
/** whether a column is hidden */
89
protected boolean[] m_ColHidden = null;
91
/** whether a row is hidden */
92
protected boolean[] m_RowHidden = null;
94
/** the significance */
95
protected int[][] m_Significance = null;
98
protected double[][] m_Mean = null;
100
/** the standard deviation */
101
protected double[][] m_StdDev = null;
103
/** the counts for the different datasets */
104
protected double[] m_Counts = null;
106
/** the standard mean precision */
107
protected int m_MeanPrec;
109
/** the standard std. deviation preicision */
110
protected int m_StdDevPrec;
112
/** whether std. deviations are printed as well */
113
protected boolean m_ShowStdDev;
115
/** whether the average for each column should be printed */
116
protected boolean m_ShowAverage;
118
/** whether the names or numbers are output as column declarations */
119
protected boolean m_PrintColNames;
121
/** whether the names or numbers are output as row declarations */
122
protected boolean m_PrintRowNames;
124
/** whether a "(x)" is printed before each column name with "x" as the
126
protected boolean m_EnumerateColNames;
128
/** whether a "(x)" is printed before each row name with "x" as the index */
129
protected boolean m_EnumerateRowNames;
131
/** the size of the names of the columns */
132
protected int m_ColNameWidth;
134
/** the size of the names of the rows */
135
protected int m_RowNameWidth;
137
/** the size of the mean columns */
138
protected int m_MeanWidth;
140
/** the size of the std dev columns */
141
protected int m_StdDevWidth;
143
/** the size of the significance columns */
144
protected int m_SignificanceWidth;
146
/** the size of the counts */
147
protected int m_CountWidth;
149
/** contains the keys for the header */
150
protected Vector m_HeaderKeys = null;
152
/** contains the values for the header */
153
protected Vector m_HeaderValues = null;
155
/** the non-significant wins */
156
protected int[][] m_NonSigWins = null;
158
/** the significant wins */
159
protected int[][] m_Wins = null;
161
/** the wins in ranking */
162
protected int[] m_RankingWins = null;
164
/** the losses in ranking */
165
protected int[] m_RankingLosses = null;
167
/** the difference between wins and losses */
168
protected int[] m_RankingDiff = null;
170
/** the ordering of the rows */
171
protected int[] m_RowOrder = null;
173
/** the ordering of the columns */
174
protected int[] m_ColOrder = null;
176
/** whether to remove the filter name from the dataaset name */
177
protected boolean m_RemoveFilterName = false;
180
* initializes the matrix as 1x1 matrix
182
public ResultMatrix() {
187
* initializes the matrix with the given dimensions
189
public ResultMatrix(int cols, int rows) {
195
* initializes the matrix with the values from the given matrix
196
* @param matrix the matrix to get the values from
198
public ResultMatrix(ResultMatrix matrix) {
203
* returns the name of the output format
205
public abstract String getDisplayName();
208
* acquires the data from the given matrix
210
public void assign(ResultMatrix matrix) {
214
setSize(matrix.getColCount(), matrix.getRowCount());
217
TIE_STRING = matrix.TIE_STRING;
218
WIN_STRING = matrix.WIN_STRING;
219
LOSS_STRING = matrix.LOSS_STRING;
220
LEFT_PARENTHESES = matrix.LEFT_PARENTHESES;
221
RIGHT_PARENTHESES = matrix.RIGHT_PARENTHESES;
222
m_MeanPrec = matrix.m_MeanPrec;
223
m_StdDevPrec = matrix.m_StdDevPrec;
224
m_ShowStdDev = matrix.m_ShowStdDev;
225
m_ShowAverage = matrix.m_ShowAverage;
226
m_PrintColNames = matrix.m_PrintColNames;
227
m_PrintRowNames = matrix.m_PrintRowNames;
228
m_EnumerateColNames = matrix.m_EnumerateColNames;
229
m_EnumerateRowNames = matrix.m_EnumerateRowNames;
230
m_RowNameWidth = matrix.m_RowNameWidth;
231
m_MeanWidth = matrix.m_MeanWidth;
232
m_StdDevWidth = matrix.m_StdDevWidth;
233
m_SignificanceWidth = matrix.m_SignificanceWidth;
234
m_CountWidth = matrix.m_CountWidth;
235
m_RemoveFilterName = matrix.m_RemoveFilterName;
238
m_HeaderKeys = (Vector) matrix.m_HeaderKeys.clone();
239
m_HeaderValues = (Vector) matrix.m_HeaderValues.clone();
242
for (i = 0; i < matrix.m_Mean.length; i++) {
243
for (n = 0; n < matrix.m_Mean[i].length; n++) {
244
m_Mean[i][n] = matrix.m_Mean[i][n];
245
m_StdDev[i][n] = matrix.m_StdDev[i][n];
246
m_Significance[i][n] = matrix.m_Significance[i][n];
250
for (i = 0; i < matrix.m_ColNames.length; i++) {
251
m_ColNames[i] = matrix.m_ColNames[i];
252
m_ColHidden[i] = matrix.m_ColHidden[i];
255
for (i = 0; i < matrix.m_RowNames.length; i++) {
256
m_RowNames[i] = matrix.m_RowNames[i];
257
m_RowHidden[i] = matrix.m_RowHidden[i];
260
for (i = 0; i < matrix.m_Counts.length; i++)
261
m_Counts[i] = matrix.m_Counts[i];
264
if (matrix.m_NonSigWins != null) {
265
m_NonSigWins = new int[matrix.m_NonSigWins.length][];
266
m_Wins = new int[matrix.m_NonSigWins.length][];
267
for (i = 0; i < matrix.m_NonSigWins.length; i++) {
268
m_NonSigWins[i] = new int[matrix.m_NonSigWins[i].length];
269
m_Wins[i] = new int[matrix.m_NonSigWins[i].length];
271
for (n = 0; n < matrix.m_NonSigWins[i].length; n++) {
272
m_NonSigWins[i][n] = matrix.m_NonSigWins[i][n];
273
m_Wins[i][n] = matrix.m_Wins[i][n];
279
if (matrix.m_RankingWins != null) {
280
m_RankingWins = new int[matrix.m_RankingWins.length];
281
m_RankingLosses = new int[matrix.m_RankingWins.length];
282
m_RankingDiff = new int[matrix.m_RankingWins.length];
283
for (i = 0; i < matrix.m_RankingWins.length; i++) {
284
m_RankingWins[i] = matrix.m_RankingWins[i];
285
m_RankingLosses[i] = matrix.m_RankingLosses[i];
286
m_RankingDiff[i] = matrix.m_RankingDiff[i];
292
* removes the stored data and the ordering, but retains the dimensions of
295
public void clear() {
298
m_ShowStdDev = false;
299
m_ShowAverage = false;
300
m_PrintColNames = true;
301
m_PrintRowNames = true;
302
m_EnumerateColNames = true;
303
m_EnumerateRowNames = false;
308
m_SignificanceWidth = 0;
311
setSize(getColCount(), getRowCount());
315
* clears the content of the matrix and sets the new size
316
* @param cols the number of mean columns
317
* @param rows the number of mean rows
319
public void setSize(int cols, int rows) {
323
m_ColNames = new String[cols];
324
m_RowNames = new String[rows];
325
m_Counts = new double[rows];
326
m_ColHidden = new boolean[cols];
327
m_RowHidden = new boolean[rows];
328
m_Mean = new double[rows][cols];
329
m_Significance = new int[rows][cols];
330
m_StdDev = new double[rows][cols];
334
// NaN means that there exists no value! -> toArray()
335
for (i = 0; i < m_Mean.length; i++) {
336
for (n = 0; n < m_Mean[i].length; n++)
337
m_Mean[i][n] = Double.NaN;
340
for (i = 0; i < m_ColNames.length; i++)
341
m_ColNames[i] = "col" + i;
342
for (i = 0; i < m_RowNames.length; i++)
343
m_RowNames[i] = "row" + i;
351
* sets the precision for the means
353
public void setMeanPrec(int prec) {
359
* returns the current precision for the means
361
public int getMeanPrec() {
366
* sets the precision for the standard deviation
368
public void setStdDevPrec(int prec) {
374
* returns the current standard deviation precision
376
public int getStdDevPrec() {
381
* sets the width for the column names (0 = optimal)
383
public void setColNameWidth(int width) {
385
m_ColNameWidth = width;
389
* returns the current width for the column names
391
public int getColNameWidth() {
392
return m_ColNameWidth;
396
* sets the width for the row names (0 = optimal)
398
public void setRowNameWidth(int width) {
400
m_RowNameWidth = width;
404
* returns the current width for the row names
406
public int getRowNameWidth() {
407
return m_RowNameWidth;
411
* sets the width for the mean (0 = optimal)
413
public void setMeanWidth(int width) {
419
* returns the current width for the mean
421
public int getMeanWidth() {
426
* sets the width for the std dev (0 = optimal)
428
public void setStdDevWidth(int width) {
430
m_StdDevWidth = width;
434
* returns the current width for the std dev
436
public int getStdDevWidth() {
437
return m_StdDevWidth;
441
* sets the width for the significance (0 = optimal)
443
public void setSignificanceWidth(int width) {
445
m_SignificanceWidth = width;
449
* returns the current width for the significance
451
public int getSignificanceWidth() {
452
return m_SignificanceWidth;
456
* sets the width for the counts (0 = optimal)
458
public void setCountWidth(int width) {
460
m_CountWidth = width;
464
* returns the current width for the counts
466
public int getCountWidth() {
471
* sets whether to display the std deviations or not
473
public void setShowStdDev(boolean show) {
478
* returns whether std deviations are displayed or not
480
public boolean getShowStdDev() {
485
* sets whether to display the average per column or not
487
public void setShowAverage(boolean show) {
488
m_ShowAverage = show;
492
* returns whether average per column is displayed or not
494
public boolean getShowAverage() {
495
return m_ShowAverage;
499
* sets whether to remove the filter classname from the dataset name
501
public void setRemoveFilterName(boolean remove) {
502
m_RemoveFilterName = remove;
506
* returns whether the filter classname is removed from the dataset name
508
public boolean getRemoveFilterName() {
509
return m_RemoveFilterName;
513
* sets whether the column names or numbers instead are printed.
514
* deactivating automatically sets m_EnumerateColNames to TRUE.
515
* @see #setEnumerateColNames(boolean)
517
public void setPrintColNames(boolean print) {
518
m_PrintColNames = print;
520
setEnumerateColNames(true);
524
* returns whether column names or numbers instead are printed
526
public boolean getPrintColNames() {
527
return m_PrintColNames;
531
* sets whether the row names or numbers instead are printed
532
* deactivating automatically sets m_EnumerateColNames to TRUE.
533
* @see #setEnumerateRowNames(boolean)
535
public void setPrintRowNames(boolean print) {
536
m_PrintRowNames = print;
538
setEnumerateRowNames(true);
542
* returns whether row names or numbers instead are printed
544
public boolean getPrintRowNames() {
545
return m_PrintRowNames;
549
* sets whether the column names are prefixed with "(x)" where "x" is
552
public void setEnumerateColNames(boolean enumerate) {
553
m_EnumerateColNames = enumerate;
557
* returns whether column names or numbers instead are enumerateed
559
public boolean getEnumerateColNames() {
560
return m_EnumerateColNames;
564
* sets whether to the row names or numbers instead are enumerateed
566
public void setEnumerateRowNames(boolean enumerate) {
567
m_EnumerateRowNames = enumerate;
571
* returns whether row names or numbers instead are enumerateed
573
public boolean getEnumerateRowNames() {
574
return m_EnumerateRowNames;
578
* returns the number of columns
580
public int getColCount() {
581
return m_ColNames.length;
585
* returns the number of visible columns
587
public int getVisibleColCount() {
592
for (i = 0; i < getColCount(); i++) {
593
if (!getColHidden(i))
601
* returns the number of rows
603
public int getRowCount() {
604
return m_RowNames.length;
608
* returns the number of visible rows
610
public int getVisibleRowCount() {
615
for (i = 0; i < getRowCount(); i++) {
616
if (!getRowHidden(i))
624
* sets the name of the column (if the index is valid)
625
* @param index the index of the column
626
* @param name the name of the column
628
public void setColName(int index, String name) {
629
if ( (index >= 0) && (index < getColCount()) )
630
m_ColNames[index] = name;
634
* returns the name of the row, if the index is valid, otherwise null.
635
* if getPrintColNames() is FALSE then an empty string is returned or if
636
* getEnumerateColNames() is TRUE then the 1-based index surrounded by
638
* @see #setPrintColNames(boolean)
639
* @see #getPrintColNames()
640
* @see #setEnumerateColNames(boolean)
641
* @see #getEnumerateColNames()
643
public String getColName(int index) {
648
if ( (index >= 0) && (index < getColCount()) ) {
649
if (getPrintColNames())
650
result = m_ColNames[index];
654
if (getEnumerateColNames()) {
655
result = LEFT_PARENTHESES
656
+ Integer.toString(index + 1)
659
result = result.trim();
667
* sets the name of the row (if the index is valid)
668
* @param index the index of the row
669
* @param name the name of the row
671
public void setRowName(int index, String name) {
672
if ( (index >= 0) && (index < getRowCount()) )
673
m_RowNames[index] = name;
677
* returns the name of the row, if the index is valid, otherwise null.
678
* if getPrintRowNames() is FALSE then an empty string is returned or if
679
* getEnumerateRowNames() is TRUE then the 1-based index surrounded by
681
* @see #setPrintRowNames(boolean)
682
* @see #getPrintRowNames()
683
* @see #setEnumerateRowNames(boolean)
684
* @see #getEnumerateRowNames()
686
public String getRowName(int index) {
691
if ( (index >= 0) && (index < getRowCount()) ) {
692
if (getPrintRowNames())
693
result = m_RowNames[index];
697
if (getEnumerateRowNames()) {
698
result = LEFT_PARENTHESES
699
+ Integer.toString(index + 1)
702
result = result.trim();
710
* sets the hidden status of the column (if the index is valid)
711
* @param index the index of the column
712
* @param hidden the hidden status of the column
714
public void setColHidden(int index, boolean hidden) {
715
if ( (index >= 0) && (index < getColCount()) )
716
m_ColHidden[index] = hidden;
720
* returns the hidden status of the column, if the index is valid, otherwise
723
public boolean getColHidden(int index) {
724
if ( (index >= 0) && (index < getColCount()) )
725
return m_ColHidden[index];
731
* sets the hidden status of the row (if the index is valid)
732
* @param index the index of the row
733
* @param hidden the hidden status of the row
735
public void setRowHidden(int index, boolean hidden) {
736
if ( (index >= 0) && (index < getRowCount()) )
737
m_RowHidden[index] = hidden;
741
* returns the hidden status of the row, if the index is valid, otherwise
744
public boolean getRowHidden(int index) {
745
if ( (index >= 0) && (index < getRowCount()) )
746
return m_RowHidden[index];
752
* sets the count for the row (if the index is valid)
753
* @param index the index of the row
754
* @param count the count for the row
756
public void setCount(int index, double count) {
757
if ( (index >= 0) && (index < getRowCount()) )
758
m_Counts[index] = count;
762
* returns the count for the row. if the index is invalid then 0.
763
* @param index the index of the row
764
* @return the count for the row
766
public double getCount(int index) {
767
if ( (index >= 0) && (index < getRowCount()) )
768
return m_Counts[index];
774
* sets the mean at the given position (if the position is valid)
775
* @param col the column of the mean
776
* @param row the row of the mean
777
* @param value the value of the mean
779
public void setMean(int col, int row, double value) {
780
if ( (col >= 0) && (col < getColCount())
781
&& (row >= 0) && (row < getRowCount()) )
782
m_Mean[row][col] = value;
786
* returns the mean at the given position, if the position is valid,
789
public double getMean(int col, int row) {
790
if ( (col >= 0) && (col < getColCount())
791
&& (row >= 0) && (row < getRowCount()) )
792
return m_Mean[row][col];
798
* returns the average of the mean at the given position, if the position is
801
public double getAverage(int col) {
806
if ( (col >= 0) && (col < getColCount()) ) {
810
for (i = 0; i < getRowCount(); i++) {
811
if (!Double.isNaN(getMean(col, i))) {
812
avg += getMean(col, i);
817
return avg / (double) count;
825
* sets the std deviation at the given position (if the position is valid)
826
* @param col the column of the std. deviation
827
* @param row the row of the std deviation
828
* @param value the value of the std deviation
830
public void setStdDev(int col, int row, double value) {
831
if ( (col >= 0) && (col < getColCount())
832
&& (row >= 0) && (row < getRowCount()) )
833
m_StdDev[row][col] = value;
837
* returns the std deviation at the given position, if the position is valid,
840
public double getStdDev(int col, int row) {
841
if ( (col >= 0) && (col < getColCount())
842
&& (row >= 0) && (row < getRowCount()) )
843
return m_StdDev[row][col];
849
* sets the significance at the given position (if the position is valid)
850
* @param col the column of the significance
851
* @param row the row of the significance
852
* @param value the value of the significance
854
public void setSignificance(int col, int row, int value) {
855
if ( (col >= 0) && (col < getColCount())
856
&& (row >= 0) && (row < getRowCount()) )
857
m_Significance[row][col] = value;
861
* returns the significance at the given position, if the position is valid,
862
* otherwise SIGNIFICANCE_ATIE
864
public int getSignificance(int col, int row) {
865
if ( (col >= 0) && (col < getColCount())
866
&& (row >= 0) && (row < getRowCount()) )
867
return m_Significance[row][col];
869
return SIGNIFICANCE_TIE;
873
* counts the occurrences of the given significance type in the given
875
* @param col the columnn to gather the information from
876
* @param type the significance type, WIN/TIE/LOSS
878
public int getSignificanceCount(int col, int type) {
884
if ( (col >= 0) && (col < getColCount()) ) {
885
for (i = 0; i < getRowCount(); i++) {
890
if (Double.isNaN(getMean(col, i)))
893
if (getSignificance(col, i) == type)
902
* sets the ordering of the rows, null means default
903
* @param order the new order of the rows
905
public void setRowOrder(int[] order) {
913
if (order.length == getRowCount()) {
914
m_RowOrder = new int[order.length];
915
for (i = 0; i < order.length; i++)
916
m_RowOrder[i] = order[i];
919
System.err.println("setRowOrder: length does not match ("
920
+ order.length + " <> " + getRowCount() + ") - ignored!");
926
* returns the current order of the rows, null means the default order
927
* @return the current order of the rows
929
public int[] getRowOrder() {
934
* returns the displayed index of the given row, depending on the order of
935
* rows, returns -1 if index out of bounds
936
* @param index the row to get the displayed index for
937
* @return the real index of the row
939
public int getDisplayRow(int index) {
940
if ( (index >= 0) && (index < getRowCount()) ) {
941
if (getRowOrder() == null)
944
return getRowOrder()[index];
952
* sets the ordering of the columns, null means default
953
* @param order the new order of the columns
955
public void setColOrder(int[] order) {
963
if (order.length == getColCount()) {
964
m_ColOrder = new int[order.length];
965
for (i = 0; i < order.length; i++)
966
m_ColOrder[i] = order[i];
969
System.err.println("setColOrder: length does not match ("
970
+ order.length + " <> " + getColCount() + ") - ignored!");
976
* returns the current order of the columns, null means the default order
977
* @return the current order of the columns
979
public int[] getColOrder() {
984
* returns the displayed index of the given col, depending on the order of
985
* columns, returns -1 if index out of bounds
986
* @param index the column to get the displayed index for
987
* @return the real index of the column
989
public int getDisplayCol(int index) {
990
if ( (index >= 0) && (index < getColCount()) ) {
991
if (getColOrder() == null)
994
return getColOrder()[index];
1002
* returns the given number as string rounded to the given number of
1003
* decimals. additional necessary 0's are added
1004
* @param d the number to format
1005
* @param prec the number of decimals after the point
1006
* @return the formatted number
1008
protected String doubleToString(double d, int prec) {
1013
result = Utils.doubleToString(d, prec);
1016
if (result.indexOf(".") == -1)
1019
// precision so far?
1020
currentPrec = result.length() - result.indexOf(".") - 1;
1021
for (i = currentPrec; i < prec; i++)
1028
* trims the given string down to the given length if longer, otherwise
1029
* leaves it unchanged. a length of "0" leaves the string always
1031
* @param s the string to trim (if too long)
1032
* @param length the max. length (0 means infinity)
1033
* @return the trimmed string
1035
protected String trimString(String s, int length) {
1036
if ( (length > 0) && (s.length() > length) )
1037
return s.substring(0, length);
1043
* pads the given string on the right until it reaches the given length, if
1044
* longer cuts it down. if length is 0 then nothing is done.
1045
* @param s the string to pad
1046
* @param length the max. length of the string
1047
* @return the padded string
1049
protected String padString(String s, int length) {
1050
return padString(s, length, false);
1054
* pads the given string until it reaches the given length, if longer cuts
1055
* it down. if length is 0 then nothing is done.
1056
* @param s the string to pad
1057
* @param length the max. length of the string
1058
* @param left whether to pad left or right
1059
* @return the padded string
1061
protected String padString(String s, int length, boolean left) {
1068
for (i = s.length(); i < length; i++) {
1070
result = " " + result;
1072
result = result + " ";
1076
if ( (length > 0) && (result.length() > length) )
1077
result = result.substring(0, length);
1083
* returns the length of the longest cell in the given column
1084
* @param data the data to base the calculation on
1085
* @param col the column to check
1086
* @return the maximum length
1088
protected int getColSize(String[][] data, int col) {
1089
return getColSize(data, col, false, false);
1093
* returns the length of the longest cell in the given column
1094
* @param data the data to base the calculation on
1095
* @param col the column to check
1096
* @param skipFirst whether to skip the first row
1097
* @param skipLast whether to skip the last row
1098
* @return the maximum length
1100
protected int getColSize( String[][] data, int col,
1101
boolean skipFirst, boolean skipLast ) {
1107
if ( (col >= 0) && (col < data[0].length) ) {
1108
for (i = 0; i < data.length; i++) {
1110
if ( (i == 0) && (skipFirst) )
1114
if ( (i == data.length - 1) && (skipLast) )
1117
if (data[i][col].length() > result)
1118
result = data[i][col].length();
1126
* removes the filter classname from the given string if it should be
1127
* removed, otherwise leaves the string alone
1128
* @see #getRemoveFilterName()
1130
protected String removeFilterName(String s) {
1131
if (getRemoveFilterName())
1132
return s.replaceAll("-weka\\.filters\\..*", "")
1133
.replaceAll("-unsupervised\\..*", "")
1134
.replaceAll("-supervised\\..*", "");
1140
* returns a 2-dimensional array with the prepared data. includes the column
1141
* and row names. hidden cols/rows are already excluded. <br>
1142
* first row: column names<br>
1143
* last row: wins/ties/losses<br>
1144
* first col: row names<br>
1146
protected String[][] toArray() {
1154
String[][] tmpResult;
1158
boolean valueExists;
1160
// determine visible cols/rows
1161
rows = getVisibleRowCount();
1162
if (getShowAverage())
1164
cols = getVisibleColCount();
1165
if (getShowStdDev())
1166
cols = cols*3; // mean + stddev + sign.
1168
cols = cols*2; // mean + stddev
1170
result = new String[rows + 2][cols + 1];
1173
result[0][0] = trimString("Dataset", getRowNameWidth());
1175
for (ii = 0; ii < getColCount(); ii++) {
1176
i = getDisplayCol(ii);
1177
if (getColHidden(i))
1180
result[0][x] = trimString(
1181
removeFilterName(getColName(i)), getColNameWidth());
1184
if (getShowStdDev()) {
1195
for (ii = 0; ii < getRowCount(); ii++) {
1196
i = getDisplayRow(ii);
1197
if (!getRowHidden(i)) {
1198
result[y][0] = trimString(
1199
removeFilterName(getRowName(i)), getRowNameWidth());
1204
// fill in mean/std dev
1206
for (ii = 0; ii < getRowCount(); ii++) {
1207
i = getDisplayRow(ii);
1208
if (getRowHidden(i))
1212
for (nn = 0; nn < getColCount(); nn++) {
1213
n = getDisplayCol(nn);
1214
if (getColHidden(n))
1217
// do we have a value in the matrix?
1218
valueExists = (!Double.isNaN(getMean(n, i)));
1224
result[y][x] = doubleToString(getMean(n, i), getMeanPrec());
1228
if (getShowStdDev()) {
1231
else if (Double.isInfinite(getStdDev(n, i)))
1232
result[y][x] = "Inf";
1234
result[y][x] = doubleToString(getStdDev(n, i), getStdDevPrec());
1243
switch (getSignificance(n, i)) {
1244
case SIGNIFICANCE_TIE:
1245
result[y][x] = TIE_STRING;
1247
case SIGNIFICANCE_WIN:
1248
result[y][x] = WIN_STRING;
1250
case SIGNIFICANCE_LOSS:
1251
result[y][x] = LOSS_STRING;
1262
if (getShowAverage()) {
1263
y = result.length - 2;
1265
result[y][0] = "Average";
1267
for (ii = 0; ii < getColCount(); ii++) {
1268
i = getDisplayCol(ii);
1269
if (getColHidden(i))
1273
result[y][x] = doubleToString(getAverage(i), getMeanPrec());
1277
if (getShowStdDev()) {
1289
y = result.length - 1;
1291
result[y][0] = LEFT_PARENTHESES
1295
+ RIGHT_PARENTHESES;
1297
for (ii = 0; ii < getColCount(); ii++) {
1298
i = getDisplayCol(ii);
1299
if (getColHidden(i))
1307
if (getShowStdDev()) {
1313
result[y][x] = LEFT_PARENTHESES
1314
+ getSignificanceCount(i, SIGNIFICANCE_WIN) + "/"
1315
+ getSignificanceCount(i, SIGNIFICANCE_TIE) + "/"
1316
+ getSignificanceCount(i, SIGNIFICANCE_LOSS)
1317
+ RIGHT_PARENTHESES;
1321
// base column has no significance -> remove these columns
1322
tmpResult = new String[result.length][result[0].length - 1];
1325
for (i = 0; i < result[0].length; i++) {
1327
if ( ((i == 3) && ( getShowStdDev()))
1328
|| ((i == 2) && (!getShowStdDev())) )
1331
for (n = 0; n < result.length; n++)
1332
tmpResult[n][x] = result[n][i];
1342
* returns true if the index (in the array produced by toArray(boolean))
1345
protected boolean isRowName(int index) {
1346
return (index == 0);
1350
* returns true if the index (in the array produced by toArray(boolean))
1353
protected boolean isMean(int index) {
1356
return true; // base column
1359
index--; // base column
1364
if (getShowStdDev())
1365
return (index % 3 == 1);
1367
return (index % 2 == 0);
1372
* returns true if the row index (in the array produced by toArray(boolean))
1373
* contains the average row
1375
protected boolean isAverage(int rowIndex) {
1376
if (getShowAverage())
1377
return (getVisibleRowCount() + 1 == rowIndex);
1383
* returns true if the index (in the array produced by toArray(boolean))
1384
* contains a std deviation
1386
protected boolean isStdDev(int index) {
1388
index--; // base column
1390
if (getShowStdDev()) {
1392
return true; // stddev of base column
1395
index--; // stddev of base column
1400
return (index % 3 == 1);
1408
* returns true if the index (in the array produced by toArray(boolean))
1409
* contains a significance column
1411
protected boolean isSignificance(int index) {
1413
index--; // base column
1414
if (getShowStdDev()) {
1415
index--; // stddev of base column
1420
return (index % 3 == 2);
1426
return (index % 2 == 1);
1431
* returns the matrix as a string
1433
public abstract String toStringMatrix();
1436
* returns the matrix as a string
1437
* @see #toStringMatrix()
1439
public String toString() {
1440
return toStringMatrix();
1444
* removes all the header information
1446
public void clearHeader() {
1447
m_HeaderKeys = new Vector();
1448
m_HeaderValues = new Vector();
1452
* adds the key-value pair to the header
1453
* @param key the name of the header value
1454
* @param value the value of the header value
1456
public void addHeader(String key, String value) {
1459
pos = m_HeaderKeys.indexOf(key);
1461
m_HeaderValues.set(pos, value);
1464
m_HeaderKeys.add(key);
1465
m_HeaderValues.add(value);
1470
* returns the value associated with the given key, null if if cannot be
1472
* @param key the key to retrieve the value for
1473
* @return the associated value
1475
public String getHeader(String key) {
1478
pos = m_HeaderKeys.indexOf(key);
1482
return (String) m_HeaderKeys.get(pos);
1486
* returns an enumeration of the header keys
1487
* @return all stored keys
1489
public Enumeration headerKeys() {
1490
return m_HeaderKeys.elements();
1494
* returns the header of the matrix as a string
1495
* @see #m_HeaderKeys
1496
* @see #m_HeaderValues
1498
public abstract String toStringHeader();
1501
* returns returns a key for all the col names, for better readability if
1502
* the names got cut off
1504
public abstract String toStringKey();
1507
* clears the current summary data
1509
public void clearSummary() {
1510
m_NonSigWins = null;
1515
* sets the non-significant and significant wins of the resultsets
1516
* @param nonSigWins the non-significant wins
1517
* @param wins the significant wins
1519
public void setSummary(int[][] nonSigWins, int[][] wins) {
1523
m_NonSigWins = new int[nonSigWins.length][nonSigWins[0].length];
1524
m_Wins = new int[wins.length][wins[0].length];
1526
for (i = 0; i < m_NonSigWins.length; i++) {
1527
for (n = 0; n < m_NonSigWins[i].length; n++) {
1528
m_NonSigWins[i][n] = nonSigWins[i][n];
1529
m_Wins[i][n] = wins[i][n];
1535
* returns the character representation of the given column
1537
protected String getSummaryTitle(int col) {
1538
return "" + (char) ((int) 'a' + col % 26);
1542
* returns the summary as string
1544
public abstract String toStringSummary();
1547
* clears the currently stored ranking data
1549
public void clearRanking() {
1550
m_RankingWins = null;
1551
m_RankingLosses = null;
1552
m_RankingDiff = null;
1556
* sets the ranking data based on the wins
1557
* @param wins the wins
1559
public void setRanking(int[][] wins) {
1563
m_RankingWins = new int[wins.length];
1564
m_RankingLosses = new int[wins.length];
1565
m_RankingDiff = new int[wins.length];
1567
for (i = 0; i < wins.length; i++) {
1568
for (j = 0; j < wins[i].length; j++) {
1569
m_RankingWins[j] += wins[i][j];
1570
m_RankingDiff[j] += wins[i][j];
1571
m_RankingLosses[i] += wins[i][j];
1572
m_RankingDiff[i] -= wins[i][j];
1578
* returns the ranking in a string representation
1580
public abstract String toStringRanking();