Class CommonsMatrixAlgebra
- java.lang.Object
-
- com.opengamma.strata.math.impl.matrix.MatrixAlgebra
-
- com.opengamma.strata.math.impl.matrix.CommonsMatrixAlgebra
-
public class CommonsMatrixAlgebra extends MatrixAlgebra
Provides matrix algebra by using the Commons library.
-
-
Constructor Summary
Constructors Constructor Description CommonsMatrixAlgebra()
-
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 real matrix raised to some real power Currently this method is limited to symmetric matrices only as Commons Math does not support the diagonalization of asymmetric matrices.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)
Description copied from class:MatrixAlgebraReturns the condition number of the matrix.- Specified by:
getConditionin classMatrixAlgebra- Parameters:
m- A matrix, not null- Returns:
- The condition number of the matrix
-
getDeterminant
public double getDeterminant(Matrix m)
Description copied from class:MatrixAlgebraReturns the determinant of the matrix.- Specified by:
getDeterminantin classMatrixAlgebra- Parameters:
m- A matrix, not null- Returns:
- The determinant of the matrix
-
getInnerProduct
public double getInnerProduct(Matrix m1, Matrix m2)
Description copied from class:MatrixAlgebraReturns 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)
Description copied from class:MatrixAlgebraReturns the inverse (or pseudo-inverse) of the matrix.- Specified by:
getInversein classMatrixAlgebra- Parameters:
m- A matrix, not null- Returns:
- The inverse matrix
-
getNorm1
public double getNorm1(Matrix m)
Description copied from class:MatrixAlgebraFor 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
-
getNorm2
public double getNorm2(Matrix m)
Description copied from class:MatrixAlgebraFor a vector, returns $L_2$ norm (also known as the Euclidean norm).For a matrix, returns the spectral norm
- Specified by:
getNorm2in classMatrixAlgebra- Parameters:
m- A vector or matrix, not null- Returns:
- the norm
-
getNormInfinity
public double getNormInfinity(Matrix m)
Description copied from class:MatrixAlgebraFor 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
-
getOuterProduct
public DoubleMatrix getOuterProduct(Matrix m1, Matrix m2)
Description copied from class:MatrixAlgebraReturns 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)
Description copied from class:MatrixAlgebraReturns 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
-
getPower
public DoubleMatrix getPower(Matrix m, double p)
Returns a real matrix raised to some real power Currently this method is limited to symmetric matrices only as Commons Math does not support the diagonalization of asymmetric matrices.- Specified by:
getPowerin classMatrixAlgebra- Parameters:
m- The symmetric matrix to take the power of.p- The power to raise to matrix to- Returns:
- The result
-
getTrace
public double getTrace(Matrix m)
Description copied from class:MatrixAlgebraReturns 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)
Description copied from class:MatrixAlgebraReturns 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$
- Specified by:
multiplyin classMatrixAlgebra- Parameters:
m1- The first matrix, not null.m2- The second matrix, not null.- Returns:
- The product of the two matrices.
-
-