Class SparseByteVector
- java.lang.Object
-
- elki.data.SparseByteVector
-
- All Implemented Interfaces:
FeatureVector<java.lang.Number>,NumberVector,SparseFeatureVector<java.lang.Number>,SparseNumberVector,SpatialComparable
public class SparseByteVector extends java.lang.Object implements SparseNumberVector
Sparse vector type, usingbyte[]for storing the values, andint[]for storing the indexes, approximately 5 bytes per non-zero value (limited to -128..+127).- Since:
- 0.6.0
- Author:
- Arthur Zimek
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSparseByteVector.FactoryFactory class.static classSparseByteVector.VariableSerializerSerialization class using VarInt encodings.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ByteBYTE0Value to return for missing entires.private intdimensionalityThe dimensionality of this feature vector.static SparseByteVector.FactoryFACTORYStatic instance.private int[]indexesIndexes of values.private byte[]valuesStored values.static ByteBufferSerializer<SparseByteVector>VARIABLE_SERIALIZERSerializer using varint encoding.-
Fields inherited from interface elki.data.FeatureVector
TYPE
-
Fields inherited from interface elki.data.NumberVector
ATTRIBUTE_SEPARATOR, FIELD_1D, FIELD_2D
-
Fields inherited from interface elki.data.SparseNumberVector
FIELD, VARIABLE_LENGTH
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description bytebyteValue(int dimension)Returns the value in the specified dimension as byte.doubledoubleValue(int dimension)Deprecated.intgetDimensionality()The dimensionality of the vector space where of this FeatureVector of V is an element.private intgetMaxDim()Get the maximum dimensionality.java.lang.BytegetValue(int dimension)Deprecated.byteiterByteValue(int iter)Get the value of the iterators' current dimension.intiterDim(int iter)Get the dimension an iterator points to.doubleiterDoubleValue(int iter)Get the value of the iterators' current dimension.longiterLongValue(int iter)Get the value of the iterators' current dimension.booleaniterValid(int iter)Test the iterator position for validity.longlongValue(int dimension)Deprecated.voidsetDimensionality(int dimensionality)Sets the dimensionality to the new value.double[]toArray()Returns a double array copy of this vector.java.lang.StringtoString()Create a String representation of this SparseByteVector as suitable forSparseNumberVectorLabelParser.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface elki.data.NumberVector
getMax, getMin
-
Methods inherited from interface elki.data.SparseFeatureVector
iterAdvance, iterRetract
-
Methods inherited from interface elki.data.SparseNumberVector
floatValue, intValue, iter, iterFloatValue, iterIntValue, iterShortValue, shortValue
-
-
-
-
Field Detail
-
FACTORY
public static final SparseByteVector.Factory FACTORY
Static instance.
-
VARIABLE_SERIALIZER
public static final ByteBufferSerializer<SparseByteVector> VARIABLE_SERIALIZER
Serializer using varint encoding.
-
indexes
private final int[] indexes
Indexes of values.
-
values
private final byte[] values
Stored values.
-
dimensionality
private int dimensionality
The dimensionality of this feature vector.
-
BYTE0
private static final java.lang.Byte BYTE0
Value to return for missing entires.
-
-
Constructor Detail
-
SparseByteVector
public SparseByteVector(int[] indexes, byte[] values, int dimensionality)Direct constructor.- Parameters:
indexes- Indexes Must be sorted!values- Associated value.dimensionality- "true" dimensionality
-
SparseByteVector
public SparseByteVector(it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap values, int dimensionality) throws java.lang.IllegalArgumentExceptionCreate a SparseByteVector consisting of double values according to the specified mapping of indices and values.- Parameters:
values- the values to be set as values of the real vectordimensionality- the dimensionality of this feature vector- Throws:
java.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)
-
SparseByteVector
public SparseByteVector(byte[] values) throws java.lang.IllegalArgumentExceptionCreate a SparseByteVector consisting of double values according to the specified mapping of indices and values.- Parameters:
values- the values to be set as values of the real vector- Throws:
java.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)
-
-
Method Detail
-
getMaxDim
private int getMaxDim()
Get the maximum dimensionality.- Returns:
- the maximum dimensionality seen
-
getDimensionality
public int getDimensionality()
Description copied from interface:FeatureVectorThe dimensionality of the vector space where of this FeatureVector of V is an element.- Specified by:
getDimensionalityin interfaceFeatureVector<java.lang.Number>- Specified by:
getDimensionalityin interfaceSpatialComparable- Returns:
- the number of dimensions of this FeatureVector of V
-
setDimensionality
public void setDimensionality(int dimensionality) throws java.lang.IllegalArgumentExceptionSets the dimensionality to the new value.- Specified by:
setDimensionalityin interfaceSparseNumberVector- Parameters:
dimensionality- the new dimensionality- Throws:
java.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)
-
getValue
@Deprecated public java.lang.Byte getValue(int dimension)
Deprecated.Description copied from interface:FeatureVectorReturns the value in the specified dimension.- Specified by:
getValuein interfaceFeatureVector<java.lang.Number>- Specified by:
getValuein interfaceNumberVector- Parameters:
dimension- the desired dimension, where 0 ≤ dimension ≤this.getDimensionality()-1- Returns:
- the value in the specified dimension
-
doubleValue
@Deprecated public double doubleValue(int dimension)
Deprecated.Description copied from interface:NumberVectorReturns the value in the specified dimension as double.Note: this might seem redundant with respect to
getValue(dim).doubleValue(), but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
doubleValuein interfaceNumberVector- Specified by:
doubleValuein interfaceSparseNumberVector- Parameters:
dimension- the desired dimension, where 0 ≤ dimension <this.getDimensionality()- Returns:
- the value in the specified dimension
-
longValue
@Deprecated public long longValue(int dimension)
Deprecated.Description copied from interface:NumberVectorReturns the value in the specified dimension as long.Note: this might seem redundant with respect to
getValue(dim).longValue(), but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
longValuein interfaceNumberVector- Specified by:
longValuein interfaceSparseNumberVector- Parameters:
dimension- the desired dimension, where 0 ≤ dimension <this.getDimensionality()- Returns:
- the value in the specified dimension
-
byteValue
public byte byteValue(int dimension)
Description copied from interface:NumberVectorReturns the value in the specified dimension as byte.Note: this might seem redundant with respect to
getValue(dim).byteValue(), but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
byteValuein interfaceNumberVector- Specified by:
byteValuein interfaceSparseNumberVector- Parameters:
dimension- the desired dimension, where 0 ≤ dimension <this.getDimensionality()- Returns:
- the value in the specified dimension
-
toArray
public double[] toArray()
Description copied from interface:NumberVectorReturns a double array copy of this vector.- Specified by:
toArrayin interfaceNumberVector- Returns:
- Copy as
double[]
-
toString
public java.lang.String toString()
Create a String representation of this SparseByteVector as suitable forSparseNumberVectorLabelParser.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- Specified by:
toStringin interfaceFeatureVector<java.lang.Number>- Overrides:
toStringin classjava.lang.Object- Returns:
- a String representation of this SparseByteVector
-
iterDim
public int iterDim(int iter)
Description copied from interface:SparseFeatureVectorGet the dimension an iterator points to.- Specified by:
iterDimin interfaceSparseFeatureVector<java.lang.Number>- Parameters:
iter- Iterator position- Returns:
- Dimension the iterator refers to
-
iterValid
public boolean iterValid(int iter)
Description copied from interface:SparseFeatureVectorTest the iterator position for validity.- Specified by:
iterValidin interfaceSparseFeatureVector<java.lang.Number>- Parameters:
iter- Iterator position- Returns:
truewhen it refers to a valid position.
-
iterDoubleValue
public double iterDoubleValue(int iter)
Description copied from interface:SparseNumberVectorGet the value of the iterators' current dimension.- Specified by:
iterDoubleValuein interfaceSparseNumberVector- Parameters:
iter- Iterator- Returns:
- Value at the current position
-
iterLongValue
public long iterLongValue(int iter)
Description copied from interface:SparseNumberVectorGet the value of the iterators' current dimension.- Specified by:
iterLongValuein interfaceSparseNumberVector- Parameters:
iter- Iterator- Returns:
- Value at the current position
-
iterByteValue
public byte iterByteValue(int iter)
Description copied from interface:SparseNumberVectorGet the value of the iterators' current dimension.- Specified by:
iterByteValuein interfaceSparseNumberVector- Parameters:
iter- Iterator- Returns:
- Value at the current position
-
-