Class SparseDoubleVector

  • All Implemented Interfaces:
    Vector

    public class SparseDoubleVector
    extends AbstractVector
    Sparse vector implementation wrapping the MTJ implementation of a sparse vector.
    • Field Detail

      • internalVector

        protected no.uib.cipr.matrix.sparse.SparseVector internalVector
    • Constructor Detail

      • SparseDoubleVector

        public SparseDoubleVector​(int[] indices,
                                  double[] values,
                                  int dimension)
        Creates a new SparseDoubleVector which contains the given values.
        Parameters:
        indices - An array which includes all indices for which there exists a value.
        values - An array which contains all values.
        dimension - The total dimension of the vector.
      • SparseDoubleVector

        public SparseDoubleVector​(int dimension)
        Creates a new SparseDoubleVector which contains only zero values.
        Parameters:
        dimension - The dimension of the vector.
      • SparseDoubleVector

        public SparseDoubleVector​(double[] data)
        Creates a new SparseDoubleVector which contains the given values.
        Parameters:
        data - A double array, which can be interpreted as a vector.
      • SparseDoubleVector

        public SparseDoubleVector​(no.uib.cipr.matrix.sparse.SparseVector mtjVector)
        Creates a new SparseDoubleVector from an MTJ SparseVector.
        Parameters:
        mtjVector - The MTJ vector.
    • Method Detail

      • addVector

        public void addVector​(double[] vectorAsArray)
        Description copied from interface: Vector
        Adds the given double array interpreted as a vector to this vector.
        Parameters:
        vectorAsArray - The vector to be added as array.
      • subtractVector

        public void subtractVector​(double[] vectorAsArray)
        Description copied from interface: Vector
        Subtracts the given double array interpreted as a vector from this vector.
        Parameters:
        vectorAsArray - The vector to be subtracted as an array.
      • multiplyByVectorPairwise

        public void multiplyByVectorPairwise​(double[] vectorAsArray)
        Description copied from interface: Vector
        Multiplies this vector with the given double array interpreted as a pairwise vector and stores the result in this vector.
        Parameters:
        vectorAsArray - The vector to be multiplied with.
      • divideByVectorPairwise

        public void divideByVectorPairwise​(double[] vectorAsArray)
        Description copied from interface: Vector
        Divides this vector by the given double array interpreted as a pairwise vector and stores the result in this vector.
        Parameters:
        vectorAsArray - The vector to be divided by.
      • dotProduct

        public double dotProduct​(double[] vectorAsArray)
        Description copied from interface: Vector
        Computes the dot product of the given vector and this vector.
        Parameters:
        vectorAsArray - The vector to compute dot product with.
        Returns:
        The dot product of the given and this vector.
      • length

        public int length()
        Description copied from interface: Vector
        Returns the number of dimensions of this vector.
        Returns:
        The number of dimensions of this vector.
      • getValue

        public double getValue​(int index)
        Description copied from interface: Vector
        Returns the value at the given index of this vector.
        Parameters:
        index - The index of the value to look for.
        Returns:
        The value at the given index.
      • setValue

        public void setValue​(int index,
                             double value)
        Description copied from interface: Vector
        Sets the value at the given index of this vector to the given value.
        Parameters:
        index - The index to set the value at.
        value - The value to be set at the specified index.
      • addVector

        public void addVector​(Vector vector)
        Description copied from interface: Vector
        Adds the given vector to this vector. The result is stored in this vector.
        Parameters:
        vector - The vector to be added to this vector.
      • subtractVector

        public void subtractVector​(Vector vector)
        Description copied from interface: Vector
        Subtracts the given vector from this vector. The result is stored in this vector.
        Parameters:
        vector - The vector to subtract from this vector.
      • multiplyByVectorPairwise

        public void multiplyByVectorPairwise​(Vector secondVector)
        Description copied from interface: Vector
        Multiplies this vector with the given vector pairwisely and stores the result in this vector.
        Parameters:
        secondVector - The vector to be multiplied with.
      • multiplyByConstant

        public void multiplyByConstant​(double constant)
        Description copied from interface: Vector
        Multiplies this vector with the given constant.
        Parameters:
        constant - The constant to multiply this vector with.
      • divideByVectorPairwise

        public void divideByVectorPairwise​(Vector secondVector)
        Description copied from interface: Vector
        Divides this vector by the given pairwise vector and stores the result in this vector.
        Parameters:
        secondVector - The vector to be divided by.
      • divideByConstant

        public void divideByConstant​(double constant)
        Description copied from interface: Vector
        Divides this vector by the given constant.
        Parameters:
        constant - The constant to divide this vector by.
      • dotProduct

        public double dotProduct​(Vector vector)
        Description copied from interface: Vector
        Computes the dot product of the given vector and this vector.
        Parameters:
        vector - The vector to compute dot product with.
        Returns:
        The dot product of the given and this vector.
      • isSparse

        public boolean isSparse()
        Description copied from interface: Vector
        Checks if this vector is sparse.
        Returns:
        true, if this vector is sparse, false if not.
      • asArray

        public double[] asArray()
        Description copied from interface: Vector
        Returns this vector as a double array.
        Returns:
        The current vector as a double array.
      • duplicate

        public Vector duplicate()
        Description copied from interface: Vector
        Creates a deep copy of this vector.
        Returns:
        A deep copy of this vector.
      • normalize

        public void normalize()
        Description copied from interface: Vector
        Normalizes this vector to the unit interval.
      • addConstant

        public void addConstant​(double constant)
        Description copied from interface: Vector
        Adds the given constant to this vector.
        Parameters:
        constant - The constant to be added.
      • subtractConstant

        public void subtractConstant​(double constant)
        Description copied from interface: Vector
        Subtracts the given constant from this vector.
        Parameters:
        constant - The constant to be subtracted.
      • fillRandomly

        public void fillRandomly()
        Description copied from interface: Vector
        Fills this vector with random values from the unit interval.
      • getNonZeroIndices

        public int[] getNonZeroIndices()
        Returns an array containing the non-zero indices of this sparse vector.
        Returns:
        an integer array containing the non-zero indices of this sparse vector
      • kroneckerProduct

        public Vector kroneckerProduct​(double[] vectorAsArray)
        Description copied from interface: Vector
        Computes the kronecker product of this vector (v) with the given vector (w). That is, v⊗w . The resulting vector has length v.length * w.length
        Parameters:
        vectorAsArray - the vector to perform the kronecker product with. i.e. the right-hand operand
        Returns:
        the resulting vector
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class AbstractVector