Class BandMatrix

java.lang.Object
smile.math.matrix.fp32.IMatrix
smile.math.matrix.fp32.BandMatrix
All Implemented Interfaces:
Serializable, Cloneable

public class BandMatrix extends IMatrix
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:
  • Constructor Details

    • BandMatrix

      public BandMatrix(int m, int n, int kl, int ku)
      Constructor.
      Parameters:
      m - the number of rows.
      n - the number of columns.
      kl - the number of subdiagonals.
      ku - the number of superdiagonals.
    • BandMatrix

      public BandMatrix(int m, int n, int kl, int ku, float[][] AB)
      Constructor.
      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).
  • Method Details

    • clone

      public BandMatrix clone()
      Overrides:
      clone in class Object
    • nrow

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

      public int ncol()
      Description copied from class: IMatrix
      Returns the number of columns.
      Specified by:
      ncol in class IMatrix
      Returns:
      the number of columns.
    • size

      public long size()
      Description copied from class: IMatrix
      Returns the number of stored matrix elements. For conventional matrix, it is simply nrow * ncol. But it is usually much less for band, packed or sparse matrix.
      Specified by:
      size in class IMatrix
      Returns:
      the number of stored matrix elements.
    • 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 Layout 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).
    • uplo

      public BandMatrix uplo(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
    • equals

      public boolean equals(BandMatrix o, float epsilon)
      Returns true if two matrices equal in given precision.
      Parameters:
      o - the other matrix.
      epsilon - a number close to zero.
      Returns:
      true if two matrices equal in given precision.
    • get

      public float get(int i, int j)
      Description copied from class: IMatrix
      Returns A[i,j].
      Overrides:
      get in class IMatrix
      Parameters:
      i - the row index.
      j - the column index.
      Returns:
      the matrix cell value.
    • set

      public void set(int i, int j, float x)
      Description copied from class: IMatrix
      Sets A[i,j] = x.
      Overrides:
      set in class IMatrix
      Parameters:
      i - the row index.
      j - the column index.
      x - the matrix cell value.
    • mv

      public void mv(Transpose trans, float alpha, float[] x, float beta, float[] y)
      Description copied from class: IMatrix
      Matrix-vector multiplication.
      
           y = alpha * op(A) * x + beta * y
       
      where op is the transpose operation.
      Specified by:
      mv in class IMatrix
      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.
    • mv

      public void mv(float[] work, int inputOffset, int outputOffset)
      Description copied from class: IMatrix
      Matrix-vector multiplication A * x.
      Specified by:
      mv in class IMatrix
      Parameters:
      work - the workspace for both input and output vector.
      inputOffset - the offset of input vector in workspace.
      outputOffset - the offset of output vector in workspace.
    • tv

      public void tv(float[] work, int inputOffset, int outputOffset)
      Description copied from class: IMatrix
      Matrix-vector multiplication A' * x.
      Specified by:
      tv in class IMatrix
      Parameters:
      work - the workspace for both input and output vector.
      inputOffset - the offset of input vector in workspace.
      outputOffset - the offset of output vector in workspace.
    • lu

      public BandMatrix.LU lu()
      LU decomposition.
      Returns:
      LU decomposition.
    • cholesky

      public BandMatrix.Cholesky cholesky()
      Cholesky decomposition for symmetric and positive definite matrix.
      Returns:
      Cholesky decomposition.
      Throws:
      ArithmeticException - if the matrix is not positive definite.