public interface SparseDataset extends Dataset<smile.util.SparseArray>
LIL is typically used to construct the matrix. Once the matrix is constructed, it is typically converted to a format, such as Harwell-Boeing column-compressed sparse matrix format, which is more efficient for matrix operations.
| Modifier and Type | Method and Description |
|---|---|
static SparseDataset |
from(java.nio.file.Path path)
Parses spare dataset in coordinate triple tuple list format.
|
static SparseDataset |
from(java.nio.file.Path path,
int arrayIndexOrigin)
Reads spare dataset in coordinate triple tuple list format.
|
default double |
get(int i,
int j)
Returns the value at entry (i, j).
|
int |
ncols()
Returns the number of columns.
|
default int |
nrows()
Returns the number of rows.
|
int |
nz()
Returns the number of nonzero entries.
|
int |
nz(int j)
Returns the number of nonzero entries in column j.
|
static SparseDataset |
of(java.util.Collection<smile.util.SparseArray> data)
Returns a default implementation of SparseDataset from a collection.
|
static SparseDataset |
of(java.util.Collection<smile.util.SparseArray> data,
int ncols)
Returns a default implementation of SparseDataset from a collection.
|
static SparseDataset |
of(Dataset<Instance<smile.util.SparseArray>> data)
Strips the response variable and returns a SparseDataset.
|
static SparseDataset |
of(java.util.stream.Stream<smile.util.SparseArray> data)
Returns a default implementation of SparseDataset from a collection.
|
default smile.math.matrix.SparseMatrix |
toMatrix()
Convert into Harwell-Boeing column-compressed sparse matrix format.
|
default void |
unitize()
Unitize each row so that L2 norm of x = 1.
|
default void |
unitize1()
Unitize each row so that L1 norm of x is 1.
|
int nz()
int nz(int j)
default int nrows()
int ncols()
default double get(int i,
int j)
i - the row index.j - the column index.default void unitize()
default void unitize1()
default smile.math.matrix.SparseMatrix toMatrix()
static SparseDataset of(java.util.stream.Stream<smile.util.SparseArray> data)
data - sparse arrays.static SparseDataset of(java.util.Collection<smile.util.SparseArray> data)
data - sparse arrays.static SparseDataset of(java.util.Collection<smile.util.SparseArray> data, int ncols)
data - sparse arrays.ncols - the number of columns.static SparseDataset of(Dataset<Instance<smile.util.SparseArray>> data)
static SparseDataset from(java.nio.file.Path path) throws java.io.IOException, java.text.ParseException
path - the input file path.java.io.IOExceptionjava.text.ParseExceptionstatic SparseDataset from(java.nio.file.Path path, int arrayIndexOrigin) throws java.io.IOException, java.text.ParseException
instanceID attributeID value instanceID attributeID value instanceID attributeID value instanceID attributeID value ... instanceID attributeID value instanceID attributeID value instanceID attributeID valueIdeally, the entries are sorted (by row index, then column index) to improve random access times. This format is good for incremental matrix construction.
In addition, there may a header line
D W N // The number of rows, columns and nonzero entries.or 3 header lines
D // The number of rows W // The number of columns N // The total number of nonzero entries in the dataset.
path - the input file path.arrayIndexOrigin - the starting index of array. By default, it is
0 as in C/C++ and Java. But it could be 1 to parse data produced
by other programming language such as Fortran.java.io.IOException - if stream to file cannot be read or closed.java.text.ParseException - if an index is not an integer or the value is not a double.