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[] index
    An arrays containing the indexes of the vector values.
    int nonZero
    The number of non-zero entry in this vector.
    double[] value
    An 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
    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.
    double get​(int idx)
    Gets the value at index idx.
    static ImmutableSparseVector getInstance​(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 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.
    static ImmutableSparseVector getInstance​(int size, double[] value, int[] index, int id)
    Returns an instance of given size from an array of values.
    static ImmutableSparseVector getInstance​(Vector v, double threshold, int id)
    Returns an instance containing all the values of a given vector larger or smaller of a given threshold.
    void scale​(double alpha)
    Scale values in this vector by a value alpha.
    void set​(int idx, double val)
    Sets the value val at index idx.
    void zero()
    Reset (to zero) this vector.

    Methods inherited from class it.unimi.dsi.law.vector.Vector

    isMutable

    Methods inherited from class java.lang.Object

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

    • value

      public final double[] value
      An arrays containing vector values.
    • index

      public final int[] index
      An arrays containing the indexes of the vector values.
    • nonZero

      public final int nonZero
      The number of non-zero entry in this vector.
  • Method Details

    • getInstance

      public static ImmutableSparseVector getInstance​(int size, double[] value, int[] index, int id)
      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

      public static ImmutableSparseVector getInstance​(Vector v, double threshold, int id)
      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

      public static ImmutableSparseVector getInstance​(double[] value, double threshold, int id)
      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: Vector
      Sets the value val at index idx.
      Specified by:
      set in class Vector
      Parameters:
      idx - the index.
      val - the value.
    • get

      public double get​(int idx)
      Description copied from class: Vector
      Gets the value at index idx.
      Specified by:
      get in class Vector
      Parameters:
      idx - the index.
      Returns:
      the value at index idx.
    • add

      public void add​(double alpha, Vector v)
      Description copied from class: Vector
      Adds values in vector v scaled by alpha to this vector.
      Overrides:
      add in class Vector
      Parameters:
      alpha - the scaling factor.
      v - the vector to add.
    • scale

      public void scale​(double alpha)
      Description copied from class: Vector
      Scale values in this vector by a value alpha.
      Overrides:
      scale in class Vector
      Parameters:
      alpha - the scaling factor
    • zero

      public void zero()
      Description copied from class: Vector
      Reset (to zero) this vector.
      Overrides:
      zero in class Vector
    • dotProduct

      public double dotProduct​(Vector v)
      Description copied from class: Vector
      Returns the dot product between v and this vector.
      Overrides:
      dotProduct in class Vector
      Parameters:
      v - the vector.
      Returns:
      the dot product.
    • euclideanDistance

      public double euclideanDistance​(Vector v)
      Description copied from class: Vector
      Returns the euclidean distance between v and this vector.
      Overrides:
      euclideanDistance in class Vector
      Parameters:
      v - the vector.
      Returns:
      the euclidean distance.
    • ell2Norm

      public double ell2Norm()
      Description copied from class: Vector
      Returns the l2 norm of this vector.
      Overrides:
      ell2Norm in class Vector
      Returns:
      the l2 norm.
    • ell1Norm

      public double ell1Norm()
      Description copied from class: Vector
      Returns the l1 norm of this vector.
      Overrides:
      ell1Norm in class Vector