smile.math.matrix
Class JMatrix
- java.lang.Object
-
- smile.math.matrix.Matrix
-
- smile.math.matrix.DenseMatrix
-
- smile.math.matrix.JMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, MatrixMultiplication<DenseMatrix,DenseMatrix>
public class JMatrix extends DenseMatrix
A pure Java implementation of DenseMatrix whose data is stored in a single 1D array of doubles in column major order.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description JMatrix(double[] A)Constructor of a column vector/matrix with given array as the internal storage.JMatrix(double[][] A)Constructor.JMatrix(int rows, int cols)Constructor of all-zero matrix.JMatrix(int rows, int cols, double value)Constructor.JMatrix(int rows, int cols, double[] value)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description JMatrixaat()Returns A * A'JMatrixabmm(DenseMatrix B)Returns the result of matrix multiplication A * B.JMatrixabtmm(DenseMatrix B)Returns the result of matrix multiplication A * B'.JMatrixadd(DenseMatrix b)In place addition A = A + BDenseMatrixadd(DenseMatrix b, DenseMatrix c)C = A + BJMatrixadd(double x)In place element-wise addition A = A + xDenseMatrixadd(double x, DenseMatrix c)Element-wise addition C = A + xJMatrixadd(double x, JMatrix c)doubleadd(int i, int j, double x)A[i][j] += xJMatrixadd(JMatrix b)JMatrixadd(JMatrix b, JMatrix c)JMatrixata()Returns A' * AJMatrixatbmm(DenseMatrix B)Returns the result of matrix multiplication A' * B.double[]atx(double[] x, double[] y)y = A' * xdouble[]atxpy(double[] x, double[] y)y = A' * x + ydouble[]atxpy(double[] x, double[] y, double b)y = A' * x + b * ydouble[]ax(double[] x, double[] y)y = A * xdouble[]axpy(double[] x, double[] y)y = A * x + ydouble[]axpy(double[] x, double[] y, double b)y = A * x + b * yCholeskycholesky()Cholesky decomposition for symmetric and positive definite matrix.JMatrixcopy()Returns a copy of this matrix.double[]data()Returns the array of storing the matrix.JMatrixdiv(DenseMatrix b)In place element-wise division A = A / B A = A - BDenseMatrixdiv(DenseMatrix b, DenseMatrix c)C = A / BJMatrixdiv(double x)In place element-wise division A = A / xDenseMatrixdiv(double x, DenseMatrix c)Element-wise addition C = A / xJMatrixdiv(double x, JMatrix c)doublediv(int i, int j, double x)A[i][j] /= xJMatrixdiv(JMatrix b)JMatrixdiv(JMatrix b, JMatrix c)double[]eig()Returns the eigen values in an array of size 2N.EVDeigen()Returns the eigen value decomposition.doubleget(int i, int j)Returns the entry value at row i and column j.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.LUlu()LU decomposition is computed by a "left-looking", dot-product, Crout/Doolittle algorithm.JMatrixmul(DenseMatrix b)In place element-wise multiplication A = A * BDenseMatrixmul(DenseMatrix b, DenseMatrix c)C = A * BJMatrixmul(double x)In place element-wise multiplication A = A * xDenseMatrixmul(double x, DenseMatrix c)Element-wise addition C = A * xJMatrixmul(double x, JMatrix c)doublemul(int i, int j, double x)A[i][j] *= xJMatrixmul(JMatrix b)JMatrixmul(JMatrix b, JMatrix c)intncols()Returns the number of columns.intnrows()Returns the number of rows.QRqr()QR Decomposition is computed by Householder reflections.JMatrixreplaceNaN(double x)Replaces NaN's with given value.doubleset(int i, int j, double x)Set the entry value at row i and column j.JMatrixsub(DenseMatrix b)In place subtraction A = A - BDenseMatrixsub(DenseMatrix b, DenseMatrix c)C = A - BJMatrixsub(double x)In place element-wise subtraction A = A - xDenseMatrixsub(double x, DenseMatrix c)Element-wise addition C = A - xJMatrixsub(double x, JMatrix c)doublesub(int i, int j, double x)A[i][j] -= xJMatrixsub(JMatrix b)JMatrixsub(JMatrix b, JMatrix c)doublesum()Returns the sum of all elements in the matrix.SVDsvd()Returns the singular value decomposition.JMatrixtranspose()Returns the matrix transpose.-
Methods inherited from class smile.math.matrix.DenseMatrix
array, cholesky, colMeans, colSums, eig, eigen, inverse, inverse, lu, norm, norm1, norm2, normFro, normInf, qr, rowMeans, rowSums, svd, update, xax
-
Methods inherited from class smile.math.matrix.Matrix
apply, diag, diag, eigen, eigen, eye, eye, isSymmetric, newInstance, newInstance, newInstance, ones, randn, randn, setSymmetric, svd, svd, toString, toString, trace, zeros
-
-
-
-
Constructor Detail
-
JMatrix
public JMatrix(double[][] A)
Constructor.- Parameters:
A- the array of matrix.
-
JMatrix
public JMatrix(double[] A)
Constructor of a column vector/matrix with given array as the internal storage.- Parameters:
A- the array of column vector.
-
JMatrix
public JMatrix(int rows, int cols)Constructor of all-zero matrix.
-
JMatrix
public JMatrix(int rows, int cols, double value)Constructor. Fill the matrix with given value.
-
JMatrix
public JMatrix(int rows, int cols, double[] value)Constructor.- Parameters:
value- the array of matrix values arranged in column major format
-
-
Method Detail
-
copy
public JMatrix copy()
Description copied from class:DenseMatrixReturns a copy of this matrix.- Specified by:
copyin classDenseMatrix
-
data
public double[] data()
Description copied from class:DenseMatrixReturns the array of storing the matrix.- Specified by:
datain classDenseMatrix
-
transpose
public JMatrix transpose()
Description copied from class:DenseMatrixReturns the matrix transpose.- Specified by:
transposein classDenseMatrix
-
nrows
public int nrows()
Description copied from class:MatrixReturns the number of rows.
-
ncols
public int ncols()
Description copied from class:MatrixReturns the number of columns.
-
ld
public int ld()
Description copied from class:DenseMatrixThe 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).- Specified by:
ldin classDenseMatrix- Returns:
- the leading dimension
-
get
public double get(int i, int j)Description copied from class:MatrixReturns the entry value at row i and column j.
-
set
public double set(int i, int j, double x)Description copied from class:DenseMatrixSet the entry value at row i and column j.- Specified by:
setin classDenseMatrix
-
add
public double add(int i, int j, double x)Description copied from class:DenseMatrixA[i][j] += x- Specified by:
addin classDenseMatrix
-
sub
public double sub(int i, int j, double x)Description copied from class:DenseMatrixA[i][j] -= x- Specified by:
subin classDenseMatrix
-
mul
public double mul(int i, int j, double x)Description copied from class:DenseMatrixA[i][j] *= x- Specified by:
mulin classDenseMatrix
-
div
public double div(int i, int j, double x)Description copied from class:DenseMatrixA[i][j] /= x- Specified by:
divin classDenseMatrix
-
add
public JMatrix add(DenseMatrix b)
Description copied from class:DenseMatrixIn place addition A = A + B- Overrides:
addin classDenseMatrix- Returns:
- this matrix
-
add
public DenseMatrix add(DenseMatrix b, DenseMatrix c)
Description copied from class:DenseMatrixC = A + B- Overrides:
addin classDenseMatrix- Returns:
- the result matrix
-
sub
public JMatrix sub(DenseMatrix b)
Description copied from class:DenseMatrixIn place subtraction A = A - B- Overrides:
subin classDenseMatrix- Returns:
- this matrix
-
sub
public DenseMatrix sub(DenseMatrix b, DenseMatrix c)
Description copied from class:DenseMatrixC = A - B- Overrides:
subin classDenseMatrix- Returns:
- the result matrix
-
mul
public JMatrix mul(DenseMatrix b)
Description copied from class:DenseMatrixIn place element-wise multiplication A = A * B- Overrides:
mulin classDenseMatrix- Returns:
- this matrix
-
mul
public DenseMatrix mul(DenseMatrix b, DenseMatrix c)
Description copied from class:DenseMatrixC = A * B- Overrides:
mulin classDenseMatrix- Returns:
- the result matrix
-
div
public JMatrix div(DenseMatrix b)
Description copied from class:DenseMatrixIn place element-wise division A = A / B A = A - B- Overrides:
divin classDenseMatrix- Returns:
- this matrix
-
div
public DenseMatrix div(DenseMatrix b, DenseMatrix c)
Description copied from class:DenseMatrixC = A / B- Overrides:
divin classDenseMatrix- Returns:
- the result matrix
-
add
public JMatrix add(double x)
Description copied from class:DenseMatrixIn place element-wise addition A = A + x- Overrides:
addin classDenseMatrix
-
add
public DenseMatrix add(double x, DenseMatrix c)
Description copied from class:DenseMatrixElement-wise addition C = A + x- Overrides:
addin classDenseMatrix
-
sub
public JMatrix sub(double x)
Description copied from class:DenseMatrixIn place element-wise subtraction A = A - x- Overrides:
subin classDenseMatrix
-
sub
public DenseMatrix sub(double x, DenseMatrix c)
Description copied from class:DenseMatrixElement-wise addition C = A - x- Overrides:
subin classDenseMatrix
-
mul
public JMatrix mul(double x)
Description copied from class:DenseMatrixIn place element-wise multiplication A = A * x- Overrides:
mulin classDenseMatrix
-
mul
public DenseMatrix mul(double x, DenseMatrix c)
Description copied from class:DenseMatrixElement-wise addition C = A * x- Overrides:
mulin classDenseMatrix
-
div
public JMatrix div(double x)
Description copied from class:DenseMatrixIn place element-wise division A = A / x- Overrides:
divin classDenseMatrix
-
div
public DenseMatrix div(double x, DenseMatrix c)
Description copied from class:DenseMatrixElement-wise addition C = A / x- Overrides:
divin classDenseMatrix
-
replaceNaN
public JMatrix replaceNaN(double x)
Description copied from class:DenseMatrixReplaces NaN's with given value.- Overrides:
replaceNaNin classDenseMatrix
-
sum
public double sum()
Description copied from class:DenseMatrixReturns the sum of all elements in the matrix.- Overrides:
sumin classDenseMatrix- Returns:
- the sum of all elements.
-
ata
public JMatrix ata()
Description copied from class:MatrixReturns A' * A- Specified by:
atain classDenseMatrix
-
aat
public JMatrix aat()
Description copied from class:MatrixReturns A * A'- Specified by:
aatin classDenseMatrix
-
ax
public double[] ax(double[] x, double[] y)Description copied from class:Matrixy = A * x
-
axpy
public double[] axpy(double[] x, double[] y)Description copied from class:Matrixy = A * x + y
-
axpy
public double[] axpy(double[] x, double[] y, double b)Description copied from class:Matrixy = A * x + b * y
-
atx
public double[] atx(double[] x, double[] y)Description copied from class:Matrixy = A' * x
-
atxpy
public double[] atxpy(double[] x, double[] y)Description copied from class:Matrixy = A' * x + y
-
atxpy
public double[] atxpy(double[] x, double[] y, double b)Description copied from class:Matrixy = A' * x + b * y
-
abmm
public JMatrix abmm(DenseMatrix B)
Description copied from interface:MatrixMultiplicationReturns the result of matrix multiplication A * B.
-
abtmm
public JMatrix abtmm(DenseMatrix B)
Description copied from interface:MatrixMultiplicationReturns the result of matrix multiplication A * B'.
-
atbmm
public JMatrix atbmm(DenseMatrix B)
Description copied from interface:MatrixMultiplicationReturns the result of matrix multiplication A' * B.
-
lu
public LU lu()
LU decomposition is computed by a "left-looking", dot-product, Crout/Doolittle algorithm.- Specified by:
luin classDenseMatrix
-
cholesky
public Cholesky cholesky()
Cholesky decomposition for symmetric and positive definite matrix. Only the lower triangular part will be used in the decomposition.- Specified by:
choleskyin classDenseMatrix- Throws:
java.lang.IllegalArgumentException- if the matrix is not positive definite.
-
qr
public QR qr()
QR Decomposition is computed by Householder reflections.- Specified by:
qrin classDenseMatrix
-
svd
public SVD svd()
Description copied from class:DenseMatrixReturns the singular value decomposition. Note that the input matrix will hold U on output.- Specified by:
svdin classDenseMatrix
-
eig
public double[] eig()
Description copied from class:DenseMatrixReturns 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.- Specified by:
eigin classDenseMatrix
-
eigen
public EVD eigen()
Description copied from class:DenseMatrixReturns the eigen value decomposition. Note that the input matrix will be overwritten on output.- Specified by:
eigenin classDenseMatrix
-
-
DataMelt 3.0 © DataMelt by jWork.ORG