/** * 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 synchronized double[] getColumn(int column) { return m.getColumn(column); }
/** * {@inheritDoc} */ public synchronized SparseDoubleVector getColumnVector(int column) { return m.getColumnVector(column); }
/** * {@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; }
BitSet allRows = new BitSet(sm.rows()); allRows.set(0, sm.rows()); LOGGER.info("CBC begining Phase 2"); List<Committee> committees = phase2( for (int r = 0; r < m.rows(); ++r) { LOGGER.fine("Computing Phase 3 for row " + r); SparseDoubleVector row = sm.getRowVector(r);
/** * {@inheritDoc} */ public synchronized SparseDoubleVector getRowVector(int row) { return m.getRowVector(row); }
public void writeMatrix(SparseMatrix m, OutputStream s) { for (int col = 0; col < m.columns(); ++col) colOrder.add(new ArrayList<String>()); for (int r = 0; r < m.rows(); ++r) { SparseDoubleVector sv = m.getRowVector(r); int[] nonZeros = sv.getNonZeroIndices(); nonZeroCount += nonZeros.length; pw.printf("%d %d %d\n", m.rows(), m.columns(), nonZeroCount);
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); total += termGraph.get(r,c); for (int r = 0; r < termGraph.rows(); ++r) { String word = basis.getDimensionDescription(r); Double l = referenceLikilhood.get(word);
/** * {@inheritDoc} */ public synchronized void set(int row, int col, double val) { m.set(row, col, val); }
/** * {@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()); } }
this.rows = rows; centroid = new CompactSparseVector(sm.columns()); double simSum = 0d; for (int r : rows) { SparseDoubleVector row = sm.getRowVector(r); VectorMath.add(centroid, row); continue; simSum += Similarity. cosineSimilarity(row, sm.getRowVector(r2));
/** * {@inheritDoc} */ public synchronized int rows() { return m.rows(); }
/** * {@inheritDoc} */ public int columns() { return backing.columns(); }
/** * {@inheritDoc} */ public synchronized void setColumn(int column, double[] values) { m.setColumn(column, values); }
/** * {@inheritDoc} */ public synchronized void setRow(int row, double[] values) { m.setRow(row, values); }
/** * {@inheritDoc} */ public synchronized double get(int row, int col) { return m.get(row, col); }
/** * {@inheritDoc} */ public synchronized double[] getRow(int row) { return m.getRow(row); }
BitSet allRows = new BitSet(sm.rows()); allRows.set(0, sm.rows()); LOGGER.info("CBC begining Phase 2"); List<Committee> committees = phase2( for (int r = 0; r < m.rows(); ++r) { LOGGER.fine("Computing Phase 3 for row " + r); SparseDoubleVector row = sm.getRowVector(r);
/** * {@inheritDoc} */ public synchronized SparseDoubleVector getRowVector(int row) { return m.getRowVector(row); }