Package it.unimi.dsi.law.vector
Class Vector
java.lang.Object
it.unimi.dsi.law.vector.Vector
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DenseVector,ImmutableSparseVector,Int2DoubleMapVector
public abstract class Vector extends Object implements Serializable
A class representing a vector of
double. Different implementation can allow mutable or immutable values
through suitably implemented set(int, double) and get(int) method. Immutable implementation should throw an
UnsupportedOperationException if a method that cause a mutation is called.- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected doubleell1normThe value of computed L1 norm.protected doubleell2normThe value of computed norm.intidThe description ID associated with this vector (immutable).static intINVALID_IDA value indicating that the norm is not computed for current values.static doubleINVALID_NORMA value indicating that the norm is not computed for current values.intsizeThe vector size (immutable). -
Constructor Summary
Constructors Modifier Constructor Description protectedVector(int size, boolean mutable, int id)Build a vector of given size and set the mutability status of this vector. -
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.abstract doubleget(int idx)Gets the value at index idx.booleanisMutable()Returns the mutability status of this vector.voidscale(double alpha)Scale values in this vector by a value alpha.abstract voidset(int idx, double val)Sets the value val at index idx.voidzero()Reset (to zero) this vector.
-
Field Details
-
INVALID_ID
public static final int INVALID_IDA value indicating that the norm is not computed for current values.- See Also:
- Constant Field Values
-
INVALID_NORM
public static final double INVALID_NORMA value indicating that the norm is not computed for current values.- See Also:
- Constant Field Values
-
size
public final int sizeThe vector size (immutable). -
id
public final int idThe description ID associated with this vector (immutable). -
ell2norm
protected double ell2normThe value of computed norm. It can beINVALID_NORMif the norm is not computer for current values. -
ell1norm
protected double ell1normThe value of computed L1 norm.
-
-
Constructor Details
-
Vector
protected Vector(int size, boolean mutable, int id)Build a vector of given size and set the mutability status of this vector.- Parameters:
size- the size.mutable- the mutability status.id- the id of description of this vector.
-
-
Method Details
-
set
public abstract void set(int idx, double val)Sets the value val at index idx.- Parameters:
idx- the index.val- the value.
-
get
public abstract double get(int idx)Gets the value at index idx.- Parameters:
idx- the index.- Returns:
- the value at index idx.
-
add
Adds values in vector v scaled by alpha to this vector.- Parameters:
alpha- the scaling factor.v- the vector to add.
-
scale
public void scale(double alpha)Scale values in this vector by a value alpha.- Parameters:
alpha- the scaling factor
-
zero
public void zero()Reset (to zero) this vector. -
isMutable
public boolean isMutable()Returns the mutability status of this vector.- Returns:
trueif the vector is mutable;falseotherwise.
-
dotProduct
Returns the dot product between v and this vector.- Parameters:
v- the vector.- Returns:
- the dot product.
-
euclideanDistance
Returns the euclidean distance between v and this vector.- Parameters:
v- the vector.- Returns:
- the euclidean distance.
-
ell2Norm
public double ell2Norm()Returns the l2 norm of this vector.- Returns:
- the l2 norm.
-
ell1Norm
public double ell1Norm()Returns the l1 norm of this vector.
-