Class Matrix

java.lang.Object
org.drip.numerical.linearalgebra.Matrix

public class Matrix
extends java.lang.Object
Matrix implements Matrix manipulation routines. It exports the following functionality:
  • Matrix Inversion using Closed form solutions (for low-dimension matrices), or using Gaussian elimination
  • Matrix Product
  • Matrix Diagonalization and Diagonal Pivoting
  • Matrix Regularization through Row Addition/Row Swap




Author:
Lakshmi Krishnamurthy
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int LOWER_AND_UPPER_TRIANGULAR
    Lower+Upper Triangular Matrix
    static int LOWER_TRIANGULAR
    Lower Triangular Matrix
    static int NON_TRIANGULAR
    Non Triangular Matrix
    static int UPPER_TRIANGULAR
    Upper Triangular Matrix
  • Constructor Summary

    Constructors
    Constructor Description
    Matrix()  
  • Method Summary

    Modifier and Type Method Description
    static double[][] CholeskyBanachiewiczFactorization​(double[][] aadblA)
    Compute the Cholesky-Banachiewicz Factorization of the specified Matrix.
    static double[][] CrossProduct​(double[] vector1, double[] vector2)
    Compute the Cross Product between the Specified Vectors
    static boolean DiagonalizeRow​(int iQ, double[][] aadblZ2XJack, double[][] aadblZ2YJack)
    Diagonalize the specified row in the source matrix, and apply comparable operations to the target
    static double DotProduct​(double[] adblA, double[] adblE)
    Dot Product of Vectors A and E
    static double[][] GrahamSchmidtOrthogonalization​(double[][] aadblV)
    Orthogonalize the Specified Matrix Using the Graham-Schmidt Method
    static double[][] GrahamSchmidtOrthonormalization​(double[][] aadblV)
    Orthonormalize the Specified Matrix Using the Graham-Schmidt Method
    static double[][] Invert​(double[][] aadblA, java.lang.String strMethod)
    Invert the input matrix using the specified Method
    static double[][] Invert2DMatrixUsingCramerRule​(double[][] aadblA)
    Invert a 2D Matrix using Cramer's Rule
    static double[][] InvertUsingGaussianElimination​(double[][] aadblSource)
    Invert the Source Matrix using Gaussian Elimination
    static boolean IsDiagonal​(double[][] matrix)
    Indicate if the Specified Matrix is Diagonal
    static double[][] MakeSquareDiagonal​(double[] adblA)
    Make a Square Diagonal Matrix from a Row
    static double Modulus​(double[] adbl)
    Compute the Modulus of the Input Vector
    static boolean NegativeOrZero​(double[] adbl)
    Indicate if the Array Entries are Negative or Zero
    static double[] Normalize​(double[] adbl)
    Normalize the Input Vector
    static MatrixComplementTransform PivotDiagonal​(double[][] aadblA)
    Pivot the Diagonal of the Input Matrix
    static boolean PositiveLinearlyIndependent​(double[] adbl)
    Indicate if the Array Entries are Positive Linearly Independent
    static boolean PositiveOrZero​(double[] adbl)
    Indicate if the Array Entries are Positive or Zero
    static double[] Product​(double[][] aadblA, double[] adblB)
    Compute the Product of an Input Matrix and a Column
    static double[][] Product​(double[][] aadblA, double[][] aadblB)
    Compute the Product of the input matrices
    static double[][] Product​(double[] adblA, double[][] aadblB)
    Compute the Product of an input column and a matrix
    static double[] Project​(double[] adblA, double[] adblE)
    Project the Vector A along the Vector E
    static QR QRDecomposition​(double[][] aadblA)
    Perform a QR Decomposition on the Input Matrix
    static int Rank​(double[][] aadblSource)
    Compute the Rank of the Matrix
    static double RayleighQuotient​(double[][] matrix, double[] eigenvector)
    Compute the Rayleigh Quotient given the Matrix and one of its Eigenvector
    static boolean RegularizeUsingRowAddition​(MatrixComplementTransform mct)
    Regularize the specified diagonal entry of the input matrix using Row Addition
    static boolean RegularizeUsingRowSwap​(MatrixComplementTransform mct)
    Regularize the specified diagonal entry of the input matrix using Row Swapping
    static double[] Scale1D​(double[] vector, double scaleFactor)
    Scale the Entries of the Input Vector by the Factor
    static double[][] Scale2D​(double[][] matrix, double scaleFactor)
    Scale the Entries of the Input Matrix by the Factor
    static double Sum​(double[] adbl)
    Compute the Sum of the Input Vector
    static double[][] Transpose​(double[][] aadblA)
    Transpose the specified Square Matrix
    static int TriangularType​(double[][] aadblA, double dblFloor)
    Retrieve the Triangular Type of the Matrix

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOWER_TRIANGULAR

      public static int LOWER_TRIANGULAR
      Lower Triangular Matrix
    • UPPER_TRIANGULAR

      public static int UPPER_TRIANGULAR
      Upper Triangular Matrix
    • LOWER_AND_UPPER_TRIANGULAR

      public static int LOWER_AND_UPPER_TRIANGULAR
      Lower+Upper Triangular Matrix
    • NON_TRIANGULAR

      public static int NON_TRIANGULAR
      Non Triangular Matrix
  • Constructor Details

    • Matrix

      public Matrix()
  • Method Details

    • DiagonalizeRow

      public static final boolean DiagonalizeRow​(int iQ, double[][] aadblZ2XJack, double[][] aadblZ2YJack)
      Diagonalize the specified row in the source matrix, and apply comparable operations to the target
      Parameters:
      iQ - Row in the Source Matrix
      aadblZ2XJack - Source Matrix
      aadblZ2YJack - Target Matrix
      Returns:
      TRUE - Diagonalization was successful
    • Product

      public static final double[] Product​(double[][] aadblA, double[] adblB)
      Compute the Product of an Input Matrix and a Column
      Parameters:
      aadblA - Matrix A
      adblB - Array B
      Returns:
      The Product
    • Product

      public static final double[][] Product​(double[] adblA, double[][] aadblB)
      Compute the Product of an input column and a matrix
      Parameters:
      adblA - Column A
      aadblB - Matrix B
      Returns:
      The Product
    • Product

      public static final double[][] Product​(double[][] aadblA, double[][] aadblB)
      Compute the Product of the input matrices
      Parameters:
      aadblA - Matrix A
      aadblB - Matrix B
      Returns:
      The Product
    • MakeSquareDiagonal

      public static final double[][] MakeSquareDiagonal​(double[] adblA)
      Make a Square Diagonal Matrix from a Row
      Parameters:
      adblA - The Row Array
      Returns:
      The corresponding Square Diagonal Matrix
    • Invert2DMatrixUsingCramerRule

      public static final double[][] Invert2DMatrixUsingCramerRule​(double[][] aadblA)
      Invert a 2D Matrix using Cramer's Rule
      Parameters:
      aadblA - Input 2D Matrix
      Returns:
      The Inverted Matrix
    • RegularizeUsingRowSwap

      public static final boolean RegularizeUsingRowSwap​(MatrixComplementTransform mct)
      Regularize the specified diagonal entry of the input matrix using Row Swapping
      Parameters:
      mct - The Input Matrix Complement Transform
      Returns:
      The Regularization was successful
    • RegularizeUsingRowAddition

      public static final boolean RegularizeUsingRowAddition​(MatrixComplementTransform mct)
      Regularize the specified diagonal entry of the input matrix using Row Addition
      Parameters:
      mct - The Input Matrix Complement Transform
      Returns:
      The Regularization was successful
    • PivotDiagonal

      public static final MatrixComplementTransform PivotDiagonal​(double[][] aadblA)
      Pivot the Diagonal of the Input Matrix
      Parameters:
      aadblA - The Input Matrix
      Returns:
      The Matrix Complement Transform Instance
    • InvertUsingGaussianElimination

      public static final double[][] InvertUsingGaussianElimination​(double[][] aadblSource)
      Invert the Source Matrix using Gaussian Elimination
      Parameters:
      aadblSource - Source Matrix
      Returns:
      The Inverted Matrix
    • Invert

      public static final double[][] Invert​(double[][] aadblA, java.lang.String strMethod)
      Invert the input matrix using the specified Method
      Parameters:
      aadblA - Input Matrix
      strMethod - The Inversion Method
      Returns:
      The Inverted Matrix
    • Rank

      public static final int Rank​(double[][] aadblSource) throws java.lang.Exception
      Compute the Rank of the Matrix
      Parameters:
      aadblSource - Source Matrix
      Returns:
      The Rank of the Matrix
      Throws:
      java.lang.Exception - Thrown if the Rank Cannot be computed
    • Transpose

      public static final double[][] Transpose​(double[][] aadblA)
      Transpose the specified Square Matrix
      Parameters:
      aadblA - The Input Square Matrix
      Returns:
      The Transpose of the Square Matrix
    • CholeskyBanachiewiczFactorization

      public static final double[][] CholeskyBanachiewiczFactorization​(double[][] aadblA)
      Compute the Cholesky-Banachiewicz Factorization of the specified Matrix.
      Parameters:
      aadblA - The Input Matrix
      Returns:
      The Factorized Matrix
    • DotProduct

      public static final double DotProduct​(double[] adblA, double[] adblE) throws java.lang.Exception
      Dot Product of Vectors A and E
      Parameters:
      adblA - Vector A
      adblE - Vector E
      Returns:
      The Dot Product
      Throws:
      java.lang.Exception - Thrown if the Dot-Product cannot be computed
    • CrossProduct

      public static final double[][] CrossProduct​(double[] vector1, double[] vector2)
      Compute the Cross Product between the Specified Vectors
      Parameters:
      vector1 - Vector #1
      vector2 - Vector #2
      Returns:
      The Cross Product
    • Project

      public static final double[] Project​(double[] adblA, double[] adblE)
      Project the Vector A along the Vector E
      Parameters:
      adblA - Vector A
      adblE - Vector E
      Returns:
      The Vector of Projection of A along E
    • Sum

      public static final double Sum​(double[] adbl) throws java.lang.Exception
      Compute the Sum of the Input Vector
      Parameters:
      adbl - The Input Vector
      Returns:
      TRUE - The Sum of the Input Vector
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • Modulus

      public static final double Modulus​(double[] adbl) throws java.lang.Exception
      Compute the Modulus of the Input Vector
      Parameters:
      adbl - The Input Vector
      Returns:
      TRUE - The Modulus of the Input Vector
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • PositiveOrZero

      public static final boolean PositiveOrZero​(double[] adbl) throws java.lang.Exception
      Indicate if the Array Entries are Positive or Zero
      Parameters:
      adbl - The Array
      Returns:
      TRUE - The Array Entries are Positive or Zero
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • NegativeOrZero

      public static final boolean NegativeOrZero​(double[] adbl) throws java.lang.Exception
      Indicate if the Array Entries are Negative or Zero
      Parameters:
      adbl - The Array
      Returns:
      The Array Entries are Negative or Zero
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • PositiveLinearlyIndependent

      public static final boolean PositiveLinearlyIndependent​(double[] adbl) throws java.lang.Exception
      Indicate if the Array Entries are Positive Linearly Independent
      Parameters:
      adbl - The Array
      Returns:
      TRUE - The Array Entries are Positive Linearly Independent
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • Normalize

      public static final double[] Normalize​(double[] adbl)
      Normalize the Input Vector
      Parameters:
      adbl - The Input Vector
      Returns:
      The Normalized Vector
    • GrahamSchmidtOrthogonalization

      public static final double[][] GrahamSchmidtOrthogonalization​(double[][] aadblV)
      Orthogonalize the Specified Matrix Using the Graham-Schmidt Method
      Parameters:
      aadblV - The Input Matrix
      Returns:
      The Orthogonalized Matrix
    • GrahamSchmidtOrthonormalization

      public static final double[][] GrahamSchmidtOrthonormalization​(double[][] aadblV)
      Orthonormalize the Specified Matrix Using the Graham-Schmidt Method
      Parameters:
      aadblV - The Input Matrix
      Returns:
      The Orthonormalized Matrix
    • QRDecomposition

      public static final QR QRDecomposition​(double[][] aadblA)
      Perform a QR Decomposition on the Input Matrix
      Parameters:
      aadblA - The Input Matrix
      Returns:
      The Output of QR Decomposition
    • TriangularType

      public static final int TriangularType​(double[][] aadblA, double dblFloor)
      Retrieve the Triangular Type of the Matrix
      Parameters:
      aadblA - The Input Matrix
      dblFloor - The Floor Level that means "Zero"
      Returns:
      The Triangular Type
    • RayleighQuotient

      public static final double RayleighQuotient​(double[][] matrix, double[] eigenvector) throws java.lang.Exception
      Compute the Rayleigh Quotient given the Matrix and one of its Eigenvector
      Parameters:
      matrix - The Given Matrix
      eigenvector - The corresponding Eigenvector
      Returns:
      The Computed Rayleigh Quotient
      Throws:
      java.lang.Exception - Thrown if the Inputs are Invalid
    • Scale1D

      public static final double[] Scale1D​(double[] vector, double scaleFactor)
      Scale the Entries of the Input Vector by the Factor
      Parameters:
      vector - The Input Vector
      scaleFactor - The Scale Factor
      Returns:
      The Scaled Matrix
    • Scale2D

      public static final double[][] Scale2D​(double[][] matrix, double scaleFactor)
      Scale the Entries of the Input Matrix by the Factor
      Parameters:
      matrix - The Input Matrix
      scaleFactor - The Scale Factor
      Returns:
      The Scaled Matrix
    • IsDiagonal

      public static final boolean IsDiagonal​(double[][] matrix)
      Indicate if the Specified Matrix is Diagonal
      Parameters:
      matrix - The Matrix
      Returns:
      TRUE - The Specified Matrix is Diagonal