Interface Vector

All Superinterfaces:
Serializable, scala.Serializable
All Known Implementing Classes:
DenseVector, SparseVector

public interface Vector extends scala.Serializable
Represents a numeric vector, whose index type is Int and value type is Double.

Note:
Users should not implement this interface.
  • Method Summary

    Modifier and Type
    Method
    Description
    scala.collection.Iterator<scala.Tuple2<Object,Object>>
    Returns an iterator over all the active elements of this vector.
    double
    apply(int i)
    Gets the value of the ith element.
    int
    Find the index of a maximal element.
    breeze.linalg.Vector<Object>
    Converts the instance to a breeze vector.
    Convert this vector to the new mllib-local representation.
    Returns a vector in either dense or sparse format, whichever uses less storage.
    Makes a deep copy of this vector.
    double
    Calculate the dot product of this vector with another.
    boolean
    equals(Object other)
     
    void
    foreach(scala.Function2<Object,Object,scala.runtime.BoxedUnit> f)
    Applies a function f to all the elements of dense and sparse vector.
    void
    foreachActive(scala.Function2<Object,Object,scala.runtime.BoxedUnit> f)
    Applies a function f to all the active elements of dense and sparse vector.
    void
    foreachNonZero(scala.Function2<Object,Object,scala.runtime.BoxedUnit> f)
    Applies a function f to all the non-zero elements of dense and sparse vector.
    int
    Returns a hash code value for the vector.
    scala.collection.Iterator<scala.Tuple2<Object,Object>>
    Returns an iterator over all the elements of this vector.
    scala.collection.Iterator<scala.Tuple2<Object,Object>>
    Returns an iterator over all the non-zero elements of this vector.
    int
    Number of active entries.
    int
    Number of nonzero elements.
    int
    Size of the vector.
    double
    Returns the ratio of number of zeros by total number of values.
    double[]
    Converts the instance to a double array.
    Converts this vector to a dense vector.
    Converts the vector to a JSON string.
    Converts this vector to a sparse vector with all explicit zeros removed.
    Converts this vector to a sparse vector with all explicit zeros removed when the size is known.
  • Method Details

    • activeIterator

      scala.collection.Iterator<scala.Tuple2<Object,Object>> activeIterator()
      Returns an iterator over all the active elements of this vector.
      Returns:
      (undocumented)
    • apply

      double apply(int i)
      Gets the value of the ith element.
      Parameters:
      i - index
      Returns:
      (undocumented)
    • argmax

      int argmax()
      Find the index of a maximal element. Returns the first maximal element in case of a tie. Returns -1 if vector has length 0.
      Returns:
      (undocumented)
    • asBreeze

      breeze.linalg.Vector<Object> asBreeze()
      Converts the instance to a breeze vector.
      Returns:
      (undocumented)
    • asML

      Vector asML()
      Convert this vector to the new mllib-local representation. This does NOT copy the data; it copies references.
      Returns:
      (undocumented)
    • compressed

      Vector compressed()
      Returns a vector in either dense or sparse format, whichever uses less storage.
      Returns:
      (undocumented)
    • copy

      Vector copy()
      Makes a deep copy of this vector.
      Returns:
      (undocumented)
    • dot

      double dot(Vector v)
      Calculate the dot product of this vector with another.

      If size does not match an IllegalArgumentException is thrown.

      Parameters:
      v - (undocumented)
      Returns:
      (undocumented)
    • equals

      boolean equals(Object other)
      Overrides:
      equals in class Object
    • foreach

      void foreach(scala.Function2<Object,Object,scala.runtime.BoxedUnit> f)
      Applies a function f to all the elements of dense and sparse vector.

      Parameters:
      f - the function takes two parameters where the first parameter is the index of the vector with type Int, and the second parameter is the corresponding value with type Double.
    • foreachActive

      void foreachActive(scala.Function2<Object,Object,scala.runtime.BoxedUnit> f)
      Applies a function f to all the active elements of dense and sparse vector.

      Parameters:
      f - the function takes two parameters where the first parameter is the index of the vector with type Int, and the second parameter is the corresponding value with type Double.
    • foreachNonZero

      void foreachNonZero(scala.Function2<Object,Object,scala.runtime.BoxedUnit> f)
      Applies a function f to all the non-zero elements of dense and sparse vector.

      Parameters:
      f - the function takes two parameters where the first parameter is the index of the vector with type Int, and the second parameter is the corresponding value with type Double.
    • hashCode

      int hashCode()
      Returns a hash code value for the vector. The hash code is based on its size and its first 128 nonzero entries, using a hash algorithm similar to java.util.Arrays.hashCode.
      Overrides:
      hashCode in class Object
      Returns:
      (undocumented)
    • iterator

      scala.collection.Iterator<scala.Tuple2<Object,Object>> iterator()
      Returns an iterator over all the elements of this vector.
      Returns:
      (undocumented)
    • nonZeroIterator

      scala.collection.Iterator<scala.Tuple2<Object,Object>> nonZeroIterator()
      Returns an iterator over all the non-zero elements of this vector.
      Returns:
      (undocumented)
    • numActives

      int numActives()
      Number of active entries. An "active entry" is an element which is explicitly stored, regardless of its value.

      Returns:
      (undocumented)
      Note:
      Inactive entries have value 0.
    • numNonzeros

      int numNonzeros()
      Number of nonzero elements. This scans all active values and count nonzeros.
      Returns:
      (undocumented)
    • size

      int size()
      Size of the vector.
      Returns:
      (undocumented)
    • sparsity

      double sparsity()
      Returns the ratio of number of zeros by total number of values.
      Returns:
      (undocumented)
    • toArray

      double[] toArray()
      Converts the instance to a double array.
      Returns:
      (undocumented)
    • toDense

      DenseVector toDense()
      Converts this vector to a dense vector.
      Returns:
      (undocumented)
    • toJson

      String toJson()
      Converts the vector to a JSON string.
      Returns:
      (undocumented)
    • toSparse

      SparseVector toSparse()
      Converts this vector to a sparse vector with all explicit zeros removed.
      Returns:
      (undocumented)
    • toSparseWithSize

      SparseVector toSparseWithSize(int nnz)
      Converts this vector to a sparse vector with all explicit zeros removed when the size is known. This method is used to avoid re-computing the number of non-zero elements when it is already known. This method should only be called after computing the number of non-zero elements via numNonzeros(). e.g.
      
         val nnz = numNonzeros
         val sv = toSparse(nnz)
       

      If nnz is under-specified, a ArrayIndexOutOfBoundsException is thrown.

      Parameters:
      nnz - (undocumented)
      Returns:
      (undocumented)