contextFold.features
Class AbstractFeatureVector

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

public abstract class AbstractFeatureVector
extends java.lang.Object
implements Dotable<AbstractFeatureVector>, java.io.Serializable

A weight vector object.

See Also:
Serialized Form

Field Summary
protected  java.util.Map<java.lang.Integer,java.lang.String> featureNames
           
 
Constructor Summary
AbstractFeatureVector()
           
 
Method Summary
 void add(AbstractFeatureVector other)
          The same as add(AbstractFeatureVector, float), where amount = 1.
 void add(AbstractFeatureVector other, float amount)
          Adds to this object another weight vector.
abstract  void clear()
          Sets all weights to 0.
abstract  int countNonZeroEntries()
           
 float dot(AbstractFeatureVector other)
          Computes the dot-product of two vectors.
 float filter(float propOfMaxWeight)
           
abstract  float getFeatureWeight(int featureIx)
           
abstract  java.util.Iterator<java.lang.Integer> getNonZeroFeatures()
           
abstract  float norm()
           
 void setFeatureNames(java.util.Map<java.lang.Integer,java.lang.String> names)
           
abstract  void setFeatureWeight(int featureIx, float newFeatureWeight)
          Sets the weight of a given feature.
 void sub(AbstractFeatureVector other)
          The same as sub(AbstractFeatureVector, float), where amount = 1.
 void sub(AbstractFeatureVector other, float amount)
          The same as add(AbstractFeatureVector, float), where other is being subtracted rather than added.
 float sum()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

featureNames

protected java.util.Map<java.lang.Integer,java.lang.String> featureNames
Constructor Detail

AbstractFeatureVector

public AbstractFeatureVector()
Method Detail

norm

public abstract float norm()
Returns:
the L_2 norm of the vector.

add

public void add(AbstractFeatureVector other,
                float amount)
Adds to this object another weight vector. Each weight entry w_i of this object is set to be w_i = w_i + amount*w'_i, where w'_i is the i-th weight of the other vector, and amount is the given scaling parameter.

Parameters:
other - a weight vector to be added.
amount - a scaling parameter.

add

public void add(AbstractFeatureVector other)
The same as add(AbstractFeatureVector, float), where amount = 1.

Parameters:
other - a weight vector to be added.

sub

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

Parameters:
other - a weight vector to be subtracted.
amount - a scaling parameter.

sub

public void sub(AbstractFeatureVector other)
The same as sub(AbstractFeatureVector, float), where amount = 1.

Parameters:
other - a weight vector to be subtracted.

getFeatureWeight

public abstract float getFeatureWeight(int featureIx)
Parameters:
featureIx - an index of a feature.
Returns:
the weight of the feature which index is featureIx.

setFeatureWeight

public abstract void setFeatureWeight(int featureIx,
                                      float newFeatureWeight)
Sets the weight of a given feature.

Parameters:
featureIx - an index of a feature.
newFeatureWeight - a value to be set as the weight of the feature which index is featureIx.

getNonZeroFeatures

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

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>
Parameters:
other - another vector.
Returns:
the dot-product of this and other.

clear

public abstract void clear()
Sets all weights to 0.


sum

public float sum()
Returns:
the summation of all weights.

setFeatureNames

public void setFeatureNames(java.util.Map<java.lang.Integer,java.lang.String> names)

countNonZeroEntries

public abstract int countNonZeroEntries()
Returns:
the number of features which weights are not 0.

filter

public float filter(float propOfMaxWeight)
Parameters:
propOfMaxWeight - a fraction s.t. weights whose absolute values are below this faction with respect to the absolute maximum weight, are set to 0.
Returns:
the proportion of filtered weights with respect to all non-zero weights.