public class SparseShortVector extends AbstractNumberVector<Short> implements SparseNumberVector<Short>
A SparseShortVector is to store real values as double values.
A SparseShortVector only requires storage for those attribute values that are non-zero.Modifier and Type | Class and Description |
---|---|
static class |
SparseShortVector.Factory
Factory class.
|
static class |
SparseShortVector.VariableSerializer
Serialization class using VarInt encodings.
|
Modifier and Type | Field and Description |
---|---|
private int |
dimensionality
The dimensionality of this feature vector.
|
static SparseShortVector.Factory |
FACTORY
Static instance.
|
private int[] |
indexes
Indexes of values.
|
private short[] |
values
Stored values.
|
static ByteBufferSerializer<SparseShortVector> |
VARIABLE_SERIALIZER
Serializer using varint encoding.
|
ATTRIBUTE_SEPARATOR
Constructor and Description |
---|
SparseShortVector(int[] indexes,
short[] values,
int dimensionality)
Direct constructor.
|
SparseShortVector(short[] values)
Provides a SparseShortVector consisting of double values according to the
specified mapping of indices and values.
|
SparseShortVector(gnu.trove.map.TIntDoubleMap values,
int dimensionality)
Provides a SparseShortVector consisting of double values according to the
specified mapping of indices and values.
|
Modifier and Type | Method and Description |
---|---|
double |
doubleValue(int dimension)
Deprecated.
|
Vector |
getColumnVector()
Returns a Vector representing in one column and
getDimensionality() rows the values of this NumberVector of V. |
int |
getDimensionality()
The dimensionality of the vector space where of this FeatureVector of V is
an element.
|
private int |
getMaxDim()
Get the maximum dimensionality.
|
Short |
getValue(int dimension)
Deprecated.
|
private double[] |
getValues()
Returns an array consisting of the values of this feature vector.
|
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.
|
long |
longValue(int dimension)
Deprecated.
|
void |
setDimensionality(int dimensionality)
Sets the dimensionality to the new value.
|
short |
shortValue(int dimension)
Deprecated.
|
String |
toString()
Provides a String representation of this SparseShortVector as suitable for
SparseNumberVectorLabelParser
. |
byteValue, floatValue, getMax, getMin, intValue
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
byteValue, floatValue, intValue
getMax, getMin
public static final SparseShortVector.Factory FACTORY
public static final ByteBufferSerializer<SparseShortVector> VARIABLE_SERIALIZER
private final int[] indexes
private final short[] values
private int dimensionality
public SparseShortVector(int[] indexes, short[] values, int dimensionality)
indexes
- Indexes Must be sorted!values
- Associated value.dimensionality
- "true" dimensionalitypublic SparseShortVector(gnu.trove.map.TIntDoubleMap values, int dimensionality) throws IllegalArgumentException
values
- the values to be set as values of the real vectordimensionality
- the dimensionality of this feature vectorIllegalArgumentException
- 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 SparseShortVector(short[] values) throws IllegalArgumentException
values
- the values to be set as values of the real vectorIllegalArgumentException
- 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<Short>
getDimensionality
in interface SpatialComparable
public void setDimensionality(int dimensionality) throws IllegalArgumentException
setDimensionality
in interface SparseNumberVector<Short>
dimensionality
- the new dimensionalityIllegalArgumentException
- 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 Short getValue(int dimension)
FeatureVector
getValue
in interface FeatureVector<Short>
getValue
in interface NumberVector<Short>
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<Short>
doubleValue
in interface SparseNumberVector<Short>
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<Short>
longValue
in interface SparseNumberVector<Short>
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
@Deprecated public short shortValue(int dimension)
NumberVector
getValue(dim).shortValue()
, but usually this is much more efficient
due to boxing/unboxing cost.shortValue
in interface NumberVector<Short>
shortValue
in interface SparseNumberVector<Short>
shortValue
in class AbstractNumberVector<Short>
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
public Vector getColumnVector()
NumberVector
getDimensionality()
rows the values of this NumberVector of V.getColumnVector
in interface NumberVector<Short>
getDimensionality()
rows the values of this
NumberVector of Vpublic String toString()
Provides a String representation of this SparseShortVector as suitable for
SparseNumberVectorLabelParser
.
The returned String is a single line with entries separated by
AbstractNumberVector.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
toString
in interface FeatureVector<Short>
toString
in class Object
private double[] getValues()
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<Short>
iter
in interface SparseNumberVector<Short>
public int iterDim(int iter)
SparseFeatureVector
iterDim
in interface SparseFeatureVector<Short>
iter
- Iterator positionpublic int iterAdvance(int iter)
SparseFeatureVector
iterAdvance
in interface SparseFeatureVector<Short>
iter
- Previous iterator positionpublic boolean iterValid(int iter)
SparseFeatureVector
iterValid
in interface SparseFeatureVector<Short>
iter
- Iterator positiontrue
when it refers to a valid position.public double iterDoubleValue(int iter)
SparseNumberVector
iterDoubleValue
in interface SparseNumberVector<Short>
iter
- Iteratorpublic float iterFloatValue(int iter)
SparseNumberVector
iterFloatValue
in interface SparseNumberVector<Short>
iter
- Iteratorpublic int iterIntValue(int iter)
SparseNumberVector
iterIntValue
in interface SparseNumberVector<Short>
iter
- Iteratorpublic short iterShortValue(int iter)
SparseNumberVector
iterShortValue
in interface SparseNumberVector<Short>
iter
- Iteratorpublic long iterLongValue(int iter)
SparseNumberVector
iterLongValue
in interface SparseNumberVector<Short>
iter
- Iteratorpublic byte iterByteValue(int iter)
SparseNumberVector
iterByteValue
in interface SparseNumberVector<Short>
iter
- Iterator