Package rocks.palaiologos.maja.matrix
Class DoubleMatrix
A class representing a two-dimensional matrix of double precision floating point numbers.
- Author:
- Palaiologos
-
Constructor Summary
ConstructorsConstructorDescriptionDoubleMatrix
(double[][] data) DoubleMatrix
(int rows, int columns) DoubleMatrix
(Double[][] data) DoubleMatrix
(List<List<Double>> data) -
Method Summary
Modifier and TypeMethodDescriptiondouble
alt
(BiFunction<Double, Double, Double> vector, BiFunction<Double, Double, Double> scalar) The expressionsA.alt(Maja::sub, Maja::mul)
andA.alt(Maja::add, Maja::mul)
are for square matrix arguments A, the determinant and the permanent of mathematics.cholesky()
Perform the Cholesky decomposition algorithm.copy()
Copy the matrix.double
det()
Compute the determinant of the matrix.dot
(Matrix<Double> another, BiFunction<Double, Double, Double> scalar, BiFunction<Double, Double, Double> vector) Compute the generalised dot product of the matrix with another matrix.eigen()
Perform eigenvalue decomposition.static DoubleMatrix
identity
(int n) Generate an identity matrix of the given order.static DoubleMatrix
invert()
Invert the matrix.Invert the matrix given the LUP decomposition of the current matrix.Invert the matrix given the QR decomposition of the current matrix.LU()
Computes the LU decomposition of a matrix using the Doolittle algorithm.LUP()
Computes the LUP decomposition of a rectangular or square matrix.Map each cell of the matrix with a specified mapper.Map each cell of the matrix with a specified mapper, which takes the index of the cell as an additional argument.double
perm()
Compute the permanent of the matrix.product
(DoubleMatrix other) Compute the standard matrix product.QR()
Perform the QR decomposition algorithm using the Householder transformation.Reverse the matrix on the first axis.Reverse the matrix on the last axis.Solve A * X = Bsvd()
Compute the compact singular value decomposition of the matrix.toString()
double
trace()
Compute the trace of a matrix.Transpose the matrix, i.e.Zip two matrices together to produce a new matrix, using a specified zipper function.
-
Constructor Details
-
DoubleMatrix
-
DoubleMatrix
public DoubleMatrix(int rows, int columns) -
DoubleMatrix
-
DoubleMatrix
public DoubleMatrix(double[][] data)
-
-
Method Details
-
identity
Generate an identity matrix of the given order. -
det
public double det()Compute the determinant of the matrix.- Throws:
IllegalArgumentException
- if the matrix is not square.
-
perm
public double perm()Compute the permanent of the matrix.- Throws:
IllegalArgumentException
- if the matrix is not square.
-
alt
The expressionsA.alt(Maja::sub, Maja::mul)
andA.alt(Maja::add, Maja::mul)
are for square matrix arguments A, the determinant and the permanent of mathematics. The generalization to arguments other than plus, minus and times is based on construing the determinant as an alternating sum over products over the diagonals of tables obtained by permuting the major cells of A.- Throws:
IllegalArgumentException
- if the matrix is not square.
-
LU
Computes the LU decomposition of a matrix using the Doolittle algorithm.- Throws:
IllegalArgumentException
- if the matrix is not square.
-
LUP
Computes the LUP decomposition of a rectangular or square matrix. Also determines whether the matrix is singular and computes its determinant. -
trace
public double trace()Compute the trace of a matrix. -
QR
Perform the QR decomposition algorithm using the Householder transformation. -
cholesky
Perform the Cholesky decomposition algorithm. -
eigen
Perform eigenvalue decomposition. -
into
-
svd
Compute the compact singular value decomposition of the matrix. -
invert
Invert the matrix.- Throws:
IllegalArgumentException
- if the matrix is singular or not square.
-
invert
Invert the matrix given the LUP decomposition of the current matrix.- Throws:
IllegalArgumentException
- if the matrix is singular or not square.
-
invert
Invert the matrix given the QR decomposition of the current matrix.- Throws:
IllegalArgumentException
- if the matrix is singular or not square.
-
product
Compute the standard matrix product.- Throws:
IllegalArgumentException
- if the matrices' dimensions do not match.
-
solve
Solve A * X = B- Parameters:
B
-- Returns:
- solution X if A is square, least squares solution otherwise
-
copy
Description copied from class:Matrix
Copy the matrix. -
transpose
Description copied from class:Matrix
Transpose the matrix, i.e. swap its axes. -
map
Description copied from class:Matrix
Map each cell of the matrix with a specified mapper. -
zipWith
Description copied from class:Matrix
Zip two matrices together to produce a new matrix, using a specified zipper function. -
reverseFirst
Description copied from class:Matrix
Reverse the matrix on the first axis.- Overrides:
reverseFirst
in classMatrix<Double>
- Returns:
-
reverseLast
Description copied from class:Matrix
Reverse the matrix on the last axis.- Overrides:
reverseLast
in classMatrix<Double>
- Returns:
-
mapIdx
Description copied from class:Matrix
Map each cell of the matrix with a specified mapper, which takes the index of the cell as an additional argument. -
dot
public DoubleMatrix dot(Matrix<Double> another, BiFunction<Double, Double, Double> scalar, BiFunction<Double, Double, Double> vector) Description copied from class:Matrix
Compute the generalised dot product of the matrix with another matrix. The generalised dot product is defined as follows:(A o B) = sum_{i,j} (A_{i,j} o B_{i,j})
Where o is the *scalar* product and sum is the *vector* sum. For example, to multiply two matrices, one would use:
dot(A, B, (a, b) -> a * b, (a, b) -> a + b)
-
toString
-