/** Gets the average degree of this matrix. */ public double getAvgDegree() { double rowSums = 0; for (int i = 0; i < matrix.rows(); i++) { for (int j = 0; j < matrix.columns(); j++) { rowSums += matrix.get(i, j); } } return rowSums / matrix.rows(); }
/** * Copies the matrix elements from the specified DenseDoubleMatrix2D. The matrix element at ij is * set to 0 if the element at DoubleMatrix[i][j] = 0, otherwise the matrix element at ij is set to * 1. * * @param m the actual matrix data for this AdjacencyMatrix */ public void setMatrix(DenseDoubleMatrix2D m) { int rows = m.rows(); int cols = m.columns(); matrix = new BitMatrix2D(rows, cols); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { matrix.set(i, j, (byte) m.getQuick(i, j)); } } }
/** * Returns a String representation of this AdjacencyMatrix (comment etc.) together with the actual * data matrix. */ public String toString() { String s = "Matrix Name: " + this.matrixLabel + "\n"; s += "Matrix Labels: "; for (int i = 0; i < labels.size(); i++) { if (i == 0) { s += (String) labels.get(i); } else { s += ", " + (String) labels.get(i); } } s += "\nComment: " + comment; return s + "\nAvg Degree: " + getAvgDegree() + "\n" + matrix.toString(); }
/** Returns a String representation of only the actual data matrix. */ public String matrixToString() { String m = matrix.toString(); int index = m.indexOf("\n"); return m.substring(index + 1, m.length()); }
/** Returns the number of columns in the matrix. */ public int columns() { return matrix.columns(); }
/** Returns the number of rows int matrix. */ public int rows() { return matrix.rows(); }
/** * Gets the value at row, col. This returns a double rather than a byte for implementation * reasons. * * @param row the row index (i) * @param col the col index (j) * @return the byte value at row, col (ij) as a double. */ public double get(int row, int col) { return matrix.get(row, col); }
/** * Sets a data value in this matrix. If val equals the matrix element at row, col will be set to * 0, otherwise it is set to 1. * * @param row the row index (i) * @param col the col index (j) * @para val the value to set ij to. */ public void set(int row, int col, double val) { matrix.set(row, col, (byte) val); }
/** * Sets a data value in this matrix. If val equals the matrix element at row, col will be set to * 0, otherwise it is set to 1. * * @param row the row index (i) * @param col the col index (j) * @para val the value to set ij to. */ public void set(int row, int col, byte val) { matrix.set(row, col, val); }
/** Gets (computes) the density of this matrix. */ public double getDensity() { double sum = matrix.zSum(); return sum / matrix.rows() * (matrix.rows() - 1); }
/** * Gets the specified row of data for this matrix. * * @param row the index of the row to get */ public DenseDoubleMatrix1D getRow(int row) { return matrix.getRow(row); }