de.lmu.ifi.dbs.elki.data
Class SparseFloatVector

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.data.AbstractNumberVector<SparseFloatVector,Float>
      extended by de.lmu.ifi.dbs.elki.data.SparseFloatVector
All Implemented Interfaces:
FeatureVector<SparseFloatVector,Float>, NumberVector<SparseFloatVector,Float>, SparseFeatureVector<SparseFloatVector,Float>, SparseNumberVector<SparseFloatVector,Float>, SpatialComparable

public class SparseFloatVector
extends AbstractNumberVector<SparseFloatVector,Float>
implements SparseNumberVector<SparseFloatVector,Float>

A SparseFloatVector is to store real values approximately as float values.

A SparseFloatVector only requires storage for those attribute values that are non-zero.


Field Summary
private  int dimensionality
          The dimensionality of this feature vector.
private  int[] indexes
          Indexes of values
private  float[] values
          Stored values
 
Fields inherited from class de.lmu.ifi.dbs.elki.data.AbstractNumberVector
ATTRIBUTE_SEPARATOR
 
Constructor Summary
SparseFloatVector(float[] values)
          Provides a SparseFloatVector consisting of double values according to the specified mapping of indices and values.
SparseFloatVector(int[] indexes, float[] values, int dimensionality)
          Direct constructor.
SparseFloatVector(Map<Integer,Float> values, int dimensionality)
          Provides a SparseFloatVector consisting of double values according to the specified mapping of indices and values.
 
Method Summary
 double doubleValue(int dimension)
          Returns the value in the specified dimension as double.
 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.
 BitSet getNotNullMask()
          Bit set of non-null features
 Matrix getRowVector()
          Returns a Matrix representing in one row and getDimensionality() columns the values of this NumberVector of V.
 Float getValue(int dimension)
          Returns the value in the specified dimension.
private  double[] getValues()
          Returns an array consisting of the values of this feature vector.
 long longValue(int dimension)
          Returns the value in the specified dimension as long.
 SparseFloatVector minus(SparseFloatVector fv)
          Returns a new NumberVector of V that is the sum of this NumberVector of V and the negativeVector() of given NumberVector of V.
 SparseFloatVector multiplicate(double k)
          Returns a new NumberVector of V that is the result of a scalar multiplication with the given scalar.
 SparseFloatVector negativeVector()
          Returns the additive inverse to this NumberVector of V.
 SparseFloatVector newInstance(double[] values)
          Returns a new NumberVector of N for the given values.
 SparseFloatVector newInstance(Float[] values)
          Returns a new FeatureVector of V for the given values.
 SparseFloatVector newInstance(List<Float> values)
          Returns a new FeatureVector of V for the given values.
 SparseFloatVector newInstance(Vector values)
          Returns a new NumberVector of N for the given values.
 SparseFloatVector nullVector()
          Provides a null vector of the same Vector Space as this NumberVector of V (that is, of the same dimensionality).
 SparseFloatVector plus(SparseFloatVector fv)
          Returns a new NumberVector of V that is the sum of this NumberVector of V and the given NumberVector of V.
 Float scalarProduct(SparseFloatVector fv)
          Provides the scalar product (inner product) of this and the given SparseFloatVector.
 void setDimensionality(int dimensionality)
          Sets the dimensionality to the new value.
 String toString()
           Provides a String representation of this SparseFloatVector as suitable for SparseFloatVectorLabelParser.
 
Methods inherited from class de.lmu.ifi.dbs.elki.data.AbstractNumberVector
byteValue, equals, floatValue, getMax, getMin, hashCode, intValue, shortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.lmu.ifi.dbs.elki.data.NumberVector
byteValue, floatValue, intValue, shortValue
 
Methods inherited from interface de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable
getMax, getMin
 

Field Detail

indexes

private int[] indexes
Indexes of values


values

private float[] values
Stored values


dimensionality

private int dimensionality
The dimensionality of this feature vector.

Constructor Detail

SparseFloatVector

public SparseFloatVector(int[] indexes,
                         float[] values,
                         int dimensionality)
Direct constructor.

Parameters:
indexes - Indexes Must be sorted!
values - Associated value.
dimensionality - "true" dimensionality

SparseFloatVector

public SparseFloatVector(Map<Integer,Float> values,
                         int dimensionality)
                  throws IllegalArgumentException
Provides a SparseFloatVector 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
dimensionality - the dimensionality of this feature vector
Throws:
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)

SparseFloatVector

public SparseFloatVector(float[] values)
                  throws IllegalArgumentException
Provides a SparseFloatVector 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:
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 interface FeatureVector<SparseFloatVector,Float>
Specified by:
getDimensionality in interface SpatialComparable
Returns:
the number of dimensions of this FeatureVector of V

setDimensionality

public void setDimensionality(int dimensionality)
                       throws IllegalArgumentException
Sets the dimensionality to the new value.

Parameters:
dimensionality - the new dimensionality
Throws:
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

public Float getValue(int dimension)
Description copied from interface: FeatureVector
Returns the value in the specified dimension.

Specified by:
getValue in interface FeatureVector<SparseFloatVector,Float>
Parameters:
dimension - the desired dimension, where 1 ≤ dimension ≤ this.getDimensionality()
Returns:
the value in the specified dimension

doubleValue

public double doubleValue(int dimension)
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 interface NumberVector<SparseFloatVector,Float>
Parameters:
dimension - the desired dimension, where 1 ≤ dimension ≤ this.getDimensionality()
Returns:
the value in the specified dimension

longValue

public long longValue(int dimension)
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 interface NumberVector<SparseFloatVector,Float>
Parameters:
dimension - the desired dimension, where 1 ≤ dimension ≤ this.getDimensionality()
Returns:
the value in the specified dimension

getColumnVector

public Vector getColumnVector()
Description copied from interface: NumberVector
Returns a Vector representing in one column and getDimensionality() rows the values of this NumberVector of V.

Specified by:
getColumnVector in interface NumberVector<SparseFloatVector,Float>
Returns:
a Matrix representing in one column and getDimensionality() rows the values of this NumberVector of V

getRowVector

public Matrix getRowVector()
Description copied from interface: NumberVector
Returns a Matrix representing in one row and getDimensionality() columns the values of this NumberVector of V.

Specified by:
getRowVector in interface NumberVector<SparseFloatVector,Float>
Returns:
a Matrix representing in one row and getDimensionality() columns the values of this NumberVector of V

plus

public SparseFloatVector plus(SparseFloatVector fv)
Description copied from interface: NumberVector
Returns a new NumberVector of V that is the sum of this NumberVector of V and the given NumberVector of V.

Specified by:
plus in interface NumberVector<SparseFloatVector,Float>
Parameters:
fv - a NumberVector of V to be added to this NumberVector of V
Returns:
a new NumberVector of V that is the sum of this NumberVector of V and the given NumberVector of V

minus

public SparseFloatVector minus(SparseFloatVector fv)
Description copied from interface: NumberVector
Returns a new NumberVector of V that is the sum of this NumberVector of V and the negativeVector() of given NumberVector of V.

Specified by:
minus in interface NumberVector<SparseFloatVector,Float>
Parameters:
fv - a NumberVector of V to be subtracted to this NumberVector of V
Returns:
a new NumberVector of V that is the sum of this NumberVector of V and the negative of given NumberVector of V

nullVector

public SparseFloatVector nullVector()
Description copied from interface: NumberVector
Provides a null vector of the same Vector Space as this NumberVector of V (that is, of the same dimensionality).

Specified by:
nullVector in interface NumberVector<SparseFloatVector,Float>
Returns:
a null vector of the same Vector Space as this NumberVector of V (that is, of the same dimensionality)

negativeVector

public SparseFloatVector negativeVector()
Description copied from interface: NumberVector
Returns the additive inverse to this NumberVector of V.

Specified by:
negativeVector in interface NumberVector<SparseFloatVector,Float>
Returns:
the additive inverse to this NumberVector of V

multiplicate

public SparseFloatVector multiplicate(double k)
Description copied from interface: NumberVector
Returns a new NumberVector of V that is the result of a scalar multiplication with the given scalar.

Specified by:
multiplicate in interface NumberVector<SparseFloatVector,Float>
Parameters:
k - a scalar to multiply this NumberVector of V with
Returns:
a new NumberVector of V that is the result of a scalar multiplication with the given scalar

toString

public String toString()

Provides a String representation of this SparseFloatVector as suitable for SparseFloatVectorLabelParser.

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 Integer and Float where the Integer gives the index of the dimensionality and the Float 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 interface FeatureVector<SparseFloatVector,Float>
Overrides:
toString in class Object
Returns:
a String representation of this SparseFloatVector

getValues

private double[] getValues()
Returns an array consisting of the values of this feature vector.

Returns:
an array consisting of the values of this feature vector

scalarProduct

public Float scalarProduct(SparseFloatVector fv)
Provides the scalar product (inner product) of this and the given SparseFloatVector.

Specified by:
scalarProduct in interface NumberVector<SparseFloatVector,Float>
Parameters:
fv - the SparseFloatVector to compute the scalar product for
Returns:
the scalar product (inner product) of this and the given SparseFloatVector

newInstance

public SparseFloatVector newInstance(Vector values)
Description copied from interface: NumberVector
Returns a new NumberVector of N for the given values.

Specified by:
newInstance in interface NumberVector<SparseFloatVector,Float>
Parameters:
values - the values of the NumberVector
Returns:
a new NumberVector of N for the given values

newInstance

public SparseFloatVector newInstance(double[] values)
Description copied from interface: NumberVector
Returns a new NumberVector of N for the given values.

Specified by:
newInstance in interface NumberVector<SparseFloatVector,Float>
Parameters:
values - the values of the NumberVector
Returns:
a new NumberVector of N for the given values

newInstance

public SparseFloatVector newInstance(List<Float> values)
Description copied from interface: FeatureVector
Returns a new FeatureVector of V for the given values.

Specified by:
newInstance in interface FeatureVector<SparseFloatVector,Float>
Parameters:
values - the values of the featureVector
Returns:
a new FeatureVector of V for the given values

newInstance

public SparseFloatVector newInstance(Float[] values)
Description copied from interface: FeatureVector
Returns a new FeatureVector of V for the given values.

Specified by:
newInstance in interface FeatureVector<SparseFloatVector,Float>
Parameters:
values - the values of the featureVector
Returns:
a new FeatureVector of V for the given values

getNotNullMask

public BitSet getNotNullMask()
Description copied from interface: SparseFeatureVector
Bit set of non-null features

Specified by:
getNotNullMask in interface SparseFeatureVector<SparseFloatVector,Float>
Returns:
Bit set

Release 0.4.0 (2011-09-20_1324)