/** * {@inheritDoc} */ public int rows() { return backingMatrix.rows(); }
/** * {@inheritDoc} */ public int columns() { return m.rows(); }
/** * {@inheritDoc} */ public Assignments cluster(Matrix adj, Properties props) { return cluster(adj, (int) (adj.rows() * .10), props); }
/** * {@inheritDoc} */ public double[][] toDenseArray() { double[][] arr = new double[backingMatrix.rows()][columns]; for (int i = 0; i < columnToReal.length; ++i) arr[i] = backingMatrix.getColumn(columnToReal[i]); return arr; }
/** * Initializes every value in {@code m} to be a random value between 0 and * 1, inclusive. */ public static void initialize(Matrix m) { for (int r = 0; r < m.rows(); ++r) for (int c = 0; c < m.columns(); ++c) m.set(r,c,Math.random()); } }
/** * Initializes every value in {@code m} to be a random value between 0 and * 1, inclusive. */ public static void initialize(Matrix m) { for (int r = 0; r < m.rows(); ++r) for (int c = 0; c < m.columns(); ++c) m.set(r,c,Math.random()); } }
/** * Initializes every value in {@code m} to be a random value between 0 and * 1, inclusive. */ public static void initialize(Matrix m) { for (int r = 0; r < m.rows(); ++r) for (int c = 0; c < m.columns(); ++c) m.set(r,c,Math.random()); }
/** * {@inheritDoc} */ public double[] rank(Matrix adj) { return rank(adj, initialRanks(adj.rows())); }
private static Matrix multiplyLeftDiag(Matrix m1, Matrix m2) { Matrix resultMatrix = create(m1.rows(), m2.columns(), true); for (int r = 0; r < m1.rows(); ++r) { double element = m1.get(r, r); double[] m2Row = m2.getRow(r); for (int c = 0; c < m2.columns(); ++c) resultMatrix.set(r, c, element * m2Row[c]); } return resultMatrix; }
/** * Sets any negative values of {@code m} to zero. */ public static void makeNonZero(Matrix m) { for (int r = 0; r < m.rows(); ++r) for (int c = 0; c < m.columns(); ++c) if (m.get(r,c) < 0d) m.set(r,c,0); }
private static Matrix multiplyRightDiag(Matrix m1, Matrix m2) { Matrix resultMatrix = create(m1.rows(), m2.columns(), true); for (int r = 0; r < m1.rows(); ++r) { double[] row = m1.getRow(r); for (int c = 0; c < m2.columns(); ++c) { double value = m2.get(c, c); resultMatrix.set(r, c, value * row[c]); } } return resultMatrix; }
/** * Sets any negative values of {@code m} to zero. */ public static void makeNonZero(Matrix m) { for (int r = 0; r < m.rows(); ++r) for (int c = 0; c < m.columns(); ++c) if (m.get(r,c) < 0d) m.set(r,c,0); }
private static Matrix multiplyRightDiag(Matrix m1, Matrix m2) { Matrix resultMatrix = create(m1.rows(), m2.columns(), true); for (int r = 0; r < m1.rows(); ++r) { double[] row = m1.getRow(r); for (int c = 0; c < m2.columns(); ++c) { double value = m2.get(c, c); resultMatrix.set(r, c, value * row[c]); } } return resultMatrix; }
private static Matrix multiplyLeftDiag(Matrix m1, Matrix m2) { Matrix resultMatrix = create(m1.rows(), m2.columns(), true); for (int r = 0; r < m1.rows(); ++r) { double element = m1.get(r, r); double[] m2Row = m2.getRow(r); for (int c = 0; c < m2.columns(); ++c) resultMatrix.set(r, c, element * m2Row[c]); } return resultMatrix; }
/** * Compute the row sums of the values in {@code matrix} and returns the * values in a vector of length {@code matrix.columns()}. */ protected static <T extends Matrix> DoubleVector computeMatrixRowSum( T matrix) { DoubleVector rowSums = new DenseVector(matrix.columns()); for (int r = 0; r < matrix.rows(); ++r) VectorMath.add(rowSums, matrix.getRowVector(r)); return rowSums; }
/** * Updates the values in {@code X} based on the difference found in {@code * G} with each value scaled by the {@code learningRate}. */ private void updateX(Matrix G, double[] learningRate) { for (int k = 0; k < X.rows(); ++k) for (int c = 0; c < X.columns(); ++c) X.set(k, c, X.get(k, c) - learningRate[k] * G.get(k, c)); makeNonZero(X); }
/** * Updates the values in {@code A} based on the difference found in {@code * G} with each value scaled by the {@code learningRate}. */ private void updateA(Matrix G, double[] learningRate) { for (int r = 0; r < A.rows(); ++r) for (int k = 0; k < A.columns(); ++k) A.set(r, k, A.get(r, k) - learningRate[k] * G.get(r, k)); makeNonZero(A); }
/** * Updates the values in {@code X} based on the difference found in {@code * G} with each value scaled by the {@code learningRate}. */ private void updateX(Matrix G, double[] learningRate) { for (int k = 0; k < X.rows(); ++k) for (int c = 0; c < X.columns(); ++c) X.set(k, c, X.get(k, c) - learningRate[k] * G.get(k, c)); makeNonZero(X); }