contextFold.features
Class DenseFeatureVector

java.lang.Object
  extended by contextFold.features.AbstractFeatureVector
      extended by contextFold.features.DenseFeatureVector
All Implemented Interfaces:
Dotable<AbstractFeatureVector>, java.io.Serializable

public class DenseFeatureVector
extends AbstractFeatureVector

A dense implementation of a feature vector

See Also:
Serialized Form

Field Summary
protected  float[] acc
           
protected  int dimension
           
protected  int[] intWeights
           
protected  boolean isCompressed
           
protected  int[] upd
           
protected  int updateTime
           
protected  float[] weights
           
 
Fields inherited from class contextFold.features.AbstractFeatureVector
featureNames
 
Constructor Summary
DenseFeatureVector(DenseFeatureVector toCopy)
          A copy constructor.
DenseFeatureVector(int dimension)
          A constructor.
DenseFeatureVector(int length, float epsilon)
          A constructor.
 
Method Summary
 void add(AbstractFeatureVector other)
          The same as AbstractFeatureVector.add(AbstractFeatureVector, float), where amount = 1.
 void average()
          Setting weights to the average values over all updates.
 void clear()
          Sets all weights to 0.
 void compress()
           
 void compress(int intRange)
          Maps all float weights to the given range of integers.
 int countNonZeroEntries()
           
 int dim()
           
 float dot(AbstractFeatureVector other)
          Computes the dot-product of two vectors.
 float getFeatureWeight(int featureIx)
           
 java.util.Iterator<java.lang.Integer> getNonZeroFeatures()
           
 int getUpdateTime()
           
 float max()
           
 float min()
           
 DenseFeatureVector newEmpty()
           
 float norm()
           
 void setFeatureWeight(int featureIx, float newFeatureWeight)
          Sets the weight of a given feature.
 void sub(AbstractFeatureVector other)
          The same as AbstractFeatureVector.sub(AbstractFeatureVector, float), where amount = 1.
 void sub(AbstractFeatureVector other, float amount)
          The same as AbstractFeatureVector.add(AbstractFeatureVector, float), where other is being subtracted rather than added.
 void tick()
          Increases time stamp by one.
 void uncompress()
           
 void update(AbstractFeatureVector other, float s)
          Executes add(other, s), while maintaining an inner state that allows averaging over all updates.
 
Methods inherited from class contextFold.features.AbstractFeatureVector
add, filter, setFeatureNames, sum
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

weights

protected float[] weights

acc

protected float[] acc

upd

protected int[] upd

intWeights

protected int[] intWeights

dimension

protected int dimension

updateTime

protected int updateTime

isCompressed

protected boolean isCompressed
Constructor Detail

DenseFeatureVector

public DenseFeatureVector(int dimension)
A constructor.

Parameters:
dimension - the length of the constructed vector.

DenseFeatureVector

public DenseFeatureVector(int length,
                          float epsilon)
A constructor.

Parameters:
length - the length of the constructed vector.
epsilon - an initial value to set in all the entries.

DenseFeatureVector

public DenseFeatureVector(DenseFeatureVector toCopy)
A copy constructor.

Parameters:
toCopy - the vector to be copied.
Method Detail

getUpdateTime

public int getUpdateTime()
Returns:
the time-stamp of the last update to the vector

dot

public float dot(AbstractFeatureVector other)
Description copied from interface: Dotable
Computes the dot-product of two vectors.

Specified by:
dot in interface Dotable<AbstractFeatureVector>
Overrides:
dot in class AbstractFeatureVector
Parameters:
other - another vector.
Returns:
the dot-product of this and other.

add

public void add(AbstractFeatureVector other)
Description copied from class: AbstractFeatureVector
The same as AbstractFeatureVector.add(AbstractFeatureVector, float), where amount = 1.

Overrides:
add in class AbstractFeatureVector
Parameters:
other - a weight vector to be added.

sub

public void sub(AbstractFeatureVector other,
                float amount)
Description copied from class: AbstractFeatureVector
The same as AbstractFeatureVector.add(AbstractFeatureVector, float), where other is being subtracted rather than added.

Overrides:
sub in class AbstractFeatureVector
Parameters:
other - a weight vector to be subtracted.
amount - a scaling parameter.

sub

public void sub(AbstractFeatureVector other)
Description copied from class: AbstractFeatureVector
The same as AbstractFeatureVector.sub(AbstractFeatureVector, float), where amount = 1.

Overrides:
sub in class AbstractFeatureVector
Parameters:
other - a weight vector to be subtracted.

tick

public void tick()
Increases time stamp by one.


update

public void update(AbstractFeatureVector other,
                   float s)
Executes add(other, s), while maintaining an inner state that allows averaging over all updates.

Parameters:
other -
s -

average

public void average()
Setting weights to the average values over all updates.


newEmpty

public DenseFeatureVector newEmpty()
Returns:
a new DenseFeatureVector object of the same dimension as this one.

dim

public int dim()
Returns:
the dimension of the vector.

getFeatureWeight

public float getFeatureWeight(int featureIx)
Specified by:
getFeatureWeight in class AbstractFeatureVector
Parameters:
featureIx - an index of a feature.
Returns:
the weight of the feature which index is featureIx.

getNonZeroFeatures

public java.util.Iterator<java.lang.Integer> getNonZeroFeatures()
Specified by:
getNonZeroFeatures in class AbstractFeatureVector
Returns:
an Iterator over the indices of features which weights are not zero.

setFeatureWeight

public void setFeatureWeight(int featureIx,
                             float newFeatureWeight)
Description copied from class: AbstractFeatureVector
Sets the weight of a given feature.

Specified by:
setFeatureWeight in class AbstractFeatureVector
Parameters:
featureIx - an index of a feature.
newFeatureWeight - a value to be set as the weight of the feature which index is featureIx.

clear

public void clear()
Description copied from class: AbstractFeatureVector
Sets all weights to 0.

Specified by:
clear in class AbstractFeatureVector

norm

public float norm()
Specified by:
norm in class AbstractFeatureVector
Returns:
the L_2 norm of the vector.

countNonZeroEntries

public int countNonZeroEntries()
Specified by:
countNonZeroEntries in class AbstractFeatureVector
Returns:
the number of features which weights are not 0.

max

public float max()
Returns:
the maximum value in the vector

min

public float min()
Returns:
the minimum value in the vector

compress

public void compress()

compress

public void compress(int intRange)
Maps all float weights to the given range of integers. This allows for a more compact serialization of the object.
IMPORTANT! After compressing the object, it cannot be used before applying the uncompress() method (otherwise, exceptions will be thrown). In addition, compression deletes information which is required for averaging the vector.

Parameters:
intRange - the range of integers to which the weights are mapped.

uncompress

public void uncompress()