/** * NEVER call this from real code. Java's serialization code will need to * call this, but if all of the values aren't immediately filled with useful * values through introspection, the instance created with this method won't * provide useful values. */ protected MultipartiteValenceMatrix() { // NOTE: I have to pass something, but it's going to be overwritten immediately super(new SparseMatrix(1, 1)); }
/** * NEVER call this from real code. Java's serialization code will need to * call this, but if all of the values aren't immediately filled with useful * values through introspection, the instance created with this method won't * provide useful values. */ protected MultipartiteValenceMatrix() { // NOTE: I have to pass something, but it's going to be overwritten immediately super(new SparseMatrix(1, 1)); }
/** * NEVER call this from real code. Java's serialization code will need to * call this, but if all of the values aren't immediately filled with useful * values through introspection, the instance created with this method won't * provide useful values. */ protected MultipartiteValenceMatrix() { // NOTE: I have to pass something, but it's going to be overwritten immediately super(new SparseMatrix(1, 1)); }
/** * {@inheritDoc} * * NOTE: Returned matrix is sparse row format. * * @return {@inheritDoc} */ @Override final public SparseMatrix createMatrix( final int numRows, final int numColumns) { return new SparseMatrix(numRows, numColumns); }
/** * {@inheritDoc} * * NOTE: Returned matrix is sparse row format. * * @return {@inheritDoc} */ @Override final public SparseMatrix createMatrix( final int numRows, final int numColumns) { return new SparseMatrix(numRows, numColumns); }
/** * {@inheritDoc} * * NOTE: Returned matrix is sparse row format. * * @return {@inheritDoc} */ @Override final public SparseMatrix createMatrix( final int numRows, final int numColumns) { return new SparseMatrix(numRows, numColumns); }
/** * Helper method converts P into a pivot matrix that can pre-multiply * L*U. * * @return an identity matrix with the appropriate row swaps to * re-generate the original matrix A when P * L * U is calculated. */ public Matrix getPivotMatrix() { SparseMatrix pivot = new SparseMatrix(L.getNumRows(), L.getNumRows()); pivot.identity(); for (int i = 0; i < P.size(); ++i) { if (P.get(i) != i) { Vector tmp = pivot.getRow(i); pivot.setRow(i, pivot.getRow(P.get(i))); pivot.setRow(P.get(i), tmp); } } return pivot; }
/** * Helper method converts P into a pivot matrix that can pre-multiply * L*U. * * @return an identity matrix with the appropriate row swaps to * re-generate the original matrix A when P * L * U is calculated. */ public Matrix getPivotMatrix() { SparseMatrix pivot = new SparseMatrix(L.getNumRows(), L.getNumRows()); pivot.identity(); for (int i = 0; i < P.size(); ++i) { if (P.get(i) != i) { Vector tmp = pivot.getRow(i); pivot.setRow(i, pivot.getRow(P.get(i))); pivot.setRow(P.get(i), tmp); } } return pivot; }
@Override final public Matrix getSubMatrix( final int minRow, final int maxRow, final int minColumn, final int maxColumn) { checkSubmatrixRange(minRow, maxRow, minColumn, maxColumn); SparseMatrix result = new SparseMatrix(maxRow - minRow + 1, maxColumn - minColumn + 1); // You only need worry about the diagonal, so one of the extents will do for (int i = minRow; i <= maxRow; ++i) { // Check to make sure that this element of the diagonal is also in // the other extents if (i >= minColumn && i <= maxColumn) { // If it is, add it at the right place in the output result.setElement(i - minRow, i - minColumn, get(i, i)); } } return result; }
@Override final public Matrix getSubMatrix( final int minRow, final int maxRow, final int minColumn, final int maxColumn) { checkSubmatrixRange(minRow, maxRow, minColumn, maxColumn); SparseMatrix result = new SparseMatrix(maxRow - minRow + 1, maxColumn - minColumn + 1); // You only need worry about the diagonal, so one of the extents will do for (int i = minRow; i <= maxRow; ++i) { // Check to make sure that this element of the diagonal is also in // the other extents if (i >= minColumn && i <= maxColumn) { // If it is, add it at the right place in the output result.setElement(i - minRow, i - minColumn, get(i, i)); } } return result; }
/** * {@inheritDoc} * * NOTE: Upon completion this is in the compressed Yale format. * @return {@inheritDoc} */ @Override public final Matrix times( final DiagonalMatrix other) { this.assertMultiplicationDimensions(other); if (!isCompressed()) { compress(); } SparseMatrix result = new SparseMatrix(getNumRows(), getNumColumns()); result.columnIndices = Arrays.copyOf(columnIndices, columnIndices.length); result.firstIndicesForRows = Arrays.copyOf(firstIndicesForRows, firstIndicesForRows.length); result.values = new double[values.length]; for (int i = 0; i < values.length; ++i) { result.values[i] = values[i] * other.get(columnIndices[i], columnIndices[i]); } return result; }
@Override public final Matrix outerProduct( final SparseVector other) { compress(); other.compress(); int numRows = getDimensionality(); int numCols = other.getDimensionality(); SparseMatrix result = new SparseMatrix(numRows, numCols, true); int idx = 0; for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); if ((idx < indices.length) && (indices[idx] == i)) { for (int j = 0; j < other.indices.length; ++j) { row.elements.put(other.indices[j], new MutableDouble(values[idx] * other.values[j])); } ++idx; } result.setRowInternal(i, row); } return result; }
@Override public final Matrix outerProduct( final SparseVector other) { compress(); other.compress(); int numRows = getDimensionality(); int numCols = other.getDimensionality(); SparseMatrix result = new SparseMatrix(numRows, numCols, true); int idx = 0; for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); if ((idx < indices.length) && (indices[idx] == i)) { for (int j = 0; j < other.indices.length; ++j) { row.elements.put(other.indices[j], new MutableDouble(values[idx] * other.values[j])); } ++idx; } result.setRowInternal(i, row); } return result; }
@Override public final Matrix outerProduct( final SparseVector other) { compress(); other.compress(); int numRows = getDimensionality(); int numCols = other.getDimensionality(); SparseMatrix result = new SparseMatrix(numRows, numCols, true); int idx = 0; for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); if ((idx < indices.length) && (indices[idx] == i)) { for (int j = 0; j < other.indices.length; ++j) { row.elements.put(other.indices[j], new MutableDouble(values[idx] * other.values[j])); } ++idx; } result.setRowInternal(i, row); } return result; }
/** * Creates the U, Sigma, and V matrices to their correct sizes, but * leaves them as zero matrices. * * @param A The matrix that will be decomposed and so it specifies the * sizes for U, Sigma, and V. */ private SVD( final DenseMatrix A) { U = new DenseMatrix(A.getNumRows(), A.getNumRows()); Sigma = new SparseMatrix(A.getNumRows(), A.getNumColumns()); V = new DenseMatrix(A.getNumColumns(), A.getNumColumns()); }
/** * Creates the U, Sigma, and V matrices to their correct sizes, but * leaves them as zero matrices. * * @param A The matrix that will be decomposed and so it specifies the * sizes for U, Sigma, and V. */ private SVD( final DenseMatrix A) { U = new DenseMatrix(A.getNumRows(), A.getNumRows()); Sigma = new SparseMatrix(A.getNumRows(), A.getNumColumns()); V = new DenseMatrix(A.getNumColumns(), A.getNumColumns()); }
/** * Creates the U, Sigma, and V matrices to their correct sizes, but * leaves them as zero matrices. * * @param A The matrix that will be decomposed and so it specifies the * sizes for U, Sigma, and V. */ private SVD( final DenseMatrix A) { U = new DenseMatrix(A.getNumRows(), A.getNumRows()); Sigma = new SparseMatrix(A.getNumRows(), A.getNumColumns()); V = new DenseMatrix(A.getNumColumns(), A.getNumColumns()); }
@Override public final Matrix outerProduct( final SparseVector other) { int numRows = getDimensionality(); int numCols = other.getDimensionality(); SparseMatrix result = new SparseMatrix(numRows, numCols, true); other.compress(); int[] locs = other.getIndices(); double[] vals = other.getValues(); for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); for (int j = 0; j < locs.length; ++j) { row.setElement(locs[j], values[i] * vals[j]); } result.setRowInternal(i, row); } return result; }
@Override public final Matrix outerProduct( final SparseVector other) { int numRows = getDimensionality(); int numCols = other.getDimensionality(); SparseMatrix result = new SparseMatrix(numRows, numCols, true); other.compress(); int[] locs = other.getIndices(); double[] vals = other.getValues(); for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); for (int j = 0; j < locs.length; ++j) { row.setElement(locs[j], values[i] * vals[j]); } result.setRowInternal(i, row); } return result; }
@Override public final Matrix outerProduct( final SparseVector other) { int numRows = getDimensionality(); int numCols = other.getDimensionality(); SparseMatrix result = new SparseMatrix(numRows, numCols, true); other.compress(); int[] locs = other.getIndices(); double[] vals = other.getValues(); for (int i = 0; i < numRows; ++i) { SparseVector row = new SparseVector(numCols); for (int j = 0; j < locs.length; ++j) { row.setElement(locs[j], values[i] * vals[j]); } result.setRowInternal(i, row); } return result; }