Package elki.data

Class SparseFloatVector

    • Field Detail

      • indexes

        private final int[] indexes
        Indexes of values.
      • values

        private final float[] values
        Stored values.
      • dimensionality

        private int dimensionality
        The dimensionality of this feature vector.
    • Constructor Detail

      • SparseFloatVector

        public SparseFloatVector​(int[] indexes,
                                 float[] values,
                                 int dimensionality)
        Direct constructor.
        Parameters:
        indexes - Indexes Must be sorted!
        values - Associated value.
        dimensionality - "true" dimensionality
      • SparseFloatVector

        public SparseFloatVector​(it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap values,
                                 int dimensionality)
                          throws java.lang.IllegalArgumentException
        Create a SparseFloatVector consisting of double values according to the specified mapping of indices and values.
        Parameters:
        values - the values to be set as values of the real vector
        dimensionality - the dimensionality of this feature vector
        Throws:
        java.lang.IllegalArgumentException - if the given dimensionality is too small to cover the given values (i.e., the maximum index of any value not zero is bigger than the given dimensionality)
      • SparseFloatVector

        public SparseFloatVector​(float[] values)
                          throws java.lang.IllegalArgumentException
        Create a SparseFloatVector consisting of double values according to the specified mapping of indices and values.
        Parameters:
        values - the values to be set as values of the real vector
        Throws:
        java.lang.IllegalArgumentException - if the given dimensionality is too small to cover the given values (i.e., the maximum index of any value not zero is bigger than the given dimensionality)
    • Method Detail

      • getMaxDim

        private int getMaxDim()
        Get the maximum dimensionality.
        Returns:
        the maximum dimensionality seen
      • getDimensionality

        public int getDimensionality()
        Description copied from interface: FeatureVector
        The dimensionality of the vector space where of this FeatureVector of V is an element.
        Specified by:
        getDimensionality in interface FeatureVector<java.lang.Number>
        Specified by:
        getDimensionality in interface SpatialComparable
        Returns:
        the number of dimensions of this FeatureVector of V
      • setDimensionality

        public void setDimensionality​(int dimensionality)
                               throws java.lang.IllegalArgumentException
        Sets the dimensionality to the new value.
        Specified by:
        setDimensionality in interface SparseNumberVector
        Parameters:
        dimensionality - the new dimensionality
        Throws:
        java.lang.IllegalArgumentException - if the given dimensionality is too small to cover the given values (i.e., the maximum index of any value not zero is bigger than the given dimensionality)
      • getValue

        @Deprecated
        public java.lang.Float getValue​(int dimension)
        Deprecated.
        Description copied from interface: FeatureVector
        Returns the value in the specified dimension.
        Specified by:
        getValue in interface FeatureVector<java.lang.Number>
        Specified by:
        getValue in interface NumberVector
        Parameters:
        dimension - the desired dimension, where 0 ≤ dimension ≤ this.getDimensionality()-1
        Returns:
        the value in the specified dimension
      • doubleValue

        @Deprecated
        public double doubleValue​(int dimension)
        Deprecated.
        Description copied from interface: NumberVector
        Returns the value in the specified dimension as double.

        Note: this might seem redundant with respect to getValue(dim).doubleValue(), but usually this is much more efficient due to boxing/unboxing cost.

        Specified by:
        doubleValue in interface NumberVector
        Specified by:
        doubleValue in interface SparseNumberVector
        Parameters:
        dimension - the desired dimension, where 0 ≤ dimension < this.getDimensionality()
        Returns:
        the value in the specified dimension
      • floatValue

        @Deprecated
        public float floatValue​(int dimension)
        Deprecated.
        Description copied from interface: NumberVector
        Returns the value in the specified dimension as float.

        Note: this might seem redundant with respect to getValue(dim).floatValue(), but usually this is much more efficient due to boxing/unboxing cost.

        Specified by:
        floatValue in interface NumberVector
        Specified by:
        floatValue in interface SparseNumberVector
        Parameters:
        dimension - the desired dimension, where 0 ≤ dimension < this.getDimensionality()
        Returns:
        the value in the specified dimension
      • longValue

        @Deprecated
        public long longValue​(int dimension)
        Deprecated.
        Description copied from interface: NumberVector
        Returns the value in the specified dimension as long.

        Note: this might seem redundant with respect to getValue(dim).longValue(), but usually this is much more efficient due to boxing/unboxing cost.

        Specified by:
        longValue in interface NumberVector
        Specified by:
        longValue in interface SparseNumberVector
        Parameters:
        dimension - the desired dimension, where 0 ≤ dimension < this.getDimensionality()
        Returns:
        the value in the specified dimension
      • toArray

        public double[] toArray()
        Description copied from interface: NumberVector
        Returns a double array copy of this vector.
        Specified by:
        toArray in interface NumberVector
        Returns:
        Copy as double[]
      • toString

        public java.lang.String toString()
        Create a String representation of this SparseFloatVector as suitable for SparseNumberVectorLabelParser . The returned String is a single line with entries separated by NumberVector.ATTRIBUTE_SEPARATOR. The first entry gives the number of values actually not zero. Following entries are pairs of Integer and Float where the Integer gives the index of the dimensionality and the Float gives the corresponding value. Example: a vector (0,1.2,1.3,0)T would result in the String
        2 2 1.2 3 1.3
        Specified by:
        toString in interface FeatureVector<java.lang.Number>
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representation of this SparseFloatVector
      • iterDim

        public int iterDim​(int iter)
        Description copied from interface: SparseFeatureVector
        Get the dimension an iterator points to.
        Specified by:
        iterDim in interface SparseFeatureVector<java.lang.Number>
        Parameters:
        iter - Iterator position
        Returns:
        Dimension the iterator refers to
      • iterValid

        public boolean iterValid​(int iter)
        Description copied from interface: SparseFeatureVector
        Test the iterator position for validity.
        Specified by:
        iterValid in interface SparseFeatureVector<java.lang.Number>
        Parameters:
        iter - Iterator position
        Returns:
        true when it refers to a valid position.
      • iterDoubleValue

        public double iterDoubleValue​(int iter)
        Description copied from interface: SparseNumberVector
        Get the value of the iterators' current dimension.
        Specified by:
        iterDoubleValue in interface SparseNumberVector
        Parameters:
        iter - Iterator
        Returns:
        Value at the current position
      • iterFloatValue

        public float iterFloatValue​(int iter)
        Description copied from interface: SparseNumberVector
        Get the value of the iterators' current dimension.
        Specified by:
        iterFloatValue in interface SparseNumberVector
        Parameters:
        iter - Iterator
        Returns:
        Value at the current position
      • iterLongValue

        public long iterLongValue​(int iter)
        Description copied from interface: SparseNumberVector
        Get the value of the iterators' current dimension.
        Specified by:
        iterLongValue in interface SparseNumberVector
        Parameters:
        iter - Iterator
        Returns:
        Value at the current position