Package it.unimi.dsi.law.vector
Class ImmutableSparseVector
java.lang.Object
it.unimi.dsi.law.vector.Vector
it.unimi.dsi.law.vector.ImmutableSparseVector
- All Implemented Interfaces:
Serializable
public class ImmutableSparseVector extends Vector
An immutable implementation of
Vector optimized for sparse vectors.- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description int[]indexAn arrays containing the indexes of the vector values.intnonZeroThe number of non-zero entry in this vector.double[]valueAn arrays containing vector values.Fields inherited from class it.unimi.dsi.law.vector.Vector
ell1norm, ell2norm, id, INVALID_ID, INVALID_NORM, size -
Method Summary
Modifier and Type Method Description voidadd(double alpha, Vector v)Adds values in vector v scaled by alpha to this vector.doubledotProduct(Vector v)Returns the dot product between v and this vector.doubleell1Norm()Returns the l1 norm of this vector.doubleell2Norm()Returns the l2 norm of this vector.doubleeuclideanDistance(Vector v)Returns the euclidean distance between v and this vector.doubleget(int idx)Gets the value at index idx.static ImmutableSparseVectorgetInstance(double[] value, double threshold, int id)Returns an instance containing all the values of a given array larger or smaller of a given threshold.static ImmutableSparseVectorgetInstance(int[] index, double[] value, int size, double threshold, int id)Returns an instance containing all the values of a given array larger than a given threshold.static ImmutableSparseVectorgetInstance(int size, double[] value, int[] index, int id)Returns an instance of given size from an array of values.static ImmutableSparseVectorgetInstance(Vector v, double threshold, int id)Returns an instance containing all the values of a given vector larger or smaller of a given threshold.voidscale(double alpha)Scale values in this vector by a value alpha.voidset(int idx, double val)Sets the value val at index idx.voidzero()Reset (to zero) this vector.
-
Field Details
-
value
public final double[] valueAn arrays containing vector values. -
index
public final int[] indexAn arrays containing the indexes of the vector values. -
nonZero
public final int nonZeroThe number of non-zero entry in this vector.
-
-
Method Details
-
getInstance
Returns an instance of given size from an array of values.- Parameters:
size- the size.value- the value.index- the index.id- the id of description of this vector.- Returns:
- an immutable vector.
-
getInstance
Returns an instance containing all the values of a given vector larger or smaller of a given threshold. The vector will have size equal to the vector length.- Parameters:
v- the vector.threshold- the threshold.id- the id of description of this vector.- Returns:
- an immutable vector
-
getInstance
Returns an instance containing all the values of a given array larger or smaller of a given threshold. The vector will have size equal to the array length.- Parameters:
value- tha array of double.threshold- the threshold.id- the id of description associated with this vector.- Returns:
- an immutable vector.
-
getInstance
public static ImmutableSparseVector getInstance(int[] index, double[] value, int size, double threshold, int id)Returns an instance containing all the values of a given array larger than a given threshold. The vector will have the given size- Parameters:
value- tha array of double.threshold- the threshold.id- the id of description associated with this vector.- Returns:
- an immutable vector.
-
set
public void set(int idx, double val)Description copied from class:VectorSets the value val at index idx. -
get
public double get(int idx)Description copied from class:VectorGets the value at index idx. -
add
Description copied from class:VectorAdds values in vector v scaled by alpha to this vector. -
scale
public void scale(double alpha)Description copied from class:VectorScale values in this vector by a value alpha. -
zero
public void zero()Description copied from class:VectorReset (to zero) this vector. -
dotProduct
Description copied from class:VectorReturns the dot product between v and this vector.- Overrides:
dotProductin classVector- Parameters:
v- the vector.- Returns:
- the dot product.
-
euclideanDistance
Description copied from class:VectorReturns the euclidean distance between v and this vector.- Overrides:
euclideanDistancein classVector- Parameters:
v- the vector.- Returns:
- the euclidean distance.
-
ell2Norm
public double ell2Norm()Description copied from class:VectorReturns the l2 norm of this vector. -
ell1Norm
public double ell1Norm()Description copied from class:VectorReturns the l1 norm of this vector.
-