## edu.stanford.nlp.maxent
Class Feature

    java.lang.Object
      edu.stanford.nlp.maxent.Feature

Direct Known Subclasses:
  TaggerFeature

    public class Feature

extends Object

This class is used as a base class for TaggerFeature for the tagging problem and for BinaryFeature for the general problem with binary features.

Author:
  Kristina Toutanova

Field Summary
`protected HashMap<Integer,Double>` `hashValues`
`int[]` `indexedValues` This will contain the (x,y) pairs for which the feature is non-zero in case it is sparse.
`Index<IntPair>` `instanceIndex`
`double` `sum`
`double[]` `valuesI` These are the non-zero values we want to keep for the points in indexedValues.

Constructor Summary
`Feature()`
`Feature(Experiments e, double[][] vals, Index<IntPair> instanceIndex)`
`Feature(Experiments e, double[] vals, Index<IntPair> instanceIndex)` This is if we are given an array of double with a value for each training sample in the order of their occurrence.
`Feature(Experiments e, int[] indexes, double[] vals, Index<IntPair> instanceIndex)`
`Feature(Experiments e, int numElems, Index<IntPair> instanceIndex)`

Method Summary
`double` `ftilde()`
`double` `getVal(int index)` Get the value at the index-ed non zero value pair (x,y)
`double` `getVal(int x, int y)` This is rarely used because it is slower and requires initHashVals() to be called beforehand to initiallize the hashValues
`int` `getX(int index)`
`int` `getY(int index)`
`void` `initHashVals()` Creates a hashmap with keys pairs (x,y) and values the value of the function at the pair; required for use of getVal(x,y)
`boolean` `isEmpty()`
`int` `len()`
`void` `print()` Prints out the points where the feature is non-zero and the values at these points.
`void` `print(PrintStream pf)`
`void` `read(InDataStreamFile inf)`
`void` `save(OutDataStreamFile oF)`
`void` `setSum()`
`void` `setValue(int index, int key, double value)` used to sequentially set the values of a feature -- index is the pace in the arrays ; key goes into indexedValues, and value goes into valuesI
`double` `sumValues()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### indexedValues

    public int[] indexedValues

  This will contain the (x,y) pairs for which the feature is non-zero in case it is sparse. The pairs (x,y) are coded as x*ySize+y. The values are kept in valuesI. For example, if a feature has only two non-zero values, e.g f(1,2)=3 and f(6,3)=0.74, then indexedValues will have values indexedValues={1*ySize+2,6*ySzie+2} and valuesI will be {3,.74}

### valuesI

    public double[] valuesI

  These are the non-zero values we want to keep for the points in indexedValues.

### hashValues

    protected HashMap<Integer,Double> hashValues

### sum

    public double sum

### instanceIndex

    public Index<IntPair> instanceIndex

Constructor Detail

### Feature

    public Feature()

### Feature

    public Feature(Experiments e,
                   double[] vals,
                   Index<IntPair> instanceIndex)

  This is if we are given an array of double with a value for each training sample in the order of their occurrence.

### Feature

    public Feature(Experiments e,
                   double[][] vals,
                   Index<IntPair> instanceIndex)

Parameters:
  `vals` - a value for each (x,y) pair

### Feature

    public Feature(Experiments e,
                   int numElems,
                   Index<IntPair> instanceIndex)

### Feature

    public Feature(Experiments e,
                   int[] indexes,
                   double[] vals,
                   Index<IntPair> instanceIndex)

Parameters:
  `indexes` - The pairs (x,y) for which the feature is non-zero. They are coded as x*ySize+y
  `vals` - The values at these points.

Method Detail

### print

    public void print()

  Prints out the points where the feature is non-zero and the values at these points.

### setValue

    public void setValue(int index,
                         int key,
                         double value)

  used to sequentially set the values of a feature -- index is the pace in the arrays ; key goes into indexedValues, and value goes into valuesI

### print

    public void print(PrintStream pf)

### getVal

    public double getVal(int index)

  Get the value at the index-ed non zero value pair (x,y)

### setSum

    public void setSum()

### sumValues

    public double sumValues()

### save

    public void save(OutDataStreamFile oF)

### read

    public void read(InDataStreamFile inf)

### len

    public int len()

### isEmpty

    public boolean isEmpty()

  Returns:
    true if the feature does not have non-zero values

### getX

    public int getX(int index)

  Returns:
    the history x of the index-th (x,y) pair

### getY

    public int getY(int index)

  Returns:
    the outcome y of the index-th (x,y) pair

### getVal

    public double getVal(int x,
                         int y)

  This is rarely used because it is slower and requires initHashVals() to be called beforehand to initiallize the hashValues

### initHashVals

    public void initHashVals()

  Creates a hashmap with keys pairs (x,y) and values the value of the function at the pair; required for use of getVal(x,y)

### ftilde

    public double ftilde()

  Returns:
    the emptirical expectation of the feature

Stanford NLP Group