public class ConditionalClassification extends ScoredClassification
ConditionalClassification
is a scored classification
which estimates conditional probabilities of categories given an
input. By default, the scores are the conditional probabilities;
if the scores are different than the conditional probabilities,
they must be in the same order. Both score and conditional
probability are tracked independently by the evaluators. The
method conditionalProbability(int)
returns the conditional
probability based on rank while the superclass method ScoredClassification.score(int)
returns the score by rank.
The conditional probabilities must sum to one over the set of categories:
Σ_{rank<size()}
score(rank) = 1.0
The constructors check that this criterion is satisfied to
within a specified arithmetic tolerance. The convenience method
Statistics.normalize(double[])
may be used
to normalize an array of probability ratios so that they will be an
acceptable input to this constructor, but note the warning in that
method's documentation concerning arithmetic precision.
Constructor and Description 

ConditionalClassification(String[] categories,
double[] conditionalProbs)
Construct a conditional classification with the specified
categories and conditional probabilities which sum to one
within the default tolerance of
0.01 . 
ConditionalClassification(String[] categories,
double[] conditionalProbs,
double tolerance)
Construct a conditional classification with the specified
categories and conditional probabilities whose probabilities
sum to one within the specified tolerance.

ConditionalClassification(String[] categories,
double[] scores,
double[] conditionalProbs)
Construct a conditional classification with the specified
categories, scores and conditional probabilities which sum to
one within the default tolerance of
0.01 . 
ConditionalClassification(String[] categories,
double[] scores,
double[] conditionalProbs,
double tolerance)
Construct a conditional classification with the specified
categories and conditional probabilities whose probabilities
sum to one within the specified tolerance.

Modifier and Type  Method and Description 

double 
conditionalProbability(int rank)
Returns the conditional probability estimate for the category
at the specified rank.

double 
conditionalProbability(String category)
Returns the conditional probability estimate for the specified category.

static ConditionalClassification 
createLogProbs(String[] categories,
double[] logProbabilities)
Return a conditional classification given the categories and
log probabilities.

static ConditionalClassification 
createProbs(String[] categories,
double[] probabilityRatios)
Static factory method for conditional classifications based on
the specified categories and linear probability ratios.

String 
toString()
Returns a stringbased representation of this conditional
probability ranked classification.

create, create, score
category, size
bestCategory
public ConditionalClassification(String[] categories, double[] conditionalProbs)
0.01
. The
conditional probabilities are used as the scores.categories
 Categories assigned by classification.conditionalProbs
 Conditional probabilities of the
categories.IllegalArgumentException
 If the category and
probability arrays are of different lengths, if the
probabilities or scores are not in descending order, if any
probability is less than zero or greater than one, or if their
sum is not 1.0 plus or minus 0.01.public ConditionalClassification(String[] categories, double[] scores, double[] conditionalProbs)
0.01
. The
scores and conditional probs must be of the same length as the
categories and in descending numerical order.categories
 Categories assigned by classification.scores
 Scores of the categories.conditionalProbs
 Conditional probabilities of the
categories.IllegalArgumentException
 If the category and
probability arrays are of different lengths, if the
probabilities or scores are not in descending order, if any
probability is less than zero or greater than one, or if their
sum is not 1.0 plus or minus 0.01.public ConditionalClassification(String[] categories, double[] conditionalProbs, double tolerance)
Double.POSITIVE_INFINITY
, there is
effectively no consistency requirement placed on the
conditional probabilities.categories
 Categories assigned by classification.conditionalProbs
 Conditional probabilities of the
categories.tolerance
 Tolerance within which the conditional probabilities
must sum to one.IllegalArgumentException
 If the category and
probability arrays are of different lengths, if the probabilities
are not in descending order, if any probability is less than
zero or greater than one, or if their sum is not 1.0 plus or
minus the tolerance, or if the tolerance is not a positive number.public ConditionalClassification(String[] categories, double[] scores, double[] conditionalProbs, double tolerance)
Double.POSITIVE_INFINITY
, there is
effectively no consistency requirement placed on the
conditional probabilities.categories
 Categories assigned by classification.scores
 Scores of the categories.conditionalProbs
 Conditional probabilities of the
categories.tolerance
 Tolerance within which the conditional probabilities
must sum to one.IllegalArgumentException
 If the category and
probability or score arrays are of different lengths, if the
probabilities or scores are not in descending order, if any
probability is less than zero or greater than one, or if their
sum is not 1.0 plus or minus the tolerance, or if the tolerance
is not a positive number.public double conditionalProbability(int rank)
ScoredClassification.score(int)
if this classification was initialized
without explicit score values.rank
 Rank of category.IllegalArgumentException
 If the rank is out of range.public double conditionalProbability(String category)
category
 category to look forIllegalArgumentException
 If there is no such category.public String toString()
toString
in class ScoredClassification
public static ConditionalClassification createLogProbs(String[] categories, double[] logProbabilities)
categories
 Array of categories.logProbabilities
 Parallel array of log probabilities.IllegalArgumentException
 If any of the log probabilities
is infinite, not a number, or positive, or if the arrays are not
of the same length.public static ConditionalClassification createProbs(String[] categories, double[] probabilityRatios)
If all probability ratios are zero, the result will be a uniform distribution of the same probability for each entry.
categories
 Categories for classification.probabilityRatios
 Parallel array of linear probability
ratios for the specified categories.IllegalArgumentException
 If any of the probability ratios
are not nonnegative and finite numbers.