edu.umd.cloud9.io
Class VectorFloat<F extends WritableComparable>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<F,Float>
          extended by edu.umd.cloud9.io.VectorFloat<F>
Type Parameters:
F - type of feature
All Implemented Interfaces:
Serializable, Cloneable, Map<F,Float>, Writable

public class VectorFloat<F extends WritableComparable>
extends HashMap<F,Float>
implements Writable

Writable representing a vector of float values. This generic class, based on the Java HashMap, supports the use of any class for the features (i.e., component of the vector), but all values are floats.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
VectorFloat()
          Creates a VectorFloat object.
 
Method Summary
 float dot(VectorFloat<F> v)
          Computes the dot product between this vector and another vector.
 float get(F f)
          Returns the value of a feature.
 SortedSet<Map.Entry<F,Float>> getSortedEntries()
          Returns feature-value entries sorted by descending value.
 SortedSet<Map.Entry<F,Float>> getSortedEntries(int n)
          Returns top n feature-value entries sorted by descending value.
 float length()
          Computes the length of this vector.
 void normalize()
          Normalizes this vector to a unit-length vector.
 void plus(VectorFloat<F> v)
          Adds another vector to this vector, based on feature-wise addition.
 void readFields(DataInput in)
          Deserializes the vector.
 void set(F f, float v)
          Sets the value of a feature.
 void write(DataOutput out)
          Serializes the vector.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

VectorFloat

public VectorFloat()
Creates a VectorFloat object.

Method Detail

readFields

public void readFields(DataInput in)
                throws IOException
Deserializes the vector.

Specified by:
readFields in interface Writable
Parameters:
in - source for raw byte representation
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Serializes the vector.

Specified by:
write in interface Writable
Parameters:
out - where to write the raw byte representation
Throws:
IOException

set

public void set(F f,
                float v)
Sets the value of a feature.

Parameters:
f - the feature
v - the value

get

public float get(F f)
Returns the value of a feature.

Parameters:
f - the feature
Returns:
the value of the feature

plus

public void plus(VectorFloat<F> v)
Adds another vector to this vector, based on feature-wise addition.

Parameters:
v - vector to add

dot

public float dot(VectorFloat<F> v)
Computes the dot product between this vector and another vector.

Parameters:
v - the other vector

length

public float length()
Computes the length of this vector.

Returns:
length of tis vector

normalize

public void normalize()
Normalizes this vector to a unit-length vector.


getSortedEntries

public SortedSet<Map.Entry<F,Float>> getSortedEntries()
Returns feature-value entries sorted by descending value. Ties broken by the natural sort order of the feature.

Returns:
feature-value entries sorted by descending value

getSortedEntries

public SortedSet<Map.Entry<F,Float>> getSortedEntries(int n)
Returns top n feature-value entries sorted by descending value. Ties broken by the natural sort order of the feature.

Parameters:
n - number of entries to return
Returns:
top n feature-value entries sorted by descending value