public class BitVector extends AbstractNumberVector implements SparseNumberVector
long[]
storage.Modifier and Type | Class and Description |
---|---|
static class |
BitVector.Factory
Factory for bit vectors.
|
static class |
BitVector.ShortSerializer
Serialization class for dense integer vectors with up to
Short.MAX_VALUE dimensions, by using a short for storing the
dimensionality. |
Modifier and Type | Field and Description |
---|---|
private long[] |
bits
Storing the bits.
|
private int |
dimensionality
Dimensionality of this bit vector.
|
static BitVector.Factory |
FACTORY
Static instance.
|
static ByteBufferSerializer<BitVector> |
SHORT_SERIALIZER
Serializer for up to 2^15-1 dimensions.
|
ATTRIBUTE_SEPARATOR
Constructor and Description |
---|
BitVector(long[] bits,
int dimensionality)
Create a new BitVector corresponding to the specified bits and of the
specified dimensionality.
|
Modifier and Type | Method and Description |
---|---|
void |
andOnto(long[] v)
Combine onto v using the AND operation, i.e.
|
boolean |
booleanValue(int dimension)
Get the value of a single bit.
|
int |
cardinality()
Compute the vector cardinality (uncached!)
|
long[] |
cloneBits()
Returns a copy of the bits currently set in this BitVector.
|
boolean |
contains(long[] 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.
|
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 vector space where of this FeatureVector of V is
an element.
|
Bit |
getValue(int dimension)
Deprecated.
|
int |
hammingDistance(BitVector v2)
Compute the Hamming distance of two bit vectors.
|
boolean |
intersect(BitVector v2)
Compute whether two vectors intersect.
|
int |
intersectionSize(BitVector v2)
Compute the vector intersection size.
|
int |
iter()
Iterator over non-zero features only, ascendingly.
|
int |
iterAdvance(int iter)
Advance the iterator to the next position.
|
byte |
iterByteValue(int iter)
Get the value of the iterators' current dimension.
|
int |
iterDim(int iter)
Get the dimension an iterator points to.
|
double |
iterDoubleValue(int iter)
Get the value of the iterators' current dimension.
|
float |
iterFloatValue(int iter)
Get the value of the iterators' current dimension.
|
int |
iterIntValue(int iter)
Get the value of the iterators' current dimension.
|
long |
iterLongValue(int iter)
Get the value of the iterators' current dimension.
|
short |
iterShortValue(int iter)
Get the value of the iterators' current dimension.
|
boolean |
iterValid(int iter)
Test the iterator position for validity.
|
double |
jaccardSimilarity(BitVector v2)
Compute the Jaccard similarity of two bit vectors.
|
long |
longValue(int dimension)
Returns the value in the specified dimension as long.
|
void |
orOnto(long[] v)
Combine onto v using the OR operation, i.e.
|
void |
setDimensionality(int dimensionality)
Update the vector space dimensionality.
|
String |
toString()
Returns a String representation of this BitVector.
|
int |
unionSize(BitVector v2)
Compute the vector union size.
|
void |
xorOnto(long[] v)
Combine onto v using the XOR operation, i.e.
|
byteValue, floatValue, getMax, getMin, intValue, shortValue
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
byteValue, floatValue, intValue, shortValue
getMax, getMin
public static final BitVector.Factory FACTORY
public static final ByteBufferSerializer<BitVector> SHORT_SERIALIZER
private final long[] bits
private int dimensionality
public BitVector(long[] bits, int dimensionality)
bits
- the bits to be set in this BitVector.dimensionality
- the dimensionality of this BitVectorpublic int getDimensionality()
FeatureVector
getDimensionality
in interface FeatureVector<Number>
getDimensionality
in interface SpatialComparable
public void setDimensionality(int dimensionality)
SparseNumberVector
setDimensionality
in interface SparseNumberVector
dimensionality
- New dimensionalitypublic boolean booleanValue(int dimension)
dimension
- Bit number to gettrue
when set@Deprecated public Bit getValue(int dimension)
FeatureVector
getValue
in interface FeatureVector<Number>
getValue
in interface NumberVector
dimension
- the desired dimension, where 0 ≤ dimension ≤
this.getDimensionality()-1
public double doubleValue(int dimension)
NumberVector
getValue(dim).doubleValue()
, but usually this is much more
efficient due to boxing/unboxing cost.doubleValue
in interface NumberVector
doubleValue
in interface SparseNumberVector
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
public long longValue(int dimension)
NumberVector
getValue(dim).longValue()
, but usually this is much more efficient
due to boxing/unboxing cost.longValue
in interface NumberVector
longValue
in interface SparseNumberVector
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
public int iter()
SparseNumberVector
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.
}
iter
in interface SparseFeatureVector<Number>
iter
in interface SparseNumberVector
public int iterAdvance(int iter)
SparseFeatureVector
iterAdvance
in interface SparseFeatureVector<Number>
iter
- Previous iterator positionpublic boolean iterValid(int iter)
SparseFeatureVector
iterValid
in interface SparseFeatureVector<Number>
iter
- Iterator positiontrue
when it refers to a valid position.public int iterDim(int iter)
SparseFeatureVector
iterDim
in interface SparseFeatureVector<Number>
iter
- Iterator positionpublic double iterDoubleValue(int iter)
SparseNumberVector
iterDoubleValue
in interface SparseNumberVector
iter
- Iteratorpublic float iterFloatValue(int iter)
SparseNumberVector
iterFloatValue
in interface SparseNumberVector
iter
- Iteratorpublic int iterIntValue(int iter)
SparseNumberVector
iterIntValue
in interface SparseNumberVector
iter
- Iteratorpublic short iterShortValue(int iter)
SparseNumberVector
iterShortValue
in interface SparseNumberVector
iter
- Iteratorpublic long iterLongValue(int iter)
SparseNumberVector
iterLongValue
in interface SparseNumberVector
iter
- Iteratorpublic byte iterByteValue(int iter)
SparseNumberVector
iterByteValue
in interface SparseNumberVector
iter
- Iteratorpublic Vector getColumnVector()
getDimensionality()
rows the values of this BitVector as
double values.getColumnVector
in interface NumberVector
getDimensionality()
rows the values of this BitVector
as double valuesNumberVector.getColumnVector()
public boolean contains(long[] bitset)
bitset
- the bits to inspect in this BitVectorpublic long[] cloneBits()
public int cardinality()
public double jaccardSimilarity(BitVector v2)
v2
- Second bit vectorpublic int hammingDistance(BitVector v2)
v2
- Second bit vectorpublic int intersectionSize(BitVector v2)
v2
- Second bit vectorpublic int unionSize(BitVector v2)
v2
- Second bit vectorpublic boolean intersect(BitVector v2)
v2
- Second bit vectortrue
if they intersect in at least one bit.public void andOnto(long[] v)
v &= this
.v
- Existing bit set of same length.public void orOnto(long[] v)
v |= this
.v
- Existing bit set of same length.public void xorOnto(long[] v)
v ^= this
.v
- Existing bit set of same length.public String toString()
BitVectorLabelParser
.
Returns a String representation of the FeatureVector of V as a line that is
suitable to be printed in a sequential file.toString
in interface FeatureVector<Number>
toString
in class Object
Copyright © 2015 ELKI Development Team, Lehr- und Forschungseinheit für Datenbanksysteme, Ludwig-Maximilians-Universität München. License information.