Package org.apache.spark.mllib.linalg
Class Matrices
Object
org.apache.spark.mllib.linalg.Matrices
Factory methods for 
Matrix.- 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionstatic Matrixdense(int numRows, int numCols, double[] values) Creates a column-major dense matrix.static MatrixGenerate a diagonal matrix inMatrixformat from the supplied values.static Matrixeye(int n) Generate a dense Identity Matrix inMatrixformat.static MatrixConvert new linalg type to spark.mllib type.static MatrixHorizontally concatenate a sequence of matrices.static Matrixones(int numRows, int numCols) Generate aDenseMatrixconsisting of ones.static MatrixGenerate aDenseMatrixconsisting ofi.i.d.uniform random numbers.static MatrixGenerate aDenseMatrixconsisting ofi.i.d.gaussian random numbers.static Matrixsparse(int numRows, int numCols, int[] colPtrs, int[] rowIndices, double[] values) Creates a column-major sparse matrix in Compressed Sparse Column (CSC) format.static Matrixspeye(int n) Generate a sparse Identity Matrix inMatrixformat.static MatrixGenerate aSparseMatrixconsisting ofi.i.d.uniform random numbers.static MatrixGenerate aSparseMatrixconsisting ofi.i.d.gaussian random numbers.static MatrixVertically concatenate a sequence of matrices.static Matrixzeros(int numRows, int numCols) Generate aMatrixconsisting 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 aMatrixconsisting of zeros.- Parameters:
 numRows- number of rows of the matrixnumCols- number of columns of the matrix- Returns:
 Matrixwith sizenumRowsxnumColsand values of zeros
 - 
ones
Generate aDenseMatrixconsisting of ones.- Parameters:
 numRows- number of rows of the matrixnumCols- number of columns of the matrix- Returns:
 Matrixwith sizenumRowsxnumColsand values of ones
 - 
eye
Generate a dense Identity Matrix inMatrixformat.- Parameters:
 n- number of rows and columns of the matrix- Returns:
 Matrixwith sizenxnand values of ones on the diagonal
 - 
speye
Generate a sparse Identity Matrix inMatrixformat.- Parameters:
 n- number of rows and columns of the matrix- Returns:
 Matrixwith sizenxnand values of ones on the diagonal
 - 
rand
Generate aDenseMatrixconsisting 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:
 Matrixwith sizenumRowsxnumColsand values in U(0, 1)
 - 
sprand
Generate aSparseMatrixconsisting 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:
 Matrixwith sizenumRowsxnumColsand values in U(0, 1)
 - 
randn
Generate aDenseMatrixconsisting 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:
 Matrixwith sizenumRowsxnumColsand values in N(0, 1)
 - 
sprandn
Generate aSparseMatrixconsisting 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:
 Matrixwith sizenumRowsxnumColsand values in N(0, 1)
 - 
diag
Generate a diagonal matrix inMatrixformat from the supplied values.- Parameters:
 vector- aVectorthat will form the values on the diagonal of the matrix- Returns:
 - Square 
Matrixwith sizevalues.lengthxvalues.lengthandvalueson 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 emptyDenseMatrixwill be returned.- Parameters:
 matrices- array of matrices- Returns:
 - a single 
Matrixcomposed 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 emptyDenseMatrixwill be returned.- Parameters:
 matrices- array of matrices- Returns:
 - a single 
Matrixcomposed of the matrices that were vertically concatenated 
 - 
fromML
Convert new linalg type to spark.mllib type. Light copy; only copies references- Parameters:
 m- (undocumented)- Returns:
 - (undocumented)
 
 
 -