jnisvmlight
Class FeatureVector


java.lang.Object

  extended by jnisvmlight.FeatureVector

All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
LabeledFeatureVector

public class FeatureVector
extends java.lang.Object
implements java.io.Serializable

A feature vector. Features are dimension-value pairs. This class implements a simple dictionary data structure to map dimensions onto their values. Note that for convenience, features do not have be sorted according to their dimensions at this point. The SVMLightTrainer class has an option for sorting input vectors prior to training.

See Also:
Serialized Form

Field Summary
protected  int[] m_dims
           
protected  double[] m_vals
           
 
Constructor Summary
FeatureVector(int size)
           
FeatureVector(int[] dims, double[] vals)
           
 
Method Summary
 double getCosine(FeatureVector v)
          Returns the cosine similarity between two feature vectors.
 int getDimAt(int index)
           
 double getL1Norm()
          Returns the linear norm factor of this vector's values (i.e., the sum of it's values).
 double getL2Norm()
          Returns the L2 norm factor of this vector's values.
 double getValueAt(int index)
           
 void normalizeL1()
          Performs a linear normalization to the value 1.
 void normalizeL1(double norm)
          Performs a linear normalization to the given norm value.
 void normalizeL2()
          Performs an L2 normalization to the value 1.
 void setFeatures(int[] dims, double[] vals)
           
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_dims


protected int[] m_dims

m_vals


protected double[] m_vals
Constructor Detail

FeatureVector


public FeatureVector(int size)

FeatureVector


public FeatureVector(int[] dims,

                     double[] vals)
Method Detail

getCosine


public double getCosine(FeatureVector v)
Returns the cosine similarity between two feature vectors.


getDimAt


public int getDimAt(int index)

getL1Norm


public double getL1Norm()
Returns the linear norm factor of this vector's values (i.e., the sum of it's values).


getL2Norm


public double getL2Norm()
Returns the L2 norm factor of this vector's values.


getValueAt


public double getValueAt(int index)

normalizeL1


public void normalizeL1()
Performs a linear normalization to the value 1.


normalizeL1


public void normalizeL1(double norm)
Performs a linear normalization to the given norm value.


normalizeL2


public void normalizeL2()
Performs an L2 normalization to the value 1.


setFeatures


public void setFeatures(int[] dims,

                        double[] vals)

size


public int size()

toString


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