Class PCAMatrix


  • public class PCAMatrix
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      PCAMatrix​(double[][] A)
      Construct a matrix from a 2-D array.
      PCAMatrix​(double[][] A, int m, int n)
      Construct a matrix quickly without checking arguments.
      PCAMatrix​(double[] vals, int m)
      Construct a matrix from a one-dimensional packed array
      PCAMatrix​(int m, int n)
      Construct an m-by-n matrix of zeros.
      PCAMatrix​(int m, int n, double s)
      Construct an m-by-n constant matrix.
    • Constructor Detail

      • PCAMatrix

        public PCAMatrix​(int m,
                         int n)
        Construct an m-by-n matrix of zeros.
        Parameters:
        m - Number of rows.
        n - Number of colums.
      • PCAMatrix

        public PCAMatrix​(int m,
                         int n,
                         double s)
        Construct an m-by-n constant matrix.
        Parameters:
        m - Number of rows.
        n - Number of colums.
        s - Fill the matrix with this scalar value.
      • PCAMatrix

        public PCAMatrix​(double[][] A)
        Construct a matrix from a 2-D array.
        Parameters:
        A - Two-dimensional array of doubles.
        Throws:
        java.lang.IllegalArgumentException - All rows must have the same length
      • PCAMatrix

        public PCAMatrix​(double[][] A,
                         int m,
                         int n)
        Construct a matrix quickly without checking arguments.
        Parameters:
        A - Two-dimensional array of doubles.
        m - Number of rows.
        n - Number of colums.
      • PCAMatrix

        public PCAMatrix​(double[] vals,
                         int m)
        Construct a matrix from a one-dimensional packed array
        Parameters:
        vals - One-dimensional array of doubles, packed by columns (ala Fortran).
        m - Number of rows.
        Throws:
        java.lang.IllegalArgumentException - Array length must be a multiple of m.
    • Method Detail

      • identity

        public static PCAMatrix identity​(int m,
                                         int n)
        Generate identity matrix
        Parameters:
        m - Number of rows.
        n - Number of colums.
        Returns:
        An m-by-n matrix with ones on the diagonal and zeros elsewhere.
      • getArray

        public double[][] getArray()
        Access the internal two-dimensional array.
        Returns:
        Pointer to the two-dimensional array of matrix elements.
      • random

        public static PCAMatrix random​(int m,
                                       int n)
        Generate matrix with random elements
        Parameters:
        m - Number of rows.
        n - Number of colums.
        Returns:
        An m-by-n matrix with uniformly distributed random elements.
      • hypot

        public static double hypot​(double a,
                                   double b)
        sqrt(a^2 + b^2) without under/overflow.
      • copy

        public PCAMatrix copy()
        Make a deep copy of a matrix
      • getArrayCopy

        public double[][] getArrayCopy()
        Copy the internal two-dimensional array.
        Returns:
        Two-dimensional array copy of matrix elements.
      • getRowDimension

        public int getRowDimension()
        Get row dimension.
        Returns:
        m, the number of rows.
      • getColumnDimension

        public int getColumnDimension()
        Get column dimension.
        Returns:
        n, the number of columns.
      • get

        public double get​(int i,
                          int j)
        Get a single element.
        Parameters:
        i - Row index.
        j - Column index.
        Returns:
        A(i, j)
        Throws:
        java.lang.ArrayIndexOutOfBoundsException
      • set

        public void set​(int i,
                        int j,
                        double s)
        Set a single element.
        Parameters:
        i - Row index.
        j - Column index.
        s - A(i,j).
        Throws:
        java.lang.ArrayIndexOutOfBoundsException
      • times

        public PCAMatrix times​(double s)
        Multiply a matrix by a scalar, C = s*A
        Parameters:
        s - scalar
        Returns:
        s*A
      • minus

        public PCAMatrix minus​(PCAMatrix B)
        C = A - B
        Parameters:
        B - another matrix
        Returns:
        A - B
      • times

        public PCAMatrix times​(PCAMatrix B)
        Linear algebraic matrix multiplication, A * B
        Parameters:
        B - another matrix
        Returns:
        Matrix product, A * B
        Throws:
        java.lang.IllegalArgumentException - Matrix inner dimensions must agree.
      • trace

        public double trace()
        Matrix trace.
        Returns:
        sum of the diagonal elements.
      • transpose

        public PCAMatrix transpose()
        Matrix transpose.
        Returns:
        A'