public class DenseMatrix
extends java.lang.Object
Constructor and Description |
---|
DenseMatrix(DenseMatrix mat)
Construct a dense matrix by copying data from a given matrix
|
DenseMatrix(double[][] array)
Construct a dense matrix by copying data from a given 2D array
|
DenseMatrix(int numRows,
int numColumns)
Construct a dense matrix with specified dimensions
|
Modifier and Type | Method and Description |
---|---|
DenseMatrix |
add(DenseMatrix mat)
Do
A + B matrix operation |
void |
add(int row,
int column,
double val)
Add a value to entry [row, column]
|
DenseMatrix |
cholesky() |
DenseMatrix |
clone()
Make a deep copy of current matrix
|
static double |
colMult(DenseMatrix m,
int mcol,
DenseMatrix n,
int ncol)
column x column of two matrix
|
DenseVector |
column(int column) |
double |
columnMean(int column)
Compute mean of a column of the current matrix
|
DenseMatrix |
cov() |
static DenseMatrix |
eye(int dim)
Construct an identity matrix
|
double |
get(int row,
int column)
Get the value at entry [row, column]
|
void |
init()
initialize a dense matrix with small random values in (0, 1)
|
void |
init(double range)
initialize a dense matrix with small random values in (0, range)
|
void |
init(double mean,
double sigma)
Initialize a dense matrix with small Guassian values
NOTE: small initial values make it easier to train a model; otherwise a very small learning rate may be needed (especially when the number of factors is large) which can cause bad performance. |
DenseMatrix |
inv()
NOTE: this implementation (adopted from PREA package) is slightly faster
than
inverse , especailly when numRows is large. |
DenseMatrix |
inverse()
Deprecated.
use
inv instead which is slightly faster |
DenseMatrix |
mult(DenseMatrix mat)
Matrix multiplication with a dense matrix
|
DenseVector |
mult(DenseVector vec)
Do
matrix x vector between current matrix and a given vector |
DenseMatrix |
mult(SparseMatrix mat)
Matrix multiplication with a sparse matrix
|
static DenseMatrix |
mult(SparseMatrix sm,
DenseMatrix dm)
Matrix multiplication of a sparse matrix by a dense matrix
|
double |
norm() |
int |
numColumns() |
int |
numRows() |
static double |
product(DenseMatrix m,
int mrow,
DenseMatrix n,
int ncol)
dot product of row x col between two matrices
|
DenseVector |
row(int rowId) |
DenseVector |
row(int rowId,
boolean deep) |
static double |
rowMult(DenseMatrix m,
int mrow,
DenseMatrix n,
int nrow)
row x row of two matrix
|
DenseMatrix |
scale(double val) |
void |
set(int row,
int column,
double val)
Set a value to entry [row, column]
|
void |
setRow(int row,
double val)
set one value to the whole row
|
java.lang.String |
toString() |
DenseMatrix |
transpose() |
public DenseMatrix(int numRows, int numColumns)
numRows
- number of rowsnumColumns
- number of columnspublic DenseMatrix(double[][] array)
array
- data arraypublic DenseMatrix(DenseMatrix mat)
mat
- input matrixpublic DenseMatrix clone()
clone
in class java.lang.Object
public static DenseMatrix eye(int dim)
dim
- dimensionpublic void init(double mean, double sigma)
public void init(double range)
public void init()
public int numRows()
public int numColumns()
public DenseVector row(int rowId)
rowId
- row idpublic DenseVector row(int rowId, boolean deep)
rowId
- row iddeep
- whether to copy data or only shallow copy for executing
speedup purposepublic DenseVector column(int column)
column
- column idpublic double columnMean(int column)
column
- column idpublic double norm()
public static double rowMult(DenseMatrix m, int mrow, DenseMatrix n, int nrow)
m
- the first matrixmrow
- row of the first matrixn
- the second matrixnrow
- row of the second matrixpublic static double colMult(DenseMatrix m, int mcol, DenseMatrix n, int ncol)
m
- the first matrixmcol
- column of the first matrixn
- the second matrixncol
- column of the second matrixpublic static double product(DenseMatrix m, int mrow, DenseMatrix n, int ncol)
m
- the first matrixmrow
- row id of the first matrixn
- the second matrixncol
- column id of the second matrixpublic DenseMatrix mult(DenseMatrix mat)
mat
- a dense matrixpublic DenseMatrix mult(SparseMatrix mat)
mat
- a sparse matrixpublic DenseVector mult(DenseVector vec)
matrix x vector
between current matrix and a given vectormatrix x vector
public static DenseMatrix mult(SparseMatrix sm, DenseMatrix dm)
sm
- a sparse matrixdm
- a dense matrixpublic double get(int row, int column)
public void set(int row, int column, double val)
public void add(int row, int column, double val)
public DenseMatrix scale(double val)
public DenseMatrix add(DenseMatrix mat)
A + B
matrix operationC = A + B
public DenseMatrix cholesky()
public DenseMatrix transpose()
public DenseMatrix cov()
public DenseMatrix inverse()
inv
instead which is slightly fasterpublic DenseMatrix inv()
inverse
, especailly when numRows
is large.public void setRow(int row, double val)
row
- row idval
- value to be setpublic java.lang.String toString()
toString
in class java.lang.Object