edu.cmu.minorthird.classify
Class ClassLabel

java.lang.Object
  extended by edu.cmu.minorthird.classify.ClassLabel
All Implemented Interfaces:
java.io.Serializable

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

A label which is associated with an instance---either by a classifier, or in training data.

ClassLabels should be weighted to that the weight for a class name is (approximately) the log-odds having that class name, ie if the probability of class "POS" is p, the getWeight("POS") should return Math.log( p/(1-p) ). The POS and NEG class labels (as defined in ExampleSchema.POS_CLASS_NAME and ExampleSchema.NEG_CLASS_NAME) are special. Binary class labels should be created with the positiveLabel(posWeight) and negativeLabel(negWeight) routines, or else the binaryLabel routine. The numericLabel() returns +1 or -1 for binary classLabels. The posWeight() method returns the score of the positive class. The classLabel.numericLabel() method ignores the underlying score. For testing binary examples, classLabel.isPositive(), classLabel.isNegative(), and classLabel.bestWeight() should be used.

Author:
William Cohen
See Also:
Serialized Form

Constructor Summary
ClassLabel()
           
ClassLabel(java.lang.String label)
           
ClassLabel(java.lang.String label, double weight)
           
 
Method Summary
 void add(java.lang.String label, double weight)
          Add a label with the given weight to this ClassLabel.
 java.lang.String bestClassName()
          Returns the highest-ranking label.
 double bestWeight()
          Returns the weight of the highest-ranking label.
static ClassLabel binaryLabel(double score)
          Create a binary label, either positive or negative, as appropriate, with the associated score (in logits).
 double getProbability(java.lang.String label)
          Returns the probability of a label.
 double getWeight(java.lang.String label)
          Returns the weight of the label.
 boolean isBinary()
          See if this is one of the distinguished binary labels.
 boolean isCorrect(ClassLabel otherLabel)
          Is this label correct, relative to another label?
 boolean isCorrect(double otherLabel)
          Is this label correct, relative to a numeric label?
 boolean isNegative()
          See if this is the distinguished negative label.
 boolean isPositive()
          See if this is the distinguished positive label.
static ClassLabel multiLabel(java.lang.String name, double score)
          Create a binary label, either positive or negative, as appropriate, with the associated score (in logits).
static ClassLabel multiNegLabel(java.lang.String label, double score)
          Create a positive binary label, with the associated score (in logits).
static ClassLabel multiPosLabel(java.lang.String label, double score)
          Create a positive binary label, with the associated score (in logits).
static ClassLabel negativeLabel(double score)
          Create a negative binary label, with the associated score (in logits).
 double numericLabel()
          Return a numeric score of +1, or -1 for a binary example
static ClassLabel positiveLabel(double score)
          Create a positive binary label, with the associated score (in logits).
 double posProbability()
          Returns the probability of the positive class name
 java.util.Set<java.lang.String> possibleLabels()
          Returns the set of labels that appear in the ranking.
 double posWeight()
          Returns the weight of the positive class name
 java.lang.String toDetails()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassLabel

public ClassLabel()

ClassLabel

public ClassLabel(java.lang.String label)

ClassLabel

public ClassLabel(java.lang.String label,
                  double weight)
Method Detail

multiPosLabel

public static ClassLabel multiPosLabel(java.lang.String label,
                                       double score)
Create a positive binary label, with the associated score (in logits).


multiNegLabel

public static ClassLabel multiNegLabel(java.lang.String label,
                                       double score)
Create a positive binary label, with the associated score (in logits).


multiLabel

public static ClassLabel multiLabel(java.lang.String name,
                                    double score)
Create a binary label, either positive or negative, as appropriate, with the associated score (in logits).


positiveLabel

public static ClassLabel positiveLabel(double score)
Create a positive binary label, with the associated score (in logits).


negativeLabel

public static ClassLabel negativeLabel(double score)
Create a negative binary label, with the associated score (in logits).


binaryLabel

public static ClassLabel binaryLabel(double score)
Create a binary label, either positive or negative, as appropriate, with the associated score (in logits).


isBinary

public boolean isBinary()
See if this is one of the distinguished binary labels.


isPositive

public boolean isPositive()
See if this is the distinguished positive label.


isNegative

public boolean isNegative()
See if this is the distinguished negative label.


numericLabel

public double numericLabel()
Return a numeric score of +1, or -1 for a binary example


bestClassName

public java.lang.String bestClassName()
Returns the highest-ranking label.


bestWeight

public double bestWeight()
Returns the weight of the highest-ranking label.


posWeight

public double posWeight()
Returns the weight of the positive class name


posProbability

public double posProbability()
Returns the probability of the positive class name


getWeight

public double getWeight(java.lang.String label)
Returns the weight of the label.


getProbability

public double getProbability(java.lang.String label)
Returns the probability of a label.


possibleLabels

public java.util.Set<java.lang.String> possibleLabels()
Returns the set of labels that appear in the ranking.


isCorrect

public boolean isCorrect(ClassLabel otherLabel)
Is this label correct, relative to another label?


isCorrect

public boolean isCorrect(double otherLabel)
Is this label correct, relative to a numeric label?


add

public void add(java.lang.String label,
                double weight)
Add a label with the given weight to this ClassLabel.


toString

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

toDetails

public java.lang.String toDetails()