Class BandMatrix

java.lang.Object
smile.tensor.BandMatrix
All Implemented Interfaces:
Serializable, Matrix, Tensor

public abstract class BandMatrix extends Object implements Matrix, Serializable
A band matrix is a sparse matrix, whose non-zero entries are confined to a diagonal band, comprising the main diagonal and zero or more diagonals on either side.

In numerical analysis, matrices from finite element or finite difference problems are often banded. Such matrices can be viewed as descriptions of the coupling between the problem variables; the bandedness corresponds to the fact that variables are not coupled over arbitrarily large distances. Such matrices can be further divided - for instance, banded matrices exist where every element in the band is nonzero. These often arise when discretizing one-dimensional problems. Problems in higher dimensions also lead to banded matrices, in which case the band itself also tends to be sparse. For instance, a partial differential equation on a square domain (using central differences) will yield a matrix with a half-bandwidth equal to the square root of the matrix dimension, but inside the band only 5 diagonals are nonzero. Unfortunately, applying Gaussian elimination (or equivalently an LU decomposition) to such a matrix results in the band being filled in by many non-zero elements. As sparse matrices lend themselves to more efficient computation than dense matrices, there has been much research focused on finding ways to minimize the bandwidth (or directly minimize the fill in) by applying permutations to the matrix, or other such equivalence or similarity transformations.

From a computational point of view, working with band matrices is always preferential to working with similarly dimensioned dense square matrices. A band matrix can be likened in complexity to a rectangular matrix whose row dimension is equal to the bandwidth of the band matrix. Thus, the work involved in performing operations such as multiplication falls significantly, often leading to huge savings in terms of calculation time and complexity.

Given an n-by-n band matrix with m1 rows below the diagonal and m2 rows above. The matrix is compactly stored in an array A[0,n-1][0,m1+m2]. The diagonal elements are in A[0,n-1][m1]. The subdiagonal elements are in A[j,n-1][0,m1-1] with j > 0 appropriate to the number of elements on each subdiagonal. The superdiagonal elements are in A[0,j][m1+1,m2+m2] with j < n-1 appropriate to the number of elements on each superdiagonal.

See Also:
  • Method Details

    • zeros

      public static BandMatrix zeros(ScalarType scalarType, int m, int n, int kl, int ku)
      Returns a zero matrix.
      Parameters:
      m - the number of rows.
      n - the number of columns.
      kl - the number of subdiagonals.
      ku - the number of superdiagonals.
    • of

      public static BandMatrix of(int m, int n, int kl, int ku, double[][] ab)
      Returns a symmetric matrix from a two-dimensional array.
      Parameters:
      m - the number of rows.
      n - the number of columns.
      kl - the number of subdiagonals.
      ku - the number of superdiagonals.
      ab - the band matrix. A[i,j] is stored in AB[ku+i-j, j] for max(0, j-ku) <= i <= min(m-1, j+kl).
    • of

      public static BandMatrix of(int m, int n, int kl, int ku, float[][] ab)
      Returns a symmetric matrix from a two-dimensional array.
      Parameters:
      m - the number of rows.
      n - the number of columns.
      kl - the number of subdiagonals.
      ku - the number of superdiagonals.
      ab - the band matrix. A[i,j] is stored in AB[ku+i-j, j] for max(0, j-ku) <= i <= min(m-1, j+kl).
    • nrow

      public int nrow()
      Description copied from interface: Matrix
      Returns the number of rows.
      Specified by:
      nrow in interface Matrix
      Returns:
      the number of rows.
    • ncol

      public int ncol()
      Description copied from interface: Matrix
      Returns the number of columns.
      Specified by:
      ncol in interface Matrix
      Returns:
      the number of columns.
    • kl

      public int kl()
      Returns the number of subdiagonals.
      Returns:
      the number of subdiagonals.
    • ku

      public int ku()
      Returns the number of superdiagonals.
      Returns:
      the number of superdiagonals.
    • layout

      public Order layout()
      Returns the matrix layout.
      Returns:
      the matrix layout.
    • ld

      public int ld()
      Returns the leading dimension.
      Returns:
      the leading dimension.
    • isSymmetric

      public boolean isSymmetric()
      Return true if the matrix is symmetric (uplo != null).
      Returns:
      true if the matrix is symmetric (uplo != null).
    • scale

      public BandMatrix scale(double alpha)
      Description copied from interface: Matrix
      A *= alpha
      Specified by:
      scale in interface Matrix
      Parameters:
      alpha - the scaling factor.
      Returns:
      this matrix.
    • copy

      public abstract BandMatrix copy()
      Description copied from interface: Matrix
      Returns a deep copy of matrix.
      Specified by:
      copy in interface Matrix
      Returns:
      a deep copy of matrix.
    • transpose

      public BandMatrix transpose()
      Description copied from interface: Matrix
      Returns the transpose of matrix. The transpose may share the storage with this matrix.
      Specified by:
      transpose in interface Matrix
      Returns:
      the transpose of matrix.
    • withUplo

      public BandMatrix withUplo(UPLO uplo)
      Sets the format of symmetric band matrix.
      Parameters:
      uplo - the format of symmetric band matrix.
      Returns:
      this matrix.
    • uplo

      public UPLO uplo()
      Gets the format of packed matrix.
      Returns:
      the format of packed matrix.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • mv

      public void mv(Transpose trans, double alpha, Vector x, double beta, Vector y)
      Description copied from interface: Matrix
      Matrix-vector multiplication.
          y = alpha * A * x + beta * y
      
      Specified by:
      mv in interface Matrix
      Parameters:
      trans - normal, transpose, or conjugate transpose operation on the matrix.
      alpha - the scalar alpha.
      x - the input vector.
      beta - the scalar beta. When beta is supplied as zero, y need not be set on input.
      y - the input and output vector.
    • solve

      public Vector solve(double[] b)
      Solve A * x = b.
      Parameters:
      b - the right hand side of linear systems.
      Returns:
      the solution vector.
      Throws:
      RuntimeException - when the matrix is singular.
    • solve

      public Vector solve(float[] b)
      Solve A * x = b.
      Parameters:
      b - the right hand side of linear systems.
      Returns:
      the solution vector.
      Throws:
      RuntimeException - when the matrix is singular.
    • solve

      public void solve(DenseMatrix B)
      Solves the linear system A * X = B.
      Parameters:
      B - the right hand side of linear systems. On output, B will be overwritten with the solution matrix.