Class Matrices

Object
org.apache.spark.ml.linalg.Matrices

public class Matrices extends Object
Factory methods for Matrix.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Matrix
    dense(int numRows, int numCols, double[] values)
    Creates a column-major dense matrix.
    static Matrix
    diag(Vector vector)
    Generate a diagonal matrix in Matrix format from the supplied values.
    static Matrix
    eye(int n)
    Generate a dense Identity Matrix in Matrix format.
    static Matrix
    horzcat(Matrix[] matrices)
    Horizontally concatenate a sequence of matrices.
    static Matrix
    ones(int numRows, int numCols)
    Generate a DenseMatrix consisting of ones.
    static Matrix
    rand(int numRows, int numCols, Random rng)
    Generate a DenseMatrix consisting of i.i.d. uniform random numbers.
    static Matrix
    randn(int numRows, int numCols, Random rng)
    Generate a DenseMatrix consisting of i.i.d. gaussian random numbers.
    static Matrix
    sparse(int numRows, int numCols, int[] colPtrs, int[] rowIndices, double[] values)
    Creates a column-major sparse matrix in Compressed Sparse Column (CSC) format.
    static Matrix
    speye(int n)
    Generate a sparse Identity Matrix in Matrix format.
    static Matrix
    sprand(int numRows, int numCols, double density, Random rng)
    Generate a SparseMatrix consisting of i.i.d. uniform random numbers.
    static Matrix
    sprandn(int numRows, int numCols, double density, Random rng)
    Generate a SparseMatrix consisting of i.i.d. gaussian random numbers.
    static Matrix
    vertcat(Matrix[] matrices)
    Vertically concatenate a sequence of matrices.
    static Matrix
    zeros(int numRows, int numCols)
    Generate a Matrix consisting of zeros.

    Methods inherited from class java.lang.Object

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

    • Matrices

      public Matrices()
  • Method Details

    • dense

      public static Matrix dense(int numRows, int numCols, double[] values)
      Creates a column-major dense matrix.

      Parameters:
      numRows - number of rows
      numCols - number of columns
      values - matrix entries in column major
      Returns:
      (undocumented)
    • sparse

      public static Matrix sparse(int numRows, int numCols, int[] colPtrs, int[] rowIndices, double[] values)
      Creates a column-major sparse matrix in Compressed Sparse Column (CSC) format.

      Parameters:
      numRows - number of rows
      numCols - number of columns
      colPtrs - the index corresponding to the start of a new column
      rowIndices - the row index of the entry
      values - non-zero matrix entries in column major
      Returns:
      (undocumented)
    • zeros

      public static Matrix zeros(int numRows, int numCols)
      Generate a Matrix consisting of zeros.
      Parameters:
      numRows - number of rows of the matrix
      numCols - number of columns of the matrix
      Returns:
      Matrix with size numRows x numCols and values of zeros
    • ones

      public static Matrix ones(int numRows, int numCols)
      Generate a DenseMatrix consisting of ones.
      Parameters:
      numRows - number of rows of the matrix
      numCols - number of columns of the matrix
      Returns:
      Matrix with size numRows x numCols and values of ones
    • eye

      public static Matrix eye(int n)
      Generate a dense Identity Matrix in Matrix format.
      Parameters:
      n - number of rows and columns of the matrix
      Returns:
      Matrix with size n x n and values of ones on the diagonal
    • speye

      public static Matrix speye(int n)
      Generate a sparse Identity Matrix in Matrix format.
      Parameters:
      n - number of rows and columns of the matrix
      Returns:
      Matrix with size n x n and values of ones on the diagonal
    • rand

      public static Matrix rand(int numRows, int numCols, Random rng)
      Generate a DenseMatrix consisting of i.i.d. uniform random numbers.
      Parameters:
      numRows - number of rows of the matrix
      numCols - number of columns of the matrix
      rng - a random number generator
      Returns:
      Matrix with size numRows x numCols and values in U(0, 1)
    • sprand

      public static Matrix sprand(int numRows, int numCols, double density, Random rng)
      Generate a SparseMatrix consisting of i.i.d. uniform random numbers.
      Parameters:
      numRows - number of rows of the matrix
      numCols - number of columns of the matrix
      density - the desired density for the matrix
      rng - a random number generator
      Returns:
      Matrix with size numRows x numCols and values in U(0, 1)
    • randn

      public static Matrix randn(int numRows, int numCols, Random rng)
      Generate a DenseMatrix consisting of i.i.d. gaussian random numbers.
      Parameters:
      numRows - number of rows of the matrix
      numCols - number of columns of the matrix
      rng - a random number generator
      Returns:
      Matrix with size numRows x numCols and values in N(0, 1)
    • sprandn

      public static Matrix sprandn(int numRows, int numCols, double density, Random rng)
      Generate a SparseMatrix consisting of i.i.d. gaussian random numbers.
      Parameters:
      numRows - number of rows of the matrix
      numCols - number of columns of the matrix
      density - the desired density for the matrix
      rng - a random number generator
      Returns:
      Matrix with size numRows x numCols and values in N(0, 1)
    • diag

      public static Matrix diag(Vector vector)
      Generate a diagonal matrix in Matrix format from the supplied values.
      Parameters:
      vector - a Vector that will form the values on the diagonal of the matrix
      Returns:
      Square Matrix with size values.length x values.length and values on the diagonal
    • horzcat

      public static Matrix horzcat(Matrix[] matrices)
      Horizontally concatenate a sequence of matrices. The returned matrix will be in the format the matrices are supplied in. Supplying a mix of dense and sparse matrices will result in a sparse matrix. If the Array is empty, an empty DenseMatrix will be returned.
      Parameters:
      matrices - array of matrices
      Returns:
      a single Matrix composed of the matrices that were horizontally concatenated
    • vertcat

      public static Matrix vertcat(Matrix[] matrices)
      Vertically concatenate a sequence of matrices. The returned matrix will be in the format the matrices are supplied in. Supplying a mix of dense and sparse matrices will result in a sparse matrix. If the Array is empty, an empty DenseMatrix will be returned.
      Parameters:
      matrices - array of matrices
      Returns:
      a single Matrix composed of the matrices that were vertically concatenated