Class LinearAlgebra

java.lang.Object
com.quantfinlib.stats.LinearAlgebra

public final class LinearAlgebra extends Object
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 Type
    Method
    Description
    static double[][]
    cholesky(double[][] a)
    Cholesky decomposition: returns lower-triangular L with A = L * L'.
    static double
    dot(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 product m v.
    static double
    quadraticForm(double[] w, double[][] m)
    w' * M * w (quadratic form).
    static double[]
    solveLinear(double[][] a, double[] b)
    Solves A x = b by Gaussian elimination with partial pivoting.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 product m 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)
      Solves A x = b by 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.