Package org.apache.spark.ml.linalg
Class Matrices
Object
org.apache.spark.ml.linalg.Matrices
Factory methods for
Matrix
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Matrix
dense
(int numRows, int numCols, double[] values) Creates a column-major dense matrix.static Matrix
Generate a diagonal matrix inMatrix
format from the supplied values.static Matrix
eye
(int n) Generate a dense Identity Matrix inMatrix
format.static Matrix
Horizontally concatenate a sequence of matrices.static Matrix
ones
(int numRows, int numCols) Generate aDenseMatrix
consisting of ones.static Matrix
Generate aDenseMatrix
consisting ofi.i.d.
uniform random numbers.static Matrix
Generate aDenseMatrix
consisting ofi.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 inMatrix
format.static Matrix
Generate aSparseMatrix
consisting ofi.i.d.
uniform random numbers.static Matrix
Generate aSparseMatrix
consisting ofi.i.d.
gaussian random numbers.static Matrix
Vertically concatenate a sequence of matrices.static Matrix
zeros
(int numRows, int numCols) Generate aMatrix
consisting of zeros.
-
Constructor Details
-
Matrices
public Matrices()
-
-
Method Details
-
dense
Creates a column-major dense matrix.- Parameters:
numRows
- number of rowsnumCols
- number of columnsvalues
- 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 rowsnumCols
- number of columnscolPtrs
- the index corresponding to the start of a new columnrowIndices
- the row index of the entryvalues
- non-zero matrix entries in column major- Returns:
- (undocumented)
-
zeros
Generate aMatrix
consisting of zeros.- Parameters:
numRows
- number of rows of the matrixnumCols
- number of columns of the matrix- Returns:
Matrix
with sizenumRows
xnumCols
and values of zeros
-
ones
Generate aDenseMatrix
consisting of ones.- Parameters:
numRows
- number of rows of the matrixnumCols
- number of columns of the matrix- Returns:
Matrix
with sizenumRows
xnumCols
and values of ones
-
eye
Generate a dense Identity Matrix inMatrix
format.- Parameters:
n
- number of rows and columns of the matrix- Returns:
Matrix
with sizen
xn
and values of ones on the diagonal
-
speye
Generate a sparse Identity Matrix inMatrix
format.- Parameters:
n
- number of rows and columns of the matrix- Returns:
Matrix
with sizen
xn
and values of ones on the diagonal
-
rand
Generate aDenseMatrix
consisting ofi.i.d.
uniform random numbers.- Parameters:
numRows
- number of rows of the matrixnumCols
- number of columns of the matrixrng
- a random number generator- Returns:
Matrix
with sizenumRows
xnumCols
and values in U(0, 1)
-
sprand
Generate aSparseMatrix
consisting ofi.i.d.
uniform random numbers.- Parameters:
numRows
- number of rows of the matrixnumCols
- number of columns of the matrixdensity
- the desired density for the matrixrng
- a random number generator- Returns:
Matrix
with sizenumRows
xnumCols
and values in U(0, 1)
-
randn
Generate aDenseMatrix
consisting ofi.i.d.
gaussian random numbers.- Parameters:
numRows
- number of rows of the matrixnumCols
- number of columns of the matrixrng
- a random number generator- Returns:
Matrix
with sizenumRows
xnumCols
and values in N(0, 1)
-
sprandn
Generate aSparseMatrix
consisting ofi.i.d.
gaussian random numbers.- Parameters:
numRows
- number of rows of the matrixnumCols
- number of columns of the matrixdensity
- the desired density for the matrixrng
- a random number generator- Returns:
Matrix
with sizenumRows
xnumCols
and values in N(0, 1)
-
diag
Generate a diagonal matrix inMatrix
format from the supplied values.- Parameters:
vector
- aVector
that will form the values on the diagonal of the matrix- Returns:
- Square
Matrix
with sizevalues.length
xvalues.length
andvalues
on the diagonal
-
horzcat
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 emptyDenseMatrix
will be returned.- Parameters:
matrices
- array of matrices- Returns:
- a single
Matrix
composed of the matrices that were horizontally concatenated
-
vertcat
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 emptyDenseMatrix
will be returned.- Parameters:
matrices
- array of matrices- Returns:
- a single
Matrix
composed of the matrices that were vertically concatenated
-