com.sun.labs.minion.classification
Class ContingencyFeature

java.lang.Object
  extended by com.sun.labs.minion.classification.WeightedFeature
      extended by com.sun.labs.minion.classification.ContingencyFeature
All Implemented Interfaces:
Feature, Occurrence, java.io.Serializable, java.lang.Comparable<Feature>

public class ContingencyFeature
extends WeightedFeature

A weighted feature class that contains a 2x2 contingency table that can be used to calculate the Mutual Information or Chi-squared measures.

See Also:
Serialized Form

Field Summary
protected  int a
          The number of documents in the class that contain this feature.
protected  int b
          The number of documents not in the class that contain this feature.
protected  int c
          The number of documents in the class that don't contain this feature.
static int CHI_SQUARED
          A constant indicating that we should return the Chi-squared value as the weight for this feature.
protected  int d
          The number of documents not in the class that don't contain this feature.
protected  java.util.Set<java.lang.Integer> docIDs
           
static int MUTUAL_INFORMATION
          A constant indicating that we should return the MI value as the weight for this feature.
protected  int N
          The total number of documents.
protected  int type
          The type of weight that we'll return.
protected  boolean weightCalculated
          Whether we've already calculated the weight.
 
Fields inherited from class com.sun.labs.minion.classification.WeightedFeature
entry, freq, id, invWeightComparator, name, weight, weightComparator
 
Constructor Summary
ContingencyFeature()
          Creates an empty contingency feature with the default MI type
ContingencyFeature(ContingencyFeature cf)
          Creates a copy of a contingency feature
ContingencyFeature(int type)
          Creates an empty feature.
ContingencyFeature(java.lang.String name)
          Creates a feature with the given name.
 
Method Summary
 void addDoc(int docID)
           
 int getA()
           
 int getB()
           
protected  java.util.Set<java.lang.Integer> getDocs()
           
 float getWeight()
          Gets the weight associated with this term.
 void setWeight(float weight)
          Sets the weight associated with this feature.
 void sum(ContingencyFeature other)
          Adds the other feature's weights to this one's
 java.lang.String toString()
           
protected  void wipeDocs()
           
 
Methods inherited from class com.sun.labs.minion.classification.WeightedFeature
combine, compareTo, decode, encode, equals, getCount, getEntry, getFreq, getID, getInverseWeightComparator, getName, getWeightComparator, setCount, setEntry, setFreq, setID, setName
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

protected int type
The type of weight that we'll return.

See Also:
MUTUAL_INFORMATION, CHI_SQUARED

a

protected int a
The number of documents in the class that contain this feature.


b

protected int b
The number of documents not in the class that contain this feature.


c

protected int c
The number of documents in the class that don't contain this feature.


d

protected int d
The number of documents not in the class that don't contain this feature.


N

protected int N
The total number of documents.


weightCalculated

protected boolean weightCalculated
Whether we've already calculated the weight.


MUTUAL_INFORMATION

public static final int MUTUAL_INFORMATION
A constant indicating that we should return the MI value as the weight for this feature.

See Also:
Constant Field Values

CHI_SQUARED

public static final int CHI_SQUARED
A constant indicating that we should return the Chi-squared value as the weight for this feature.

See Also:
Constant Field Values

docIDs

protected java.util.Set<java.lang.Integer> docIDs
Constructor Detail

ContingencyFeature

public ContingencyFeature()
Creates an empty contingency feature with the default MI type


ContingencyFeature

public ContingencyFeature(int type)
Creates an empty feature.


ContingencyFeature

public ContingencyFeature(java.lang.String name)
Creates a feature with the given name.


ContingencyFeature

public ContingencyFeature(ContingencyFeature cf)
Creates a copy of a contingency feature

Parameters:
cf - feature to copy
Method Detail

sum

public void sum(ContingencyFeature other)
Adds the other feature's weights to this one's

Parameters:
other -

getA

public int getA()

getB

public int getB()

addDoc

public void addDoc(int docID)

wipeDocs

protected void wipeDocs()

getDocs

protected java.util.Set<java.lang.Integer> getDocs()

getWeight

public float getWeight()
Gets the weight associated with this term.

Overrides:
getWeight in class WeightedFeature

setWeight

public void setWeight(float weight)
Description copied from class: WeightedFeature
Sets the weight associated with this feature.

Overrides:
setWeight in class WeightedFeature
Parameters:
weight - the weight

toString

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