Package smile.math.matrix
Interface DenseMatrix
-
- All Superinterfaces:
Matrix
,MatrixMultiplication<DenseMatrix,DenseMatrix>
,java.io.Serializable
- All Known Implementing Classes:
JMatrix
public interface DenseMatrix extends Matrix, MatrixMultiplication<DenseMatrix,DenseMatrix>
An abstract interface of dense matrix.- Author:
- Haifeng Li
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description DenseMatrix
aat()
Returns A * A'default DenseMatrix
add(double x)
In place element-wise addition A = A + xdefault DenseMatrix
add(double x, DenseMatrix c)
Element-wise addition C = A + xdouble
add(int i, int j, double x)
A[i][j] += xdefault DenseMatrix
add(DenseMatrix b)
In place addition A = A + Bdefault DenseMatrix
add(DenseMatrix b, DenseMatrix c)
C = A + Bdefault double[][]
array()
Return the two-dimensional array of matrix.DenseMatrix
ata()
Returns A' * ACholesky
cholesky()
Returns the Cholesky decomposition.default Cholesky
cholesky(boolean inPlace)
Returns the Cholesky decomposition.default double[]
colMeans()
Returns the mean of each column for a matrix.default double[]
colSums()
Returns the sum of each column for a matrix.DenseMatrix
copy()
Returns a copy of this matrix.double[]
data()
Returns the array of storing the matrix.default DenseMatrix
div(double x)
In place element-wise division A = A / xdefault DenseMatrix
div(double x, DenseMatrix c)
Element-wise addition C = A / xdouble
div(int i, int j, double x)
A[i][j] /= xdefault DenseMatrix
div(DenseMatrix b)
In place element-wise division A = A / B A = A - Bdefault DenseMatrix
div(DenseMatrix b, DenseMatrix c)
C = A / Bdouble[]
eig()
Returns the eigen values in an array of size 2N.default double[]
eig(boolean inPlace)
Returns the eigen values in an array of size 2N.EVD
eigen()
Returns the eigen value decomposition.default EVD
eigen(boolean inPlace)
Returns the eigen value decomposition.default DenseMatrix
inverse()
Returns the inverse matrix.default DenseMatrix
inverse(boolean inPlace)
Returns the inverse matrix.int
ld()
The LDA (and LDB, LDC, etc.) parameter in BLAS is effectively the stride of the matrix as it is laid out in linear memory.LU
lu()
Returns the LU decomposition.default LU
lu(boolean inPlace)
Returns the LU decomposition.default DenseMatrix
mul(double x)
In place element-wise multiplication A = A * xdefault DenseMatrix
mul(double x, DenseMatrix c)
Element-wise addition C = A * xdouble
mul(int i, int j, double x)
A[i][j] *= xdefault DenseMatrix
mul(DenseMatrix b)
In place element-wise multiplication A = A * Bdefault DenseMatrix
mul(DenseMatrix b, DenseMatrix c)
C = A * Bdefault double
norm()
L2 matrix norm.default double
norm1()
L1 matrix norm.default double
norm2()
L2 matrix norm.default double
normFro()
Frobenius matrix norm.default double
normInf()
Infinity matrix norm.QR
qr()
Returns the QR decomposition.default QR
qr(boolean inPlace)
Returns the QR decomposition.default DenseMatrix
replaceNaN(double x)
Replaces NaN's with given value.default double[]
rowMeans()
Returns the mean of each row for a matrix.default double[]
rowSums()
Returns the sum of each row for a matrix.double
set(int i, int j, double x)
Set the entry value at row i and column j.default DenseMatrix
sub(double x)
In place element-wise subtraction A = A - xdefault DenseMatrix
sub(double x, DenseMatrix c)
Element-wise addition C = A - xdouble
sub(int i, int j, double x)
A[i][j] -= xdefault DenseMatrix
sub(DenseMatrix b)
In place subtraction A = A - Bdefault DenseMatrix
sub(DenseMatrix b, DenseMatrix c)
C = A - Bdefault double
sum()
Returns the sum of all elements in the matrix.SVD
svd()
Returns the singular value decomposition.default SVD
svd(boolean inPlace)
Returns the singular value decomposition.DenseMatrix
transpose()
Returns the matrix transpose.default double
update(int i, int j, double x)
Set the entry value at row i and column j.default double
xax(double[] x)
Returns x' * A * x.-
Methods inherited from interface smile.math.matrix.Matrix
apply, atx, atxpy, atxpy, ax, axpy, axpy, diag, eigen, eigen, get, isSymmetric, ncols, nrows, setSymmetric, svd, svd, toString, trace
-
Methods inherited from interface smile.math.matrix.MatrixMultiplication
abmm, abtmm, atbmm
-
-
-
-
Method Detail
-
data
double[] data()
Returns the array of storing the matrix.
-
ld
int ld()
The LDA (and LDB, LDC, etc.) parameter in BLAS is effectively the stride of the matrix as it is laid out in linear memory. It is perfectly valid to have an LDA value which is larger than the leading dimension of the matrix which is being operated on. Typical cases where it is either useful or necessary to use a larger LDA value are when you are operating on a sub matrix from a larger dense matrix, and when hardware or algorithms offer performance advantages when storage is padded to round multiples of some optimal size (cache lines or GPU memory transaction size, or load balance in multiprocessor implementations, for example).- Returns:
- the leading dimension
-
set
double set(int i, int j, double x)
Set the entry value at row i and column j.
-
update
default double update(int i, int j, double x)
Set the entry value at row i and column j. For Scala users.
-
lu
LU lu()
Returns the LU decomposition. This input matrix will be overwritten with the decomposition.
-
lu
default LU lu(boolean inPlace)
Returns the LU decomposition.- Parameters:
inPlace
- if true, this matrix will be used for matrix decomposition.
-
cholesky
Cholesky cholesky()
Returns the Cholesky decomposition. This input matrix will be overwritten with the decomposition.- Throws:
java.lang.IllegalArgumentException
- if the matrix is not positive definite.
-
cholesky
default Cholesky cholesky(boolean inPlace)
Returns the Cholesky decomposition.- Parameters:
inPlace
- if true, this matrix will be used for matrix decomposition.- Throws:
java.lang.IllegalArgumentException
- if the matrix is not positive definite.
-
qr
QR qr()
Returns the QR decomposition. This input matrix will be overwritten with the decomposition.
-
qr
default QR qr(boolean inPlace)
Returns the QR decomposition.- Parameters:
inPlace
- if true, this matrix will be used for matrix decomposition.
-
svd
SVD svd()
Returns the singular value decomposition. Note that the input matrix will hold U on output.
-
svd
default SVD svd(boolean inPlace)
Returns the singular value decomposition.- Parameters:
inPlace
- if true, this matrix will hold U on output.
-
eigen
EVD eigen()
Returns the eigen value decomposition. Note that the input matrix will be overwritten on output.
-
eigen
default EVD eigen(boolean inPlace)
Returns the eigen value decomposition.- Parameters:
inPlace
- if true, this matrix will be overwritten U on output.
-
eig
double[] eig()
Returns the eigen values in an array of size 2N. The first half and second half of returned array contain the real and imaginary parts, respectively, of the computed eigenvalues.
-
eig
default double[] eig(boolean inPlace)
Returns the eigen values in an array of size 2N. The first half and second half of returned array contain the real and imaginary parts, respectively, of the computed eigenvalues.- Parameters:
inPlace
- if true, this matrix will be overwritten U on output.
-
transpose
DenseMatrix transpose()
Returns the matrix transpose.
-
inverse
default DenseMatrix inverse()
Returns the inverse matrix.
-
inverse
default DenseMatrix inverse(boolean inPlace)
Returns the inverse matrix.- Parameters:
inPlace
- if true, this matrix will be used for matrix decomposition.
-
norm1
default double norm1()
L1 matrix norm. Maximum column sum.
-
norm2
default double norm2()
L2 matrix norm. Maximum singular value.
-
norm
default double norm()
L2 matrix norm. Maximum singular value.
-
normInf
default double normInf()
Infinity matrix norm. Maximum row sum.
-
normFro
default double normFro()
Frobenius matrix norm. Sqrt of sum of squares of all elements.
-
xax
default double xax(double[] x)
Returns x' * A * x. The left upper submatrix of A is used in the computation based on the size of x.
-
rowSums
default double[] rowSums()
Returns the sum of each row for a matrix.
-
rowMeans
default double[] rowMeans()
Returns the mean of each row for a matrix.
-
colSums
default double[] colSums()
Returns the sum of each column for a matrix.
-
colMeans
default double[] colMeans()
Returns the mean of each column for a matrix.
-
copy
DenseMatrix copy()
Returns a copy of this matrix.
-
ata
DenseMatrix ata()
Description copied from interface:Matrix
Returns A' * A
-
aat
DenseMatrix aat()
Description copied from interface:Matrix
Returns A * A'
-
add
double add(int i, int j, double x)
A[i][j] += x
-
sub
double sub(int i, int j, double x)
A[i][j] -= x
-
mul
double mul(int i, int j, double x)
A[i][j] *= x
-
div
double div(int i, int j, double x)
A[i][j] /= x
-
add
default DenseMatrix add(DenseMatrix b, DenseMatrix c)
C = A + B- Returns:
- the result matrix
-
add
default DenseMatrix add(DenseMatrix b)
In place addition A = A + B- Returns:
- this matrix
-
sub
default DenseMatrix sub(DenseMatrix b, DenseMatrix c)
C = A - B- Returns:
- the result matrix
-
sub
default DenseMatrix sub(DenseMatrix b)
In place subtraction A = A - B- Returns:
- this matrix
-
mul
default DenseMatrix mul(DenseMatrix b, DenseMatrix c)
C = A * B- Returns:
- the result matrix
-
mul
default DenseMatrix mul(DenseMatrix b)
In place element-wise multiplication A = A * B- Returns:
- this matrix
-
div
default DenseMatrix div(DenseMatrix b, DenseMatrix c)
C = A / B- Returns:
- the result matrix
-
div
default DenseMatrix div(DenseMatrix b)
In place element-wise division A = A / B A = A - B- Returns:
- this matrix
-
add
default DenseMatrix add(double x, DenseMatrix c)
Element-wise addition C = A + x
-
add
default DenseMatrix add(double x)
In place element-wise addition A = A + x
-
sub
default DenseMatrix sub(double x, DenseMatrix c)
Element-wise addition C = A - x
-
sub
default DenseMatrix sub(double x)
In place element-wise subtraction A = A - x
-
mul
default DenseMatrix mul(double x, DenseMatrix c)
Element-wise addition C = A * x
-
mul
default DenseMatrix mul(double x)
In place element-wise multiplication A = A * x
-
div
default DenseMatrix div(double x, DenseMatrix c)
Element-wise addition C = A / x
-
div
default DenseMatrix div(double x)
In place element-wise division A = A / x
-
replaceNaN
default DenseMatrix replaceNaN(double x)
Replaces NaN's with given value.
-
sum
default double sum()
Returns the sum of all elements in the matrix.- Returns:
- the sum of all elements.
-
array
default double[][] array()
Return the two-dimensional array of matrix.- Returns:
- the two-dimensional array of matrix.
-
-