Package elki.data

Class BitVector

    • Field Detail

      • bits

        private final long[] bits
        Storing the bits.
      • dimensionality

        private int dimensionality
        Dimensionality of this bit vector.
    • Constructor Detail

      • BitVector

        public BitVector​(long[] bits,
                         int dimensionality)
        Create a new BitVector corresponding to the specified bits and of the specified dimensionality.
        Parameters:
        bits - the bits to be set in this BitVector.
        dimensionality - the dimensionality of this BitVector
    • Method Detail

      • 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)
        Description copied from interface: SparseNumberVector
        Update the vector space dimensionality.
        Specified by:
        setDimensionality in interface SparseNumberVector
        Parameters:
        dimensionality - New dimensionality
      • booleanValue

        public boolean booleanValue​(int dimension)
        Get the value of a single bit.
        Parameters:
        dimension - Bit number to get
        Returns:
        true when set
      • getValue

        @Deprecated
        public Bit 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

        public double doubleValue​(int dimension)
        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
      • longValue

        public long longValue​(int dimension)
        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
      • iter

        public int iter()
        Description copied from interface: SparseNumberVector
        Iterator over non-zero features only, ascendingly.

        Note: depending on the underlying implementation, this may or may not be the dimension. Use SparseFeatureVector.iterDim(int) to get the actual dimension. In fact, usually this will be the ith non-zero value, assuming an array representation.

        Think of this number as an iterator. For efficiency, it has a primitive type!

        Intended usage:

         
         for (int iter = v.iter(); v.iterValid(iter); iter = v.iterAdvance(iter)) {
           final int dim = v.iterDim(iter);
           final double val = v.iterDoubleValue(iter);
           // Do something.
         }
         
         
        Specified by:
        iter in interface SparseFeatureVector<java.lang.Number>
        Specified by:
        iter in interface SparseNumberVector
        Returns:
        Identifier for the first non-zero dimension, not necessarily the dimension!
      • iterAdvance

        public int iterAdvance​(int iter)
        Description copied from interface: SparseFeatureVector
        Advance the iterator to the next position.
        Specified by:
        iterAdvance in interface SparseFeatureVector<java.lang.Number>
        Parameters:
        iter - Previous iterator position
        Returns:
        Next iterator position
      • iterRetract

        public int iterRetract​(int iter)
        Description copied from interface: SparseFeatureVector
        Retract the iterator to the next position.
        Specified by:
        iterRetract in interface SparseFeatureVector<java.lang.Number>
        Parameters:
        iter - Next iterator position
        Returns:
        Previous iterator position
      • 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.
      • 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
      • 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
      • 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
      • toArray

        public double[] toArray()
        Returns a Vector representing in one column and getDimensionality() rows the values of this BitVector as double values.
        Specified by:
        toArray in interface NumberVector
        Returns:
        a Matrix representing in one column and getDimensionality() rows the values of this BitVector as double values
        See Also:
        NumberVector.toArray()
      • contains

        public boolean contains​(long[] bitset)
        Returns whether this BitVector contains all bits that are set to true in the specified BitSet.
        Parameters:
        bitset - the bits to inspect in this BitVector
        Returns:
        true if this BitVector contains all bits that are set to true in the specified BitSet, false otherwise
      • cloneBits

        public long[] cloneBits()
        Returns a copy of the bits currently set in this BitVector.
        Returns:
        a copy of the bits currently set in this BitVector
      • cardinality

        public int cardinality()
        Compute the vector cardinality (uncached!)
        Returns:
        Vector cardinality
      • jaccardSimilarity

        public double jaccardSimilarity​(BitVector v2)
        Compute the Jaccard similarity of two bit vectors.
        Parameters:
        v2 - Second bit vector
        Returns:
        Jaccard similarity (intersection / union)
      • hammingDistance

        public int hammingDistance​(BitVector v2)
        Compute the Hamming distance of two bit vectors.
        Parameters:
        v2 - Second bit vector
        Returns:
        Hamming distance (number of bits difference)
      • intersectionSize

        public int intersectionSize​(BitVector v2)
        Compute the vector intersection size.
        Parameters:
        v2 - Second bit vector
        Returns:
        Intersection size (number of bits in both)
      • unionSize

        public int unionSize​(BitVector v2)
        Compute the vector union size.
        Parameters:
        v2 - Second bit vector
        Returns:
        Intersection size (number of bits in both)
      • intersect

        public boolean intersect​(BitVector v2)
        Compute whether two vectors intersect.
        Parameters:
        v2 - Second bit vector
        Returns:
        true if they intersect in at least one bit.
      • andOnto

        public void andOnto​(long[] v)
        Combine onto v using the AND operation, i.e. v &= this.
        Parameters:
        v - Existing bit set of same length.
      • orOnto

        public void orOnto​(long[] v)
        Combine onto v using the OR operation, i.e. v |= this.
        Parameters:
        v - Existing bit set of same length.
      • xorOnto

        public void xorOnto​(long[] v)
        Combine onto v using the XOR operation, i.e. v ^= this.
        Parameters:
        v - Existing bit set of same length.
      • toString

        public java.lang.String toString()
        Returns a String representation of this BitVector. The representation is suitable to be parsed by BitVectorLabelParser.
        Specified by:
        toString in interface FeatureVector<java.lang.Number>
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representation of the FeatureVector of V
      • equals

        public boolean equals​(java.lang.Object obj)
        Indicates whether some other object is "equal to" this BitVector. This BitVector is equal to the given object, if the object is a BitVector of same dimensionality and with identical bits set.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object