Class PCAMatrix

java.lang.Object
com.macrofocus.high_d.mds.pca.PCAMatrix

public class PCAMatrix extends Object
  • Constructor Details

    • 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:
      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:
      IllegalArgumentException - Array length must be a multiple of m.
  • Method Details

    • 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:
      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:
      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:
      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'