Package elki.data
Class SparseShortVector
- java.lang.Object
-
- elki.data.SparseShortVector
-
- All Implemented Interfaces:
FeatureVector<java.lang.Number>
,NumberVector
,SparseFeatureVector<java.lang.Number>
,SparseNumberVector
,SpatialComparable
public class SparseShortVector extends java.lang.Object implements SparseNumberVector
Sparse vector type, usingshort[]
for storing the values, andint[]
for storing the indexes, approximately 6 bytes per non-zero value.- Since:
- 0.6.0
- Author:
- Arthur Zimek
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SparseShortVector.Factory
Factory class.static class
SparseShortVector.VariableSerializer
Serialization class using VarInt encodings.
-
Field Summary
Fields Modifier and Type Field Description private int
dimensionality
The dimensionality of this feature vector.static SparseShortVector.Factory
FACTORY
Static instance.private int[]
indexes
Indexes of values.private static short
SHORT0
Constant value, for use in (inefficient)getValue(int)
API.private short[]
values
Stored values.static ByteBufferSerializer<SparseShortVector>
VARIABLE_SERIALIZER
Serializer 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 SparseShortVector(int[] indexes, short[] values, int dimensionality)
Direct constructor.SparseShortVector(short[] values)
Create a SparseShortVector consisting of double values according to the specified mapping of indices and values.SparseShortVector(it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap values, int dimensionality)
Create a SparseShortVector 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 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.Short
getValue(int dimension)
Deprecated.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.short
iterShortValue(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.short
shortValue(int dimension)
Deprecated.double[]
toArray()
Returns a double array copy of this vector.java.lang.String
toString()
Create a String representation of this SparseShortVector 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
byteValue, floatValue, intValue, iter, iterByteValue, iterFloatValue, iterIntValue
-
-
-
-
Field Detail
-
FACTORY
public static final SparseShortVector.Factory FACTORY
Static instance.
-
VARIABLE_SERIALIZER
public static final ByteBufferSerializer<SparseShortVector> VARIABLE_SERIALIZER
Serializer using varint encoding.
-
SHORT0
private static final short SHORT0
Constant value, for use in (inefficient)getValue(int)
API.- See Also:
- Constant Field Values
-
indexes
private final int[] indexes
Indexes of values.
-
values
private final short[] values
Stored values.
-
dimensionality
private int dimensionality
The dimensionality of this feature vector.
-
-
Constructor Detail
-
SparseShortVector
public SparseShortVector(int[] indexes, short[] values, int dimensionality)
Direct constructor.- Parameters:
indexes
- Indexes Must be sorted!values
- Associated value.dimensionality
- "true" dimensionality
-
SparseShortVector
public SparseShortVector(it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap values, int dimensionality) throws java.lang.IllegalArgumentException
Create a SparseShortVector 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)
-
SparseShortVector
public SparseShortVector(short[] values) throws java.lang.IllegalArgumentException
Create a SparseShortVector 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:FeatureVector
The dimensionality of the vector space where of this FeatureVector of V is an element.- Specified by:
getDimensionality
in interfaceFeatureVector<java.lang.Number>
- Specified by:
getDimensionality
in interfaceSpatialComparable
- Returns:
- the number of dimensions of this FeatureVector of V
-
setDimensionality
public void setDimensionality(int dimensionality) throws java.lang.IllegalArgumentException
Sets the dimensionality to the new value.- Specified by:
setDimensionality
in 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.Short getValue(int dimension)
Deprecated.Description copied from interface:FeatureVector
Returns the value in the specified dimension.- Specified by:
getValue
in interfaceFeatureVector<java.lang.Number>
- Specified by:
getValue
in 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:NumberVector
Returns 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:
doubleValue
in interfaceNumberVector
- Specified by:
doubleValue
in 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:NumberVector
Returns 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:
longValue
in interfaceNumberVector
- Specified by:
longValue
in interfaceSparseNumberVector
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
shortValue
@Deprecated public short shortValue(int dimension)
Deprecated.Description copied from interface:NumberVector
Returns the value in the specified dimension as short.Note: this might seem redundant with respect to
getValue(dim).shortValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
shortValue
in interfaceNumberVector
- Specified by:
shortValue
in 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:NumberVector
Returns a double array copy of this vector.- Specified by:
toArray
in interfaceNumberVector
- Returns:
- Copy as
double[]
-
toString
public java.lang.String toString()
Create a String representation of this SparseShortVector as suitable forSparseNumberVectorLabelParser
. The returned String is a single line with entries separated byNumberVector.ATTRIBUTE_SEPARATOR
. The first entry gives the number of values actually not zero. Following entries are pairs of Short and Short where the Short gives the index of the dimensionality and the Short 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:
toString
in interfaceFeatureVector<java.lang.Number>
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String representation of this SparseShortVector
-
iterDim
public int iterDim(int iter)
Description copied from interface:SparseFeatureVector
Get the dimension an iterator points to.- Specified by:
iterDim
in interfaceSparseFeatureVector<java.lang.Number>
- Parameters:
iter
- Iterator position- Returns:
- Dimension the iterator refers to
-
iterValid
public boolean iterValid(int iter)
Description copied from interface:SparseFeatureVector
Test the iterator position for validity.- Specified by:
iterValid
in interfaceSparseFeatureVector<java.lang.Number>
- Parameters:
iter
- Iterator position- Returns:
true
when it refers to a valid position.
-
iterDoubleValue
public double iterDoubleValue(int iter)
Description copied from interface:SparseNumberVector
Get the value of the iterators' current dimension.- Specified by:
iterDoubleValue
in interfaceSparseNumberVector
- Parameters:
iter
- Iterator- Returns:
- Value at the current position
-
iterShortValue
public short iterShortValue(int iter)
Description copied from interface:SparseNumberVector
Get the value of the iterators' current dimension.- Specified by:
iterShortValue
in interfaceSparseNumberVector
- Parameters:
iter
- Iterator- Returns:
- Value at the current position
-
iterLongValue
public long iterLongValue(int iter)
Description copied from interface:SparseNumberVector
Get the value of the iterators' current dimension.- Specified by:
iterLongValue
in interfaceSparseNumberVector
- Parameters:
iter
- Iterator- Returns:
- Value at the current position
-
-