finMath lib documentation
net.finmath.functions

## Class LinearAlgebra

• public class LinearAlgebra
extends Object
This class implements some methods from linear algebra (e.g. solution of a linear equation, PCA). It is basically a functional wrapper using either the Colt library or Apache commons math. I am currently preferring to use Colt, due to better performance in some situations, however it allows to easily switch some parts to Apache commons math (this is the motivation for this class).
Version:
1.6
Author:
Christian Fries
• ### Constructor Summary

Constructors
Constructor and Description
LinearAlgebra()
• ### Method Summary

All Methods
Modifier and Type Method and Description
double[][] exp(double[][] matrix)
Calculate the "matrix exponential" (expm).
org.apache.commons.math3.linear.RealMatrix exp(org.apache.commons.math3.linear.RealMatrix matrix)
Calculate the "matrix exponential" (expm).
static double[][] factorReduction(double[][] correlationMatrix, int numberOfFactors)
Returns a correlation matrix which has rank < n and for which the first n factors agree with the factors of correlationMatrix.
static double[][] factorReductionUsingCommonsMath(double[][] correlationMatrix, int numberOfFactors)
Returns a correlation matrix which has rank < n and for which the first n factors agree with the factors of correlationMatrix.
static double[][] getFactorMatrix(double[][] correlationMatrix, int numberOfFactors)
Returns the matrix of the n Eigenvectors corresponding to the first n largest Eigenvalues of a correlation matrix.
static double[][] invert(double[][] matrix)
Returns the inverse of a given matrix.
static double[] solveLinearEquation(double[][] matrixA, double[] b)
Find a solution of the linear equation A x = b where A is an n x m - matrix given as double[n][m] b is an m - vector given as double[m], x is an n - vector given as double[n],
static double[] solveLinearEquationLeastSquare(double[][] matrix, double[] vector)
Find a solution of the linear equation A x = b in the least square sense where A is an n x m - matrix given as double[n][m] b is an m - vector given as double[m], x is an n - vector given as double[n],
static double[] solveLinearEquationSymmetric(double[][] matrix, double[] vector)
Find a solution of the linear equation A x = b where A is an symmetric n x n - matrix given as double[n][n] b is an n - vector given as double[n], x is an n - vector given as double[n],
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### LinearAlgebra

public LinearAlgebra()
• ### Method Detail

• #### solveLinearEquation

public static double[] solveLinearEquation(double[][] matrixA,
double[] b)
Find a solution of the linear equation A x = b where
• A is an n x m - matrix given as double[n][m]
• b is an m - vector given as double[m],
• x is an n - vector given as double[n],
Parameters:
matrixA - The matrix A (left hand side of the linear equation).
b - The vector (right hand of the linear equation).
Returns:
A solution x to A x = b.
• #### invert

public static double[][] invert(double[][] matrix)
Returns the inverse of a given matrix.
Parameters:
matrix - A matrix given as double[n][n].
Returns:
The inverse of the given matrix.
• #### solveLinearEquationSymmetric

public static double[] solveLinearEquationSymmetric(double[][] matrix,
double[] vector)
Find a solution of the linear equation A x = b where
• A is an symmetric n x n - matrix given as double[n][n]
• b is an n - vector given as double[n],
• x is an n - vector given as double[n],
Parameters:
matrix - The matrix A (left hand side of the linear equation).
vector - The vector b (right hand of the linear equation).
Returns:
A solution x to A x = b.
• #### solveLinearEquationLeastSquare

public static double[] solveLinearEquationLeastSquare(double[][] matrix,
double[] vector)
Find a solution of the linear equation A x = b in the least square sense where
• A is an n x m - matrix given as double[n][m]
• b is an m - vector given as double[m],
• x is an n - vector given as double[n],
Parameters:
matrix - The matrix A (left hand side of the linear equation).
vector - The vector b (right hand of the linear equation).
Returns:
A solution x to A x = b.
• #### getFactorMatrix

public static double[][] getFactorMatrix(double[][] correlationMatrix,
int numberOfFactors)
Returns the matrix of the n Eigenvectors corresponding to the first n largest Eigenvalues of a correlation matrix. These Eigenvectors can also be interpreted as "principal components" (i.e., the method implements the PCA).
Parameters:
correlationMatrix - The given correlation matrix.
numberOfFactors - The requested number of factors (eigenvectors).
Returns:
Matrix of n Eigenvectors (columns) (matrix is given as double[n][numberOfFactors], where n is the number of rows of the correlationMatrix.
• #### factorReduction

public static double[][] factorReduction(double[][] correlationMatrix,
int numberOfFactors)
Returns a correlation matrix which has rank < n and for which the first n factors agree with the factors of correlationMatrix.
Parameters:
correlationMatrix - The given correlation matrix.
numberOfFactors - The requested number of factors (Eigenvectors).
Returns:
Factor reduced correlation matrix.
• #### factorReductionUsingCommonsMath

public static double[][] factorReductionUsingCommonsMath(double[][] correlationMatrix,
int numberOfFactors)
Returns a correlation matrix which has rank < n and for which the first n factors agree with the factors of correlationMatrix.
Parameters:
correlationMatrix - The given correlation matrix.
numberOfFactors - The requested number of factors (Eigenvectors).
Returns:
Factor reduced correlation matrix.
• #### exp

public double[][] exp(double[][] matrix)
Calculate the "matrix exponential" (expm). Note: The function currently requires jblas. If jblas is not availabe on your system, an exception will be thrown. A future version of this function may implement a fall back.
Parameters:
matrix - The given matrix.
Returns:
The exp(matrix).
• #### exp

public org.apache.commons.math3.linear.RealMatrix exp(org.apache.commons.math3.linear.RealMatrix matrix)
Calculate the "matrix exponential" (expm). Note: The function currently requires jblas. If jblas is not availabe on your system, an exception will be thrown. A future version of this function may implement a fall back.
Parameters:
matrix - The given matrix.
Returns:
The exp(matrix).