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.logging.AbstractLoggable
      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:
WekaObject<WekaNumericAttribute>, DatabaseObject, FeatureVector<BitVector,Bit>, SpatialComparable, SpatialObject, Loggable

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
 
Fields inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debug
 
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.
 
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)
          This BitVector is equal to a given Object, if the Object is a BitVector of same dimensionality and with identical bits set.
 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 FeatureVector.
 int getDimensionality()
          The dimensionality of the vector space whereof this FeatureVector is an element.
 Matrix getRowVector()
          Returns a Matrix representing in one row and getDimensionality() columns the values of this FeatureVector.
 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)
          Returns a new FeatureVector of T 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.
 BitVector randomInstance(Bit min, Bit max, Random random)
          Returns the same as randomInstance(Random).
 BitVector randomInstance(Random random)
          Returns a FeatureVector of T with uniformly distributed (0-1) 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
getAttributes, getMax, getMin
 
Methods inherited from class de.lmu.ifi.dbs.elki.data.AbstractDatabaseObject
getID, setID
 
Methods inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debugFine, debugFiner, debugFinest, exception, message, progress, progress, progress, verbose, verbose, warning
 
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 specifiying the bits in this bit vector
Method Detail

newInstance

public BitVector newInstance(Bit[] values)
Description copied from interface: FeatureVector
Returns a new FeatureVector of T for the given values.

Specified by:
newInstance in interface FeatureVector<BitVector,Bit>
Overrides:
newInstance in class NumberVector<BitVector,Bit>
Parameters:
values - the values of the featureVector
Returns:
a new FeatureVector of T for the given values
See Also:
FeatureVector.newInstance(Number[])

randomInstance

public BitVector randomInstance(Random random)
Description copied from interface: FeatureVector
Returns a FeatureVector of T with uniformly distributed (0-1) random values.

Parameters:
random - a Random instance
Returns:
a FeatureVector of T with random values
See Also:
FeatureVector.randomInstance(Random)

randomInstance

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

Parameters:
min - minimum of random value
max - maximu of random value
random - a random instance
Returns:
a FeatureVector of T with random values between min and max
See Also:
FeatureVector.randomInstance(Number, Number, Random)

getDimensionality

public int getDimensionality()
Description copied from interface: FeatureVector
The dimensionality of the vector space whereof this FeatureVector is an element.

Returns:
the number of dimensions of this FeatureVector
See Also:
FeatureVector.getDimensionality()

getValue

public Bit getValue(int dimension)
Description copied from interface: FeatureVector
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()
Description copied from interface: FeatureVector
Returns a Vector representing in one column and getDimensionality() rows the values of this FeatureVector.

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

getRowVector

public Matrix getRowVector()
Description copied from interface: FeatureVector
Returns a Matrix representing in one row and getDimensionality() columns the values of this FeatureVector.

Returns:
a Matrix representing in one row and getDimensionality() columns the values of this FeatureVector
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 - a scalar to multiply this FeatureVector with
Returns:
a new FeatureVector that is the result of a scalar multiplication with the given scalar
See Also:
FeatureVector.multiplicate(double)

negativeVector

public BitVector negativeVector()
Returns the inverse of the bit vector.

Returns:
the additive inverse to this FeatureVector
See Also:
FeatureVector.negativeVector()

nullVector

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

Returns:
a null vector of the same Feature Vector Space as this FeatureVector (that is, of the same dimensionality)
See Also:
FeatureVector.nullVector()

plus

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

Parameters:
fv - a FeatureVector to be added to this Featurevector
Returns:
a new FeatureVector that is the sum of this FeatureVector and the given FeatureVector
See Also:
FeatureVector.plus(FeatureVector)

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
See Also:
Object.toString()

equals

public boolean equals(Object obj)
This BitVector is equal to a 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.1 (2008-07-10_1838)