Sparse Matrix
Also Sparse Matrices
A sparse matrix is a matrix with mostly zero entries, stored as the list of its non-zero entries as (value, row index, column index) triples instead of all m × n entries.
Know these firstVector Space Model
Typical case: a term-document matrix in the Vector Space Model, where is large but each document contains only a small fraction of the vocabulary, so storing all entries is infeasible.
Properties#
- Space: for non-zero entries, instead of for the dense matrix.
- Storage orders:
- row-major: sorted by row index first; the entries of one row are consecutive.
- column-major: sorted by column index first; the entries of one column are consecutive.
- PyTorch:
torch.sparse_coo_tensor(indices, values)builds a sparse matrix from a index tensor (rows, columns) and the values; “coo” stands for “coordinates”. Internally the non-zero values are always stored in row-major order. A sparse tensor can be multiplied with a dense tensor, so works directly on the sparse .
Example#
Sources#
- Slides 11, p. 14 (triples), Slides 11, p. 15 (row-/column-major, inverted index), Slides 11, p. 16 (PyTorch)
- DBIS_VL11 > Sparse matrices, DBIS_VL11 > Sparse matrices in PyTorch