gov.sandia.cognition.learning.function.categorization
Class MaximumAPosterioriCategorizer<ObservationType,CategoryType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.statistics.AbstractDistribution<ObservationType>
          extended by gov.sandia.cognition.learning.function.categorization.MaximumAPosterioriCategorizer<ObservationType,CategoryType>
Type Parameters:
ObservationType - Type of observations
CategoryType - Type of categories
All Implemented Interfaces:
Evaluator<ObservationType,CategoryType>, Categorizer<ObservationType,CategoryType>, DiscriminantCategorizer<ObservationType,CategoryType,Double>, Distribution<ObservationType>, CloneableSerializable, Serializable, Cloneable

@PublicationReference(author="Wikipedia",
                      title="Maximum a posteriori estimation",
                      type=WebPage,
                      year=2010,
                      url="http://en.wikipedia.org/wiki/Maximum_a_posteriori_estimation")
public class MaximumAPosterioriCategorizer<ObservationType,CategoryType>
extends AbstractDistribution<ObservationType>
implements DiscriminantCategorizer<ObservationType,CategoryType,Double>

Categorizer that returns the category with the highest posterior likelihood for a given observation. This is known as a MAP categorizer, where the posterior is proportionate to the category's conditional likelihood for a given observation times the prior probability of the category.

Since:
3.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Nested Class Summary
static class MaximumAPosterioriCategorizer.Learner<ObservationType,CategoryType>
          Learner for the MAP categorizer
 
Constructor Summary
MaximumAPosterioriCategorizer()
          Creates a new instance of MaximumAPosterioriCategorizer
 
Method Summary
 void addCategory(CategoryType category, double mass, ProbabilityFunction<ObservationType> conditional)
          Adds the given category with the given mass (which is divided by the masses of all categories to determine the prior probability weight) and the distribution function
 MaximumAPosterioriCategorizer<ObservationType,CategoryType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 double computePosterior(ObservationType observation, CategoryType category)
          Computes the posterior of the observation given the category.
 CategoryType evaluate(ObservationType input)
          Evaluates the function on the given input and returns the output.
 DefaultWeightedValueDiscriminant<CategoryType> evaluateWithDiscriminant(ObservationType input)
          Evaluate the categorizer on the given input to produce the expected category plus a discriminant for later producing an ordering of how well items fit into that category.
 Set<? extends CategoryType> getCategories()
          Gets the list of possible categories that the categorizer can produce.
 WeightedValue<ProbabilityFunction<ObservationType>> getCategory(CategoryType category)
          Gets the prior probability weight and conditional distribution for the given category.
 ObservationType getMean()
          Gets the mean category, if it is a number or ring.
 ArrayList<? extends ObservationType> sample(Random random, int numSamples)
          Draws multiple random samples from the distribution.
 
Methods inherited from class gov.sandia.cognition.statistics.AbstractDistribution
sample
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MaximumAPosterioriCategorizer

public MaximumAPosterioriCategorizer()
Creates a new instance of MaximumAPosterioriCategorizer

Method Detail

clone

public MaximumAPosterioriCategorizer<ObservationType,CategoryType> clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

addCategory

public void addCategory(CategoryType category,
                        double mass,
                        ProbabilityFunction<ObservationType> conditional)
Adds the given category with the given mass (which is divided by the masses of all categories to determine the prior probability weight) and the distribution function

Parameters:
category - Category to add
mass - Mass of the category
conditional - Conditional probability function of observations for the category

getCategory

public WeightedValue<ProbabilityFunction<ObservationType>> getCategory(CategoryType category)
Gets the prior probability weight and conditional distribution for the given category.

Parameters:
category - Category to consider
Returns:
Prior probability weight and conditional distribution for the given category.

getCategories

public Set<? extends CategoryType> getCategories()
Description copied from interface: Categorizer
Gets the list of possible categories that the categorizer can produce.

Specified by:
getCategories in interface Categorizer<ObservationType,CategoryType>
Returns:
The list of possible categories.

evaluate

public CategoryType evaluate(ObservationType input)
Description copied from interface: Evaluator
Evaluates the function on the given input and returns the output.

Specified by:
evaluate in interface Evaluator<ObservationType,CategoryType>
Parameters:
input - The input to evaluate.
Returns:
The output produced by evaluating the input.

evaluateWithDiscriminant

public DefaultWeightedValueDiscriminant<CategoryType> evaluateWithDiscriminant(ObservationType input)
Description copied from interface: DiscriminantCategorizer
Evaluate the categorizer on the given input to produce the expected category plus a discriminant for later producing an ordering of how well items fit into that category.

Specified by:
evaluateWithDiscriminant in interface DiscriminantCategorizer<ObservationType,CategoryType,Double>
Parameters:
input - The input value to categorize with a discriminate
Returns:
A pair containing the value and the discriminant value used for ordering results belonging to the same category.

computePosterior

public double computePosterior(ObservationType observation,
                               CategoryType category)
Computes the posterior of the observation given the category. Actually, this is the conjunctive likelihood since we've not normalizing by the likelihood of the observation over all categories. Since we're only interested in finding the MAP category, we're doing the standard thing and not normalizing.

Parameters:
observation - Observation to consider
category - Category to consider
Returns:
Posterior likelihood of the observation given the category.

getMean

public ObservationType getMean()
Gets the mean category, if it is a number or ring.

Returns:
The mean.

sample

public ArrayList<? extends ObservationType> sample(Random random,
                                                   int numSamples)
Description copied from interface: Distribution
Draws multiple random samples from the distribution. It is generally more efficient to use this multiple-sample method than multiple calls of the single-sample method. (But not always.)

Specified by:
sample in interface Distribution<ObservationType>
Parameters:
random - Random-number generator to use in order to generate random numbers.
numSamples - Number of samples to draw from the distribution.
Returns:
Samples drawn according to this distribution.