public class DenseMatrix extends Object implements 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.
Constructor and Description |
---|
DenseMatrix(int numRows,
int numCols,
double[] values)
Column-major dense matrix.
|
DenseMatrix(int numRows,
int numCols,
double[] values,
boolean isTransposed) |
Modifier and Type | Method and Description |
---|---|
double |
apply(int i,
int j)
Gets the (i, j)-th element.
|
DenseMatrix |
asML()
Convert this matrix to the new mllib-local representation.
|
scala.collection.Iterator<Vector> |
colIter()
Returns an iterator of column vectors.
|
DenseMatrix |
copy()
Get a deep copy of the matrix.
|
static DenseMatrix |
diag(Vector vector)
Generate a diagonal matrix in
DenseMatrix format from the supplied values. |
boolean |
equals(Object o) |
static DenseMatrix |
eye(int n)
Generate an Identity Matrix in
DenseMatrix format. |
static DenseMatrix |
fromML(DenseMatrix m)
Convert new linalg type to spark.mllib type.
|
int |
hashCode() |
boolean |
isTransposed()
Flag that keeps track whether the matrix is transposed or not.
|
int |
numActives()
Find the number of values stored explicitly.
|
int |
numCols()
Number of columns.
|
int |
numNonzeros()
Find the number of non-zero active values.
|
int |
numRows()
Number of rows.
|
static DenseMatrix |
ones(int numRows,
int numCols)
Generate a
DenseMatrix consisting of ones. |
static DenseMatrix |
rand(int numRows,
int numCols,
java.util.Random rng)
Generate a
DenseMatrix consisting of i.i.d. uniform random numbers. |
static DenseMatrix |
randn(int numRows,
int numCols,
java.util.Random rng)
Generate a
DenseMatrix consisting of i.i.d. gaussian random numbers. |
SparseMatrix |
toSparse()
Generate a
SparseMatrix from the given DenseMatrix . |
DenseMatrix |
transpose()
Transpose the Matrix.
|
double[] |
values() |
static DenseMatrix |
zeros(int numRows,
int numCols)
Generate a
DenseMatrix consisting of zeros. |
public DenseMatrix(int numRows, int numCols, double[] values, boolean isTransposed)
public DenseMatrix(int numRows, int numCols, double[] values)
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]
.
numRows
- number of rowsnumCols
- number of columnsvalues
- matrix entries in column majorpublic static DenseMatrix zeros(int numRows, int numCols)
DenseMatrix
consisting of zeros.numRows
- number of rows of the matrixnumCols
- number of columns of the matrixDenseMatrix
with size numRows
x numCols
and values of zerospublic static DenseMatrix ones(int numRows, int numCols)
DenseMatrix
consisting of ones.numRows
- number of rows of the matrixnumCols
- number of columns of the matrixDenseMatrix
with size numRows
x numCols
and values of onespublic static DenseMatrix eye(int n)
DenseMatrix
format.n
- number of rows and columns of the matrixDenseMatrix
with size n
x n
and values of ones on the diagonalpublic static DenseMatrix rand(int numRows, int numCols, java.util.Random rng)
DenseMatrix
consisting of i.i.d.
uniform random numbers.numRows
- number of rows of the matrixnumCols
- number of columns of the matrixrng
- a random number generatorDenseMatrix
with size numRows
x numCols
and values in U(0, 1)public static DenseMatrix randn(int numRows, int numCols, java.util.Random rng)
DenseMatrix
consisting of i.i.d.
gaussian random numbers.numRows
- number of rows of the matrixnumCols
- number of columns of the matrixrng
- a random number generatorDenseMatrix
with size numRows
x numCols
and values in N(0, 1)public static DenseMatrix diag(Vector vector)
DenseMatrix
format from the supplied values.vector
- a Vector
that will form the values on the diagonal of the matrixDenseMatrix
with size values.length
x values.length
and values
on the diagonalpublic static DenseMatrix fromML(DenseMatrix m)
m
- (undocumented)public int numRows()
Matrix
public int numCols()
Matrix
public double[] values()
public boolean isTransposed()
Matrix
isTransposed
in interface Matrix
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public double apply(int i, int j)
Matrix
public DenseMatrix copy()
Matrix
public DenseMatrix transpose()
Matrix
Matrix
instance sharing the same underlying data.public int numNonzeros()
Matrix
numNonzeros
in interface Matrix
public int numActives()
Matrix
numActives
in interface Matrix
public SparseMatrix toSparse()
SparseMatrix
from the given DenseMatrix
. The new matrix will have isTransposed
set to false.public scala.collection.Iterator<Vector> colIter()
Matrix
public DenseMatrix asML()
Matrix