📄 resultmatrix.java
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* * ResultMatrix.java * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand * */package weka.experiment;import weka.core.Utils;import java.io.Serializable;import java.lang.reflect.Array;import java.util.Enumeration;import java.util.Vector;/** * This matrix is a container for the datasets and classifier setups and * their statistics. Derived classes output the data in different formats. * Derived classes need to implement the following methods: * <ul> * <li><code>toStringMatrix()</code></li> * <li><code>toStringKey()</code></li> * <li><code>toStringHeader()</code></li> * <li><code>toStringSummary()</code></li> * <li><code>toStringRanking()</code></li> * </ul> * * * @author FracPete (fracpete at waikato dot ac dot nz) * @version $Revision: 1.7 $ * @see #toStringMatrix() * @see #toStringKey() * @see #toStringHeader() * @see #toStringSummary() * @see #toStringRanking() */public abstract class ResultMatrix implements Serializable { /** tie */ public final static int SIGNIFICANCE_TIE = 0; /** win */ public final static int SIGNIFICANCE_WIN = 1; /** loss */ public final static int SIGNIFICANCE_LOSS = 2; /** tie string */ public String TIE_STRING = " "; /** win string */ public String WIN_STRING = "v"; /** loss string */ public String LOSS_STRING = "*"; /** the left parentheses for enumerating cols/rows */ public String LEFT_PARENTHESES = "("; /** the right parentheses for enumerating cols/rows */ public String RIGHT_PARENTHESES = ")"; /** the column names */ protected String[] m_ColNames = null; /** the row names */ protected String[] m_RowNames = null; /** whether a column is hidden */ protected boolean[] m_ColHidden = null; /** whether a row is hidden */ protected boolean[] m_RowHidden = null; /** the significance */ protected int[][] m_Significance = null; /** the values */ protected double[][] m_Mean = null; /** the standard deviation */ protected double[][] m_StdDev = null; /** the counts for the different datasets */ protected double[] m_Counts = null; /** the standard mean precision */ protected int m_MeanPrec; /** the standard std. deviation preicision */ protected int m_StdDevPrec; /** whether std. deviations are printed as well */ protected boolean m_ShowStdDev; /** whether the average for each column should be printed */ protected boolean m_ShowAverage; /** whether the names or numbers are output as column declarations */ protected boolean m_PrintColNames; /** whether the names or numbers are output as row declarations */ protected boolean m_PrintRowNames; /** whether a "(x)" is printed before each column name with "x" as the * index */ protected boolean m_EnumerateColNames; /** whether a "(x)" is printed before each row name with "x" as the index */ protected boolean m_EnumerateRowNames; /** the size of the names of the columns */ protected int m_ColNameWidth; /** the size of the names of the rows */ protected int m_RowNameWidth; /** the size of the mean columns */ protected int m_MeanWidth; /** the size of the std dev columns */ protected int m_StdDevWidth; /** the size of the significance columns */ protected int m_SignificanceWidth; /** the size of the counts */ protected int m_CountWidth; /** contains the keys for the header */ protected Vector m_HeaderKeys = null; /** contains the values for the header */ protected Vector m_HeaderValues = null; /** the non-significant wins */ protected int[][] m_NonSigWins = null; /** the significant wins */ protected int[][] m_Wins = null; /** the wins in ranking */ protected int[] m_RankingWins = null; /** the losses in ranking */ protected int[] m_RankingLosses = null; /** the difference between wins and losses */ protected int[] m_RankingDiff = null; /** the ordering of the rows */ protected int[] m_RowOrder = null; /** the ordering of the columns */ protected int[] m_ColOrder = null; /** whether to remove the filter name from the dataaset name */ protected boolean m_RemoveFilterName = false; /** * initializes the matrix as 1x1 matrix */ public ResultMatrix() { this(1, 1); } /** * initializes the matrix with the given dimensions */ public ResultMatrix(int cols, int rows) { setSize(cols, rows); clear(); } /** * initializes the matrix with the values from the given matrix * @param matrix the matrix to get the values from */ public ResultMatrix(ResultMatrix matrix) { assign(matrix); } /** * returns the name of the output format */ public abstract String getDisplayName(); /** * acquires the data from the given matrix */ public void assign(ResultMatrix matrix) { int i; int n; setSize(matrix.getColCount(), matrix.getRowCount()); // output parameters TIE_STRING = matrix.TIE_STRING; WIN_STRING = matrix.WIN_STRING; LOSS_STRING = matrix.LOSS_STRING; LEFT_PARENTHESES = matrix.LEFT_PARENTHESES; RIGHT_PARENTHESES = matrix.RIGHT_PARENTHESES; m_MeanPrec = matrix.m_MeanPrec; m_StdDevPrec = matrix.m_StdDevPrec; m_ShowStdDev = matrix.m_ShowStdDev; m_ShowAverage = matrix.m_ShowAverage; m_PrintColNames = matrix.m_PrintColNames; m_PrintRowNames = matrix.m_PrintRowNames; m_EnumerateColNames = matrix.m_EnumerateColNames; m_EnumerateRowNames = matrix.m_EnumerateRowNames; m_RowNameWidth = matrix.m_RowNameWidth; m_MeanWidth = matrix.m_MeanWidth; m_StdDevWidth = matrix.m_StdDevWidth; m_SignificanceWidth = matrix.m_SignificanceWidth; m_CountWidth = matrix.m_CountWidth; m_RemoveFilterName = matrix.m_RemoveFilterName; // header m_HeaderKeys = (Vector) matrix.m_HeaderKeys.clone(); m_HeaderValues = (Vector) matrix.m_HeaderValues.clone(); // matrix for (i = 0; i < matrix.m_Mean.length; i++) { for (n = 0; n < matrix.m_Mean[i].length; n++) { m_Mean[i][n] = matrix.m_Mean[i][n]; m_StdDev[i][n] = matrix.m_StdDev[i][n]; m_Significance[i][n] = matrix.m_Significance[i][n]; } } for (i = 0; i < matrix.m_ColNames.length; i++) { m_ColNames[i] = matrix.m_ColNames[i]; m_ColHidden[i] = matrix.m_ColHidden[i]; } for (i = 0; i < matrix.m_RowNames.length; i++) { m_RowNames[i] = matrix.m_RowNames[i]; m_RowHidden[i] = matrix.m_RowHidden[i]; } for (i = 0; i < matrix.m_Counts.length; i++) m_Counts[i] = matrix.m_Counts[i]; // summary if (matrix.m_NonSigWins != null) { m_NonSigWins = new int[matrix.m_NonSigWins.length][]; m_Wins = new int[matrix.m_NonSigWins.length][]; for (i = 0; i < matrix.m_NonSigWins.length; i++) { m_NonSigWins[i] = new int[matrix.m_NonSigWins[i].length]; m_Wins[i] = new int[matrix.m_NonSigWins[i].length]; for (n = 0; n < matrix.m_NonSigWins[i].length; n++) { m_NonSigWins[i][n] = matrix.m_NonSigWins[i][n]; m_Wins[i][n] = matrix.m_Wins[i][n]; } } } // ranking if (matrix.m_RankingWins != null) { m_RankingWins = new int[matrix.m_RankingWins.length]; m_RankingLosses = new int[matrix.m_RankingWins.length]; m_RankingDiff = new int[matrix.m_RankingWins.length]; for (i = 0; i < matrix.m_RankingWins.length; i++) { m_RankingWins[i] = matrix.m_RankingWins[i]; m_RankingLosses[i] = matrix.m_RankingLosses[i]; m_RankingDiff[i] = matrix.m_RankingDiff[i]; } } } /** * removes the stored data and the ordering, but retains the dimensions of * the matrix */ public void clear() { m_MeanPrec = 2; m_StdDevPrec = 2; m_ShowStdDev = false; m_ShowAverage = false; m_PrintColNames = true; m_PrintRowNames = true; m_EnumerateColNames = true; m_EnumerateRowNames = false; m_RowNameWidth = 0; m_ColNameWidth = 0; m_MeanWidth = 0; m_StdDevWidth = 0; m_SignificanceWidth = 0; m_CountWidth = 0; setSize(getColCount(), getRowCount()); } /** * clears the content of the matrix and sets the new size * @param cols the number of mean columns * @param rows the number of mean rows */ public void setSize(int cols, int rows) { int i; int n; m_ColNames = new String[cols]; m_RowNames = new String[rows]; m_Counts = new double[rows]; m_ColHidden = new boolean[cols]; m_RowHidden = new boolean[rows]; m_Mean = new double[rows][cols]; m_Significance = new int[rows][cols]; m_StdDev = new double[rows][cols]; m_ColOrder = null; m_RowOrder = null; // NaN means that there exists no value! -> toArray() for (i = 0; i < m_Mean.length; i++) { for (n = 0; n < m_Mean[i].length; n++) m_Mean[i][n] = Double.NaN; } for (i = 0; i < m_ColNames.length; i++) m_ColNames[i] = "col" + i; for (i = 0; i < m_RowNames.length; i++) m_RowNames[i] = "row" + i; clearHeader(); clearSummary(); clearRanking(); } /** * sets the precision for the means */ public void setMeanPrec(int prec) { if (prec >= 0) m_MeanPrec = prec; } /** * returns the current precision for the means */ public int getMeanPrec() { return m_MeanPrec; } /** * sets the precision for the standard deviation */ public void setStdDevPrec(int prec) { if (prec >= 0) m_StdDevPrec = prec; } /** * returns the current standard deviation precision */ public int getStdDevPrec() { return m_StdDevPrec; } /** * sets the width for the column names (0 = optimal) */ public void setColNameWidth(int width) { if (width >= 0) m_ColNameWidth = width; } /** * returns the current width for the column names */ public int getColNameWidth() { return m_ColNameWidth; } /** * sets the width for the row names (0 = optimal) */ public void setRowNameWidth(int width) { if (width >= 0) m_RowNameWidth = width; } /** * returns the current width for the row names */ public int getRowNameWidth() { return m_RowNameWidth; } /** * sets the width for the mean (0 = optimal) */ public void setMeanWidth(int width) { if (width >= 0) m_MeanWidth = width; } /** * returns the current width for the mean */ public int getMeanWidth() { return m_MeanWidth; } /** * sets the width for the std dev (0 = optimal) */ public void setStdDevWidth(int width) { if (width >= 0) m_StdDevWidth = width; } /** * returns the current width for the std dev */ public int getStdDevWidth() { return m_StdDevWidth; } /** * sets the width for the significance (0 = optimal) */ public void setSignificanceWidth(int width) { if (width >= 0) m_SignificanceWidth = width; } /** * returns the current width for the significance */ public int getSignificanceWidth() { return m_SignificanceWidth; } /** * sets the width for the counts (0 = optimal) */ public void setCountWidth(int width) { if (width >= 0) m_CountWidth = width; } /** * returns the current width for the counts */ public int getCountWidth() { return m_CountWidth; } /** * sets whether to display the std deviations or not */ public void setShowStdDev(boolean show) { m_ShowStdDev = show; } /** * returns whether std deviations are displayed or not */ public boolean getShowStdDev() { return m_ShowStdDev; } /** * sets whether to display the average per column or not */ public void setShowAverage(boolean show) { m_ShowAverage = show; } /** * returns whether average per column is displayed or not */ public boolean getShowAverage() { return m_ShowAverage; } /** * sets whether to remove the filter classname from the dataset name */ public void setRemoveFilterName(boolean remove) { m_RemoveFilterName = remove; } /** * returns whether the filter classname is removed from the dataset name */ public boolean getRemoveFilterName() { return m_RemoveFilterName; } /** * sets whether the column names or numbers instead are printed. * deactivating automatically sets m_EnumerateColNames to TRUE. * @see #setEnumerateColNames(boolean) */ public void setPrintColNames(boolean print) { m_PrintColNames = print; if (!print) setEnumerateColNames(true); } /** * returns whether column names or numbers instead are printed */ public boolean getPrintColNames() { return m_PrintColNames; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -