public class SparseVector extends Vector
| Constructor and Description |
|---|
SparseVector()
Construct an empty sparse vector with undetermined size.
|
SparseVector(int n)
Construct an empty sparse vector with determined size.
|
SparseVector(int n,
int[] indices,
double[] values)
Construct a sparse vector with the given indices and values.
|
SparseVector(int n,
Map<Integer,Double> kv)
Construct a sparse vector with given indices to values map.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int i,
double val)
Add the i-th element of the vector by value "val".
|
SparseVector |
append(double d)
Create a new vector by adding an element to the end of the vector.
|
SparseVector |
clone() |
double |
dot(Vector other)
Compute the dot product with another vector.
|
boolean |
equals(Object o) |
double |
get(int i)
Get the i-th element of the vector.
|
int[] |
getIndices()
Get the indices array.
|
double[] |
getValues()
Get the values array.
|
int |
hashCode() |
VectorIterator |
iterator()
Get the iterator of the vector.
|
Vector |
minus(Vector vec)
Create a new vector by subtracting another vector.
|
void |
normalizeEqual(double p)
Normalize the vector.
|
double |
normInf()
Return the Inf norm of the vector.
|
double |
normL1()
Return the L1 norm of the vector.
|
double |
normL2()
Return the L2 norm of the vector.
|
double |
normL2Square()
Return the square of L2 norm of the vector.
|
int |
numberOfValues()
Get number of values in this vector.
|
DenseMatrix |
outer()
Compute the outer product with itself.
|
DenseMatrix |
outer(SparseVector other)
Compute the outer product with another vector.
|
Vector |
plus(Vector vec)
Create a new vector by plussing another vector.
|
SparseVector |
prefix(double d)
Create a new vector by adding an element to the head of the vector.
|
void |
removeZeroValues()
Remove all zero values away from this vector.
|
SparseVector |
scale(double d)
Scale the vector by value "v" and create a new vector to store the result.
|
void |
scaleEqual(double d)
Scale the vector by value "v".
|
void |
set(int i,
double val)
Set the i-th element of the vector to value "val".
|
void |
setSize(int n)
Set the size of the vector.
|
int |
size()
Get the size of the vector.
|
SparseVector |
slice(int[] indices)
Slice the vector.
|
void |
standardizeEqual(double mean,
double stdvar)
Standardize the vector.
|
DenseVector |
toDenseVector()
Convert to a dense vector.
|
String |
toString() |
public SparseVector()
public SparseVector(int n)
public SparseVector(int n,
int[] indices,
double[] values)
IllegalArgumentException - If size of indices array and values array differ.IllegalArgumentException - If n >= 0 and the indices are out of bound.public SparseVector(int n,
Map<Integer,Double> kv)
IllegalArgumentException - If n >= 0 and the indices are out of bound.public SparseVector clone()
public SparseVector prefix(double d)
Vectorpublic SparseVector append(double d)
Vectorpublic int[] getIndices()
public double[] getValues()
public int size()
Vectorpublic double get(int i)
Vectorpublic void setSize(int n)
public int numberOfValues()
public void set(int i,
double val)
Vectorpublic void add(int i,
double val)
Vectorpublic double normL2()
Vectorpublic double normL1()
Vectorpublic double normInf()
Vectorpublic double normL2Square()
VectornormL2Square in class Vectorpublic SparseVector slice(int[] indices)
Vectorpublic Vector plus(Vector vec)
Vectorpublic Vector minus(Vector vec)
Vectorpublic SparseVector scale(double d)
Vectorpublic void scaleEqual(double d)
VectorscaleEqual in class Vectorpublic void removeZeroValues()
public double dot(Vector other)
Vectorpublic DenseMatrix outer()
Vectorpublic DenseMatrix outer(SparseVector other)
public DenseVector toDenseVector()
public void standardizeEqual(double mean,
double stdvar)
VectorstandardizeEqual in class Vectorpublic void normalizeEqual(double p)
VectornormalizeEqual in class Vectorpublic VectorIterator iterator()
VectorCopyright © 2014–2021 The Apache Software Foundation. All rights reserved.