Package rocks.palaiologos.maja.matrix
Class DoubleMatrix
A class representing a two-dimensional matrix of double precision floating point numbers.
-
Field Summary
-
Constructor Summary
ConstructorsModifierConstructorDescriptionDoubleMatrix(double[][] data) DoubleMatrix(int rows, int columns) DoubleMatrix(Double[][] data) DoubleMatrix(List<List<Double>> data) privateDoubleMatrix(Matrix<Double> m) -
Method Summary
Modifier and TypeMethodDescriptiondoublealt(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.private static doublealt(Matrix<Double> a, BiFunction<Double, Double, Double> vector, BiFunction<Double, Double, Double> scalar) cholesky()Perform the Cholesky decomposition algorithm.copy()Copy the matrix.doubledet()Compute the determinant of the matrix.private static doubleprivate doubledet2x2()private doubledet3x3()private doubledet4x4()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 DoubleMatrixidentity(int n) Generate an identity matrix of the given order.static DoubleMatrixprivate DoubleMatrixinv2x2()private DoubleMatrixinv3x3()private DoubleMatrixinv4x4()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.doubleperm()Compute the permanent of the matrix.private static doubleprivate doubleperm2x2()private doubleperm3x3()private doubleperm4x4()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.private doublesmalldet()private DoubleMatrixprivate doubleSolve A * X = Bsvd()Compute the compact singular value decomposition of the matrix.toString()doubletrace()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
-
DoubleMatrix
public DoubleMatrix(double[][] data)
-
-
Method Details
-
minor
-
det
-
perm
-
alt
private static double alt(Matrix<Double> a, BiFunction<Double, Double, Double> vector, BiFunction<Double, Double, Double> scalar) -
identity
Generate an identity matrix of the given order. -
det2x2
private double det2x2() -
det3x3
private double det3x3() -
det4x4
private double det4x4() -
smalldet
private double smalldet() -
perm2x2
private double perm2x2() -
perm3x3
private double perm3x3() -
perm4x4
private double perm4x4() -
smallperm
private double smallperm() -
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. -
inv2x2
-
into
-
inv3x3
-
inv4x4
-
smallMatrixInvert
-
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:MatrixCopy the matrix. -
transpose
Description copied from class:MatrixTranspose the matrix, i.e. swap its axes. -
map
Description copied from class:MatrixMap each cell of the matrix with a specified mapper. -
zipWith
Description copied from class:MatrixZip two matrices together to produce a new matrix, using a specified zipper function. -
reverseFirst
Description copied from class:MatrixReverse the matrix on the first axis.- Overrides:
reverseFirstin classMatrix<Double>- Returns:
-
reverseLast
Description copied from class:MatrixReverse the matrix on the last axis.- Overrides:
reverseLastin classMatrix<Double>- Returns:
-
mapIdx
Description copied from class:MatrixMap 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:MatrixCompute 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
-