de.lmu.ifi.dbs.elki.data
Class BitVector

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.data.AbstractNumberVector<BitVector,Bit>
      extended by de.lmu.ifi.dbs.elki.data.BitVector
All Implemented Interfaces:
FeatureVector<BitVector,Bit>, NumberVector<BitVector,Bit>, SpatialComparable, ByteBufferSerializer<BitVector>

public class BitVector
extends AbstractNumberVector<BitVector,Bit>
implements ByteBufferSerializer<BitVector>

Provides a BitVector wrapping a BitSet.


Field Summary
private  BitSet bits
          Storing the bits.
private  int dimensionality
          Dimensionality of this bit vector.
 
Fields inherited from class de.lmu.ifi.dbs.elki.data.AbstractNumberVector
ATTRIBUTE_SEPARATOR
 
Constructor Summary
BitVector(Bit[] bits)
          Provides a new BitVector corresponding to the bits in the given array.
BitVector(BitSet bits, int dimensionality)
          Provides a new BitVector corresponding to the specified bits and of the specified dimensionality.
BitVector(List<Bit> bits)
          Provides a new BitVector corresponding to the bits in the given list.
 
Method Summary
 boolean contains(BitSet bitset)
          Returns whether this BitVector contains all bits that are set to true in the specified BitSet.
 double doubleValue(int dimension)
          Returns the value in the specified dimension as double.
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this BitVector.
 BitVector fromByteBuffer(ByteBuffer buffer)
          Deserialize an object from a byte buffer (e.g. disk)
 BitSet getBits()
          Returns a copy of the bits currently set in this BitVector.
 int getByteSize(BitVector vec)
          Get the size of the object in bytes.
 Vector getColumnVector()
          Returns a Vector representing in one column and getDimensionality() rows the values of this BitVector as double values.
 int getDimensionality()
          The dimensionality of the binary vector space of which this BitVector is an element.
 Matrix getRowVector()
          Returns a Matrix representing in one row and getDimensionality() columns the values of this BitVector as double values.
 Bit getValue(int dimension)
          Returns the value in the specified dimension.
 long longValue(int dimension)
          Returns the value in the specified dimension as long.
 BitVector minus(BitVector fv)
          Returns a bit vector corresponding to an NXOR operation on this and the specified bit vector.
 BitVector multiplicate(double k)
          Returns a bit vector equal to this bit vector, if k is not 0, a bit vector with all components equal to zero otherwise.
 BitVector negativeVector()
          Returns the inverse of the bit vector.
 BitVector newInstance(Bit[] values)
          Creates and returns a new BitVector based on the passed values.
 BitVector newInstance(double[] values)
          Returns a new NumberVector of N for the given values.
 BitVector newInstance(List<Bit> values)
          Creates and returns a new BitVector based on the passed values.
 BitVector newInstance(Vector values)
          Returns a new NumberVector of N for the given values.
 BitVector nullVector()
          Returns a bit vector of equal dimensionality but containing 0 only.
 BitVector plus(BitVector fv)
          Returns a bit vector corresponding to an XOR operation on this and the specified bit vector.
 Bit scalarProduct(BitVector fv)
          Provides the scalar product (inner product) of this BitVector and the given BitVector.
 void toByteBuffer(ByteBuffer buffer, BitVector vec)
          Serialize the object to a byte array (e.g. disk)
 String toString()
          Returns a String representation of this BitVector.
 
Methods inherited from class de.lmu.ifi.dbs.elki.data.AbstractNumberVector
byteValue, floatValue, getMax, getMin, hashCode, intValue, shortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

bits

private BitSet bits
Storing the bits.


dimensionality

private int dimensionality
Dimensionality of this bit vector.

Constructor Detail

BitVector

public BitVector(BitSet bits,
                 int dimensionality)
          throws IllegalArgumentException
Provides 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
Throws:
IllegalArgumentException - if the specified dimensionality is to small to match the given BitSet

BitVector

public BitVector(Bit[] bits)
Provides a new BitVector corresponding to the bits in the given array.

Parameters:
bits - an array of bits specifying the bits in this bit vector

BitVector

public BitVector(List<Bit> bits)
Provides a new BitVector corresponding to the bits in the given list.

Parameters:
bits - an array of bits specifying the bits in this bit vector
Method Detail

getDimensionality

public int getDimensionality()
The dimensionality of the binary vector space of which this BitVector is an element.

Specified by:
getDimensionality in interface FeatureVector<BitVector,Bit>
Specified by:
getDimensionality in interface SpatialComparable
Returns:
the number of dimensions of this FeatureVector of V
See Also:
FeatureVector.getDimensionality()

getValue

public Bit getValue(int dimension)
Returns the value in the specified dimension.

Specified by:
getValue in interface FeatureVector<BitVector,Bit>
Parameters:
dimension - the desired dimension, where 1 ≤ dimension ≤ this.getDimensionality()
Returns:
the value in the specified dimension
See Also:
FeatureVector.getValue(int)

doubleValue

public double doubleValue(int dimension)
Returns the value in the specified dimension as double.

Specified by:
doubleValue in interface NumberVector<BitVector,Bit>
Parameters:
dimension - the desired dimension, where 1 ≤ dimension ≤ this.getDimensionality()
Returns:
the value in the specified dimension
See Also:
NumberVector.doubleValue(int)

longValue

public long longValue(int dimension)
Returns the value in the specified dimension as long.

Specified by:
longValue in interface NumberVector<BitVector,Bit>
Parameters:
dimension - the desired dimension, where 1 ≤ dimension ≤ this.getDimensionality()
Returns:
the value in the specified dimension
See Also:
NumberVector.longValue(int)

getColumnVector

public Vector getColumnVector()
Returns a Vector representing in one column and getDimensionality() rows the values of this BitVector as double values.

Specified by:
getColumnVector in interface NumberVector<BitVector,Bit>
Returns:
a Matrix representing in one column and getDimensionality() rows the values of this BitVector as double values
See Also:
NumberVector.getColumnVector()

getRowVector

public Matrix getRowVector()
Returns a Matrix representing in one row and getDimensionality() columns the values of this BitVector as double values.

Specified by:
getRowVector in interface NumberVector<BitVector,Bit>
Returns:
a Matrix representing in one row and getDimensionality() columns the values of this BitVector as double values
See Also:
NumberVector.getRowVector()

multiplicate

public BitVector multiplicate(double k)
Returns a bit vector equal to this bit vector, if k is not 0, a bit vector with all components equal to zero otherwise.

Specified by:
multiplicate in interface NumberVector<BitVector,Bit>
Parameters:
k - used as multiplier 1 if k ≠ 0, otherwise the resulting bit vector will have all values equal to zero
Returns:
a bit vector equal to this bit vector, if k is not 0, a bit vector with all components equal to zero otherwise

negativeVector

public BitVector negativeVector()
Returns the inverse of the bit vector. The result is the same as obtained by flipping all bits in the underlying BitSet.

Specified by:
negativeVector in interface NumberVector<BitVector,Bit>
Returns:
the inverse of the bit vector
See Also:
BitSet.flip(int,int)

nullVector

public BitVector nullVector()
Returns a bit vector of equal dimensionality but containing 0 only.

Specified by:
nullVector in interface NumberVector<BitVector,Bit>
Returns:
a bit vector of equal dimensionality but containing 0 only

plus

public BitVector plus(BitVector fv)
Returns a bit vector corresponding to an XOR operation on this and the specified bit vector.

Specified by:
plus in interface NumberVector<BitVector,Bit>
Parameters:
fv - the bit vector to add
Returns:
a new bit vector corresponding to an XOR operation on this and the specified bit vector

minus

public BitVector minus(BitVector fv)
Returns a bit vector corresponding to an NXOR operation on this and the specified bit vector.

Specified by:
minus in interface NumberVector<BitVector,Bit>
Parameters:
fv - the bit vector to add
Returns:
a new bit vector corresponding to an NXOR operation on this and the specified bit vector

contains

public boolean contains(BitSet 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

getBits

public BitSet getBits()
Returns a copy of the bits currently set in this BitVector.

Returns:
a copy of the bits currently set in this BitVector

toString

public String toString()
Returns a String representation of this BitVector. The representation is suitable to be parsed by BitVectorLabelParser.

Specified by:
toString in interface FeatureVector<BitVector,Bit>
Overrides:
toString in class Object
Returns:
a String representation of the FeatureVector of V
See Also:
Object.toString()

equals

public boolean equals(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 AbstractNumberVector<BitVector,Bit>
Parameters:
obj - another Object
Returns:
true if the specified Object is an instance of the same runtime class and is of the identical dimensionality and the values of this AbstractNumberVector are equal to the values of obj in all dimensions, respectively

scalarProduct

public Bit scalarProduct(BitVector fv)
Provides the scalar product (inner product) of this BitVector and the given BitVector. As multiplication of Bits, the logical AND operation is used. The result is 0 if the number of bits after the AND operation is a multiple of 2, otherwise the result is 1.

Specified by:
scalarProduct in interface NumberVector<BitVector,Bit>
Parameters:
fv - the BitVector to compute the scalar product for
Returns:
the scalar product (inner product) of this and the given BitVector

newInstance

public BitVector newInstance(double[] values)
Description copied from interface: NumberVector
Returns a new NumberVector of N for the given values.

Specified by:
newInstance in interface NumberVector<BitVector,Bit>
Parameters:
values - the values of the NumberVector
Returns:
a new NumberVector of N for the given values

newInstance

public BitVector newInstance(Vector values)
Description copied from interface: NumberVector
Returns a new NumberVector of N for the given values.

Specified by:
newInstance in interface NumberVector<BitVector,Bit>
Parameters:
values - the values of the NumberVector
Returns:
a new NumberVector of N for the given values

newInstance

public BitVector newInstance(Bit[] values)
Creates and returns a new BitVector based on the passed values.

Specified by:
newInstance in interface FeatureVector<BitVector,Bit>
Parameters:
values - the values of the featureVector
Returns:
a new instance of this BitVector with the specified values

newInstance

public BitVector newInstance(List<Bit> values)
Creates and returns a new BitVector based on the passed values.

Specified by:
newInstance in interface FeatureVector<BitVector,Bit>
Parameters:
values - the values of the featureVector
Returns:
a new instance of this BitVector with the specified values

fromByteBuffer

public BitVector fromByteBuffer(ByteBuffer buffer)
                         throws IOException
Description copied from interface: ByteBufferSerializer
Deserialize an object from a byte buffer (e.g. disk)

Specified by:
fromByteBuffer in interface ByteBufferSerializer<BitVector>
Parameters:
buffer - Data array to process
Returns:
Deserialized object
Throws:
IOException

toByteBuffer

public void toByteBuffer(ByteBuffer buffer,
                         BitVector vec)
                  throws IOException
Description copied from interface: ByteBufferSerializer
Serialize the object to a byte array (e.g. disk)

Specified by:
toByteBuffer in interface ByteBufferSerializer<BitVector>
Parameters:
buffer - Buffer to serialize to
vec - Object to serialize
Throws:
IOException

getByteSize

public int getByteSize(BitVector vec)
Description copied from interface: ByteBufferSerializer
Get the size of the object in bytes.

Specified by:
getByteSize in interface ByteBufferSerializer<BitVector>
Parameters:
vec - Object to serialize
Returns:
maximum size in serialized form

Release 0.4.0 (2011-09-20_1324)