Special cases
Banded
An important special type of sparse matrices is a band matrix, defined as follows. The lower bandwidth of a matrix is the smallest number such that the entry vanishes whenever . Similarly, the upper bandwidth is the smallest number such that whenever . For example, aDiagonal
A very efficient structure for an extreme case of band matrices, the ''Symmetric
A symmetric sparse matrix arises as theBlock diagonal
A block-diagonal matrix consists of sub-matrices along its diagonal blocks. A block-diagonal matrix has the form where is a square matrix for all .Use
Reducing fill-in
The ''fill-in'' of a matrix are those entries that change from an initial zero to a non-zero value during the execution of an algorithm. To reduce the memory requirements and the number of arithmetic operations used during an algorithm, it is useful to minimize the fill-in by switching rows and columns in the matrix. The symbolic Cholesky decomposition can be used to calculate the worst possible fill-in before doing the actual Cholesky decomposition. There are other methods than the Cholesky decomposition in use. Orthogonalization methods (such as QR factorization) are common, for example, when solving problems by least squares methods. While the theoretical fill-in is still the same, in practical terms the "false non-zeros" can be different for different methods. And symbolic versions of those algorithms can be used in the same manner as the symbolic Cholesky to compute worst case fill-in.Solving sparse matrix equations
Both iterative and direct methods exist for sparse matrix solving. Iterative methods, such as conjugate gradient method and GMRES utilize fast computations of matrix-vector products , where matrix is sparse. The use of preconditioners can significantly accelerate convergence of such iterative methods.Storage
A matrix is typically stored as a two-dimensional array. Each entry in the array represents an element of the matrix and is accessed by the two indices and . Conventionally, is the row index, numbered from top to bottom, and is the column index, numbered from left to right. For an matrix, the amount of memory required to store the matrix in this format is proportional to (disregarding the fact that the dimensions of the matrix also need to be stored). In the case of a sparse matrix, substantial memory requirement reductions can be realized by storing only the non-zero entries. Depending on the number and distribution of the non-zero entries, different data structures can be used and yield huge savings in memory when compared to the basic approach. The trade-off is that accessing the individual elements becomes more complex and additional structures are needed to be able to recover the original matrix unambiguously. Formats can be divided into two groups: * Those that support efficient modification, such as DOK (Dictionary of keys), LIL (List of lists), or COO (Coordinate list). These are typically used to construct the matrices. * Those that support efficient access and matrix operations, such as CSR (Compressed Sparse Row) or CSC (Compressed Sparse Column).Dictionary of keys (DOK)
DOK consists of aList of lists (LIL)
LIL stores one list per row, with each entry containing the column index and the value. Typically, these entries are kept sorted by column index for faster lookup. This is another format good for incremental matrix construction.Coordinate list (COO)
COO stores a list of tuples. Ideally, the entries are sorted first by row index and then by column index, to improve random access times. This is another format that is good for incremental matrix construction.Compressed sparse row (CSR, CRS or Yale format)
The ''compressed sparse row'' (CSR) or ''compressed row storage'' (CRS) or Yale format represents a matrix by three (one-dimensional) arrays, that respectively contain nonzero values, the extents of rows, and column indices. It is similar to COO, but compresses the row indices, hence the name. This format allows fast row access and matrix-vector multiplications (). The CSR format has been in use since at least the mid-1960s, with the first complete description appearing in 1967. The CSR format stores a sparse matrix in row form using three (one-dimensional) arrays . Let denote the number of nonzero entries in . (Note that zero-based indices shall be used here.) * The arrays and are of length , and contain the non-zero values and the column indices of those values respectively * contains the column in which the corresponding entry is located. * The array is of length and encodes the index in and where the given row starts. This is equivalent to encoding the total number of nonzeros above row . The last element is , i.e., the fictitious index in immediately after the last valid index . For example, the matrix is a matrix with 4 nonzero elements, hence V = 5 8 3 6 COL_INDEX = 0 1 2 1 ROW_INDEX = 0 1 2 3 4 assuming a zero-indexed language. To extract a row, we first define: row_start = ROW_INDEX ow row_end = ROW_INDEX ow + 1 Then we take slices from V and COL_INDEX starting at row_start and ending at row_end. To extract the row 1 (the second row) of this matrix we setrow_start=1
and row_end=2
. Then we make the slices V :2= /code> and COL_INDEX :2= /code>. We now know that in row 1 we have one element at column 1 with value 8.
In this case the CSR representation contains 13 entries, compared to 16 in the original matrix. The CSR format saves on memory only when .
Another example, the matrix
is a matrix (24 entries) with 8 nonzero elements, so
V = 10 20 30 40 50 60 70 80 COL_INDEX = 0 1 1 3 2 3 4 5
ROW_INDEX = 0 2 4 7 8
The whole is stored as 21 entries: 8 in , 8 in , and 5 in .
* splits the array into rows: (10, 20) (30, 40) (50, 60, 70) (80)
, indicating the index of (and ) where each row starts and ends;
* aligns values in columns: (10, 20, ...) (0, 30, 0, 40, ...)(0, 0, 50, 60, 70, 0) (0, 0, 0, 0, 0, 80)
.
Note that in this format, the first value of is always zero and the last is always , so they are in some sense redundant (although in programming languages where the array length needs to be explicitly stored, would not be redundant). Nonetheless, this does avoid the need to handle an exceptional case when computing the length of each row, as it guarantees the formula works for any row . Moreover, the memory cost of this redundant storage is likely insignificant for a sufficiently large matrix.
The (old and new) Yale sparse matrix formats are instances of the CSR scheme. The old Yale format works exactly as described above, with three arrays; the new format combines and into a single array and handles the diagonal of the matrix separately.
For logical adjacency matrices, the data array can be omitted, as the existence of an entry in the row array is sufficient to model a binary adjacency relation.
It is likely known as the Yale format because it was proposed in the 1977 Yale Sparse Matrix Package report from Department of Computer Science at Yale University.
Compressed sparse column (CSC or CCS)
CSC is similar to CSR except that values are read first by column, a row index is stored for each value, and column pointers are stored. For example, CSC is , where is an array of the (top-to-bottom, then left-to-right) non-zero values of the matrix; is the row indices corresponding to the values; and, is the list of indexes where each column starts. The name is based on the fact that column index information is compressed relative to the COO format. One typically uses another format (LIL, DOK, COO) for construction. This format is efficient for arithmetic operations, column slicing, and matrix-vector products. This is the traditional format for specifying a sparse matrix in MATLAB (via the sparse
function).
Software
Many software libraries support sparse matrices, and provide solvers for sparse matrix equations. The following are open-source:
* PETSc, a large C library, containing many different matrix solvers for a variety of matrix storage formats.
* Trilinos, a large C++ library, with sub-libraries dedicated to the storage of dense and sparse matrices and solution of corresponding linear systems.
* Eigen3 is a C++ library that contains several sparse matrix solvers. However, none of them are parallelized.
* MUMPS
MUMPS ("Massachusetts General Hospital Utility Multi-Programming System"), or M, is an imperative, high-level programming language with an integrated transaction processing key–value database. It was originally developed at Massachusetts Gen ...
(MUltifrontal Massively Parallel sparse direct Solver), written in Fortran90, is a frontal solver.
* deal.II, a finite element library that also has a sub-library for sparse linear systems and their solution.
* DUNE
A dune is a landform composed of wind- or water-driven sand. It typically takes the form of a mound, ridge, or hill. An area with dunes is called a dune system or a dune complex. A large dune complex is called a dune field, while broad, flat ...
, another finite element library that also has a sub-library for sparse linear systems and their solution.
* Armadillo
Armadillos () are New World placental mammals in the order (biology), order Cingulata. They form part of the superorder Xenarthra, along with the anteaters and sloths. 21 extant species of armadillo have been described, some of which are dis ...
provides a user-friendly C++ wrapper for BLAS and LAPACK.
* SciPy provides support for several sparse matrix formats, linear algebra, and solvers.
* ALGLIB is a C++ and C# library with sparse linear algebra support
* ARPACK Fortran 77 library for sparse matrix diagonalization and manipulation, using the Arnoldi algorithm
* SLEPc Library for solution of large scale linear systems and sparse matrices
* scikit-learn
scikit-learn (formerly scikits.learn and also known as sklearn) is a free and open-source machine learning library for the Python programming language.
It features various classification, regression and clustering algorithms including support ...
, a Python library for machine learning
Machine learning (ML) is a field of study in artificial intelligence concerned with the development and study of Computational statistics, statistical algorithms that can learn from data and generalise to unseen data, and thus perform Task ( ...
, provides support for sparse matrices and solvers
SparseArrays
is a Julia standard library.
* PSBLAS, software toolkit to solve sparse linear systems supporting multiple formats also on GPU.
History
The term ''sparse matrix'' was possibly coined by Harry Markowitz who initiated some pioneering work but then left the field.Oral history interview with Harry M. Markowitz
pp. 9, 10.
See also
Notes
References
*
*
* (This book, by a professor at the State University of New York at Stony Book, was the first book exclusively dedicated to Sparse Matrices. Graduate courses using this as a textbook were offered at that University in the early 1980s).
*
*
* Also NOAA Technical Memorandum NOS NGS-4, National Geodetic Survey, Rockville, MD. Referencing .
* (Open Access)
Further reading
*
*
at the Texas A&M University.
SuiteSparse Matrix Collection
SMALL project
A EU-funded project on sparse models, algorithms and dictionary learning for large-scale data.
*
*
*
{{Numerical linear algebra
Arrays