Class LinearAlgebra
java.lang.Object
com.quantfinlib.stats.LinearAlgebra
Dense linear algebra on
double[][] row-major matrices: dot and
matrix-vector products, the quadratic form, Cholesky, a linear solve and
the inverse.
Added in 2.4.0 as the home of the matrix routines of
util.MathUtils (removed in 3.0). The code was moved, not
rewritten: results are bit-identical to the 2.3 MathUtils
methods (own test: MovedFromMathUtilsTest, pinned to the 2.3.0 jar).
- Since:
- 2.4.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[][]cholesky(double[][] a) Cholesky decomposition: returns lower-triangular L with A = L * L'.static doubledot(double[] a, double[] b) Dot product; rejects arrays of different length.static double[][]inverse(double[][] a) Matrix inverse by Gauss-Jordan elimination with partial pivoting.static double[]matVec(double[][] m, double[] v) Matrix-vector productm v.static doublequadraticForm(double[] w, double[][] m) w' * M * w (quadratic form).static double[]solveLinear(double[][] a, double[] b) SolvesA x = bby Gaussian elimination with partial pivoting.
-
Method Details
-
dot
public static double dot(double[] a, double[] b) Dot product; rejects arrays of different length. -
matVec
public static double[] matVec(double[][] m, double[] v) Matrix-vector productm v. -
quadraticForm
public static double quadraticForm(double[] w, double[][] m) w' * M * w (quadratic form). -
cholesky
public static double[][] cholesky(double[][] a) Cholesky decomposition: returns lower-triangular L with A = L * L'. Adds tiny diagonal jitter if the matrix is borderline non-PSD (rank-deficient factor models produce pivots a hair below zero), but a pivot grossly negative relative to the diagonal scale means the input is indefinite (a typo'd correlation > 1, or inconsistent pairwise estimates). Simulating a silently clamped, different dependence structure would misstate risk, so that fails loudly instead. -
solveLinear
public static double[] solveLinear(double[][] a, double[] b) SolvesA x = bby Gaussian elimination with partial pivoting. Inputs are not modified. -
inverse
public static double[][] inverse(double[][] a) Matrix inverse by Gauss-Jordan elimination with partial pivoting.
-