/** * {@inheritDoc} */ public synchronized double get(int row, int col) { return m.get(row, col); }
/** * 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(); } }
/** * {@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 synchronized double get(int row, int col) { return m.get(row, col); }
SparseDoubleVector sv = m.getRowVector(r); for (int c : sv.getNonZeroIndices()) { double v = m.get(r, c); sum += v; colSums[c] += v; SparseDoubleVector sv = m.getRowVector(r); for (int c : sv.getNonZeroIndices()) { double v = m.get(r, c); entropy -= entropy(v, sum); colEntropy[c] -= entropy(v, colSums[c]);
/** * {@inheritDoc} */ @Override public double get(int row, int column) { // Swap the ordering so only the upper triangular is accessed. if (row > column) { int tmp = column; column = row; row = tmp; } return backing.get(row, column); }
else if (r < col && sm.get(col, r) == 0) edgeList.add(new Edge(r, col));
/** * {@inheritDoc} */ @Override public double get(int row, int column) { // Swap the ordering so only the upper triangular is accessed. if (row > column) { int tmp = column; column = row; row = tmp; } return backing.get(row, column); }
else if (r < col && sm.get(col, r) == 0) edgeList.add(new Edge(r, col));
/** * {@inheritDoc} */ public synchronized double getAndAdd(int row, int col, double delta) { double value = m.get(row, col); m.set(row, col, value + delta); return value; }
/** * {@inheritDoc} */ public synchronized double addAndGet(int row, int col, double delta) { double value = m.get(row, col) + delta; m.set(row, col, value); return value; }
/** * {@inheritDoc} */ public synchronized double add(int row, int col, double delta) { double value = m.get(row, col); m.set(row, col, value + delta); return value; }
/** * {@inheritDoc} */ public synchronized double addAndGet(int row, int col, double delta) { double value = m.get(row, col) + delta; m.set(row, col, value); return value; }