public class SparseMatrix extends Matrix
QR
or lup()
decompositions.
transposeMultiply(jsat.linear.Matrix, jsat.linear.Matrix, java.util.concurrent.ExecutorService)
currently does not use multiple cores.Modifier | Constructor and Description |
---|---|
|
SparseMatrix(int rows,
int cols)
Creates a new sparse matrix
|
|
SparseMatrix(int rows,
int cols,
int rowCapacity)
Creates a new sparse matrix
|
protected |
SparseMatrix(SparseMatrix toCopy)
Copy constructor
|
|
SparseMatrix(SparseVector[] rows)
Creates a new Sparse Matrix backed by the given array of SpareVectors.
|
Modifier and Type | Method and Description |
---|---|
void |
changeSize(int newRows,
int newCols)
This method alters the size of a matrix, either adding or subtracting
rows from the internal structure of the matrix.
|
SparseMatrix |
clone() |
int |
cols()
Returns the number of columns stored in this matrix
|
double |
get(int i,
int j)
Returns the value stored at at the matrix position Ai,j
|
Vec |
getRowView(int r)
Obtains a vector that is backed by this, at very little memory
cost.
|
void |
increment(int i,
int j,
double value)
Alters the current matrix at index (i,j) to be equal to
Ai,j = Ai,j + value
|
boolean |
isSparce()
Returns
true if the matrix is sparse, false otherwise |
Matrix[] |
lup() |
Matrix[] |
lup(ExecutorService threadPool) |
void |
multiply(Matrix B,
Matrix C)
Alters the matrix C to be equal to C = C+A*B
|
void |
multiply(Matrix B,
Matrix C,
ExecutorService threadPool)
Alters the matrix C to be equal to C = C+A*B
|
void |
multiply(Vec b,
double z,
Vec c)
If this matrix is Am x n, and b has a length of n, and c has a length of m,
then this will mutate c to store c = c + A*b*z
|
void |
multiplyTranspose(Matrix B,
Matrix C)
Alters the matrix C to be equal to C = C+A*BT
|
void |
multiplyTranspose(Matrix B,
Matrix C,
ExecutorService threadPool)
Alters the matrix C to be equal to C = C+A*BT
|
void |
mutableAdd(double c)
Alters the current matrix to store the value A+c
|
void |
mutableAdd(double c,
ExecutorService threadPool)
Alters the current matrix to store the value A+c
|
void |
mutableAdd(double c,
Matrix B)
Alters the current matrix to store the value A+c*B
|
void |
mutableAdd(double c,
Matrix B,
ExecutorService threadPool)
Alters the current matrix to store the value A+c*B
|
void |
mutableMultiply(double c)
Alters the current matrix to be equal to A*c
|
void |
mutableMultiply(double c,
ExecutorService threadPool)
Alters the current matrix to be equal to A*c
|
void |
mutableTranspose()
Transposes the current matrix in place, altering its value.
|
long |
nnz()
Returns the number of non zero values stored in this matrix.
|
Matrix[] |
qr() |
Matrix[] |
qr(ExecutorService threadPool) |
int |
rows()
Returns the number of rows stored in this matrix
|
void |
set(int i,
int j,
double value)
Sets the value stored at at the matrix position Ai,j
|
void |
swapRows(int r1,
int r2)
Alters the current matrix by swapping the values stored in two different
rows.
|
void |
transpose(Matrix C)
Overwrites the values stored in matrix C to store the value of
A'
|
void |
transposeMultiply(double c,
Vec b,
Vec x)
Alters the vector x to be equal to x = x + A'*b*c
|
void |
transposeMultiply(Matrix B,
Matrix C)
Alters the matrix C so that C = C + A'*B
|
void |
transposeMultiply(Matrix B,
Matrix C,
ExecutorService threadPool)
Alters the matrix C so that C = C + A'*B
|
void |
zeroOut()
Alters the current matrix so that all values are equal to zero.
|
add, add, add, add, canBeMutated, canMultiply, copyTo, diag, diagMult, diagMult, equals, equals, eye, getColumn, getColumnView, getRow, isSquare, isSymmetric, isSymmetric, multiply, multiply, multiply, multiply, multiply, multiplyTranspose, multiplyTranspose, mutableAdd, mutableAdd, mutableSubtract, mutableSubtract, mutableSubtract, mutableSubtract, mutableSubtract, mutableSubtract, OuterProductUpdate, OuterProductUpdate, pascal, random, sameDimensions, subtract, subtract, subtract, subtract, toString, transpose, transposeMultiply, transposeMultiply, transposeMultiply, updateRow
public SparseMatrix(int rows, int cols, int rowCapacity)
rows
- the number of rows for the matrixcols
- the number of columns for the matrixrowCapacity
- the initial capacity for non zero values for each rowpublic SparseMatrix(SparseVector[] rows)
rows
- the array to back this SparseMatrixpublic SparseMatrix(int rows, int cols)
rows
- the number of rows for the matrixcols
- the number of columns for the matrixprotected SparseMatrix(SparseMatrix toCopy)
toCopy
- the object to copypublic void mutableAdd(double c, Matrix B)
Matrix
mutableAdd
in class Matrix
c
- the scalar constant to multiple B byB
- the matrix to add to thispublic void mutableAdd(double c, Matrix B, ExecutorService threadPool)
Matrix
mutableAdd
in class Matrix
c
- the scalar constant to multiple B byB
- the matrix to add to thisthreadPool
- the source of threads to do computation in parallelpublic void mutableAdd(double c)
Matrix
mutableAdd
in class Matrix
c
- the scalar constant to add to thispublic void mutableAdd(double c, ExecutorService threadPool)
Matrix
mutableAdd
in class Matrix
c
- the scalar constant to add to thisthreadPool
- the source of threads to do computation in parallelpublic void multiply(Vec b, double z, Vec c)
Matrix
public void multiply(Matrix B, Matrix C)
Matrix
public void multiply(Matrix B, Matrix C, ExecutorService threadPool)
Matrix
public void mutableMultiply(double c)
Matrix
mutableMultiply
in class Matrix
c
- the scalar constant to multiply bypublic void mutableMultiply(double c, ExecutorService threadPool)
Matrix
mutableMultiply
in class Matrix
c
- the scalar constant to multiply bythreadPool
- the source of threads to do computation in parallelpublic Matrix[] lup(ExecutorService threadPool)
public Matrix[] qr(ExecutorService threadPool)
public void mutableTranspose()
Matrix
mutableTranspose
in class Matrix
public void transpose(Matrix C)
Matrix
public void transposeMultiply(Matrix B, Matrix C)
Matrix
transposeMultiply
in class Matrix
B
- the matrix to multiply byC
- the matrix to add the result topublic void transposeMultiply(Matrix B, Matrix C, ExecutorService threadPool)
Matrix
transposeMultiply
in class Matrix
B
- the matrix to multiply byC
- the matrix to place the results inthreadPool
- the source of threads to do computation in parallelpublic void transposeMultiply(double c, Vec b, Vec x)
Matrix
transposeMultiply
in class Matrix
c
- the scalar constant to multiply byb
- the vector to multiply byx
- the vector the add the result topublic Vec getRowView(int r)
Matrix
getRowView
in class Matrix
r
- the row to obtain a view ofpublic double get(int i, int j)
Matrix
public void set(int i, int j, double value)
Matrix
public void increment(int i, int j, double value)
Matrix
public int rows()
Matrix
public int cols()
Matrix
public boolean isSparce()
Matrix
true
if the matrix is sparse, false
otherwisepublic void swapRows(int r1, int r2)
Matrix
public void zeroOut()
Matrix
public SparseMatrix clone()
public long nnz()
Matrix
public void changeSize(int newRows, int newCols)
Matrix
changeSize
in class Matrix
newRows
- the new number of rows, must be positivenewCols
- the new number of columns, must be positive.public void multiplyTranspose(Matrix B, Matrix C)
Matrix
multiplyTranspose
in class Matrix
B
- the matrix to multiply this withC
- the matrix to add the result topublic void multiplyTranspose(Matrix B, Matrix C, ExecutorService threadPool)
Matrix
multiplyTranspose
in class Matrix
B
- the matrix to multiply this withC
- the matrix to add the result tothreadPool
- the source of threads to do computation in parallelCopyright © 2017. All rights reserved.