Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

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

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

public class SparseFloatVector
extends AbstractNumberVector<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.

Author:
Arthur Zimek

Field Summary
private  int dimensionality
          The dimensionality of this feature vector.
private  Integer maximumIndex
          The maximal occurring index of any dimension.
private  Map<Integer,Float> values
          Mapping of indices and corresponding 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(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.
 List<Integer> getIndicesOfNotNullValues()
          Provides a list containing the indices (dimensions) with a value other than zero.
 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)
          Provides a new SparseFloatVector as result of the multiplication of this SparseFloatVector by the scalar k.
 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.
 SparseFloatVector randomInstance(Float min, Float max, Random random)
          Returns a NumberVector of V with random values between min and max.
 SparseFloatVector randomInstance(Random random)
          Returns a NumberVector of V with uniformly distributed (0-1) random values.
 SparseFloatVector randomInstance(SparseFloatVector min, SparseFloatVector max, Random random)
          Returns a NumberVector of V with random values between min and max.
 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 toCompleteString()
          Provides a String representation of this SparseFloatVector as suitable for FloatVectorLabelParser.
 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, intValue, shortValue
 
Methods inherited from class de.lmu.ifi.dbs.elki.data.AbstractDatabaseObject
getID, setID
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.lmu.ifi.dbs.elki.data.DatabaseObject
getID, setID
 
Methods inherited from interface de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialObject
getID
 

Field Detail

values

private Map<Integer,Float> values
Mapping of indices and corresponding values. Only non-zero values will to be stored.


maximumIndex

private Integer maximumIndex
The maximal occurring index of any dimension.


dimensionality

private int dimensionality
The dimensionality of this feature vector.

Constructor Detail

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

newInstance

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

Parameters:
values - the values of the NumberVector
Returns:
a new NumberVector of N for the given values
See Also:
NumberVector.newInstance(double[])

newInstance

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

Parameters:
values - the values of the NumberVector
Returns:
a new NumberVector of N for the given values
See Also:
NumberVector.newInstance(double[])

newInstance

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

Parameters:
values - the values of the featureVector
Returns:
a new FeatureVector of V for the given values
See Also:
FeatureVector.newInstance(java.util.List)

newInstance

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

Parameters:
values - the values of the featureVector
Returns:
a new FeatureVector of V for the given values
See Also:
FeatureVector.newInstance(D[])

randomInstance

public SparseFloatVector randomInstance(Random random)
Description copied from interface: NumberVector
Returns a NumberVector of V with uniformly distributed (0-1) random values.

Parameters:
random - a Random instance
Returns:
a NumberVector of V with random values
See Also:
NumberVector.randomInstance(java.util.Random)

randomInstance

public SparseFloatVector randomInstance(Float min,
                                        Float max,
                                        Random random)
Description copied from interface: NumberVector
Returns a NumberVector of V with random values between min and max.

Parameters:
min - minimum of random value
max - maximum of random value
random - a random instance
Returns:
a NumberVector of V with random values between min and max
See Also:
NumberVector.randomInstance(java.lang.Number, java.lang.Number, java.util.Random)

randomInstance

public SparseFloatVector randomInstance(SparseFloatVector min,
                                        SparseFloatVector max,
                                        Random random)
Description copied from interface: NumberVector
Returns a NumberVector of V with random values between min and max.

Parameters:
min - minimum of random value for each axis
max - maximum of random value for each axis
random - a random instance
Returns:
a NumberVector of V with random values between min and max
See Also:
NumberVector.randomInstance(de.lmu.ifi.dbs.elki.data.NumberVector, de.lmu.ifi.dbs.elki.data.NumberVector, java.util.Random)

getDimensionality

public int getDimensionality()
Description copied from interface: FeatureVector
The dimensionality of the vector space where of this FeatureVector of V is an element.

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.

Parameters:
dimension - the desired dimension, where 1 ≤ dimension ≤ this.getDimensionality()
Returns:
the value in the specified dimension
See Also:
FeatureVector.getValue(int)

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.

Parameters:
dimension - the desired dimension, where 1 ≤ dimension ≤ this.getDimensionality()
Returns:
the value in the specified dimension
See Also:
NumberVector.doubleValue(int)

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.

Parameters:
dimension - the desired dimension, where 1 ≤ dimension ≤ this.getDimensionality()
Returns:
the value in the specified dimension
See Also:
NumberVector.longValue(int)

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.

Returns:
a Matrix representing in one column and getDimensionality() rows the values of this NumberVector of V
See Also:
NumberVector.getColumnVector()

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.

Returns:
a Matrix representing in one row and getDimensionality() columns the values of this NumberVector of V
See Also:
NumberVector.getRowVector()

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.

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
See Also:
NumberVector.plus(de.lmu.ifi.dbs.elki.data.NumberVector)

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.

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
See Also:
NumberVector.plus(de.lmu.ifi.dbs.elki.data.NumberVector)

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).

Returns:
a null vector of the same Vector Space as this NumberVector of V (that is, of the same dimensionality)
See Also:
NumberVector.nullVector()

negativeVector

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

Returns:
the additive inverse to this NumberVector of V
See Also:
NumberVector.negativeVector()

multiplicate

public SparseFloatVector multiplicate(double k)
Provides a new SparseFloatVector as result of the multiplication of this SparseFloatVector by the scalar k.

Parameters:
k - a scalar to multiply this SparseFloatVector
Returns:
a new SparseFloatVector as result of the multiplication

toCompleteString

public String toCompleteString()
Provides a String representation of this SparseFloatVector as suitable for FloatVectorLabelParser. This includes zero valued attributes but no indices.

Example: a vector (0,1.2,1.3,0)T would result in the String
0 1.2 1.3 0

Returns:
a String representation of this SparseFloatVector as a list of all values

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

getIndicesOfNotNullValues

public List<Integer> getIndicesOfNotNullValues()
Provides a list containing the indices (dimensions) with a value other than zero. The indices of occurring dimensions are sorted in ascending order. The returned list is not backed by this SparseFloatVector, i.e., changes of this SparseFloatVector will not affect the list returned by thins method.

Returns:
a list containing the indices (dimensions) with a value other than zero

scalarProduct

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

Parameters:
fv - the SparseFloatVector to compute the scalar product for
Returns:
the scalar product (inner product) of this and the given SparseFloatVector

Release 0.3 (2010-03-31_1612)