public static double rowSparcity(Matrix mat) { double nrows = mat.getNumRows(); double nsparse = 0; for (int r = 0; r < nrows; r++) { if (mat.getRow(r).sum() == 0) { nsparse++; } } return nsparse / nrows; }
public static Vector diag(Matrix mat) { Vector ret; if (mat.getNumColumns() > mat.getNumRows()) { ret = mat.getRow(0); } else { ret = mat.getColumn(0); } int rowcol = ret.getDimensionality(); for (int rc = 0; rc < rowcol; rc++) { ret.setElement(rc, mat.getElement(rc, rc)); } return ret; }