Package org.apache.spark.mllib.linalg
Class DenseMatrix
Object
org.apache.spark.mllib.linalg.DenseMatrix
- All Implemented Interfaces:
Serializable,Matrix
Column-major dense matrix.
The entry values are stored in a single array of doubles with columns listed in sequence.
For example, the following matrix
1.0 2.0
3.0 4.0
5.0 6.0
is stored as [1.0, 3.0, 5.0, 2.0, 4.0, 6.0].
param: numRows number of rows
param: numCols number of columns
param: values matrix entries in column major if not transposed or in row major otherwise
param: isTransposed whether the matrix is transposed. If true, values stores the matrix in
row major.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDenseMatrix(int numRows, int numCols, double[] values) Column-major dense matrix.DenseMatrix(int numRows, int numCols, double[] values, boolean isTransposed) -
Method Summary
Modifier and TypeMethodDescriptiondoubleapply(int i, int j) Gets the (i, j)-th element.asML()Convert this matrix to the new mllib-local representation.scala.collection.Iterator<Vector>colIter()Returns an iterator of column vectors.copy()Get a deep copy of the matrix.static DenseMatrixGenerate a diagonal matrix inDenseMatrixformat from the supplied values.booleanstatic DenseMatrixeye(int n) Generate an Identity Matrix inDenseMatrixformat.static DenseMatrixConvert new linalg type to spark.mllib type.inthashCode()booleanFlag that keeps track whether the matrix is transposed or not.intFind the number of values stored explicitly.intnumCols()Number of columns.intFind the number of non-zero active values.intnumRows()Number of rows.static DenseMatrixones(int numRows, int numCols) Generate aDenseMatrixconsisting of ones.static DenseMatrixGenerate aDenseMatrixconsisting ofi.i.d.uniform random numbers.static DenseMatrixGenerate aDenseMatrixconsisting ofi.i.d.gaussian random numbers.toSparse()Generate aSparseMatrixfrom the givenDenseMatrix.Transpose the Matrix.double[]values()static DenseMatrixzeros(int numRows, int numCols) Generate aDenseMatrixconsisting of zeros.
-
Constructor Details
-
DenseMatrix
public DenseMatrix(int numRows, int numCols, double[] values, boolean isTransposed) -
DenseMatrix
public DenseMatrix(int numRows, int numCols, double[] values) Column-major dense matrix. The entry values are stored in a single array of doubles with columns listed in sequence. For example, the following matrix
is stored as1.0 2.0 3.0 4.0 5.0 6.0[1.0, 3.0, 5.0, 2.0, 4.0, 6.0].- Parameters:
numRows- number of rowsnumCols- number of columnsvalues- matrix entries in column major
-
-
Method Details
-
zeros
Generate aDenseMatrixconsisting of zeros.- Parameters:
numRows- number of rows of the matrixnumCols- number of columns of the matrix- Returns:
DenseMatrixwith sizenumRowsxnumColsand values of zeros
-
ones
Generate aDenseMatrixconsisting of ones.- Parameters:
numRows- number of rows of the matrixnumCols- number of columns of the matrix- Returns:
DenseMatrixwith sizenumRowsxnumColsand values of ones
-
eye
Generate an Identity Matrix inDenseMatrixformat.- Parameters:
n- number of rows and columns of the matrix- Returns:
DenseMatrixwith 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:
DenseMatrixwith 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:
DenseMatrixwith sizenumRowsxnumColsand values in N(0, 1)
-
diag
Generate a diagonal matrix inDenseMatrixformat from the supplied values.- Parameters:
vector- aVectorthat will form the values on the diagonal of the matrix- Returns:
- Square
DenseMatrixwith sizevalues.lengthxvalues.lengthandvalueson the diagonal
-
fromML
Convert new linalg type to spark.mllib type. Light copy; only copies references- Parameters:
m- (undocumented)- Returns:
- (undocumented)
-
numRows
public int numRows()Description copied from interface:MatrixNumber of rows. -
numCols
public int numCols()Description copied from interface:MatrixNumber of columns. -
values
public double[] values() -
isTransposed
public boolean isTransposed()Description copied from interface:MatrixFlag that keeps track whether the matrix is transposed or not. False by default.- Specified by:
isTransposedin interfaceMatrix
-
equals
-
hashCode
public int hashCode() -
apply
public double apply(int i, int j) Description copied from interface:MatrixGets the (i, j)-th element. -
copy
Description copied from interface:MatrixGet a deep copy of the matrix. -
transpose
Description copied from interface:MatrixTranspose the Matrix. Returns a newMatrixinstance sharing the same underlying data. -
numNonzeros
public int numNonzeros()Description copied from interface:MatrixFind the number of non-zero active values.- Specified by:
numNonzerosin interfaceMatrix- Returns:
- (undocumented)
-
numActives
public int numActives()Description copied from interface:MatrixFind the number of values stored explicitly. These values can be zero as well.- Specified by:
numActivesin interfaceMatrix- Returns:
- (undocumented)
-
toSparse
Generate aSparseMatrixfrom the givenDenseMatrix. The new matrix will have isTransposed set to false.- Returns:
- (undocumented)
-
colIter
Description copied from interface:MatrixReturns an iterator of column vectors. This operation could be expensive, depending on the underlying storage. -
asML
Description copied from interface:MatrixConvert this matrix to the new mllib-local representation. This does NOT copy the data; it copies references.
-