smile.math.matrix
Class DenseMatrix
- java.lang.Object
-
- smile.math.matrix.Matrix
-
- smile.math.matrix.DenseMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, MatrixMultiplication<DenseMatrix,DenseMatrix>
- Direct Known Subclasses:
- JMatrix
public abstract class DenseMatrix extends Matrix implements MatrixMultiplication<DenseMatrix,DenseMatrix>
An abstract interface of dense matrix.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DenseMatrix()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description abstract DenseMatrixaat()Returns A * A'DenseMatrixadd(DenseMatrix b)In place addition A = A + BDenseMatrixadd(DenseMatrix b, DenseMatrix c)C = A + BDenseMatrixadd(double x)In place element-wise addition A = A + xDenseMatrixadd(double x, DenseMatrix c)Element-wise addition C = A + xabstract doubleadd(int i, int j, double x)A[i][j] += xdouble[][]array()Return the two-dimensional array of matrix.abstract DenseMatrixata()Returns A' * Aabstract Choleskycholesky()Returns the Cholesky decomposition.Choleskycholesky(boolean inPlace)Returns the Cholesky decomposition.double[]colMeans()Returns the mean of each column for a matrix.double[]colSums()Returns the sum of each column for a matrix.abstract DenseMatrixcopy()Returns a copy of this matrix.abstract double[]data()Returns the array of storing the matrix.DenseMatrixdiv(DenseMatrix b)In place element-wise division A = A / B A = A - BDenseMatrixdiv(DenseMatrix b, DenseMatrix c)C = A / BDenseMatrixdiv(double x)In place element-wise division A = A / xDenseMatrixdiv(double x, DenseMatrix c)Element-wise addition C = A / xabstract doublediv(int i, int j, double x)A[i][j] /= xabstract double[]eig()Returns the eigen values in an array of size 2N.double[]eig(boolean inPlace)Returns the eigen values in an array of size 2N.abstract EVDeigen()Returns the eigen value decomposition.EVDeigen(boolean inPlace)Returns the eigen value decomposition.DenseMatrixinverse()Returns the inverse matrix.DenseMatrixinverse(boolean inPlace)Returns the inverse matrix.abstract intld()The LDA (and LDB, LDC, etc.) parameter in BLAS is effectively the stride of the matrix as it is laid out in linear memory.abstract LUlu()Returns the LU decomposition.LUlu(boolean inPlace)Returns the LU decomposition.DenseMatrixmul(DenseMatrix b)In place element-wise multiplication A = A * BDenseMatrixmul(DenseMatrix b, DenseMatrix c)C = A * BDenseMatrixmul(double x)In place element-wise multiplication A = A * xDenseMatrixmul(double x, DenseMatrix c)Element-wise addition C = A * xabstract doublemul(int i, int j, double x)A[i][j] *= xdoublenorm()L2 matrix norm.doublenorm1()L1 matrix norm.doublenorm2()L2 matrix norm.doublenormFro()Frobenius matrix norm.doublenormInf()Infinity matrix norm.abstract QRqr()Returns the QR decomposition.QRqr(boolean inPlace)Returns the QR decomposition.DenseMatrixreplaceNaN(double x)Replaces NaN's with given value.double[]rowMeans()Returns the mean of each row for a matrix.double[]rowSums()Returns the sum of each row for a matrix.abstract doubleset(int i, int j, double x)Set the entry value at row i and column j.DenseMatrixsub(DenseMatrix b)In place subtraction A = A - BDenseMatrixsub(DenseMatrix b, DenseMatrix c)C = A - BDenseMatrixsub(double x)In place element-wise subtraction A = A - xDenseMatrixsub(double x, DenseMatrix c)Element-wise addition C = A - xabstract doublesub(int i, int j, double x)A[i][j] -= xdoublesum()Returns the sum of all elements in the matrix.abstract SVDsvd()Returns the singular value decomposition.SVDsvd(boolean inPlace)Returns the singular value decomposition.abstract DenseMatrixtranspose()Returns the matrix transpose.doubleupdate(int i, int j, double x)Set the entry value at row i and column j.doublexax(double[] x)Returns x' * A * x.-
Methods inherited from class smile.math.matrix.Matrix
apply, atx, atxpy, atxpy, ax, axpy, axpy, diag, diag, eigen, eigen, eye, eye, get, isSymmetric, ncols, newInstance, newInstance, newInstance, nrows, ones, randn, randn, setSymmetric, svd, svd, toString, toString, trace, zeros
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface smile.math.matrix.MatrixMultiplication
abmm, abtmm, atbmm
-
-
-
-
Method Detail
-
data
public abstract double[] data()
Returns the array of storing the matrix.
-
ld
public abstract 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
public abstract double set(int i, int j, double x)Set the entry value at row i and column j.
-
update
public double update(int i, int j, double x)Set the entry value at row i and column j. For Scala users.
-
lu
public abstract LU lu()
Returns the LU decomposition. This input matrix will be overwritten with the decomposition.
-
lu
public LU lu(boolean inPlace)
Returns the LU decomposition.- Parameters:
inPlace- if true, this matrix will be used for matrix decomposition.
-
cholesky
public abstract 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
public 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
public abstract QR qr()
Returns the QR decomposition. This input matrix will be overwritten with the decomposition.
-
qr
public QR qr(boolean inPlace)
Returns the QR decomposition.- Parameters:
inPlace- if true, this matrix will be used for matrix decomposition.
-
svd
public abstract SVD svd()
Returns the singular value decomposition. Note that the input matrix will hold U on output.
-
svd
public SVD svd(boolean inPlace)
Returns the singular value decomposition.- Parameters:
inPlace- if true, this matrix will hold U on output.
-
eigen
public abstract EVD eigen()
Returns the eigen value decomposition. Note that the input matrix will be overwritten on output.
-
eigen
public EVD eigen(boolean inPlace)
Returns the eigen value decomposition.- Parameters:
inPlace- if true, this matrix will be overwritten U on output.
-
eig
public abstract 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
public 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
public abstract DenseMatrix transpose()
Returns the matrix transpose.
-
inverse
public DenseMatrix inverse()
Returns the inverse matrix.
-
inverse
public DenseMatrix inverse(boolean inPlace)
Returns the inverse matrix.- Parameters:
inPlace- if true, this matrix will be used for matrix decomposition.
-
norm1
public double norm1()
L1 matrix norm. Maximum column sum.
-
norm2
public double norm2()
L2 matrix norm. Maximum singular value.
-
norm
public double norm()
L2 matrix norm. Maximum singular value.
-
normInf
public double normInf()
Infinity matrix norm. Maximum row sum.
-
normFro
public double normFro()
Frobenius matrix norm. Sqrt of sum of squares of all elements.
-
xax
public 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
public double[] rowSums()
Returns the sum of each row for a matrix.
-
rowMeans
public double[] rowMeans()
Returns the mean of each row for a matrix.
-
colSums
public double[] colSums()
Returns the sum of each column for a matrix.
-
colMeans
public double[] colMeans()
Returns the mean of each column for a matrix.
-
copy
public abstract DenseMatrix copy()
Returns a copy of this matrix.
-
ata
public abstract DenseMatrix ata()
Description copied from class:MatrixReturns A' * A
-
aat
public abstract DenseMatrix aat()
Description copied from class:MatrixReturns A * A'
-
add
public abstract double add(int i, int j, double x)A[i][j] += x
-
sub
public abstract double sub(int i, int j, double x)A[i][j] -= x
-
mul
public abstract double mul(int i, int j, double x)A[i][j] *= x
-
div
public abstract double div(int i, int j, double x)A[i][j] /= x
-
add
public DenseMatrix add(DenseMatrix b, DenseMatrix c)
C = A + B- Returns:
- the result matrix
-
add
public DenseMatrix add(DenseMatrix b)
In place addition A = A + B- Returns:
- this matrix
-
sub
public DenseMatrix sub(DenseMatrix b, DenseMatrix c)
C = A - B- Returns:
- the result matrix
-
sub
public DenseMatrix sub(DenseMatrix b)
In place subtraction A = A - B- Returns:
- this matrix
-
mul
public DenseMatrix mul(DenseMatrix b, DenseMatrix c)
C = A * B- Returns:
- the result matrix
-
mul
public DenseMatrix mul(DenseMatrix b)
In place element-wise multiplication A = A * B- Returns:
- this matrix
-
div
public DenseMatrix div(DenseMatrix b, DenseMatrix c)
C = A / B- Returns:
- the result matrix
-
div
public DenseMatrix div(DenseMatrix b)
In place element-wise division A = A / B A = A - B- Returns:
- this matrix
-
add
public DenseMatrix add(double x, DenseMatrix c)
Element-wise addition C = A + x
-
add
public DenseMatrix add(double x)
In place element-wise addition A = A + x
-
sub
public DenseMatrix sub(double x, DenseMatrix c)
Element-wise addition C = A - x
-
sub
public DenseMatrix sub(double x)
In place element-wise subtraction A = A - x
-
mul
public DenseMatrix mul(double x, DenseMatrix c)
Element-wise addition C = A * x
-
mul
public DenseMatrix mul(double x)
In place element-wise multiplication A = A * x
-
div
public DenseMatrix div(double x, DenseMatrix c)
Element-wise addition C = A / x
-
div
public DenseMatrix div(double x)
In place element-wise division A = A / x
-
replaceNaN
public DenseMatrix replaceNaN(double x)
Replaces NaN's with given value.
-
sum
public double sum()
Returns the sum of all elements in the matrix.- Returns:
- the sum of all elements.
-
array
public double[][] array()
Return the two-dimensional array of matrix.- Returns:
- the two-dimensional array of matrix.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG