Class OGMatrixAlgebra
- java.lang.Object
-
- com.opengamma.strata.math.impl.matrix.MatrixAlgebra
-
- com.opengamma.strata.math.impl.matrix.OGMatrixAlgebra
-
public class OGMatrixAlgebra extends MatrixAlgebra
A minimal implementation of matrix algebra.This includes only some of the multiplications. For more advanced operations, such as calculating the inverse, use
CommonsMatrixAlgebra.
-
-
Constructor Summary
Constructors Constructor Description OGMatrixAlgebra()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetCondition(Matrix m)Returns the condition number of the matrix.doublegetDeterminant(Matrix m)Returns the determinant of the matrix.doublegetInnerProduct(Matrix m1, Matrix m2)Returns the inner (or dot) product.DoubleMatrixgetInverse(Matrix m)Returns the inverse (or pseudo-inverse) of the matrix.doublegetNorm1(Matrix m)For a vector, returns the $L_1$ norm (also known as the Taxicab norm or Manhattan norm), i.e.doublegetNorm2(Matrix m)For a vector, returns $L_2$ norm (also known as the Euclidean norm).doublegetNormInfinity(Matrix m)For a vector, returns the $L_\infty$ norm.DoubleMatrixgetOuterProduct(Matrix m1, Matrix m2)Returns the outer product.DoubleMatrixgetPower(Matrix m, double p)Returns a matrix raised to a power, $\mathbf{A}^3 = \mathbf{A}\mathbf{A}\mathbf{A}$.DoubleMatrixgetPower(Matrix m, int p)Returns a matrix raised to an integer power, e.g.doublegetTrace(Matrix m)Returns the trace (i.e.DoubleMatrixgetTranspose(Matrix m)Returns the transpose of a matrix.Matrixmultiply(Matrix m1, Matrix m2)Multiplies two matrices.-
Methods inherited from class com.opengamma.strata.math.impl.matrix.MatrixAlgebra
add, divide, kroneckerProduct, matrixTransposeMultiplyMatrix, scale, subtract
-
-
-
-
Method Detail
-
getCondition
public double getCondition(Matrix m)
Returns the condition number of the matrix.- Specified by:
getConditionin classMatrixAlgebra- Parameters:
m- A matrix, not null- Returns:
- The condition number of the matrix
- Throws:
UnsupportedOperationException- always
-
getDeterminant
public double getDeterminant(Matrix m)
Returns the determinant of the matrix.- Specified by:
getDeterminantin classMatrixAlgebra- Parameters:
m- A matrix, not null- Returns:
- The determinant of the matrix
- Throws:
UnsupportedOperationException- always
-
getInnerProduct
public double getInnerProduct(Matrix m1, Matrix m2)
Returns the inner (or dot) product.- Specified by:
getInnerProductin classMatrixAlgebra- Parameters:
m1- A vector, not nullm2- A vector, not null- Returns:
- The scalar dot product
-
getInverse
public DoubleMatrix getInverse(Matrix m)
Returns the inverse (or pseudo-inverse) of the matrix.- Specified by:
getInversein classMatrixAlgebra- Parameters:
m- A matrix, not null- Returns:
- The inverse matrix
- Throws:
UnsupportedOperationException- always
-
getNorm1
public double getNorm1(Matrix m)
For a vector, returns the $L_1$ norm (also known as the Taxicab norm or Manhattan norm), i.e. $\Sigma |x_i|$.For a matrix, returns the maximum absolute column sum norm of the matrix.
- Specified by:
getNorm1in classMatrixAlgebra- Parameters:
m- A vector or matrix, not null- Returns:
- The $L_1$ norm
- Throws:
UnsupportedOperationException- always
-
getNorm2
public double getNorm2(Matrix m)
For a vector, returns $L_2$ norm (also known as the Euclidean norm).For a matrix, returns the spectral norm This is only implemented for
DoubleArray.- Specified by:
getNorm2in classMatrixAlgebra- Parameters:
m- A vector or matrix, not null- Returns:
- the norm
- Throws:
IllegalArgumentException- If the matrix is not aDoubleArray
-
getNormInfinity
public double getNormInfinity(Matrix m)
For a vector, returns the $L_\infty$ norm. $L_\infty$ norm is the maximum of the absolute values of the elements.For a matrix, returns the maximum absolute row sum norm
- Specified by:
getNormInfinityin classMatrixAlgebra- Parameters:
m- a vector or a matrix, not null- Returns:
- the norm
- Throws:
UnsupportedOperationException- always
-
getOuterProduct
public DoubleMatrix getOuterProduct(Matrix m1, Matrix m2)
Returns the outer product.- Specified by:
getOuterProductin classMatrixAlgebra- Parameters:
m1- A vector, not nullm2- A vector, not null- Returns:
- The outer product
-
getPower
public DoubleMatrix getPower(Matrix m, int p)
Returns a matrix raised to an integer power, e.g. $\mathbf{A}^3 = \mathbf{A}\mathbf{A}\mathbf{A}$.- Specified by:
getPowerin classMatrixAlgebra- Parameters:
m- A square matrix, not nullp- An integer power- Returns:
- The result
- Throws:
UnsupportedOperationException- always
-
getTrace
public double getTrace(Matrix m)
Returns the trace (i.e. sum of diagonal elements) of a matrix.- Specified by:
getTracein classMatrixAlgebra- Parameters:
m- A matrix, not null. The matrix must be square.- Returns:
- The trace
-
getTranspose
public DoubleMatrix getTranspose(Matrix m)
Returns the transpose of a matrix.- Specified by:
getTransposein classMatrixAlgebra- Parameters:
m- A matrix, not null- Returns:
- The transpose matrix
-
multiply
public Matrix multiply(Matrix m1, Matrix m2)
Multiplies two matrices. The following combinations of input matrices m1 and m2 are allowed:- m1 = 2-D matrix, m2 = 2-D matrix, returns $\mathbf{C} = \mathbf{AB}$
- m1 = 2-D matrix, m2 = 1-D matrix, returns $\mathbf{C} = \mathbf{A}b$
- m1 = 1-D matrix, m2 = 2-D matrix, returns $\mathbf{C} = a^T\mathbf{B}$
- Specified by:
multiplyin classMatrixAlgebra- Parameters:
m1- The first matrix, not null.m2- The second matrix, not null.- Returns:
- The product of the two matrices.
-
getPower
public DoubleMatrix getPower(Matrix m, double p)
Returns a matrix raised to a power, $\mathbf{A}^3 = \mathbf{A}\mathbf{A}\mathbf{A}$.- Specified by:
getPowerin classMatrixAlgebra- Parameters:
m- A square matrix, not nullp- The power- Returns:
- The result
- Throws:
UnsupportedOperationException- always
-
-