infomat.vectorspace.vector
Class IVector<T extends IVectorIndex>

java.lang.Object
  extended by infomat.vectorspace.vector.IVector<T>

public class IVector<T extends IVectorIndex>
extends java.lang.Object

An implementation of a sparse vector. Should be thought of as a java.util.HashMap rather than a java.util.Vector. Contains Objects that implements the IVectorIndex interface. Consisits of a hashmap, mapping such objects to Float:s.


Nested Class Summary
private  class IVector.TLiteralComparator
          Private class for ordering the Ts in literal order.
private  class IVector.TValueComparator
          Private class for ordering the Ts in value order.
 
Field Summary
private  java.util.HashMap<T,java.lang.Float> objectValueMap
          The sparse representation, a map from T:s to Float values.
 
Constructor Summary
IVector()
           
IVector(java.util.HashMap<T,java.lang.Float> map)
          Copies the map.
IVector(IVector<T> vec)
          Copies the map.
 
Method Summary
 void add(java.util.HashMap<T,java.lang.Float> map)
          Uses the add(T, Float) method.
 void add(IVector<T> vec)
          Uses the add(T, Float) method.
 void add(T t, java.lang.Float f)
          Adds the value f to the previosus value for the T t.
 boolean contains(T t)
           
static
<U extends IVectorIndex,V extends IVectorIndex>
float
dotProduct(IVector<U> vec1, IVector<V> vec2)
          Returns the scalar product of the two IVector:s.
 java.util.HashMap<T,java.lang.Float> getMap()
          Returns the actual map.
 java.util.Vector<T> getOrderedVector()
          Returns a vector of T:s, orderd by their value.
 java.util.Vector<T> getUnorderedVector()
          Returns a vector of T:s, in no particular order.
 java.lang.Float getValue(T t)
          Returns the values for the specified T.
 IVector<T> highestRanked(int n)
          Returns the n highest ranked or as many as there is.
 java.util.Iterator<java.util.Map.Entry<T,java.lang.Float>> iterator()
           
 IVector<T> largerThan(float min)
          Returns only those that larger than the specified value.
 void log(double base)
          Uses the log(T, double) method - takes the logarithm of all elements using the provided base.
 void log(T t, double base)
          Sets this value to its logarithm with the specified base.
 void multiply(java.lang.Float f)
          Uses the multiply(T, Float) method - multiplies all elements by the the provided value.
 void multiply(T t, java.lang.Float f)
          Multiplies this value with the value for the T.
 void normalize()
           
 void print()
          For debugging.
 void put(java.util.HashMap<T,java.lang.Float> map)
          Uses the add(T, Float) method.
 void put(IVector<T> vec)
          Uses the put(T, Float) method.
 void put(T t, java.lang.Float f)
          Sets the value for t to be f.
 void remove(T t)
           
 void removeAll()
           
 int size()
          Returns the number of indexes used in this IVector.
 void sortInvert()
           
 void sortLiteral()
           
 void sortRandom()
           
 void subtract(java.util.HashMap<T,java.lang.Float> map)
          Uses the subtract(T, Float) method.
 void subtract(IVector<T> vec)
          Uses the subtract(T, Float) method.
 void subtract(T t, java.lang.Float f)
          Subtracts this value from the value for the T.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

objectValueMap

private java.util.HashMap<T extends IVectorIndex,java.lang.Float> objectValueMap
The sparse representation, a map from T:s to Float values.

Constructor Detail

IVector

public IVector()

IVector

public IVector(java.util.HashMap<T,java.lang.Float> map)
Copies the map.


IVector

public IVector(IVector<T> vec)
Copies the map.

Method Detail

add

public void add(T t,
                java.lang.Float f)
Adds the value f to the previosus value for the T t. If this mapping does not exist it is created with the value f.


add

public void add(IVector<T> vec)
Uses the add(T, Float) method.


add

public void add(java.util.HashMap<T,java.lang.Float> map)
Uses the add(T, Float) method.


put

public void put(T t,
                java.lang.Float f)
Sets the value for t to be f.


put

public void put(IVector<T> vec)
Uses the put(T, Float) method.


put

public void put(java.util.HashMap<T,java.lang.Float> map)
Uses the add(T, Float) method.


remove

public void remove(T t)

removeAll

public void removeAll()

subtract

public void subtract(T t,
                     java.lang.Float f)
Subtracts this value from the value for the T.


subtract

public void subtract(IVector<T> vec)
Uses the subtract(T, Float) method.


subtract

public void subtract(java.util.HashMap<T,java.lang.Float> map)
Uses the subtract(T, Float) method.


multiply

public void multiply(T t,
                     java.lang.Float f)
Multiplies this value with the value for the T.


multiply

public void multiply(java.lang.Float f)
Uses the multiply(T, Float) method - multiplies all elements by the the provided value.


log

public void log(T t,
                double base)
Sets this value to its logarithm with the specified base.


log

public void log(double base)
Uses the log(T, double) method - takes the logarithm of all elements using the provided base.


normalize

public void normalize()

highestRanked

public IVector<T> highestRanked(int n)
Returns the n highest ranked or as many as there is.


largerThan

public IVector<T> largerThan(float min)
Returns only those that larger than the specified value.


dotProduct

public static <U extends IVectorIndex,V extends IVectorIndex> float dotProduct(IVector<U> vec1,
                                                                               IVector<V> vec2)
Returns the scalar product of the two IVector:s.

Checks whether the second IVector is smaller than first. A small decrease in time is achieved by giving the IVector that one believes is smaller as first parameter. (Do not check it also. That increases time spent.)


size

public int size()
Returns the number of indexes used in this IVector.


getValue

public java.lang.Float getValue(T t)
Returns the values for the specified T.


contains

public boolean contains(T t)

getMap

public java.util.HashMap<T,java.lang.Float> getMap()
Returns the actual map. Not a copy!


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getOrderedVector

public java.util.Vector<T> getOrderedVector()
Returns a vector of T:s, orderd by their value.


getUnorderedVector

public java.util.Vector<T> getUnorderedVector()
Returns a vector of T:s, in no particular order. Faster than #getOrderedVector().


sortLiteral

public void sortLiteral()

sortRandom

public void sortRandom()

sortInvert

public void sortInvert()

print

public void print()
For debugging.


iterator

public java.util.Iterator<java.util.Map.Entry<T,java.lang.Float>> iterator()