Package org.apache.spark.ml.linalg
Class DenseMatrix
Object
org.apache.spark.ml.linalg.DenseMatrix
- All Implemented Interfaces:
Serializable
,Matrix
,scala.Serializable
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.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.void
foreachActive
(scala.Function3<Object, Object, Object, scala.runtime.BoxedUnit> f) Applies a functionf
to all the active elements of dense and sparse matrix.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.Transpose the Matrix.double[]
values()
static DenseMatrix
zeros
(int numRows, int numCols) Generate aDenseMatrix
consisting of zeros.Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.spark.ml.linalg.Matrix
compressed, compressedColMajor, compressedRowMajor, getDenseSizeInBytes, getSparseSizeInBytes, isColMajor, isRowMajor, multiply, multiply, multiply, rowIter, toArray, toDense, toDenseColMajor, toDenseRowMajor, toSparse, toSparseColMajor, toSparseRowMajor, toString, toString
-
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
-
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. -
foreachActive
Description copied from interface:Matrix
Applies a functionf
to all the active elements of dense and sparse matrix. The ordering of the elements are not defined.- Specified by:
foreachActive
in interfaceMatrix
- Parameters:
f
- the function takes three parameters where the first two parameters are the row and column indices respectively with the typeInt
, and the final parameter is the corresponding value in the matrix with typeDouble
.
-
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)
-
colIter
Description copied from interface:Matrix
Returns an iterator of column vectors. This operation could be expensive, depending on the underlying storage.
-