com.aliasi.classify
Class ScoredClassification

java.lang.Object
  extended by com.aliasi.classify.Classification
      extended by com.aliasi.classify.RankedClassification
          extended by com.aliasi.classify.ScoredClassification
Direct Known Subclasses:
ConditionalClassification

public class ScoredClassification
extends RankedClassification

A ScoredClassification is a ranked classification where each category also has a score that determines the ranking. The category with the highest score is the value returned as the best category. Thus if scores are costs or distances, then they should be inverted before being used to rank results in a scored classification.

Subclasses are available that interpret the scores as conditional or joint probabilities.

Since:
LingPipe2.0
Version:
3.8
Author:
Bob Carpenter

Constructor Summary
ScoredClassification(String[] categories, double[] scores)
          Construct a scored classification from parallel arrays of categories and scores.
 
Method Summary
static ScoredClassification create(ScoredObject<String>[] categoryScores)
          Factory method which returns a scored classification from the array of scored categories.
 double score(int rank)
          Returns the score of the category with the specified rank in the classification.
 String toString()
          Returns a string-based representation of this scored classification.
 
Methods inherited from class com.aliasi.classify.RankedClassification
category, size
 
Methods inherited from class com.aliasi.classify.Classification
bestCategory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScoredClassification

public ScoredClassification(String[] categories,
                            double[] scores)
Construct a scored classification from parallel arrays of categories and scores. The scores must be in non-ascending numerical order.

Note that the categories and scores are merely saved in a scored classification, so that subsequent changes to the arrays will affect the contructed classification.

Parameters:
categories - Array of categories.
scores - Array of scores.
Throws:
IllegalArgumentException - If the category and score arrays are of different lengths, or if a score later in the array is larger than one earlier in the array.
Method Detail

create

public static ScoredClassification create(ScoredObject<String>[] categoryScores)
Factory method which returns a scored classification from the array of scored categories. The category score array does not need to be sorted. The categories are taken to be the objects in the scored objects and the scores are the scores.

Parameters:
categoryScores - Array of scored categories.
Returns:
Scored classification corresponding to the input..

score

public double score(int rank)
Returns the score of the category with the specified rank in the classification. Categories are numbered from zero and thus will be greater than or equal to zero and less than the size of this classification. Scores are in decreasing order by rank, so that for ranks i and i+1:
score(i) >= score(i+1).

Parameters:
rank - Rank of result category.
Returns:
The score of the category with the specified rank.
Throws:
IllegalArgumentException - If the rank is out of range.

toString

public String toString()
Returns a string-based representation of this scored classification.

Overrides:
toString in class RankedClassification
Returns:
A string-based representation of this classification.