public class BitVector extends java.lang.Object 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.
|
FIELD, VARIABLE_LENGTH
ATTRIBUTE_SEPARATOR, FIELD_1D, FIELD_2D
TYPE
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(java.lang.Object obj)
Indicates whether some other object is "equal to" this BitVector.
|
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.
|
int |
hashCode() |
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.
|
int |
iterDim(int iter)
Get the dimension an iterator points to.
|
double |
iterDoubleValue(int iter)
Get the value of the iterators' current dimension.
|
long |
iterLongValue(int iter)
Get the value of the iterators' current dimension.
|
int |
iterRetract(int iter)
Retract the iterator to the next position.
|
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.
|
double[] |
toArray()
Returns a Vector representing in one column and
getDimensionality() rows the values of this BitVector as
double values. |
java.lang.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.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
byteValue, floatValue, intValue, iterByteValue, iterFloatValue, iterIntValue, iterShortValue, 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<java.lang.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<java.lang.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<java.lang.Number>
iter
in interface SparseNumberVector
public int iterAdvance(int iter)
SparseFeatureVector
iterAdvance
in interface SparseFeatureVector<java.lang.Number>
iter
- Previous iterator positionpublic int iterRetract(int iter)
SparseFeatureVector
iterRetract
in interface SparseFeatureVector<java.lang.Number>
iter
- Next iterator positionpublic boolean iterValid(int iter)
SparseFeatureVector
iterValid
in interface SparseFeatureVector<java.lang.Number>
iter
- Iterator positiontrue
when it refers to a valid position.public int iterDim(int iter)
SparseFeatureVector
iterDim
in interface SparseFeatureVector<java.lang.Number>
iter
- Iterator positionpublic double iterDoubleValue(int iter)
SparseNumberVector
iterDoubleValue
in interface SparseNumberVector
iter
- Iteratorpublic long iterLongValue(int iter)
SparseNumberVector
iterLongValue
in interface SparseNumberVector
iter
- Iteratorpublic double[] toArray()
getDimensionality()
rows the values of this BitVector as
double values.toArray
in interface NumberVector
getDimensionality()
rows the values of this BitVector
as double valuesNumberVector.toArray()
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 java.lang.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<java.lang.Number>
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
Copyright © 2019 ELKI Development Team. License information.