public class SparseByteVector extends java.lang.Object implements SparseNumberVector
byte[]
for storing the values, and
int[]
for storing the indexes, approximately 5 bytes per non-zero
value (limited to -128..+127).Modifier and Type | Class and Description |
---|---|
static class |
SparseByteVector.Factory
Factory class.
|
static class |
SparseByteVector.VariableSerializer
Serialization class using VarInt encodings.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.Byte |
BYTE0
Value to return for missing entires.
|
private int |
dimensionality
The dimensionality of this feature vector.
|
static SparseByteVector.Factory |
FACTORY
Static instance.
|
private int[] |
indexes
Indexes of values.
|
private byte[] |
values
Stored values.
|
static ByteBufferSerializer<SparseByteVector> |
VARIABLE_SERIALIZER
Serializer using varint encoding.
|
FIELD, VARIABLE_LENGTH
ATTRIBUTE_SEPARATOR, FIELD_1D, FIELD_2D
TYPE
Constructor and Description |
---|
SparseByteVector(byte[] values)
Create a SparseByteVector consisting of double values according to the
specified mapping of indices and values.
|
SparseByteVector(int[] indexes,
byte[] values,
int dimensionality)
Direct constructor.
|
SparseByteVector(it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap values,
int dimensionality)
Create a SparseByteVector consisting of double values according to the
specified mapping of indices and values.
|
Modifier and Type | Method and Description |
---|---|
byte |
byteValue(int dimension)
Returns the value in the specified dimension as byte.
|
double |
doubleValue(int dimension)
Deprecated.
|
int |
getDimensionality()
The dimensionality of the vector space where of this FeatureVector of V is
an element.
|
private int |
getMaxDim()
Get the maximum dimensionality.
|
java.lang.Byte |
getValue(int dimension)
Deprecated.
|
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.
|
long |
iterLongValue(int iter)
Get the value of the iterators' current dimension.
|
boolean |
iterValid(int iter)
Test the iterator position for validity.
|
long |
longValue(int dimension)
Deprecated.
|
void |
setDimensionality(int dimensionality)
Sets the dimensionality to the new value.
|
double[] |
toArray()
Returns a double array copy of this vector.
|
java.lang.String |
toString()
Create a String representation of this SparseByteVector as suitable for
SparseNumberVectorLabelParser
. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
floatValue, intValue, iter, iterFloatValue, iterIntValue, iterShortValue, shortValue
getMax, getMin
iterAdvance, iterRetract
public static final SparseByteVector.Factory FACTORY
public static final ByteBufferSerializer<SparseByteVector> VARIABLE_SERIALIZER
private final int[] indexes
private final byte[] values
private int dimensionality
private static final java.lang.Byte BYTE0
public SparseByteVector(int[] indexes, byte[] values, int dimensionality)
indexes
- Indexes Must be sorted!values
- Associated value.dimensionality
- "true" dimensionalitypublic SparseByteVector(it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap values, int dimensionality) throws java.lang.IllegalArgumentException
values
- the values to be set as values of the real vectordimensionality
- the dimensionality of this feature vectorjava.lang.IllegalArgumentException
- if the given dimensionality is too small
to cover the given values (i.e., the maximum index of any value not
zero is bigger than the given dimensionality)public SparseByteVector(byte[] values) throws java.lang.IllegalArgumentException
values
- the values to be set as values of the real vectorjava.lang.IllegalArgumentException
- if the given dimensionality is too small
to cover the given values (i.e., the maximum index of any value not
zero is bigger than the given dimensionality)private int getMaxDim()
public int getDimensionality()
FeatureVector
getDimensionality
in interface FeatureVector<java.lang.Number>
getDimensionality
in interface SpatialComparable
public void setDimensionality(int dimensionality) throws java.lang.IllegalArgumentException
setDimensionality
in interface SparseNumberVector
dimensionality
- the new dimensionalityjava.lang.IllegalArgumentException
- if the given dimensionality is too small
to cover the given values (i.e., the maximum index of any value not
zero is bigger than the given dimensionality)@Deprecated public java.lang.Byte 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
@Deprecated 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()
@Deprecated 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 byte byteValue(int dimension)
NumberVector
getValue(dim).byteValue()
, but usually this is much more efficient
due to boxing/unboxing cost.byteValue
in interface NumberVector
byteValue
in interface SparseNumberVector
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
public double[] toArray()
NumberVector
toArray
in interface NumberVector
double[]
public java.lang.String toString()
SparseNumberVectorLabelParser
.
The returned String is a single line with entries separated by
NumberVector.ATTRIBUTE_SEPARATOR
. The first entry gives the
number of values actually not zero. Following entries are pairs of Byte and
Byte where the Byte gives the index of the dimensionality and the Byte
gives the corresponding value.
Example: a vector (0,1.2,1.3,0)T would result in the String
2 2 1.2 3 1.3
toString
in interface FeatureVector<java.lang.Number>
toString
in class java.lang.Object
public int iterDim(int iter)
SparseFeatureVector
iterDim
in interface SparseFeatureVector<java.lang.Number>
iter
- 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 double iterDoubleValue(int iter)
SparseNumberVector
iterDoubleValue
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
- IteratorCopyright © 2019 ELKI Development Team. License information.