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

java.lang.Object
  extended by infomat.vectorspace.ivector.IVector<T>
All Implemented Interfaces:
IVectorIndex

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

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.IDComparator
          Private class for ordering the Ts in order of their ID.
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.
static
<U extends IVectorIndex,V extends IVectorIndex>
java.lang.Float
cartesianDistance(IVector<U> vec1, IVector<V> vec2)
          Returns the cartesian distance between the two IVector:s.
static
<U extends IVectorIndex,V extends IVectorIndex>
java.lang.Float
cartesianDistance(IVector<U> vec1, IVector<V> vec2, double sqDist)
          Returns the cartesian distance between the two IVector:s, using the squared distance to origo for the second.
static
<V extends IVectorIndex>
double
cartesianSquaredDistanceFromOrigo(IVector<V> vec)
          Returns the cartesian distance from Origo for the vector.
 boolean contains(T t)
           
static
<T extends IVectorIndex>
double
corrCoeff(IVector<T> vec1, IVector<T> vec2)
          Returns the correlation coefficient for the two IVector:s.
static
<T extends IVectorIndex>
double
covar(IVector<T> vec1, IVector<T> vec2)
          Returns the covariance for the two IVector:s.
 void dotMultiply(IVector<T> otherVec)
          Like matlabs .* operator.
static
<T extends IVectorIndex>
IVector<T>
dotMultiply(IVector<T> vec1, IVector<T> vec2)
          Like matlabs .* operator.
static
<U extends IVectorIndex,V extends IVectorIndex>
float
dotProduct(IVector<U> vec1, IVector<V> vec2)
          Returns the scalar product of the two IVector:s.
 int getID()
           
 java.lang.String getLocation()
           
 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.lang.String getString()
           
 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.
 T highestRanked()
          Returns the highest ranked or null if empty.
 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(double min)
          Returns only those that larger than the specified value.
 IVector<T> largerThanOrEquals(double 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.
 double mean()
          Returns the mean of the stored values.
 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()
           
static
<U extends IVectorIndex,V extends IVectorIndex>
int
numberOfSharedElements(IVector<U> vec1, IVector<V> vec2)
          Returns the number of elements that are in both IVector:s.
 void print()
          For debugging.
 void put(java.util.HashMap<T,java.lang.Float> map)
          Uses the put(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.
 IVector<T> smallerThanOrEquals(double max)
          Returns only those that larger than the specified value.
 void sortInIDOrder()
           
 void sortInvert()
           
 void sortLiteral()
           
 void sortRandom()
           
 double std()
          Returns the standard deviation of the stored values.
 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 the value f from the value for the T.
 java.lang.String toString()
           
 double variance()
          Returns the standard deviation of the stored values.
 
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 put(T, Float) method.


remove

public void remove(T t)

removeAll

public void removeAll()

subtract

public void subtract(T t,
                     java.lang.Float f)
Subtracts the value f from the value for the T. If the value does not exit it is not given the value -f.


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.


dotMultiply

public void dotMultiply(IVector<T> otherVec)
Like matlabs .* operator.


dotMultiply

public static <T extends IVectorIndex> IVector<T> dotMultiply(IVector<T> vec1,
                                                              IVector<T> vec2)
Like matlabs .* operator.


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 T highestRanked()
Returns the highest ranked or null if empty.


highestRanked

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


largerThan

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


largerThanOrEquals

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


smallerThanOrEquals

public IVector<T> smallerThanOrEquals(double max)
Returns only those that larger than the specified value.


numberOfSharedElements

public static <U extends IVectorIndex,V extends IVectorIndex> int numberOfSharedElements(IVector<U> vec1,
                                                                                         IVector<V> vec2)
Returns the number of elements that are in both IVector:s.


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


cartesianDistance

public static <U extends IVectorIndex,V extends IVectorIndex> java.lang.Float cartesianDistance(IVector<U> vec1,
                                                                                                IVector<V> vec2)
Returns the cartesian distance between the two IVector:s.


cartesianDistance

public static <U extends IVectorIndex,V extends IVectorIndex> java.lang.Float cartesianDistance(IVector<U> vec1,
                                                                                                IVector<V> vec2,
                                                                                                double sqDist)
Returns the cartesian distance between the two IVector:s, using the squared distance to origo for the second.


cartesianSquaredDistanceFromOrigo

public static <V extends IVectorIndex> double cartesianSquaredDistanceFromOrigo(IVector<V> vec)
Returns the cartesian distance from Origo for the vector. If there is no common indexes it returns null.


covar

public static <T extends IVectorIndex> double covar(IVector<T> vec1,
                                                    IVector<T> vec2)
Returns the covariance for the two IVector:s.


corrCoeff

public static <T extends IVectorIndex> double corrCoeff(IVector<T> vec1,
                                                        IVector<T> vec2)
Returns the correlation coefficient for the two IVector:s. Uses #covar(), #std()


size

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


mean

public double mean()
Returns the mean of the stored values.


variance

public double variance()
Returns the standard deviation of the stored values. Uses #mean().


std

public double std()
Returns the standard deviation of the stored values. Uses #variance().


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

sortInIDOrder

public void sortInIDOrder()

print

public void print()
For debugging.


iterator

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

getString

public java.lang.String getString()
Specified by:
getString in interface IVectorIndex

getLocation

public java.lang.String getLocation()
Specified by:
getLocation in interface IVectorIndex

getID

public int getID()
Specified by:
getID in interface IVectorIndex