SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal
Class BidiagonalMatrix

java.lang.Object
  extended by com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixMathImpl<T>
      extended by com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixStorageImpl<T>
          extended by com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.BidiagonalMatrix
All Implemented Interfaces:
DeepCopyable, AbelianGroup<Matrix>, Monoid<Matrix>, Ring<Matrix>, Matrix, MatrixAccessor, MatrixRing, Densifiable, MatrixDimension

public class BidiagonalMatrix
extends MatrixStorageImpl<T>

This class represents a matrix with non-zero entries only on the main, and either the super-diagonal or sub-diagonal.

See Also:
Wikipedia: Bidiagonal matrix

Nested Class Summary
static class BidiagonalMatrix.Type
          the types of bidiagonal matrices available
 
Constructor Summary
BidiagonalMatrix(BidiagonalMatrix that)
          Copy constructor.
BidiagonalMatrix(double[][] data)
          Construct a bidiagonal matrix from a 2D double[][] array.
BidiagonalMatrix(int dim, BidiagonalMatrix.Type type)
          Construct a bidiagonal matrix of dimension dim * dim.
 
Method Summary
 BidiagonalMatrix deepCopy()
          The implementation can return an instance created from this by the copy constructor of the class, or just this if the instance itself is immutable.
 DenseVector diagonal()
          Get a copy of the diagonal of the matrix.
 boolean equals(java.lang.Object obj)
          Check if two matrices (of different implementations) are equal.
 DenseVector getColumn(int col)
          Get a specified column as a vector.
 DenseVector getRow(int row)
          Get a specified row as a vector.
 int hashCode()
           
 boolean isUnreduced(double epsilon)
          A bidiagonal matrix is unreduced iff it has no 0 on both the super and main diagonals.
 Matrix multiply(Matrix that)
          this %*% that
 BidiagonalMatrix ONE()
          Get an identity matrix that has the same dimension as this matrix.
 BidiagonalMatrix scaled(double scalar)
          scalar * this
 DenseVector subDiagonal()
          Get a copy of the sub-diagonal of the matrix.
 DenseVector superDiagonal()
          Get a copy of the super-diagonal of the matrix.
 BidiagonalMatrix t()
          t(this) Compute the transpose of this matrix.
 DenseMatrix toDense()
          Densify a matrix, i.e., convert a matrix implementation to a standard dense matrix, DenseMatrix.
 java.lang.String toString()
           
 BidiagonalMatrix.Type type()
          Get the type of the bidiagonal matrix.
 BidiagonalMatrix ZERO()
          The additive element 0 in the group, such that for all elements a in the group, the equation 0 + a = a + 0 = a holds.
 
Methods inherited from class com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixStorageImpl
get, getMatrixData, set, setMatrixData
 
Methods inherited from class com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixMathImpl
add, call, getSample, minus, multiply, nCols, nRows, opposite, setColumn, setColumn, setRow, setRow
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BidiagonalMatrix

public BidiagonalMatrix(double[][] data)
Construct a bidiagonal matrix from a 2D double[][] array.

There are two rows. The longer row is the main diagonal and has one more element. If the first row is shorter, it is an upper bidiagonal matrix. If the second row is shorter, it is a lower bidiagonal matrix.

For example,

         new double[][]{
              {2, 5, 8, 11},
              {1, 4, 7, 10, 13}
          }
 
is
              | 1  2  0  0   0  |
              | 0  4  5  0   0  |
              | 0  0  7  8   0  |
              | 0  0  0  10  11 |
              | 0  0  0  0   13 |
 

We allow 'null' input when a diagonal is 0s, except for the main diagonal.

For example,

         new double[][]{
              {1, 4, 7, 10, 13},
              null
          }
 
is
              | 1  0  0  0   0  |
              | 0  4  0  0   0  |
              | 0  0  7  0   0  |
              | 0  0  0  10  0  |
              | 0  0  0  0   13 |
 

The following is not allowed because the dimension cannot be determined.

         new double[][]{
              null,
              null
          }
 

We will treat a diagonal matrix as an upper bidiagonal matrix in this class.

Parameters:
data - the 2D array input

BidiagonalMatrix

public BidiagonalMatrix(int dim,
                        BidiagonalMatrix.Type type)
Construct a bidiagonal matrix of dimension dim * dim.

Parameters:
dim - dimension of the matrix
type - the type of bidiagonal matrix to create

BidiagonalMatrix

public BidiagonalMatrix(BidiagonalMatrix that)
Copy constructor.

Parameters:
that - a BidiagonalMatrix
Method Detail

deepCopy

public BidiagonalMatrix deepCopy()
Description copied from interface: Matrix
The implementation can return an instance created from this by the copy constructor of the class, or just this if the instance itself is immutable.

Override the return type.

Returns:
an independent copy of Matrix instance

type

public BidiagonalMatrix.Type type()
Get the type of the bidiagonal matrix.

Returns:
the bidiagonal type of this matrix

t

public BidiagonalMatrix t()
Description copied from interface: MatrixRing
t(this)

Compute the transpose of this matrix. The original matrix does not change. The returned value is independent and can be modified anyhow.

This is the involution on the matrix ring.

Specified by:
t in interface MatrixRing
Overrides:
t in class MatrixMathImpl<BidiagonalMatrix>
Returns:
the transpose of this matrix, of the same type

multiply

public Matrix multiply(Matrix that)
Description copied from interface: MatrixRing
this %*% that

Specified by:
multiply in interface Monoid<Matrix>
Specified by:
multiply in interface MatrixRing
Overrides:
multiply in class MatrixMathImpl<BidiagonalMatrix>
Parameters:
that - another matrix
Returns:
the product of this and that

scaled

public BidiagonalMatrix scaled(double scalar)
Description copied from interface: Matrix
scalar * this

Specified by:
scaled in interface Matrix
Overrides:
scaled in class MatrixMathImpl<BidiagonalMatrix>
Parameters:
scalar - a double
Returns:
scalar * this

ZERO

public BidiagonalMatrix ZERO()
Description copied from interface: AbelianGroup
The additive element 0 in the group, such that for all elements a in the group, the equation
0 + a = a + 0 = a
holds.

Returns:
0

ONE

public BidiagonalMatrix ONE()
Description copied from interface: MatrixRing
Get an identity matrix that has the same dimension as this matrix.

For a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).

Returns:
an identity matrix

isUnreduced

public boolean isUnreduced(double epsilon)
A bidiagonal matrix is unreduced iff it has no 0 on both the super and main diagonals.

Parameters:
epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
Returns:
true iff this is unreduced

toDense

public DenseMatrix toDense()
Description copied from interface: Densifiable
Densify a matrix, i.e., convert a matrix implementation to a standard dense matrix, DenseMatrix.

This is equivalent to

new DenseMatrix(Matrix A)

Individual matrix implementation may optimize the conversion by taking advantage of having access to the class' private members. In other words, toDense() is in general more efficient than explicit copy construction.

As an example, for some long matrix computations, we may not be sure about the return type. We can always cast it to the standard matrix. That is,

DenseMatrix A = B.multiply(C).add(D).minus(E).toDense();

This statement always works regardless of the types of B, C, D, and E.

Specified by:
toDense in interface Densifiable
Returns:
a matrix representation in DenseMatrix

diagonal

public DenseVector diagonal()
Get a copy of the diagonal of the matrix.

Returns:
a copy of the diagonal

superDiagonal

public DenseVector superDiagonal()
Get a copy of the super-diagonal of the matrix.

Returns:
a copy of the super-diagonal

subDiagonal

public DenseVector subDiagonal()
Get a copy of the sub-diagonal of the matrix.

Returns:
a copy of the sub-diagonal

getRow

public DenseVector getRow(int row)
Description copied from interface: MatrixAccessor
Get a specified row as a vector.

Specified by:
getRow in interface MatrixAccessor
Overrides:
getRow in class MatrixMathImpl<T extends com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalDataMatrix>
Parameters:
row - the row index
Returns:
a vector A[row, ]

getColumn

public DenseVector getColumn(int col)
Description copied from interface: MatrixAccessor
Get a specified column as a vector.

Specified by:
getColumn in interface MatrixAccessor
Overrides:
getColumn in class MatrixMathImpl<T extends com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalDataMatrix>
Parameters:
col - the column index
Returns:
a vector A[, col]

toString

public java.lang.String toString()
Overrides:
toString in class MatrixMathImpl<T extends com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalDataMatrix>

equals

public boolean equals(java.lang.Object obj)
Description copied from class: MatrixStorageImpl
Check if two matrices (of different implementations) are equal. They are equal iff two matrices have the same values, entry-by-entry.

Overrides:
equals in class MatrixStorageImpl<T extends com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalDataMatrix>
Returns:
true iff two matrices have the same values, entry-by-entry

hashCode

public int hashCode()
Overrides:
hashCode in class MatrixStorageImpl<T extends com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.diagonal.DiagonalDataMatrix>

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.