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
ConstructorDescriptionDenseMatrix
(int numRows, int numCols, double[] values) Column-major dense matrix.DenseMatrix
(int numRows, int numCols, double[] values, boolean isTransposed) -
Method Summary
Modifier and TypeMethodDescriptiondouble
apply
(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 DenseMatrix
Generate a diagonal matrix inDenseMatrix
format from the supplied values.boolean
static DenseMatrix
eye
(int n) Generate an Identity Matrix inDenseMatrix
format.static DenseMatrix
Convert new linalg type to spark.mllib type.int
hashCode()
boolean
Flag that keeps track whether the matrix is transposed or not.int
Find the number of values stored explicitly.int
numCols()
Number of columns.int
Find the number of non-zero active values.int
numRows()
Number of rows.static DenseMatrix
ones
(int numRows, int numCols) Generate aDenseMatrix
consisting of ones.static DenseMatrix
Generate aDenseMatrix
consisting ofi.i.d.
uniform random numbers.static DenseMatrix
Generate aDenseMatrix
consisting ofi.i.d.
gaussian random numbers.toSparse()
Generate aSparseMatrix
from the givenDenseMatrix
.Transpose the Matrix.double[]
values()
static DenseMatrix
zeros
(int numRows, int numCols) Generate aDenseMatrix
consisting 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 aDenseMatrix
consisting of zeros.- Parameters:
numRows
- number of rows of the matrixnumCols
- number of columns of the matrix- Returns:
DenseMatrix
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:
DenseMatrix
with sizenumRows
xnumCols
and values of ones
-
eye
Generate an Identity Matrix inDenseMatrix
format.- Parameters:
n
- number of rows and columns of the matrix- Returns:
DenseMatrix
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:
DenseMatrix
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:
DenseMatrix
with sizenumRows
xnumCols
and values in N(0, 1)
-
diag
Generate a diagonal matrix inDenseMatrix
format from the supplied values.- Parameters:
vector
- aVector
that will form the values on the diagonal of the matrix- Returns:
- Square
DenseMatrix
with sizevalues.length
xvalues.length
andvalues
on 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:Matrix
Number of rows. -
numCols
public int numCols()Description copied from interface:Matrix
Number of columns. -
values
public double[] values() -
isTransposed
public boolean isTransposed()Description copied from interface:Matrix
Flag that keeps track whether the matrix is transposed or not. False by default.- Specified by:
isTransposed
in interfaceMatrix
-
equals
-
hashCode
public int hashCode() -
apply
public double apply(int i, int j) Description copied from interface:Matrix
Gets the (i, j)-th element. -
copy
Description copied from interface:Matrix
Get a deep copy of the matrix. -
transpose
Description copied from interface:Matrix
Transpose the Matrix. Returns a newMatrix
instance sharing the same underlying data. -
numNonzeros
public int numNonzeros()Description copied from interface:Matrix
Find the number of non-zero active values.- Specified by:
numNonzeros
in interfaceMatrix
- Returns:
- (undocumented)
-
numActives
public int numActives()Description copied from interface:Matrix
Find the number of values stored explicitly. These values can be zero as well.- Specified by:
numActives
in interfaceMatrix
- Returns:
- (undocumented)
-
toSparse
Generate aSparseMatrix
from the givenDenseMatrix
. The new matrix will have isTransposed set to false.- Returns:
- (undocumented)
-
colIter
Description copied from interface:Matrix
Returns an iterator of column vectors. This operation could be expensive, depending on the underlying storage. -
asML
Description copied from interface:Matrix
Convert this matrix to the new mllib-local representation. This does NOT copy the data; it copies references.
-