public class SparseMatrix extends java.lang.Object implements java.lang.Iterable<MatrixEntry>, DataMatrix, java.io.Serializable
Modifier and Type | Field and Description |
---|---|
double[] |
colData |
int[] |
colInd |
int[] |
colPtr |
boolean |
isShuffle |
int |
numColumns |
int |
numRows |
double[] |
rowData |
int[] |
rowInd |
int[] |
rowPtr |
int[] |
shuffleCursor |
int[] |
shuffleRow |
Constructor and Description |
---|
SparseMatrix(int rows,
int cols)
Define a sparse matrix without data, only use for
transpose method |
SparseMatrix(int rows,
int cols,
com.google.common.collect.Table<java.lang.Integer,java.lang.Integer,? extends java.lang.Number> dataTable)
Construct a sparse matrix with only CRS structures
|
SparseMatrix(int rows,
int cols,
com.google.common.collect.Table<java.lang.Integer,java.lang.Integer,? extends java.lang.Number> dataTable,
com.google.common.collect.Multimap<java.lang.Integer,java.lang.Integer> colMap)
Construct a sparse matrix with both CRS and CCS structures
|
SparseMatrix(SparseMatrix mat)
Construct a sparse matrix from another sparse matrix
|
SparseMatrix(SparseStringMatrix mat) |
Modifier and Type | Method and Description |
---|---|
void |
add(int row,
int column,
double val)
Add a value to entry [row, column]
|
SparseMatrix |
clone()
Make a deep clone of current matrix
|
java.util.Iterator<VectorEntry> |
colIterator(int row) |
SparseVector |
column(int col)
get a col sparse vector of a matrix
|
com.google.common.cache.LoadingCache<java.lang.Integer,SparseVector> |
columnCache(java.lang.String cacheSpec)
create a column cache of a matrix
|
com.google.common.cache.LoadingCache<java.lang.Integer,java.util.List<java.lang.Integer>> |
columnRowsCache(java.lang.String cacheSpec)
create a row cache of a matrix in {row, row-specific columns}
|
java.util.List<java.lang.Integer> |
columns() |
int |
columnSize(int col)
query the size of a specific col
|
boolean |
contains(int row,
int column)
Retrieve value at entry [row, column]
|
double |
get(int row,
int column)
Retrieve value at entry [row, column]
|
int[] |
getColumnIndices() |
java.util.List<java.lang.Integer> |
getColumns(int row)
get columns of a specific row where (row, column) entries are non-zero
|
java.util.Set<java.lang.Integer> |
getColumnsSet(int row)
get columns of a specific row where (row, column) entries are non-zero
|
double[] |
getData() |
com.google.common.collect.Table<java.lang.Integer,java.lang.Integer,java.lang.Double> |
getDataTable() |
int[] |
getRowPointers() |
java.util.List<java.lang.Integer> |
getRows(int col)
get rows of a specific column where (row, column) entries are non-zero
|
java.util.Set<java.lang.Integer> |
getRowsSet(int col)
get rows of a specific column where (row, column) entries are non-zero
|
java.util.Set<java.lang.Double> |
getValueSet() |
java.util.Iterator<MatrixEntry> |
iterator() |
java.lang.String |
matString() |
double |
mean() |
void |
normalize(double max)
Normalize the matrix entries to (0, 1) by (x/max)
|
void |
normalize(double min,
double max)
Normalize the matrix entries to (0, 1) by (x-min)/(max-min)
|
int |
numColumns() |
int |
numRows() |
SparseMatrix |
reshape(int rows,
int cols)
Return a new matrix with shape (rows, cols) with data from the current matrix.
|
static void |
reshape(SparseMatrix mat)
remove zero entries of the given matrix
|
SparseVector |
row(int row)
get a row sparse vector of a matrix
|
SparseVector |
row(int row,
int except)
get a row sparse vector of a matrix
|
com.google.common.cache.LoadingCache<java.lang.Integer,SparseVector> |
rowCache(java.lang.String cacheSpec)
create a row cache of a matrix in {row, row-specific vector}
|
com.google.common.cache.LoadingCache<java.lang.Integer,java.util.List<java.lang.Integer>> |
rowColumnsCache(java.lang.String cacheSpec)
create a row cache of a matrix in {row, row-specific columns}
|
com.google.common.cache.LoadingCache<java.lang.Integer,java.util.Set<java.lang.Integer>> |
rowColumnsSetCache(java.lang.String cacheSpec)
create a row cache of a matrix in {row, row-specific columns}
|
java.util.Iterator<VectorEntry> |
rowIterator(int col) |
java.util.List<java.lang.Integer> |
rows() |
int |
rowSize(int row)
query the size of a specific row
|
void |
set(int row,
int column,
double val)
Set a value to entry [row, column]
|
int |
size() |
void |
standardize(boolean isByRow)
Standardize the matrix entries by row- or column-wise z-scores (z=(x-u)/sigma)
|
double |
sum() |
java.lang.String |
toString() |
SparseMatrix |
transpose() |
public int numRows
public int numColumns
public double[] rowData
public int[] rowPtr
public int[] colInd
public double[] colData
public int[] colPtr
public int[] rowInd
public boolean isShuffle
public int[] shuffleRow
public int[] shuffleCursor
public SparseMatrix(int rows, int cols, com.google.common.collect.Table<java.lang.Integer,java.lang.Integer,? extends java.lang.Number> dataTable)
rows
- number of rowscols
- number of columnsdataTable
- data tablepublic SparseMatrix(int rows, int cols)
transpose
methodrows
- number of rowscols
- number of columnspublic SparseMatrix(int rows, int cols, com.google.common.collect.Table<java.lang.Integer,java.lang.Integer,? extends java.lang.Number> dataTable, com.google.common.collect.Multimap<java.lang.Integer,java.lang.Integer> colMap)
rows
- number of rowscols
- number of columnsdataTable
- data tablecolMap
- column mappublic SparseMatrix(SparseMatrix mat)
mat
- the original sparse matrixpublic SparseMatrix(SparseStringMatrix mat)
public SparseMatrix clone()
clone
in class java.lang.Object
public SparseMatrix transpose()
public int[] getRowPointers()
public int[] getColumnIndices()
public int size()
public com.google.common.collect.Table<java.lang.Integer,java.lang.Integer,java.lang.Double> getDataTable()
public int numRows()
public int numColumns()
public double[] getData()
public void set(int row, int column, double val)
set
in interface DataMatrix
row
- row idcolumn
- column idval
- value to setpublic void add(int row, int column, double val)
row
- row idcolumn
- column idval
- value to addpublic double get(int row, int column)
get
in interface DataMatrix
row
- row idcolumn
- column idpublic boolean contains(int row, int column)
row
- row idcolumn
- column idpublic SparseVector row(int row)
row
- row idpublic java.util.List<java.lang.Integer> getColumns(int row)
row
- row idpublic java.util.Set<java.lang.Integer> getColumnsSet(int row)
row
- row idpublic java.util.Set<java.lang.Integer> getRowsSet(int col)
col
- row idpublic com.google.common.cache.LoadingCache<java.lang.Integer,SparseVector> rowCache(java.lang.String cacheSpec)
cacheSpec
- cache specificationpublic com.google.common.cache.LoadingCache<java.lang.Integer,java.util.List<java.lang.Integer>> rowColumnsCache(java.lang.String cacheSpec)
cacheSpec
- cache specificationpublic com.google.common.cache.LoadingCache<java.lang.Integer,java.util.Set<java.lang.Integer>> rowColumnsSetCache(java.lang.String cacheSpec)
cacheSpec
- cache specificationpublic com.google.common.cache.LoadingCache<java.lang.Integer,SparseVector> columnCache(java.lang.String cacheSpec)
cacheSpec
- cache specificationpublic com.google.common.cache.LoadingCache<java.lang.Integer,java.util.List<java.lang.Integer>> columnRowsCache(java.lang.String cacheSpec)
cacheSpec
- cache specificationpublic SparseVector row(int row, int except)
row
- row idexcept
- row id to be excludedpublic int rowSize(int row)
row
- row idpublic java.util.List<java.lang.Integer> rows()
public SparseVector column(int col)
col
- col idpublic int columnSize(int col)
col
- col idpublic java.util.List<java.lang.Integer> getRows(int col)
col
- column idpublic java.util.List<java.lang.Integer> columns()
public double sum()
public double mean()
public void normalize(double min, double max)
min
- minimum valuemax
- maximum valuepublic void normalize(double max)
max
- maximum valuepublic void standardize(boolean isByRow)
isByRow
- standardize by row if true; otherwise by columnpublic static void reshape(SparseMatrix mat)
mat
- a given matrixpublic SparseMatrix reshape(int rows, int cols)
rows
- number of rowscols
- number of columnspublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String matString()
public java.util.Iterator<MatrixEntry> iterator()
iterator
in interface java.lang.Iterable<MatrixEntry>
public java.util.Iterator<VectorEntry> colIterator(int row)
public java.util.Iterator<VectorEntry> rowIterator(int col)
public java.util.Set<java.lang.Double> getValueSet()
Copyright © 2017. All Rights Reserved.