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 double ell1norm
    The value of computed L1 norm.
    protected double ell2norm
    The value of computed norm.
    int id
    The description ID associated with this vector (immutable).
    static int INVALID_ID
    A value indicating that the norm is not computed for current values.
    static double INVALID_NORM
    A value indicating that the norm is not computed for current values.
    int size
    The vector size (immutable).
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected Vector​(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
    void add​(double alpha, Vector v)
    Adds values in vector v scaled by alpha to this vector.
    double dotProduct​(Vector v)
    Returns the dot product between v and this vector.
    double ell1Norm()
    Returns the l1 norm of this vector.
    double ell2Norm()
    Returns the l2 norm of this vector.
    double euclideanDistance​(Vector v)
    Returns the euclidean distance between v and this vector.
    abstract double get​(int idx)
    Gets the value at index idx.
    boolean isMutable()
    Returns the mutability status of this vector.
    void scale​(double alpha)
    Scale values in this vector by a value alpha.
    abstract void set​(int idx, double val)
    Sets the value val at index idx.
    void zero()
    Reset (to zero) this vector.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INVALID_ID

      public static final int INVALID_ID
      A value indicating that the norm is not computed for current values.
      See Also:
      Constant Field Values
    • INVALID_NORM

      public static final double INVALID_NORM
      A value indicating that the norm is not computed for current values.
      See Also:
      Constant Field Values
    • size

      public final int size
      The vector size (immutable).
    • id

      public final int id
      The description ID associated with this vector (immutable).
    • ell2norm

      protected double ell2norm
      The value of computed norm. It can be INVALID_NORM if the norm is not computer for current values.
    • ell1norm

      protected double ell1norm
      The 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

      public void add​(double alpha, Vector v)
      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:
      true if the vector is mutable; false otherwise.
    • dotProduct

      public double dotProduct​(Vector v)
      Returns the dot product between v and this vector.
      Parameters:
      v - the vector.
      Returns:
      the dot product.
    • euclideanDistance

      public double euclideanDistance​(Vector v)
      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.