~ubuntu-branches/ubuntu/precise/weka/precise

« back to all changes in this revision

Viewing changes to weka/experiment/ResultMatrix.java

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2008-02-24 09:18:45 UTC
  • Revision ID: james.westby@ubuntu.com-20080224091845-1l8zy6fm6xipbzsr
Tags: upstream-3.5.7+tut1
ImportĀ upstreamĀ versionĀ 3.5.7+tut1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
6
 *
 
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.
 
11
 *
 
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.
 
15
 */
 
16
 
 
17
/*
 
18
 * ResultMatrix.java
 
19
 * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
 
20
 *
 
21
 */
 
22
 
 
23
package weka.experiment;
 
24
 
 
25
import weka.core.Utils;
 
26
 
 
27
import java.io.Serializable;
 
28
import java.util.Enumeration;
 
29
import java.util.Vector;
 
30
 
 
31
/**
 
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:
 
35
 * <ul>
 
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>
 
41
 * </ul>
 
42
 *
 
43
 *
 
44
 * @author FracPete (fracpete at waikato dot ac dot nz)
 
45
 * @version $Revision: 1.8 $
 
46
 * @see #toStringMatrix()
 
47
 * @see #toStringKey()
 
48
 * @see #toStringHeader()
 
49
 * @see #toStringSummary()
 
50
 * @see #toStringRanking()
 
51
 */
 
52
public abstract class ResultMatrix
 
53
  implements Serializable {
 
54
 
 
55
  /** for serialization */
 
56
  private static final long serialVersionUID = 4487179306428209739L;
 
57
  
 
58
  /** tie */
 
59
  public final static int SIGNIFICANCE_TIE = 0;
 
60
 
 
61
  /** win */
 
62
  public final static int SIGNIFICANCE_WIN = 1;
 
63
 
 
64
  /** loss */
 
65
  public final static int SIGNIFICANCE_LOSS = 2;
 
66
 
 
67
  /** tie string */
 
68
  public String TIE_STRING = " ";
 
69
 
 
70
  /** win string */
 
71
  public String WIN_STRING = "v";
 
72
 
 
73
  /** loss string */
 
74
  public String LOSS_STRING = "*";
 
75
 
 
76
  /** the left parentheses for enumerating cols/rows */
 
77
  public String LEFT_PARENTHESES = "(";
 
78
 
 
79
  /** the right parentheses for enumerating cols/rows */
 
80
  public String RIGHT_PARENTHESES = ")";
 
81
 
 
82
  /** the column names */
 
83
  protected String[] m_ColNames = null;
 
84
 
 
85
  /** the row names */
 
86
  protected String[] m_RowNames = null;
 
87
 
 
88
  /** whether a column is hidden */
 
89
  protected boolean[] m_ColHidden = null;
 
90
  
 
91
  /** whether a row is hidden */
 
92
  protected boolean[] m_RowHidden = null;
 
93
  
 
94
  /** the significance */
 
95
  protected int[][] m_Significance = null;
 
96
 
 
97
  /** the values */
 
98
  protected double[][] m_Mean = null;
 
99
 
 
100
  /** the standard deviation */
 
101
  protected double[][] m_StdDev = null;
 
102
 
 
103
  /** the counts for the different datasets */
 
104
  protected double[] m_Counts = null;
 
105
 
 
106
  /** the standard mean precision */
 
107
  protected int m_MeanPrec;
 
108
 
 
109
  /** the standard std. deviation preicision */
 
110
  protected int m_StdDevPrec;
 
111
 
 
112
  /** whether std. deviations are printed as well */
 
113
  protected boolean m_ShowStdDev;
 
114
 
 
115
  /** whether the average for each column should be printed */
 
116
  protected boolean m_ShowAverage;
 
117
  
 
118
  /** whether the names or numbers are output as column declarations */
 
119
  protected boolean m_PrintColNames;
 
120
 
 
121
  /** whether the names or numbers are output as row declarations */
 
122
  protected boolean m_PrintRowNames;
 
123
 
 
124
  /** whether a "(x)" is printed before each column name with "x" as the
 
125
   * index */
 
126
  protected boolean m_EnumerateColNames;
 
127
 
 
128
  /** whether a "(x)" is printed before each row name with "x" as the index */
 
129
  protected boolean m_EnumerateRowNames;
 
130
 
 
131
  /** the size of the names of the columns */
 
132
  protected int m_ColNameWidth;
 
133
 
 
134
  /** the size of the names of the rows */
 
135
  protected int m_RowNameWidth;
 
136
 
 
137
  /** the size of the mean columns */
 
138
  protected int m_MeanWidth;
 
139
 
 
140
  /** the size of the std dev columns */
 
141
  protected int m_StdDevWidth;
 
142
 
 
143
  /** the size of the significance columns */
 
144
  protected int m_SignificanceWidth;
 
145
 
 
146
  /** the size of the counts */
 
147
  protected int m_CountWidth;
 
148
 
 
149
  /** contains the keys for the header */
 
150
  protected Vector m_HeaderKeys = null;
 
151
 
 
152
  /** contains the values for the header */
 
153
  protected Vector m_HeaderValues = null;
 
154
 
 
155
  /** the non-significant wins */
 
156
  protected int[][] m_NonSigWins = null;
 
157
 
 
158
  /** the significant wins */
 
159
  protected int[][] m_Wins = null;
 
160
 
 
161
  /** the wins in ranking */
 
162
  protected int[] m_RankingWins = null;
 
163
 
 
164
  /** the losses in ranking */
 
165
  protected int[] m_RankingLosses = null;
 
166
 
 
167
  /** the difference between wins and losses */
 
168
  protected int[] m_RankingDiff = null;
 
169
 
 
170
  /** the ordering of the rows */
 
171
  protected int[] m_RowOrder = null;
 
172
 
 
173
  /** the ordering of the columns */
 
174
  protected int[] m_ColOrder = null;
 
175
 
 
176
  /** whether to remove the filter name from the dataaset name */
 
177
  protected boolean m_RemoveFilterName = false;
 
178
  
 
179
  /**
 
180
   * initializes the matrix as 1x1 matrix
 
181
   */
 
182
  public ResultMatrix() {
 
183
    this(1, 1);
 
184
  }
 
185
  
 
186
  /**
 
187
   * initializes the matrix with the given dimensions
 
188
   */
 
189
  public ResultMatrix(int cols, int rows) {
 
190
    setSize(cols, rows);
 
191
    clear();
 
192
  }
 
193
 
 
194
  /**
 
195
   * initializes the matrix with the values from the given matrix
 
196
   * @param matrix      the matrix to get the values from
 
197
   */
 
198
  public ResultMatrix(ResultMatrix matrix) {
 
199
    assign(matrix);
 
200
  }
 
201
 
 
202
  /**
 
203
   * returns the name of the output format
 
204
   */
 
205
  public abstract String getDisplayName();
 
206
 
 
207
  /**
 
208
   * acquires the data from the given matrix
 
209
   */
 
210
  public void assign(ResultMatrix matrix) {
 
211
    int         i;
 
212
    int         n;
 
213
    
 
214
    setSize(matrix.getColCount(), matrix.getRowCount());
 
215
    
 
216
    // output parameters
 
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;
 
236
    
 
237
    // header
 
238
    m_HeaderKeys   = (Vector) matrix.m_HeaderKeys.clone();
 
239
    m_HeaderValues = (Vector) matrix.m_HeaderValues.clone();
 
240
 
 
241
    // matrix
 
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];
 
247
      }
 
248
    }
 
249
 
 
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];
 
253
    }
 
254
 
 
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];
 
258
    }
 
259
 
 
260
    for (i = 0; i < matrix.m_Counts.length; i++)
 
261
      m_Counts[i] = matrix.m_Counts[i];
 
262
 
 
263
    // summary
 
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];
 
270
 
 
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];
 
274
        }
 
275
      }
 
276
    }
 
277
 
 
278
    // ranking
 
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];
 
287
      }
 
288
    }
 
289
  }
 
290
 
 
291
  /**
 
292
   * removes the stored data and the ordering, but retains the dimensions of
 
293
   * the matrix
 
294
   */
 
295
  public void clear() {
 
296
    m_MeanPrec          = 2;
 
297
    m_StdDevPrec        = 2;
 
298
    m_ShowStdDev        = false;
 
299
    m_ShowAverage       = false;
 
300
    m_PrintColNames     = true;
 
301
    m_PrintRowNames     = true;
 
302
    m_EnumerateColNames = true;
 
303
    m_EnumerateRowNames = false;
 
304
    m_RowNameWidth      = 0;
 
305
    m_ColNameWidth      = 0;
 
306
    m_MeanWidth         = 0;
 
307
    m_StdDevWidth       = 0;
 
308
    m_SignificanceWidth = 0;
 
309
    m_CountWidth        = 0;
 
310
 
 
311
    setSize(getColCount(), getRowCount());
 
312
  }
 
313
 
 
314
  /**
 
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
 
318
   */
 
319
  public void setSize(int cols, int rows) {
 
320
    int       i;
 
321
    int       n;
 
322
 
 
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];
 
331
    m_ColOrder     = null;
 
332
    m_RowOrder     = null;
 
333
 
 
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;
 
338
    }
 
339
 
 
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;
 
344
 
 
345
    clearHeader();
 
346
    clearSummary();
 
347
    clearRanking();
 
348
  }
 
349
 
 
350
  /**
 
351
   * sets the precision for the means
 
352
   */
 
353
  public void setMeanPrec(int prec) {
 
354
    if (prec >= 0)
 
355
      m_MeanPrec = prec;
 
356
  }
 
357
 
 
358
  /**
 
359
   * returns the current precision for the means
 
360
   */
 
361
  public int getMeanPrec() {
 
362
    return m_MeanPrec;
 
363
  }
 
364
 
 
365
  /**
 
366
   * sets the precision for the standard deviation
 
367
   */
 
368
  public void setStdDevPrec(int prec) {
 
369
    if (prec >= 0)
 
370
      m_StdDevPrec = prec;
 
371
  }
 
372
 
 
373
  /**
 
374
   * returns the current standard deviation precision
 
375
   */
 
376
  public int getStdDevPrec() {
 
377
    return m_StdDevPrec;
 
378
  }
 
379
 
 
380
  /**
 
381
   * sets the width for the column names (0 = optimal)
 
382
   */
 
383
  public void setColNameWidth(int width) {
 
384
    if (width >= 0)
 
385
      m_ColNameWidth = width;
 
386
  }
 
387
 
 
388
  /**
 
389
   * returns the current width for the column names
 
390
   */
 
391
  public int getColNameWidth() {
 
392
    return m_ColNameWidth;
 
393
  }
 
394
 
 
395
  /**
 
396
   * sets the width for the row names (0 = optimal)
 
397
   */
 
398
  public void setRowNameWidth(int width) {
 
399
    if (width >= 0)
 
400
      m_RowNameWidth = width;
 
401
  }
 
402
 
 
403
  /**
 
404
   * returns the current width for the row names
 
405
   */
 
406
  public int getRowNameWidth() {
 
407
    return m_RowNameWidth;
 
408
  }
 
409
 
 
410
  /**
 
411
   * sets the width for the mean (0 = optimal)
 
412
   */
 
413
  public void setMeanWidth(int width) {
 
414
    if (width >= 0)
 
415
      m_MeanWidth = width;
 
416
  }
 
417
 
 
418
  /**
 
419
   * returns the current width for the mean
 
420
   */
 
421
  public int getMeanWidth() {
 
422
    return m_MeanWidth;
 
423
  }
 
424
 
 
425
  /**
 
426
   * sets the width for the std dev (0 = optimal)
 
427
   */
 
428
  public void setStdDevWidth(int width) {
 
429
    if (width >= 0)
 
430
      m_StdDevWidth = width;
 
431
  }
 
432
 
 
433
  /**
 
434
   * returns the current width for the std dev
 
435
   */
 
436
  public int getStdDevWidth() {
 
437
    return m_StdDevWidth;
 
438
  }
 
439
 
 
440
  /**
 
441
   * sets the width for the significance (0 = optimal)
 
442
   */
 
443
  public void setSignificanceWidth(int width) {
 
444
    if (width >= 0)
 
445
      m_SignificanceWidth = width;
 
446
  }
 
447
 
 
448
  /**
 
449
   * returns the current width for the significance
 
450
   */
 
451
  public int getSignificanceWidth() {
 
452
    return m_SignificanceWidth;
 
453
  }
 
454
 
 
455
  /**
 
456
   * sets the width for the counts (0 = optimal)
 
457
   */
 
458
  public void setCountWidth(int width) {
 
459
    if (width >= 0)
 
460
      m_CountWidth = width;
 
461
  }
 
462
 
 
463
  /**
 
464
   * returns the current width for the counts
 
465
   */
 
466
  public int getCountWidth() {
 
467
    return m_CountWidth;
 
468
  }
 
469
 
 
470
  /**
 
471
   * sets whether to display the std deviations or not
 
472
   */
 
473
  public void setShowStdDev(boolean show) {
 
474
    m_ShowStdDev = show;
 
475
  }
 
476
 
 
477
  /**
 
478
   * returns whether std deviations are displayed or not
 
479
   */
 
480
  public boolean getShowStdDev() {
 
481
    return m_ShowStdDev;
 
482
  }
 
483
 
 
484
  /**
 
485
   * sets whether to display the average per column or not
 
486
   */
 
487
  public void setShowAverage(boolean show) {
 
488
    m_ShowAverage = show;
 
489
  }
 
490
 
 
491
  /**
 
492
   * returns whether average per column is displayed or not
 
493
   */
 
494
  public boolean getShowAverage() {
 
495
    return m_ShowAverage;
 
496
  }
 
497
 
 
498
  /**
 
499
   * sets whether to remove the filter classname from the dataset name
 
500
   */
 
501
  public void setRemoveFilterName(boolean remove) {
 
502
    m_RemoveFilterName = remove;
 
503
  }
 
504
 
 
505
  /**
 
506
   * returns whether the filter classname is removed from the dataset name
 
507
   */
 
508
  public boolean getRemoveFilterName() {
 
509
    return m_RemoveFilterName;
 
510
  }
 
511
 
 
512
  /**
 
513
   * sets whether the column names or numbers instead are printed.
 
514
   * deactivating automatically sets m_EnumerateColNames to TRUE.
 
515
   * @see #setEnumerateColNames(boolean)
 
516
   */
 
517
  public void setPrintColNames(boolean print) {
 
518
    m_PrintColNames = print;
 
519
    if (!print)
 
520
      setEnumerateColNames(true);
 
521
  }
 
522
 
 
523
  /**
 
524
   * returns whether column names or numbers instead are printed
 
525
   */
 
526
  public boolean getPrintColNames() {
 
527
    return m_PrintColNames;
 
528
  }
 
529
 
 
530
  /**
 
531
   * sets whether the row names or numbers instead are printed
 
532
   * deactivating automatically sets m_EnumerateColNames to TRUE.
 
533
   * @see #setEnumerateRowNames(boolean)
 
534
   */
 
535
  public void setPrintRowNames(boolean print) {
 
536
    m_PrintRowNames = print;
 
537
    if (!print)
 
538
      setEnumerateRowNames(true);
 
539
  }
 
540
 
 
541
  /**
 
542
   * returns whether row names or numbers instead are printed
 
543
   */
 
544
  public boolean getPrintRowNames() {
 
545
    return m_PrintRowNames;
 
546
  }
 
547
 
 
548
  /**
 
549
   * sets whether the column names are prefixed with "(x)" where "x" is
 
550
   * the index
 
551
   */
 
552
  public void setEnumerateColNames(boolean enumerate) {
 
553
    m_EnumerateColNames = enumerate;
 
554
  }
 
555
 
 
556
  /**
 
557
   * returns whether column names or numbers instead are enumerateed
 
558
   */
 
559
  public boolean getEnumerateColNames() {
 
560
    return m_EnumerateColNames;
 
561
  }
 
562
 
 
563
  /**
 
564
   * sets whether to the row names or numbers instead are enumerateed
 
565
   */
 
566
  public void setEnumerateRowNames(boolean enumerate) {
 
567
    m_EnumerateRowNames = enumerate;
 
568
  }
 
569
 
 
570
  /**
 
571
   * returns whether row names or numbers instead are enumerateed
 
572
   */
 
573
  public boolean getEnumerateRowNames() {
 
574
    return m_EnumerateRowNames;
 
575
  }
 
576
 
 
577
  /**
 
578
   * returns the number of columns
 
579
   */
 
580
  public int getColCount() {
 
581
    return m_ColNames.length;
 
582
  }
 
583
 
 
584
  /**
 
585
   * returns the number of visible columns
 
586
   */
 
587
  public int getVisibleColCount() {
 
588
    int         cols;
 
589
    int         i;
 
590
    
 
591
    cols = 0;
 
592
    for (i = 0; i < getColCount(); i++) {
 
593
      if (!getColHidden(i))
 
594
        cols++;
 
595
    }
 
596
 
 
597
    return cols;
 
598
  }
 
599
 
 
600
  /**
 
601
   * returns the number of rows
 
602
   */
 
603
  public int getRowCount() {
 
604
    return m_RowNames.length;
 
605
  }
 
606
 
 
607
  /**
 
608
   * returns the number of visible rows
 
609
   */
 
610
  public int getVisibleRowCount() {
 
611
    int         rows;
 
612
    int         i;
 
613
    
 
614
    rows= 0;
 
615
    for (i = 0; i < getRowCount(); i++) {
 
616
      if (!getRowHidden(i))
 
617
        rows++;
 
618
    }
 
619
 
 
620
    return rows;
 
621
  }
 
622
  
 
623
  /**
 
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
 
627
   */
 
628
  public void setColName(int index, String name) {
 
629
    if ( (index >= 0) && (index < getColCount()) )
 
630
      m_ColNames[index] = name;
 
631
  }
 
632
 
 
633
  /**
 
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
 
637
   * parentheses.
 
638
   * @see #setPrintColNames(boolean)
 
639
   * @see #getPrintColNames()
 
640
   * @see #setEnumerateColNames(boolean)
 
641
   * @see #getEnumerateColNames()
 
642
   */
 
643
  public String getColName(int index) {
 
644
    String        result;
 
645
    
 
646
    result = null;
 
647
    
 
648
    if ( (index >= 0) && (index < getColCount()) ) {
 
649
      if (getPrintColNames())
 
650
        result = m_ColNames[index];
 
651
      else
 
652
        result = "";
 
653
 
 
654
      if (getEnumerateColNames()) {
 
655
        result =   LEFT_PARENTHESES 
 
656
                 + Integer.toString(index + 1) 
 
657
                 + RIGHT_PARENTHESES
 
658
                 + " " + result;
 
659
        result = result.trim();
 
660
      }
 
661
    }
 
662
 
 
663
    return result;
 
664
  }
 
665
 
 
666
  /**
 
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
 
670
   */
 
671
  public void setRowName(int index, String name) {
 
672
    if ( (index >= 0) && (index < getRowCount()) )
 
673
      m_RowNames[index] = name;
 
674
  }
 
675
 
 
676
  /**
 
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
 
680
   * parentheses.
 
681
   * @see #setPrintRowNames(boolean)
 
682
   * @see #getPrintRowNames()
 
683
   * @see #setEnumerateRowNames(boolean)
 
684
   * @see #getEnumerateRowNames()
 
685
   */
 
686
  public String getRowName(int index) {
 
687
    String        result;
 
688
    
 
689
    result = null;
 
690
    
 
691
    if ( (index >= 0) && (index < getRowCount()) ) {
 
692
      if (getPrintRowNames())
 
693
        result = m_RowNames[index];
 
694
      else
 
695
        result = "";
 
696
 
 
697
      if (getEnumerateRowNames()) {
 
698
        result =   LEFT_PARENTHESES 
 
699
                 + Integer.toString(index + 1) 
 
700
                 + RIGHT_PARENTHESES
 
701
                 + " " + result;
 
702
        result = result.trim();
 
703
      }
 
704
    }
 
705
    
 
706
    return result;
 
707
  }
 
708
 
 
709
  /**
 
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
 
713
   */
 
714
  public void setColHidden(int index, boolean hidden) {
 
715
    if ( (index >= 0) && (index < getColCount()) )
 
716
      m_ColHidden[index] = hidden;
 
717
  }
 
718
 
 
719
  /**
 
720
   * returns the hidden status of the column, if the index is valid, otherwise
 
721
   * false
 
722
   */
 
723
  public boolean getColHidden(int index) {
 
724
    if ( (index >= 0) && (index < getColCount()) )
 
725
      return m_ColHidden[index];
 
726
    else
 
727
      return false;
 
728
  }
 
729
 
 
730
  /**
 
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
 
734
   */
 
735
  public void setRowHidden(int index, boolean hidden) {
 
736
    if ( (index >= 0) && (index < getRowCount()) )
 
737
      m_RowHidden[index] = hidden;
 
738
  }
 
739
 
 
740
  /**
 
741
   * returns the hidden status of the row, if the index is valid, otherwise
 
742
   * false
 
743
   */
 
744
  public boolean getRowHidden(int index) {
 
745
    if ( (index >= 0) && (index < getRowCount()) )
 
746
      return m_RowHidden[index];
 
747
    else
 
748
      return false;
 
749
  }
 
750
 
 
751
  /**
 
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
 
755
   */
 
756
  public void setCount(int index, double count) {
 
757
    if ( (index >= 0) && (index < getRowCount()) )
 
758
      m_Counts[index] = count;
 
759
  }
 
760
 
 
761
  /**
 
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
 
765
   */
 
766
  public double getCount(int index) {
 
767
    if ( (index >= 0) && (index < getRowCount()) )
 
768
      return m_Counts[index];
 
769
    else
 
770
      return 0;
 
771
  }
 
772
 
 
773
  /**
 
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
 
778
   */
 
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;
 
783
  }
 
784
 
 
785
  /**
 
786
   * returns the mean at the given position, if the position is valid,
 
787
   * otherwise 0
 
788
   */
 
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];
 
793
    else
 
794
      return 0;
 
795
  }
 
796
 
 
797
  /**
 
798
   * returns the average of the mean at the given position, if the position is
 
799
   * valid, otherwise 0
 
800
   */
 
801
  public double getAverage(int col) {
 
802
    int       i;
 
803
    double    avg;
 
804
    int       count;
 
805
 
 
806
    if ( (col >= 0) && (col < getColCount()) ) {
 
807
      avg   = 0;
 
808
      count = 0;
 
809
 
 
810
      for (i = 0; i < getRowCount(); i++) {
 
811
        if (!Double.isNaN(getMean(col, i))) {
 
812
          avg += getMean(col, i);
 
813
          count++;
 
814
        }
 
815
      }
 
816
      
 
817
      return avg / (double) count;
 
818
    }
 
819
    else {
 
820
      return 0;
 
821
    }
 
822
  }
 
823
 
 
824
  /**
 
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
 
829
   */
 
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;
 
834
  }
 
835
 
 
836
  /**
 
837
   * returns the std deviation at the given position, if the position is valid,
 
838
   * otherwise 0
 
839
   */
 
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];
 
844
    else
 
845
      return 0;
 
846
  }
 
847
 
 
848
  /**
 
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
 
853
   */
 
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;
 
858
  }
 
859
 
 
860
  /**
 
861
   * returns the significance at the given position, if the position is valid,
 
862
   * otherwise SIGNIFICANCE_ATIE
 
863
   */
 
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];
 
868
    else
 
869
      return SIGNIFICANCE_TIE;
 
870
  }
 
871
 
 
872
  /**
 
873
   * counts the occurrences of the given significance type in the given
 
874
   * column.
 
875
   * @param col       the columnn to gather the information from
 
876
   * @param type      the significance type, WIN/TIE/LOSS
 
877
   */
 
878
  public int getSignificanceCount(int col, int type) {
 
879
    int       result;
 
880
    int       i;
 
881
 
 
882
    result = 0;
 
883
 
 
884
    if ( (col >= 0) && (col < getColCount()) ) {
 
885
      for (i = 0; i < getRowCount(); i++) {
 
886
        if (getRowHidden(i))
 
887
          continue;
 
888
 
 
889
        // no value?
 
890
        if (Double.isNaN(getMean(col, i)))
 
891
          continue;
 
892
 
 
893
        if (getSignificance(col, i) == type)
 
894
          result++;
 
895
      }
 
896
    }
 
897
 
 
898
    return result;
 
899
  }
 
900
 
 
901
  /**
 
902
   * sets the ordering of the rows, null means default
 
903
   * @param order       the new order of the rows
 
904
   */
 
905
  public void setRowOrder(int[] order) {
 
906
    int         i;
 
907
    
 
908
    // default order?
 
909
    if (order == null) {
 
910
      m_RowOrder = null;
 
911
    }
 
912
    else {
 
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];
 
917
      }
 
918
      else {
 
919
        System.err.println("setRowOrder: length does not match (" 
 
920
            + order.length + " <> " + getRowCount() + ") - ignored!");
 
921
      }
 
922
    }
 
923
  }
 
924
 
 
925
  /**
 
926
   * returns the current order of the rows, null means the default order
 
927
   * @return        the current order of the rows
 
928
   */
 
929
  public int[] getRowOrder() {
 
930
    return m_RowOrder;
 
931
  }
 
932
 
 
933
  /**
 
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
 
938
   */
 
939
  public int getDisplayRow(int index) {
 
940
    if ( (index >= 0) && (index < getRowCount()) ) {
 
941
      if (getRowOrder() == null)
 
942
        return index;
 
943
      else
 
944
        return getRowOrder()[index];
 
945
    }
 
946
    else {
 
947
      return -1;
 
948
    }
 
949
  }
 
950
 
 
951
  /**
 
952
   * sets the ordering of the columns, null means default
 
953
   * @param order       the new order of the columns
 
954
   */
 
955
  public void setColOrder(int[] order) {
 
956
    int         i;
 
957
    
 
958
    // default order?
 
959
    if (order == null) {
 
960
      m_ColOrder = null;
 
961
    }
 
962
    else {
 
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];
 
967
      }
 
968
      else {
 
969
        System.err.println("setColOrder: length does not match (" 
 
970
            + order.length + " <> " + getColCount() + ") - ignored!");
 
971
      }
 
972
    }
 
973
  }
 
974
 
 
975
  /**
 
976
   * returns the current order of the columns, null means the default order
 
977
   * @return        the current order of the columns
 
978
   */
 
979
  public int[] getColOrder() {
 
980
    return m_ColOrder;
 
981
  }
 
982
 
 
983
  /**
 
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
 
988
   */
 
989
  public int getDisplayCol(int index) {
 
990
    if ( (index >= 0) && (index < getColCount()) ) {
 
991
      if (getColOrder() == null)
 
992
        return index;
 
993
      else
 
994
        return getColOrder()[index];
 
995
    }
 
996
    else {
 
997
      return -1;
 
998
    }
 
999
  }
 
1000
 
 
1001
  /**
 
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
 
1007
   */
 
1008
  protected String doubleToString(double d, int prec) {
 
1009
    String        result;
 
1010
    int           currentPrec;
 
1011
    int           i;
 
1012
 
 
1013
    result = Utils.doubleToString(d, prec);
 
1014
 
 
1015
    // decimal point?
 
1016
    if (result.indexOf(".") == -1)
 
1017
      result += ".";
 
1018
    
 
1019
    // precision so far?
 
1020
    currentPrec = result.length() - result.indexOf(".") - 1;
 
1021
    for (i = currentPrec; i < prec; i++)
 
1022
      result += "0";
 
1023
    
 
1024
    return result;
 
1025
  }
 
1026
 
 
1027
  /**
 
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 
 
1030
   * unchanged.
 
1031
   * @param s       the string to trim (if too long)
 
1032
   * @param length  the max. length (0 means infinity)
 
1033
   * @return        the trimmed string
 
1034
   */
 
1035
  protected String trimString(String s, int length) {
 
1036
    if ( (length > 0) && (s.length() > length) )
 
1037
      return s.substring(0, length);
 
1038
    else
 
1039
      return s;
 
1040
  }
 
1041
 
 
1042
  /**
 
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
 
1048
   */
 
1049
  protected String padString(String s, int length) {
 
1050
    return padString(s, length, false);
 
1051
  }
 
1052
 
 
1053
  /**
 
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
 
1060
   */
 
1061
  protected String padString(String s, int length, boolean left) {
 
1062
    String      result;
 
1063
    int         i;
 
1064
 
 
1065
    result = s;
 
1066
 
 
1067
    // pad with blanks
 
1068
    for (i = s.length(); i < length; i++) {
 
1069
      if (left)
 
1070
        result = " " + result;
 
1071
      else
 
1072
        result = result + " ";
 
1073
    }
 
1074
      
 
1075
    // too long?
 
1076
    if ( (length > 0) && (result.length() > length) )
 
1077
      result = result.substring(0, length);
 
1078
 
 
1079
    return result;
 
1080
  }
 
1081
 
 
1082
  /**
 
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
 
1087
   */
 
1088
  protected int getColSize(String[][] data, int col) {
 
1089
    return getColSize(data, col, false, false);
 
1090
  }
 
1091
 
 
1092
  /**
 
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
 
1099
   */
 
1100
  protected int getColSize( String[][] data, int col, 
 
1101
                            boolean skipFirst, boolean skipLast ) {
 
1102
    int       result;
 
1103
    int       i;
 
1104
 
 
1105
    result = 0;
 
1106
 
 
1107
    if ( (col >= 0) && (col < data[0].length) ) {
 
1108
      for (i = 0; i < data.length; i++) {
 
1109
        // skip first?
 
1110
        if ( (i == 0) && (skipFirst) )
 
1111
          continue;
 
1112
 
 
1113
        // skip last?
 
1114
        if ( (i == data.length - 1) && (skipLast) )
 
1115
          continue;
 
1116
        
 
1117
        if (data[i][col].length() > result)
 
1118
          result = data[i][col].length();
 
1119
      }
 
1120
    }
 
1121
 
 
1122
    return result;
 
1123
  }
 
1124
 
 
1125
  /**
 
1126
   * removes the filter classname from the given string if it should be 
 
1127
   * removed, otherwise leaves the string alone
 
1128
   * @see     #getRemoveFilterName()
 
1129
   */
 
1130
  protected String removeFilterName(String s) {
 
1131
    if (getRemoveFilterName())
 
1132
      return s.replaceAll("-weka\\.filters\\..*", "")
 
1133
              .replaceAll("-unsupervised\\..*",   "")
 
1134
              .replaceAll("-supervised\\..*",     "");
 
1135
    else
 
1136
      return s;
 
1137
  }
 
1138
 
 
1139
  /**
 
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>
 
1145
   */
 
1146
  protected String[][] toArray() {
 
1147
    int               i;
 
1148
    int               n;
 
1149
    int               ii;
 
1150
    int               nn;
 
1151
    int               x;
 
1152
    int               y;
 
1153
    String[][]        result;
 
1154
    String[][]        tmpResult;
 
1155
    int               cols;
 
1156
    int               rows;
 
1157
    int[]             widths;
 
1158
    boolean           valueExists;
 
1159
 
 
1160
    // determine visible cols/rows
 
1161
    rows = getVisibleRowCount();
 
1162
    if (getShowAverage())
 
1163
      rows++;
 
1164
    cols = getVisibleColCount();
 
1165
    if (getShowStdDev())
 
1166
      cols = cols*3;   // mean + stddev + sign.
 
1167
    else
 
1168
      cols = cols*2;   // mean + stddev
 
1169
 
 
1170
    result = new String[rows + 2][cols + 1];
 
1171
 
 
1172
    // col names
 
1173
    result[0][0] = trimString("Dataset", getRowNameWidth());
 
1174
    x = 1;
 
1175
    for (ii = 0; ii < getColCount(); ii++) {
 
1176
      i = getDisplayCol(ii);
 
1177
      if (getColHidden(i))
 
1178
        continue;
 
1179
      
 
1180
      result[0][x] = trimString(
 
1181
          removeFilterName(getColName(i)), getColNameWidth());
 
1182
      x++;
 
1183
      // std dev
 
1184
      if (getShowStdDev()) {
 
1185
        result[0][x] = "";
 
1186
        x++;
 
1187
      }
 
1188
      // sign.
 
1189
      result[0][x] = "";
 
1190
      x++;
 
1191
    }
 
1192
 
 
1193
    // row names
 
1194
    y = 1;
 
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());
 
1200
        y++;
 
1201
      }
 
1202
    }
 
1203
 
 
1204
    // fill in mean/std dev
 
1205
    y = 1;
 
1206
    for (ii = 0; ii < getRowCount(); ii++) {
 
1207
      i = getDisplayRow(ii);
 
1208
      if (getRowHidden(i))
 
1209
        continue;
 
1210
 
 
1211
      x = 1;
 
1212
      for (nn = 0; nn < getColCount(); nn++) {
 
1213
        n = getDisplayCol(nn);
 
1214
        if (getColHidden(n))
 
1215
          continue;
 
1216
 
 
1217
        // do we have a value in the matrix?
 
1218
        valueExists = (!Double.isNaN(getMean(n, i)));
 
1219
 
 
1220
        // mean
 
1221
        if (!valueExists)
 
1222
          result[y][x] = "";
 
1223
        else
 
1224
          result[y][x] = doubleToString(getMean(n, i), getMeanPrec());
 
1225
        x++;
 
1226
        
 
1227
        // stddev
 
1228
        if (getShowStdDev()) {
 
1229
          if (!valueExists)
 
1230
            result[y][x] = "";
 
1231
          else if (Double.isInfinite(getStdDev(n, i)))
 
1232
            result[y][x] = "Inf";
 
1233
          else
 
1234
            result[y][x] = doubleToString(getStdDev(n, i), getStdDevPrec());
 
1235
          x++;
 
1236
        }
 
1237
        
 
1238
        // significance
 
1239
        if (!valueExists) {
 
1240
          result[y][x] = "";
 
1241
        }
 
1242
        else {
 
1243
          switch (getSignificance(n, i)) {
 
1244
            case SIGNIFICANCE_TIE:
 
1245
              result[y][x] = TIE_STRING;
 
1246
              break;
 
1247
            case SIGNIFICANCE_WIN:
 
1248
              result[y][x] = WIN_STRING;
 
1249
              break;
 
1250
            case SIGNIFICANCE_LOSS:
 
1251
              result[y][x] = LOSS_STRING;
 
1252
              break;
 
1253
          }
 
1254
        }
 
1255
        x++;
 
1256
      }
 
1257
 
 
1258
      y++;
 
1259
    }
 
1260
 
 
1261
    // the average
 
1262
    if (getShowAverage()) {
 
1263
      y = result.length - 2;
 
1264
      x = 0;
 
1265
      result[y][0] = "Average";
 
1266
      x++;
 
1267
      for (ii = 0; ii < getColCount(); ii++) {
 
1268
        i = getDisplayCol(ii);
 
1269
        if (getColHidden(i))
 
1270
          continue;
 
1271
 
 
1272
        // mean-average
 
1273
        result[y][x] = doubleToString(getAverage(i), getMeanPrec());
 
1274
        x++;
 
1275
 
 
1276
        // std dev.
 
1277
        if (getShowStdDev()) {
 
1278
          result[y][x] = "";
 
1279
          x++;
 
1280
        }
 
1281
 
 
1282
        // significance
 
1283
        result[y][x] = "";
 
1284
        x++;
 
1285
      }
 
1286
    }
 
1287
 
 
1288
    // wins/ties/losses
 
1289
    y = result.length - 1;
 
1290
    x = 0;
 
1291
    result[y][0] =   LEFT_PARENTHESES 
 
1292
                   + WIN_STRING + "/" 
 
1293
                   + TIE_STRING + "/" 
 
1294
                   + LOSS_STRING 
 
1295
                   + RIGHT_PARENTHESES;
 
1296
    x++;
 
1297
    for (ii = 0; ii < getColCount(); ii++) {
 
1298
      i = getDisplayCol(ii);
 
1299
      if (getColHidden(i))
 
1300
        continue;
 
1301
 
 
1302
      // mean
 
1303
      result[y][x] = "";
 
1304
      x++;
 
1305
 
 
1306
      // std dev.
 
1307
      if (getShowStdDev()) {
 
1308
        result[y][x] = "";
 
1309
        x++;
 
1310
      }
 
1311
 
 
1312
      // significance
 
1313
      result[y][x] =   LEFT_PARENTHESES 
 
1314
                     + getSignificanceCount(i, SIGNIFICANCE_WIN) + "/" 
 
1315
                     + getSignificanceCount(i, SIGNIFICANCE_TIE) + "/" 
 
1316
                     + getSignificanceCount(i, SIGNIFICANCE_LOSS) 
 
1317
                     + RIGHT_PARENTHESES;
 
1318
      x++;
 
1319
    }
 
1320
 
 
1321
    // base column has no significance -> remove these columns
 
1322
    tmpResult = new String[result.length][result[0].length - 1];
 
1323
 
 
1324
    x = 0;
 
1325
    for (i = 0; i < result[0].length; i++) {
 
1326
      // significance
 
1327
      if (    ((i == 3) && ( getShowStdDev()))
 
1328
           || ((i == 2) && (!getShowStdDev())) )
 
1329
        continue;
 
1330
      
 
1331
      for (n = 0; n < result.length; n++)
 
1332
        tmpResult[n][x] = result[n][i];
 
1333
 
 
1334
      x++;
 
1335
    }
 
1336
    result = tmpResult;
 
1337
 
 
1338
    return result;
 
1339
  }
 
1340
 
 
1341
  /**
 
1342
   * returns true if the index (in the array produced by toArray(boolean))
 
1343
   * is the row name
 
1344
   */
 
1345
  protected boolean isRowName(int index) {
 
1346
    return  (index == 0);
 
1347
  }
 
1348
 
 
1349
  /**
 
1350
   * returns true if the index (in the array produced by toArray(boolean))
 
1351
   * contains a mean
 
1352
   */
 
1353
  protected boolean isMean(int index) {
 
1354
    index--;   // dataset
 
1355
    if (index == 0) {
 
1356
      return true;   // base column
 
1357
    }
 
1358
    else {
 
1359
      index--;   // base column
 
1360
 
 
1361
      if (index < 0)
 
1362
        return false;
 
1363
      
 
1364
      if (getShowStdDev())
 
1365
        return (index % 3 == 1);
 
1366
      else
 
1367
        return (index % 2 == 0);
 
1368
    }
 
1369
  }
 
1370
 
 
1371
  /**
 
1372
   * returns true if the row index (in the array produced by toArray(boolean))
 
1373
   * contains the average row
 
1374
   */
 
1375
  protected boolean isAverage(int rowIndex) {
 
1376
    if (getShowAverage())
 
1377
      return (getVisibleRowCount() + 1 == rowIndex);
 
1378
    else
 
1379
      return false;
 
1380
  }
 
1381
 
 
1382
  /**
 
1383
   * returns true if the index (in the array produced by toArray(boolean))
 
1384
   * contains a std deviation
 
1385
   */
 
1386
  protected boolean isStdDev(int index) {
 
1387
    index--;   // dataset
 
1388
    index--;   // base column
 
1389
 
 
1390
    if (getShowStdDev()) {
 
1391
      if (index == 0) {
 
1392
        return true;   // stddev of base column
 
1393
      }
 
1394
      else {
 
1395
        index--;   // stddev of base column
 
1396
 
 
1397
        if (index < 0)
 
1398
          return false;
 
1399
      
 
1400
        return (index % 3 == 1);
 
1401
      }
 
1402
    }
 
1403
    else
 
1404
      return false;
 
1405
  }
 
1406
 
 
1407
  /**
 
1408
   * returns true if the index (in the array produced by toArray(boolean))
 
1409
   * contains a significance column
 
1410
   */
 
1411
  protected boolean isSignificance(int index) {
 
1412
    index--;   // dataset
 
1413
    index--;   // base column
 
1414
    if (getShowStdDev()) {
 
1415
      index--;   // stddev of base column
 
1416
 
 
1417
      if (index < 0)
 
1418
        return false;
 
1419
      
 
1420
      return (index % 3 == 2);
 
1421
    }
 
1422
    else {
 
1423
      if (index < 0)
 
1424
        return false;
 
1425
      
 
1426
      return (index % 2 == 1);
 
1427
    }
 
1428
  }
 
1429
 
 
1430
  /**
 
1431
   * returns the matrix as a string
 
1432
   */
 
1433
  public abstract String toStringMatrix();
 
1434
 
 
1435
  /**
 
1436
   * returns the matrix as a string
 
1437
   * @see #toStringMatrix()
 
1438
   */
 
1439
  public String toString() {
 
1440
    return toStringMatrix();
 
1441
  }
 
1442
 
 
1443
  /**
 
1444
   * removes all the header information
 
1445
   */
 
1446
  public void clearHeader() {
 
1447
    m_HeaderKeys   = new Vector();
 
1448
    m_HeaderValues = new Vector();
 
1449
  }
 
1450
 
 
1451
  /**
 
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
 
1455
   */
 
1456
  public void addHeader(String key, String value) {
 
1457
    int         pos;
 
1458
    
 
1459
    pos = m_HeaderKeys.indexOf(key);
 
1460
    if (pos > -1) {
 
1461
      m_HeaderValues.set(pos, value);
 
1462
    }
 
1463
    else {
 
1464
      m_HeaderKeys.add(key);
 
1465
      m_HeaderValues.add(value);
 
1466
    }
 
1467
  }
 
1468
 
 
1469
  /**
 
1470
   * returns the value associated with the given key, null if if cannot be
 
1471
   * found
 
1472
   * @param key       the key to retrieve the value for
 
1473
   * @return          the associated value
 
1474
   */
 
1475
  public String getHeader(String key) {
 
1476
    int       pos;
 
1477
 
 
1478
    pos = m_HeaderKeys.indexOf(key);
 
1479
    if (pos == 0)
 
1480
      return null;
 
1481
    else
 
1482
      return (String) m_HeaderKeys.get(pos);
 
1483
  }
 
1484
 
 
1485
  /**
 
1486
   * returns an enumeration of the header keys
 
1487
   * @return all stored keys
 
1488
   */
 
1489
  public Enumeration headerKeys() {
 
1490
    return m_HeaderKeys.elements();
 
1491
  }
 
1492
  
 
1493
  /**
 
1494
   * returns the header of the matrix as a string
 
1495
   * @see #m_HeaderKeys
 
1496
   * @see #m_HeaderValues
 
1497
   */
 
1498
  public abstract String toStringHeader();
 
1499
 
 
1500
  /**
 
1501
   * returns returns a key for all the col names, for better readability if
 
1502
   * the names got cut off
 
1503
   */
 
1504
  public abstract String toStringKey();
 
1505
 
 
1506
  /**
 
1507
   * clears the current summary data
 
1508
   */
 
1509
  public void clearSummary() {
 
1510
    m_NonSigWins = null;
 
1511
    m_Wins       = null;
 
1512
  }
 
1513
 
 
1514
  /**
 
1515
   * sets the non-significant and significant wins of the resultsets
 
1516
   * @param nonSigWins      the non-significant wins
 
1517
   * @param wins         the significant wins
 
1518
   */
 
1519
  public void setSummary(int[][] nonSigWins, int[][] wins) {
 
1520
    int         i;
 
1521
    int         n;
 
1522
    
 
1523
    m_NonSigWins = new int[nonSigWins.length][nonSigWins[0].length];
 
1524
    m_Wins       = new int[wins.length][wins[0].length];
 
1525
 
 
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];
 
1530
      }
 
1531
    }
 
1532
  }
 
1533
 
 
1534
  /**
 
1535
   * returns the character representation of the given column
 
1536
   */
 
1537
  protected String getSummaryTitle(int col) {
 
1538
    return "" + (char) ((int) 'a' + col % 26);
 
1539
  }
 
1540
 
 
1541
  /**
 
1542
   * returns the summary as string
 
1543
   */
 
1544
  public abstract String toStringSummary();
 
1545
 
 
1546
  /**
 
1547
   * clears the currently stored ranking data
 
1548
   */
 
1549
  public void clearRanking() {
 
1550
    m_RankingWins   = null;
 
1551
    m_RankingLosses = null;
 
1552
    m_RankingDiff   = null;
 
1553
  }
 
1554
 
 
1555
  /**
 
1556
   * sets the ranking data based on the wins
 
1557
   * @param wins      the wins 
 
1558
   */
 
1559
  public void setRanking(int[][] wins) {
 
1560
    int         i;
 
1561
    int         j;
 
1562
    
 
1563
    m_RankingWins   = new int[wins.length];
 
1564
    m_RankingLosses = new int[wins.length];
 
1565
    m_RankingDiff   = new int[wins.length];
 
1566
 
 
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];
 
1573
      }
 
1574
    }
 
1575
  }
 
1576
 
 
1577
  /**
 
1578
   * returns the ranking in a string representation
 
1579
   */
 
1580
  public abstract String toStringRanking();
 
1581
}