public class SparseVector extends java.lang.Object implements java.lang.Iterable<VectorEntry>, java.io.Serializable
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoCompress |
protected int |
capacity |
protected int |
count |
protected double[] |
data |
protected int[] |
index |
protected int |
zeroCount |
protected int |
zeroFirstIndex |
Constructor and Description |
---|
SparseVector(int capcity)
Construct a sparse vector with its maximum capacity
|
SparseVector(int capcity,
double[] array)
Construct a sparse vector with its maximum capacity, filled with given
data array
|
SparseVector(int capcity,
int dataLength)
Construct a sparse vector with its maximum capacity
|
SparseVector(int capacity,
int[] index,
double[] data)
Construct a sparse vector by deeply copying with tis maximum capacity, indices to data, and data
|
SparseVector(int capacity,
int[] index,
double[] data,
int startIdx,
int endIdx)
Construct a sparse vector by deeply copying with tis maximum capacity, indices to data, and data
|
SparseVector(SparseVector sv)
Construct a sparse vector by deeply copying another vector
|
Modifier and Type | Method and Description |
---|---|
void |
add(int idx,
double val)
Add a value to entry [idx]
|
void |
append(int idx,
double val)
append a value to entry [idx] if the idx is sorted
|
protected void |
check(int idx)
Checks the index
|
void |
compress()
compress the sparse vector
|
boolean |
contains(int idx)
Check if a vector contains a specific index
|
double |
get(int idx)
Retrieve a value at entry [idx]
|
int |
getCapacity() |
int |
getCount()
Number of entries in the sparse structure
|
double[] |
getData() |
int[] |
getIndex() |
java.util.List<java.lang.Integer> |
getIndexList() |
java.util.Set<java.lang.Integer> |
getIndexSet() |
double |
inner(DenseVector vec)
Return inner product with a given dense vector.
|
double |
inner(SparseVector vec)
Return inner product with a given sparse vector
|
java.util.Iterator<VectorEntry> |
iterator() |
double |
mean() |
void |
set(int idx,
double val)
Set a value to entry [idx]
|
int |
size() |
double |
sum() |
java.util.Map<java.lang.Integer,java.lang.Double> |
toMap() |
java.lang.String |
toString() |
protected int capacity
protected double[] data
protected int[] index
protected int count
protected int zeroCount
protected int zeroFirstIndex
protected boolean autoCompress
public SparseVector(int capcity)
capcity
- maximum size of the sparse vectorpublic SparseVector(int capcity, int dataLength)
capcity
- maximum size of the sparse vectordataLength
- length of the datapublic SparseVector(int capcity, double[] array)
capcity
- maximum size of the sparse vectorarray
- input datapublic SparseVector(int capacity, int[] index, double[] data)
capacity
- maximum size of the sparse vectorindex
- indices to datadata
- datapublic SparseVector(int capacity, int[] index, double[] data, int startIdx, int endIdx)
capacity
- maximum size of the sparse vectorindex
- indices to datadata
- datastartIdx
- start indexendIdx
- end indexpublic SparseVector(SparseVector sv)
sv
- another vectorpublic boolean contains(int idx)
idx
- the idex to searchpublic double[] getData()
public int[] getIndex()
public java.util.List<java.lang.Integer> getIndexList()
public java.util.Set<java.lang.Integer> getIndexSet()
public int getCount()
public void set(int idx, double val)
idx
- indexval
- the value to setpublic void add(int idx, double val)
idx
- indexval
- the value to addpublic void append(int idx, double val)
idx
- indexval
- the value to appendpublic void compress()
public double get(int idx)
idx
- indexpublic double inner(SparseVector vec)
vec
- a given sparse vectorpublic double inner(DenseVector vec)
vec
- a given dense vectorpublic double sum()
public double mean()
public int size()
protected void check(int idx)
idx
- indexpublic java.util.Iterator<VectorEntry> iterator()
iterator
in interface java.lang.Iterable<VectorEntry>
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Map<java.lang.Integer,java.lang.Double> toMap()
public int getCapacity()
Copyright © 2017. All Rights Reserved.