- Type Parameters:
R- The number of rows in this matrix.C- The number of columns in this matrix.
- All Implemented Interfaces:
ProtobufSerializable, StructSerializable, WPISerializable
- Direct Known Subclasses:
Vector
This class is intended to be used alongside the state space library.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.ejml.simple.SimpleMatrixStorage for underlying EJML matrix. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassignBlock(int startingRow, int startingCol, Matrix<R2, C2> other) Assign a matrix of a given size and start position.block(int height, int width, int startingRow, int startingCol) Extracts a matrix of a given size and start position with new underlying storage.Extracts a matrix of a given size and start position with new underlying storage.changeBoundsUnchecked(Matrix<?, ?> mat) Reassigns dimensions of aMatrixto allow for operations with other matrices that have wildcard dimensions.copy()Returns a copy of this matrix.final doubledet()Returns the determinant of this matrix.diag()Returns the diagonal elements inside a vector or square matrix.div(double value) Divides all elements of this matrix by the given value.div(int value) Divides all elements of this matrix by the given value.elementPower(double b) Returns a matrix which is the result of an element by element power of "this" and b.elementPower(int b) Returns a matrix which is the result of an element by element power of "this" and b.final doubleComputes the sum of all the elements in the matrix.elementTimes(Matrix<R, C> other) Returns a matrix which is the result of an element by element multiplication of "this" and other.booleanChecks if an object is equal to thisMatrix.exp()Computes the matrix exponential using Eigen's solver.extractColumnVector(int column) Extracts a given column into a column vector with new underlying storage.extractFrom(int startingRow, int startingCol, Matrix<R2, C2> other) Extracts a submatrix from the supplied matrix and inserts it in a submatrix in "this".extractRowVector(int row) Extracts a given row into a row vector with new underlying storage.eye(D dim) Creates the identity matrix of the given dimension.Creates the identity matrix of the given dimension.voidfill(double value) Sets all the elements in "this" matrix equal to the specified value.final doubleget(int row, int col) Get an element of this matrix.double[]getData()Returns the row major data of this matrix as a double array.final intGets the number of columns in this matrix.final intGets the number of rows in this matrix.static <R extends Num, C extends Num>
MatrixProto<R, C> Creates an implementation of theProtobufinterface for matrices.org.ejml.simple.SimpleMatrixGets the underlyingSimpleMatrixthat thisMatrixwraps.static <R extends Num, C extends Num>
MatrixStruct<R, C> Creates an implementation of theStructinterfaces for matrices.inthashCode()inv()Returns the inverse matrix of "this" matrix.booleanChecks if anotherMatrixis equal to "this" within a specified tolerance.booleanisIdentical(Matrix<?, ?> other, double tolerance) Checks if anotherMatrixis identical to "this" one within a specified tolerance.lltDecompose(boolean lowerTriangular) Decompose "this" matrix using Cholesky Decomposition.final doublemax()Returns the largest element of this matrix.final doublemaxAbs()Returns the absolute value of the element in this matrix with the largest absolute value.final doublemean()Calculates the mean of the elements in this matrix.final doubleReturns the smallest element of this matrix.minus(double value) Subtracts the given value from all the elements of this matrix.Subtracts the given matrix from this matrix.final doublenormF()Computes the Frobenius normal of the matrix.final doubleComputes the induced p = 1 matrix norm.plus(double value) Adds the given value to all the elements of this matrix.Adds the given matrix to this matrix.pow(double exponent) Computes the matrix power using Eigen's solver.voidrankUpdate(Matrix<R, N1> v, double sigma, boolean lowerTriangular) Performs an inplace Cholesky rank update (or downdate).final voidset(int row, int col, double value) Sets the value at the given indices.final voidSets a column to a given column vector.final voidSets a row to a given row vector.Returns the solution x to the equation Ax = b, where A is "this" matrix.solveFullPivHouseholderQr(Matrix<R2, C2> other) Solves the least-squares problem Ax=B using a QR decomposition with full pivoting, where this matrix is A.times(double value) Multiplies all the elements of this matrix by the given scalar.Multiplies this matrix with another that has C rows.toString()final doubletrace()Computes the trace of the matrix.Calculates the transpose, Mᵀ of this matrix.
-
Field Details
-
m_storage
Storage for underlying EJML matrix.
-
-
Constructor Details
-
Matrix
-
Matrix
-
Matrix
Constructs a newMatrixwith the given storage. Caller should make sure that the provided generic bounds match the shape of the providedMatrix.NOTE:It is not recommend to use this constructor unless the
SimpleMatrixAPI is absolutely necessary due to the desired function not being accessible through theMatrixwrapper.- Parameters:
storage- TheSimpleMatrixto back this value.
-
Matrix
-
-
Method Details
-
getStorage
Gets the underlyingSimpleMatrixthat thisMatrixwraps.NOTE:The use of this method is heavily discouraged as this removes any guarantee of type safety. This should only be called if the
SimpleMatrixAPI is absolutely necessary due to the desired function not being accessible through theMatrixwrapper.- Returns:
- The underlying
SimpleMatrixstorage.
-
getNumCols
Gets the number of columns in this matrix.- Returns:
- The number of columns, according to the internal storage.
-
getNumRows
Gets the number of rows in this matrix.- Returns:
- The number of rows, according to the internal storage.
-
get
Get an element of this matrix.- Parameters:
row- The row of the element.col- The column of the element.- Returns:
- The element in this matrix at row,col.
-
set
Sets the value at the given indices.- Parameters:
row- The row of the element.col- The column of the element.value- The value to insert at the given location.
-
setRow
-
setColumn
-
fill
Sets all the elements in "this" matrix equal to the specified value.- Parameters:
value- The value each element is set to.
-
diag
-
max
Returns the largest element of this matrix.- Returns:
- The largest element of this matrix.
-
maxAbs
Returns the absolute value of the element in this matrix with the largest absolute value.- Returns:
- The absolute value of the element with the largest absolute value.
-
minInternal
Returns the smallest element of this matrix.- Returns:
- The smallest element of this matrix.
-
mean
Calculates the mean of the elements in this matrix.- Returns:
- The mean value of this matrix.
-
times
Multiplies this matrix with another that has C rows.As matrix multiplication is only defined if the number of columns in the first matrix matches the number of rows in the second, this operation will fail to compile under any other circumstances.
- Type Parameters:
C2- The number of columns in the second matrix.- Parameters:
other- The other matrix to multiply by.- Returns:
- The result of the matrix multiplication between "this" and the given matrix.
-
times
-
elementTimes
Returns a matrix which is the result of an element by element multiplication of "this" and other.ci,j = ai,j*otheri,j
- Parameters:
other- The otherMatrixto perform element multiplication on.- Returns:
- The element by element multiplication of "this" and other.
-
minus
-
minus
-
plus
-
plus
-
div
-
div
-
transpose
-
copy
-
inv
-
solve
Returns the solution x to the equation Ax = b, where A is "this" matrix.The matrix equation could also be written as x = A-1b. Where the pseudo inverse is used if A is not square.
Note that this method does not support solving using a QR decomposition with full-pivoting, as only column-pivoting is supported. For full-pivoting, use
solveFullPivHouseholderQr(Matrix).- Type Parameters:
C2- Columns in b.- Parameters:
b- The right-hand side of the equation to solve.- Returns:
- The solution to the linear system.
-
solveFullPivHouseholderQr
public final <R2 extends Num, C2 extends Num> Matrix<C,C2> solveFullPivHouseholderQr(Matrix<R2, C2> other) Solves the least-squares problem Ax=B using a QR decomposition with full pivoting, where this matrix is A.- Type Parameters:
R2- Number of rows in B.C2- Number of columns in B.- Parameters:
other- The B matrix.- Returns:
- The solution matrix.
-
exp
-
pow
-
det
Returns the determinant of this matrix.- Returns:
- The determinant of this matrix.
-
normF
Computes the Frobenius normal of the matrix.normF = Sqrt{ ∑i=1:m ∑j=1:n { aij2} }
- Returns:
- The matrix's Frobenius normal.
-
normIndP1
Computes the induced p = 1 matrix norm.||A||1= max(j=1 to n; sum(i=1 to m; |aij|))
- Returns:
- The norm.
-
elementSum
Computes the sum of all the elements in the matrix.- Returns:
- Sum of all the elements.
-
trace
-
elementPower
Returns a matrix which is the result of an element by element power of "this" and b.ci,j = ai,j ^ b
- Parameters:
b- Scalar.- Returns:
- The element by element power of "this" and b.
-
elementPower
Returns a matrix which is the result of an element by element power of "this" and b.ci,j = ai,j ^ b
- Parameters:
b- Scalar.- Returns:
- The element by element power of "this" and b.
-
extractRowVector
Extracts a given row into a row vector with new underlying storage.- Parameters:
row- The row to extract a vector from.- Returns:
- A row vector from the given row.
-
extractColumnVector
Extracts a given column into a column vector with new underlying storage.- Parameters:
column- The column to extract a vector from.- Returns:
- A column vector from the given column.
-
block
public final <R2 extends Num, C2 extends Num> Matrix<R2,C2> block(Nat<R2> height, Nat<C2> width, int startingRow, int startingCol) Extracts a matrix of a given size and start position with new underlying storage.- Type Parameters:
R2- Number of rows to extract.C2- Number of columns to extract.- Parameters:
height- The number of rows of the extracted matrix.width- The number of columns of the extracted matrix.startingRow- The starting row of the extracted matrix.startingCol- The starting column of the extracted matrix.- Returns:
- The extracted matrix.
-
block
public final <R2 extends Num, C2 extends Num> Matrix<R2,C2> block(int height, int width, int startingRow, int startingCol) Extracts a matrix of a given size and start position with new underlying storage.- Type Parameters:
R2- Number of rows to extract.C2- Number of columns to extract.- Parameters:
height- The number of rows of the extracted matrix.width- The number of columns of the extracted matrix.startingRow- The starting row of the extracted matrix.startingCol- The starting column of the extracted matrix.- Returns:
- The extracted matrix.
-
assignBlock
public <R2 extends Num, C2 extends Num> void assignBlock(int startingRow, int startingCol, Matrix<R2, C2> other) Assign a matrix of a given size and start position.- Type Parameters:
R2- Rows in block assignment.C2- Columns in block assignment.- Parameters:
startingRow- The row to start at.startingCol- The column to start at.other- The matrix to assign the block to.
-
extractFrom
public <R2 extends Num, C2 extends Num> void extractFrom(int startingRow, int startingCol, Matrix<R2, C2> other) Extracts a submatrix from the supplied matrix and inserts it in a submatrix in "this". The shape of "this" is used to determine the size of the matrix extracted.- Type Parameters:
R2- Number of rows to extract.C2- Number of columns to extract.- Parameters:
startingRow- The starting row in the supplied matrix to extract the submatrix.startingCol- The starting column in the supplied matrix to extract the submatrix.other- The matrix to extract the submatrix from.
-
lltDecompose
Decompose "this" matrix using Cholesky Decomposition. If the "this" matrix is zeros, it will return the zero matrix.- Parameters:
lowerTriangular- Whether we want to decompose to the lower triangular Cholesky matrix.- Returns:
- The decomposed matrix.
- Throws:
RuntimeException- if the matrix could not be decomposed(i.e. is not positive semidefinite).
-
getData
Returns the row major data of this matrix as a double array.- Returns:
- The row major data of this matrix as a double array.
-
eye
-
eye
-
changeBoundsUnchecked
-
isIdentical
Checks if anotherMatrixis identical to "this" one within a specified tolerance.This will check if each element is in tolerance of the corresponding element from the other
Matrixor if the elements have the same symbolic meaning. For two elements to have the same symbolic meaning they both must be either Double.NaN, Double.POSITIVE_INFINITY, or Double.NEGATIVE_INFINITY.NOTE:It is recommended to use
isEqual(Matrix, double)over this method when checking if two matrices are equal asisEqual(Matrix, double)will return false if an element is uncountable. This method should only be used when uncountable elements need to be compared.- Parameters:
other- TheMatrixto check against this one.tolerance- The tolerance to check equality with.- Returns:
- true if this matrix is identical to the one supplied.
-
isEqual
Checks if anotherMatrixis equal to "this" within a specified tolerance.This will check if each element is in tolerance of the corresponding element from the other
Matrix.tol ≥ |aij - bij|
- Parameters:
other- TheMatrixto check against this one.tolerance- The tolerance to check equality with.- Returns:
- true if this matrix is equal to the one supplied.
-
rankUpdate
Performs an inplace Cholesky rank update (or downdate).If this matrix contains L where A = LLᵀ before the update, it will contain L where LLᵀ = A + σvvᵀ after the update.
- Parameters:
v- Vector to use for the update.sigma- Sigma to use for the update.lowerTriangular- Whether this matrix is lower triangular.
-
toString
-
equals
-
hashCode
-
getProto
Creates an implementation of theProtobufinterface for matrices.- Type Parameters:
R- The number of rows of the matrices this serializer processes.C- The number of cols of the matrices this serializer processes.- Parameters:
rows- The number of rows of the matrices this serializer processes.cols- The number of cols of the matrices this serializer processes.- Returns:
- The protobuf implementation.
-
getStruct
Creates an implementation of theStructinterfaces for matrices.- Type Parameters:
R- The number of rows of the matrices this serializer processes.C- The number of cols of the matrices this serializer processes.- Parameters:
rows- The number of rows of the matrices this serializer processes.cols- The number of cols of the matrices this serializer processes.- Returns:
- The struct implementation.
-