gov.sandia.cognition.learning.algorithm.bayes
Class VectorNaiveBayesCategorizer<CategoryType,DistributionType extends UnivariateProbabilityDensityFunction>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.algorithm.bayes.VectorNaiveBayesCategorizer<CategoryType,DistributionType>
Type Parameters:
CategoryType - The output category type for the categorizer. Must implement equals and hash code.
DistributionType - The type of the distributions used to compute the conditionals for each dimension.
All Implemented Interfaces:
Evaluator<Vectorizable,CategoryType>, Categorizer<Vectorizable,CategoryType>, DiscriminantCategorizer<Vectorizable,CategoryType,Double>, VectorInputEvaluator<Vectorizable,CategoryType>, CloneableSerializable, Serializable, Cloneable

public class VectorNaiveBayesCategorizer<CategoryType,DistributionType extends UnivariateProbabilityDensityFunction>
extends AbstractCloneableSerializable
implements Categorizer<Vectorizable,CategoryType>, VectorInputEvaluator<Vectorizable,CategoryType>, DiscriminantCategorizer<Vectorizable,CategoryType,Double>

A naive Bayesian categorizer that takes an input vector and applies an independent scalar probability density function to each one.

Since:
3.1
Author:
Justin Basilico
See Also:
Serialized Form

Nested Class Summary
static class VectorNaiveBayesCategorizer.BatchGaussianLearner<CategoryType>
          A supervised batch distributionLearner for a vector Naive Bayes categorizer that fits a Gaussian.
static class VectorNaiveBayesCategorizer.Learner<CategoryType,DistributionType extends UnivariateProbabilityDensityFunction>
          A supervised batch distributionLearner for a vector Naive Bayes categorizer.
static class VectorNaiveBayesCategorizer.OnlineLearner<CategoryType,DistributionType extends UnivariateProbabilityDensityFunction>
          An online (incremental) distributionLearner for the Naive Bayes categorizer that uses an incremental distribution learner for the distribution representing each dimension for each category.
 
Field Summary
protected  Map<CategoryType,List<DistributionType>> conditionals
          The mapping of category to the conditional distribution for the category with one probability density function for each dimension.
protected  DataDistribution<CategoryType> priors
          The prior distribution for the categorizer.
 
Constructor Summary
VectorNaiveBayesCategorizer()
          Creates a new VectorNaiveBayesCategorizer with an empty prior and conditionals.
VectorNaiveBayesCategorizer(DataDistribution<CategoryType> priors, Map<CategoryType,List<DistributionType>> conditionals)
          Creates a new VectorNaiveBayesCategorizer with the given prior and conditionals.
 
Method Summary
 VectorNaiveBayesCategorizer<CategoryType,DistributionType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 double computeLogPosterior(Vector input, CategoryType category)
          Computes the log-posterior probability that the input belongs to the given category.
 double computePosterior(Vector input, CategoryType category)
          Computes the posterior probability that the input belongs to the given category.
 CategoryType evaluate(Vectorizable input)
          Evaluates the function on the given input and returns the output.
 DefaultWeightedValueDiscriminant<CategoryType> evaluateWithDiscriminant(Vectorizable 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<CategoryType> getCategories()
          Gets the list of possible categories that the categorizer can produce.
 Map<CategoryType,List<DistributionType>> getConditionals()
          Gets the conditional distributions, which is a mapping of category to the list of probability density functions, one for each dimension of the vector.
 int getInputDimensionality()
          Gets the expected dimensionality of the input vector to the evaluator, if it is known.
 DataDistribution<CategoryType> getPriors()
          Gets the prior distribution over the categories.
 void setConditionals(Map<CategoryType,List<DistributionType>> conditionals)
          Sets the conditional distributions, which is a mapping of category to the list of probability density functions, one for each dimension of the vector.
 void setPriors(DataDistribution<CategoryType> priors)
          Sets the prior distribution over the categories.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

priors

protected DataDistribution<CategoryType> priors
The prior distribution for the categorizer.


conditionals

protected Map<CategoryType,List<DistributionType extends UnivariateProbabilityDensityFunction>> conditionals
The mapping of category to the conditional distribution for the category with one probability density function for each dimension.

Constructor Detail

VectorNaiveBayesCategorizer

public VectorNaiveBayesCategorizer()
Creates a new VectorNaiveBayesCategorizer with an empty prior and conditionals.


VectorNaiveBayesCategorizer

public VectorNaiveBayesCategorizer(DataDistribution<CategoryType> priors,
                                   Map<CategoryType,List<DistributionType>> conditionals)
Creates a new VectorNaiveBayesCategorizer with the given prior and conditionals.

Parameters:
priors - The prior distribution.
conditionals - The conditional distribution.
Method Detail

clone

public VectorNaiveBayesCategorizer<CategoryType,DistributionType> 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.

evaluate

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

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

evaluateWithDiscriminant

public DefaultWeightedValueDiscriminant<CategoryType> evaluateWithDiscriminant(Vectorizable 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<Vectorizable,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(Vector input,
                               CategoryType category)
Computes the posterior probability that the input belongs to the given category.

Parameters:
input - The input vector.
category - The category to compute the posterior for.
Returns:
The posterior probability that the input is part of the given category. Between 0.0 and 1.0.

computeLogPosterior

public double computeLogPosterior(Vector input,
                                  CategoryType category)
Computes the log-posterior probability that the input belongs to the given category.

Parameters:
input - The input vector.
category - The category to compute the posterior for.
Returns:
The log-posterior probability.

getCategories

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

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

getInputDimensionality

public int getInputDimensionality()
Description copied from interface: VectorInputEvaluator
Gets the expected dimensionality of the input vector to the evaluator, if it is known. If it is not known, -1 is returned.

Specified by:
getInputDimensionality in interface VectorInputEvaluator<Vectorizable,CategoryType>
Returns:
The expected dimensionality of the input vector to the evaluator, or -1 if it is not known.

getPriors

public DataDistribution<CategoryType> getPriors()
Gets the prior distribution over the categories.

Returns:
The prior distribution over the categories.

setPriors

public void setPriors(DataDistribution<CategoryType> priors)
Sets the prior distribution over the categories.

Parameters:
priors - The prior distribution over the categories.

getConditionals

public Map<CategoryType,List<DistributionType>> getConditionals()
Gets the conditional distributions, which is a mapping of category to the list of probability density functions, one for each dimension of the vector.

Returns:
The conditional distributions for each category.

setConditionals

public void setConditionals(Map<CategoryType,List<DistributionType>> conditionals)
Sets the conditional distributions, which is a mapping of category to the list of probability density functions, one for each dimension of the vector.

Parameters:
conditionals - The conditional distributions for each category.