Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

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

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

public class BitVector
extends NumberVector<BitVector,Bit>

Provides a BitVector wrapping a BitSet.

Author:
Arthur Zimek

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.NumberVector
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 areSet(int[] indices)
          Returns whether the bits at all of the specified indices are set.
 boolean contains(BitSet bitset)
          Returns whether this BitVector contains all bits that are set to true in the specified BitSet.
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this BitVector.
 BitSet getBits()
          Returns a copy of the bits currently set in this BitVector.
 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.
 boolean isSet(int index)
          Returns whether the bit at specified index is set.
 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(List<Bit> values)
          Creates and returns a new BitVector based on the passed 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.
 BitVector randomInstance(Bit min, Bit max, Random random)
          Returns the same as randomInstance(random).
 BitVector randomInstance(BitVector min, BitVector max, Random random)
          Returns the same as randomInstance(random).
 BitVector randomInstance(Random random)
          Returns a BitVector with random values.
 int[] setBits()
          Returns the indices of all set bits.
 String toString()
          Returns a String representation of this BitVector.
 
Methods inherited from class de.lmu.ifi.dbs.elki.data.NumberVector
getMax, getMin, getRange
 
Methods inherited from class de.lmu.ifi.dbs.elki.data.AbstractDatabaseObject
getID, setID
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.lmu.ifi.dbs.elki.data.DatabaseObject
getID, setID
 
Methods inherited from interface de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialObject
getID
 

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

newInstance

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

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.

Parameters:
values - the values of the featureVector
Returns:
a new instance of this BitVector with the specified values

randomInstance

public BitVector randomInstance(Random random)
Returns a BitVector with random values.

Parameters:
random - an instance of random to facilitate random values
Returns:
a new instance of this BitVector with random values
See Also:
FeatureVector.randomInstance(java.util.Random)

randomInstance

public BitVector randomInstance(Bit min,
                                Bit max,
                                Random random)
Returns the same as randomInstance(random).

Parameters:
min - unused
max - unused
random - as in randomInstance(random)
Returns:
a FeatureVector of V with random values between min and max

randomInstance

public BitVector randomInstance(BitVector min,
                                BitVector max,
                                Random random)
Returns the same as randomInstance(random).

Parameters:
min - unused
max - unused
random - as in randomInstance(random)
Returns:
a FeatureVector of V with random values between min and max

getDimensionality

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

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.

Parameters:
dimension - the desired dimension, where 1 ≤ dimension ≤ this.getDimensionality()
Returns:
the value in the specified dimension
See Also:
FeatureVector.getValue(int)

getColumnVector

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

Returns:
a Matrix representing in one column and getDimensionality() rows the values of this BitVector as double values
See Also:
FeatureVector.getColumnVector()

getRowVector

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

Returns:
a Matrix representing in one row and getDimensionality() columns the values of this BitVector as double values
See Also:
FeatureVector.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.

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.

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.

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.

Parameters:
fv - the bit vector to add
Returns:
a new bit vector corresponding to an XOR operation on this and the specified bit vector

isSet

public boolean isSet(int index)
Returns whether the bit at specified index is set.

Parameters:
index - the index of the bit to inspect
Returns:
true if the bit at index index is set, false otherwise.

areSet

public boolean areSet(int[] indices)
Returns whether the bits at all of the specified indices are set.

Parameters:
indices - the indices to inspect
Returns:
true if the bits at all of the specified indices are set, false otherwise

setBits

public int[] setBits()
Returns the indices of all set bits.

Returns:
the indices of all set bits

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.

Specified by:
equals in interface DatabaseObject
Overrides:
equals in class NumberVector<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 NumberVector are equal to the values of obj in all dimensions, respectively
See Also:
DatabaseObject.equals(Object)

Release 0.2 (2009-07-06_1820)