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)
Vector
public SparseVector append(double d)
Vector
public int[] getIndices()
public double[] getValues()
public int size()
Vector
public double get(int i)
Vector
public void setSize(int n)
public int numberOfValues()
public void set(int i, double val)
Vector
public void add(int i, double val)
Vector
public double normL2()
Vector
public double normL1()
Vector
public double normInf()
Vector
public double normL2Square()
Vector
normL2Square
in class Vector
public SparseVector slice(int[] indices)
Vector
public Vector plus(Vector vec)
Vector
public Vector minus(Vector vec)
Vector
public SparseVector scale(double d)
Vector
public void scaleEqual(double d)
Vector
scaleEqual
in class Vector
public void removeZeroValues()
public double dot(Vector other)
Vector
public DenseMatrix outer()
Vector
public DenseMatrix outer(SparseVector other)
public DenseVector toDenseVector()
public void standardizeEqual(double mean, double stdvar)
Vector
standardizeEqual
in class Vector
public void normalizeEqual(double p)
Vector
normalizeEqual
in class Vector
public VectorIterator iterator()
Vector
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.