/** * Same as size * * @return the number of rows */ public int numRows() { return size(); }
/** * Same as size * * @return the number of columns */ public int numColumns() { return size(); }
/** * Gets the number of rows in the matrix. Cost matrices are square so it is * the same as the column count, i.e. the size of the matrix. * * @return the row count */ @Override public int getRowCount() { return m_matrix.size(); }
/** * Gets the number of columns in the matrix. Cost matrices are square so it * is the same as the row count, i.e. the size of the matrix. * * @return the row count */ @Override public int getColumnCount() { return m_matrix.size(); }
/** * Returns the Java code that generates an object the same as the one being * edited. Unfortunately this can't be done in a single line of code, so the * code returned will only build a default cost matrix of the same size. * * @return the initialization string */ @Override public String getJavaInitializationString() { return ("new CostMatrix(" + m_matrix.size() + ")"); }
/** * Returns the Java code that generates an object the same as the one being * edited. Unfortunately this can't be done in a single line of code, so the * code returned will only build a default cost matrix of the same size. * * @return the initialization string */ @Override public String getJavaInitializationString() { return ("new CostMatrix(" + m_matrix.size() + ")"); }
/** * Same as size * * @return the number of rows */ public int numRows() { return size(); }
/** * Gets the number of columns in the matrix. Cost matrices are square so it * is the same as the row count, i.e. the size of the matrix. * * @return the row count */ @Override public int getColumnCount() { return m_matrix.size(); }
/** * Same as size * * @return the number of columns */ public int numColumns() { return size(); }
/** * Gets the number of rows in the matrix. Cost matrices are square so it is * the same as the column count, i.e. the size of the matrix. * * @return the row count */ @Override public int getRowCount() { return m_matrix.size(); }
/** * Paints a graphical representation of the object. For the cost matrix it * prints out the text "X x X matrix", where X is the size of the matrix. * * @param gfx the graphics context to draw the representation to * @param box the bounds within which the representation should fit. */ @Override public void paintValue(Graphics gfx, Rectangle box) { gfx.drawString(m_matrix.size() + " x " + m_matrix.size() + " cost matrix", box.x, box.y + box.height); }
/** * Paints a graphical representation of the object. For the cost matrix it * prints out the text "X x X matrix", where X is the size of the matrix. * * @param gfx the graphics context to draw the representation to * @param box the bounds within which the representation should fit. */ @Override public void paintValue(Graphics gfx, Rectangle box) { gfx.drawString(m_matrix.size() + " x " + m_matrix.size() + " cost matrix", box.x, box.y + box.height); }
/** * Responds to a change in structure of the matrix being edited. * */ public void matrixChanged() { m_tableModel.fireTableStructureChanged(); m_classesField.setText("" + m_matrix.size()); }
/** * Responds to a change in structure of the matrix being edited. * */ public void matrixChanged() { m_tableModel.fireTableStructureChanged(); m_classesField.setText("" + m_matrix.size()); }
/** * Creates a cost matrix that is a copy of another. * * @param toCopy the matrix to copy. */ public CostMatrix(CostMatrix toCopy) { this(toCopy.size()); for (int i = 0; i < m_size; i++) { for (int j = 0; j < m_size; j++) { setCell(i, j, toCopy.getCell(i, j)); } } }
/** * Creates a cost matrix that is a copy of another. * * @param toCopy the matrix to copy. */ public CostMatrix(CostMatrix toCopy) { this(toCopy.size()); for (int i = 0; i < m_size; i++) { for (int j = 0; j < m_size; j++) { setCell(i, j, toCopy.getCell(i, j)); } } }
/** * Responds to the user perfoming an action. * * @param e the action event that occured */ @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == m_defaultButton) { m_matrix.initialize(); matrixChanged(); } else if (e.getSource() == m_openButton) { openMatrix(); } else if (e.getSource() == m_saveButton) { saveMatrix(); } else if ((e.getSource() == m_classesField) || (e.getSource() == m_resizeButton)) { try { int newNumClasses = Integer.parseInt(m_classesField.getText()); if (newNumClasses > 0 && newNumClasses != m_matrix.size()) { setValue(new CostMatrix(newNumClasses)); } } catch (Exception ex) { } } }
/** * Responds to the user perfoming an action. * * @param e the action event that occured */ @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == m_defaultButton) { m_matrix.initialize(); matrixChanged(); } else if (e.getSource() == m_openButton) { openMatrix(); } else if (e.getSource() == m_saveButton) { saveMatrix(); } else if ((e.getSource() == m_classesField) || (e.getSource() == m_resizeButton)) { try { int newNumClasses = Integer.parseInt(m_classesField.getText()); if (newNumClasses > 0 && newNumClasses != m_matrix.size()) { setValue(new CostMatrix(newNumClasses)); } } catch (Exception ex) { } } }
/** * Makes a copy of this ConfusionMatrix after applying the supplied CostMatrix * to the cells. The resulting ConfusionMatrix can be used to get * cost-weighted statistics. * * @param costs the CostMatrix. * @return a ConfusionMatrix that has had costs applied. * @exception Exception if the CostMatrix is not of the same size as this * ConfusionMatrix. */ public ConfusionMatrix makeWeighted(CostMatrix costs) throws Exception { if (costs.size() != size()) { throw new Exception("Cost and confusion matrices must be the same size"); } ConfusionMatrix weighted = new ConfusionMatrix(m_ClassNames); for (int row = 0; row < size(); row++) { for (int col = 0; col < size(); col++) { weighted.set(row, col, get(row, col) * costs.getElement(row, col)); } } return weighted; }
/** * Makes a copy of this ConfusionMatrix after applying the supplied CostMatrix * to the cells. The resulting ConfusionMatrix can be used to get * cost-weighted statistics. * * @param costs the CostMatrix. * @return a ConfusionMatrix that has had costs applied. * @exception Exception if the CostMatrix is not of the same size as this * ConfusionMatrix. */ public ConfusionMatrix makeWeighted(CostMatrix costs) throws Exception { if (costs.size() != size()) { throw new Exception("Cost and confusion matrices must be the same size"); } ConfusionMatrix weighted = new ConfusionMatrix(m_ClassNames); for (int row = 0; row < size(); row++) { for (int col = 0; col < size(); col++) { weighted.set(row, col, get(row, col) * costs.getElement(row, col)); } } return weighted; }