/** * {@inheritDoc} */ public synchronized int rows() { return m.rows(); }
/** * {@inheritDoc} */ public synchronized int rows() { return m.rows(); }
/** * {@inheritDoc} */ public int rows() { return backing.rows(); }
/** * {@inheritDoc} */ public int rows() { return backing.rows(); }
/** * {@inheritDoc} */ public double[] rank(SparseMatrix adj, double[] initialRanks) { double[] ranks = initialRanks; double[] columnSums = TransformStatistics.extractStatistics(adj).columnSums; for (int i = 0; i < numIterations; i++) { double[] newRanks = new double[adj.rows()]; for (int r = 0; r < adj.rows(); ++r) for (int c : adj.getRowVector(r).getNonZeroIndices()) newRanks[r] += adj.get(r, c) / columnSums[c] * ranks[r]; for (int r = 0; r < adj.rows(); ++r) newRanks[r] = alpha * newRanks[r] + beta * initialRanks[r]; ranks = newRanks; } return ranks; }
/** * {@inheritDoc} */ public double[] rank(SparseMatrix adj) { return rank(adj, initialRanks(adj.rows())); }
/** * Writes the {@link SparseMatrix} to the file using a particular format. */ public void writeMatrix(SparseMatrix m, OutputStream s) { PrintStream p = new PrintStream(s); // Check to see if the last element in the matrix is non zero. If it // has a zero value, print out a single dummy value to bound the total // size of the matrix. if (m.get(m.rows()-1, m.columns()-1) == 0d) p.printf("%d %d %f\n", m.rows(), m.columns(), 0.0); // Print the row, col, value entrie for each element in the matrix. for (int r = 0; r < m.rows(); ++r) { SparseDoubleVector v = m.getRowVector(r); for (int c : v.getNonZeroIndices()) p.printf("%d %d %f\n", r+1, c+1, m.get(r,c)); } p.flush(); p.close(); } }
StringBasisMapping finalBasis = new StringBasisMapping(); double[] termFrequency = new double[termGraph.rows()]; double total = 0; for (int r = 0; r < termGraph.rows(); ++r) for (int c = r+1; c < termGraph.columns(); ++c) { termFrequency[r] += termGraph.get(r,c); for (int r = 0; r < termGraph.rows(); ++r) { String word = basis.getDimensionDescription(r); Double l = referenceLikilhood.get(word);
double sum = 0; double[] colSums = new double[m.columns()]; double[] rowSums = new double[m.rows()]; for (int r = 0; r < m.rows(); ++r) { SparseDoubleVector sv = m.getRowVector(r); for (int c : sv.getNonZeroIndices()) { double[] rowEntropy = new double[m.rows()]; for (int r = 0; r < m.rows(); ++r) { SparseDoubleVector sv = m.getRowVector(r); for (int c : sv.getNonZeroIndices()) {
/** * {@inheritDoc} */ public void factorize(SparseMatrix m, int numDimensions) { if (numDimensions >= m.columns() || numDimensions >= m.rows()) throw new IllegalArgumentException( "Cannot factorize with more dimensions than there are " + "rows or columns"); this.numDimensions = numDimensions; A = new ArrayMatrix(m.rows(), numDimensions); initialize(A); X = new ArrayMatrix(numDimensions, m.columns()); initialize(X); for (int i = 0; i < numIterations; ++i) { updateX(computeGofX(m), computeLearningRateX()); updateA(computeGofA(m), computeLearningRateA()); } }
/** * {@inheritDoc} */ public void factorize(SparseMatrix m, int numDimensions) { if (numDimensions >= m.columns() || numDimensions >= m.rows()) throw new IllegalArgumentException( "Cannot factorize with more dimensions than there are " + "rows or columns"); this.numDimensions = numDimensions; A = new ArrayMatrix(m.rows(), numDimensions); initialize(A); X = new ArrayMatrix(numDimensions, m.columns()); initialize(X); for (int i = 0; i < numIterations; ++i) { updateX(computeGofX(m), computeLearningRateX()); updateA(computeGofA(m), computeLearningRateA()); } }
for (int r = 0; r < smatrix.rows(); ++r) { double vValue = 0; SparseDoubleVector row = smatrix.getRowVector(r);
for (int r = 0; r < smatrix.rows(); ++r) { double vValue = 0; SparseDoubleVector row = smatrix.getRowVector(r);
/** * Returns the dot product between the transpose of a given matrix and a * given vector. This method has special casing for a {@code SparseMatrix}. * This method also assumes that {@code matrix} is row based and iterates * over each of the values in the row before iterating over another row. */ protected static DoubleVector computeMatrixTransposeV(Matrix matrix, DoubleVector v) { DoubleVector newV = new DenseVector(matrix.columns()); if (matrix instanceof SparseMatrix) { SparseMatrix smatrix = (SparseMatrix) matrix; for (int r = 0; r < smatrix.rows(); ++r) { SparseDoubleVector row = smatrix.getRowVector(r); int[] nonZeros = row.getNonZeroIndices(); for (int c : nonZeros) newV.add(c, row.get(c) * v.get(r)); } } else { for (int r = 0; r < matrix.rows(); ++r) for (int c = 0; c < matrix.columns(); ++c) newV.add(c, matrix.get(r, c) * v.get(r)); } return newV; }
/** * Returns the dot product between the transpose of a given matrix and a * given vector. This method has special casing for a {@code SparseMatrix}. * This method also assumes that {@code matrix} is row based and iterates * over each of the values in the row before iterating over another row. */ protected static DoubleVector computeMatrixTransposeV(Matrix matrix, DoubleVector v) { DoubleVector newV = new DenseVector(matrix.columns()); if (matrix instanceof SparseMatrix) { SparseMatrix smatrix = (SparseMatrix) matrix; for (int r = 0; r < smatrix.rows(); ++r) { SparseDoubleVector row = smatrix.getRowVector(r); int[] nonZeros = row.getNonZeroIndices(); for (int c : nonZeros) newV.add(c, row.get(c) * v.get(r)); } } else { for (int r = 0; r < matrix.rows(); ++r) for (int c = 0; c < matrix.columns(); ++c) newV.add(c, matrix.get(r, c) * v.get(r)); } return newV; }
for (int r = 0; r < Y.rows(); ++r) {
for (int r = 0; r < Y.rows(); ++r) {
for (int r = 0; r < Y.rows(); ++r) {
for (int r = 0; r < Y.rows(); ++r) {