SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.triangle
Class LowerTriangularMatrix

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.triangle.TriangularMatrix<LowerTriangularMatrix>
              extended by com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.triangle.LowerTriangularMatrix
All Implemented Interfaces:
DeepCopyable, AbelianGroup<Matrix>, Monoid<Matrix>, Ring<Matrix>, Matrix, MatrixAccessor, MatrixRing, Densifiable, MatrixDimension

public class LowerTriangularMatrix
extends TriangularMatrix<LowerTriangularMatrix>
implements Densifiable

This class implements the lower triangular matrix, which has 0 entries whenever column index > row index.

This implementation saves about half of the data cost (except for the diagonal) when compared to the DenseMatrix implementation. Users may use this class instead of DenseMatrix when they know that the matrix is lower triangular.

Lower triangular matrices are always square.


Constructor Summary
LowerTriangularMatrix(double[][] data)
          Construct a lower triangular matrix from a 2D double[][] array.
LowerTriangularMatrix(int dim)
          Construct a lower triangular matrix of dimension dim * dim.
LowerTriangularMatrix(LowerTriangularMatrix L)
          Copy constructor performing a deep copy.
LowerTriangularMatrix(Matrix A)
          Construct a lower triangular matrix from a matrix.
 
Method Summary
 LowerTriangularMatrix add(LowerTriangularMatrix that)
          this + that Add with a LowerTriangularMatrix.
 LowerTriangularMatrix 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 getColumn(int col)
          Get a specified column as a vector.
 DenseVector getRow(int row)
          Get a specified row as a vector.
 LowerTriangularMatrix minus(LowerTriangularMatrix that)
          this - that Subtract a LowerTriangularMatrix.
 LowerTriangularMatrix multiply(LowerTriangularMatrix that)
          this %*% that Multiply by a LowerTriangularMatrix.
 LowerTriangularMatrix ONE()
          Get an identity matrix that has the same dimension as this matrix.
 LowerTriangularMatrix scaled(double scalar)
          scalar * this
 UpperTriangularMatrix t()
          t(A)
 DenseMatrix toDense()
          Densify a matrix, i.e., convert a matrix implementation to a standard dense matrix, DenseMatrix.
 LowerTriangularMatrix 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.dense.triangle.TriangularMatrix
dim, getMatrixData
 
Methods inherited from class com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixStorageImpl
equals, get, hashCode, set, setMatrixData
 
Methods inherited from class com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixMathImpl
add, call, getSample, minus, multiply, multiply, nCols, nRows, opposite, setColumn, setColumn, setRow, setRow, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LowerTriangularMatrix

public LowerTriangularMatrix(int dim)
Construct a lower triangular matrix of dimension dim * dim.

Parameters:
dim - dimension; for a square matrix, it is the number of rows or columns

LowerTriangularMatrix

public LowerTriangularMatrix(double[][] data)
Construct a lower triangular matrix from a 2D double[][] array.

Parameters:
data - the 2D array input
Throws:
java.lang.IllegalArgumentException - when the input data is not a lower triangular matrix

LowerTriangularMatrix

public LowerTriangularMatrix(Matrix A)
Construct a lower triangular matrix from a matrix.

Parameters:
A - a matrix
Throws:
java.lang.IllegalArgumentException - when A is not square

LowerTriangularMatrix

public LowerTriangularMatrix(LowerTriangularMatrix L)
Copy constructor performing a deep copy.

Parameters:
L - the LowerTriangularMatrix to be copied
Method Detail

deepCopy

public LowerTriangularMatrix 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.

Specified by:
deepCopy in interface DeepCopyable
Specified by:
deepCopy in interface Matrix
Returns:
an independent copy of Matrix instance

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

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<LowerTriangularMatrix>
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<LowerTriangularMatrix>
Parameters:
col - the column index
Returns:
a vector A[, col]

add

public LowerTriangularMatrix add(LowerTriangularMatrix that)
this + that

Add with a LowerTriangularMatrix.

Parameters:
that - another matrix
Returns:
the sum of this and that

minus

public LowerTriangularMatrix minus(LowerTriangularMatrix that)
this - that

Subtract a LowerTriangularMatrix.

Parameters:
that - another matrix
Returns:
the difference between this and that

multiply

public LowerTriangularMatrix multiply(LowerTriangularMatrix that)
this %*% that

Multiply by a LowerTriangularMatrix.

Parameters:
that - another matrix
Returns:
the product of this and that

ZERO

public LowerTriangularMatrix 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.

Specified by:
ZERO in interface AbelianGroup<Matrix>
Specified by:
ZERO in interface MatrixRing
Returns:
0

ONE

public LowerTriangularMatrix 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).

Specified by:
ONE in interface Monoid<Matrix>
Specified by:
ONE in interface MatrixRing
Returns:
an identity matrix

t

public UpperTriangularMatrix t()
t(A)

Specified by:
t in interface MatrixRing
Overrides:
t in class MatrixMathImpl<LowerTriangularMatrix>
Returns:
an upper triangular matrix which is the transpose of this

scaled

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

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

SuanShu, a Java numerical and statistical library

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