InputType
- Type of inputs to the categorizer.CategoryType
- Type of the categories of the categorizer.@PublicationReference(author={"Richard O. Duda","Peter E. Hart","David G. Stork"},title="Pattern Classification: Second Edition",type=Book,year=2001,pages={56,62}) @PublicationReference(author="Wikipedia",title="Naive Bayes classifier",type=WebPage,year=2009,url="http://en.wikipedia.org/wiki/Naive_bayes") public class DiscreteNaiveBayesCategorizer<InputType,CategoryType> extends AbstractCloneableSerializable implements DiscriminantCategorizer<java.util.Collection<InputType>,CategoryType,java.lang.Double>
Modifier and Type | Class and Description |
---|---|
static class |
DiscreteNaiveBayesCategorizer.Learner<InputType,CategoryType>
Learner for a DiscreteNaiveBayesCategorizer.
|
Modifier | Constructor and Description |
---|---|
|
DiscreteNaiveBayesCategorizer()
Creates a new instance of DiscreteNaiveBayesCategorizer
|
|
DiscreteNaiveBayesCategorizer(int inputDimensionality)
Creates a new instance of DiscreteNaiveBayesCategorizer.
|
protected |
DiscreteNaiveBayesCategorizer(int inputDimensionality,
DefaultDataDistribution<CategoryType> priorProbabilities,
java.util.Map<CategoryType,java.util.List<DefaultDataDistribution<InputType>>> conditionalProbabilities)
Creates a new instance of DiscreteNaiveBayesCategorizer.
|
Modifier and Type | Method and Description |
---|---|
DiscreteNaiveBayesCategorizer<InputType,CategoryType> |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
double |
computeConditionalProbability(java.util.Collection<InputType> inputs,
CategoryType category)
Computes the class conditional for the given inputs at the given
category assuming that each input feature is conditionally independent
of all other features.
|
double |
computeConjuctiveProbability(java.util.Collection<InputType> inputs,
CategoryType category)
Computes the conjunctive probability of the inputs and the category.
|
double |
computeEvidenceProbabilty(java.util.Collection<InputType> inputs)
Computes the probability of the given inputs.
|
double |
computePosterior(java.util.Collection<InputType> inputs,
CategoryType category)
Computes the posterior probability of the inputs for the given category.
|
CategoryType |
evaluate(java.util.Collection<InputType> inputs)
Evaluates the function on the given input and returns the output.
|
DefaultWeightedValueDiscriminant<CategoryType> |
evaluateWithDiscriminant(java.util.Collection<InputType> 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.
|
java.util.Set<CategoryType> |
getCategories()
Gets the list of possible categories that the categorizer can produce.
|
double |
getConditionalProbability(int index,
InputType input,
CategoryType category)
Gets the conditional probability for the given input and category.
|
int |
getInputDimensionality()
Getter for inputDimensionality.
|
double |
getPriorProbability(CategoryType category)
Returns the prior probability of the given category.
|
void |
setInputDimensionality(int inputDimensionality)
Setter for inputDimensionality.
|
void |
update(java.util.Collection<InputType> inputs,
CategoryType category)
Updates the probability tables from observing the sample inputs and
category.
|
public DiscreteNaiveBayesCategorizer()
public DiscreteNaiveBayesCategorizer(int inputDimensionality)
inputDimensionality
- Assumed dimensionality of the inputs.protected DiscreteNaiveBayesCategorizer(int inputDimensionality, DefaultDataDistribution<CategoryType> priorProbabilities, java.util.Map<CategoryType,java.util.List<DefaultDataDistribution<InputType>>> conditionalProbabilities)
inputDimensionality
- Assumed dimensionality of the inputs.priorProbabilities
- Table of category priors.conditionalProbabilities
- Class conditional probability table.public DiscreteNaiveBayesCategorizer<InputType,CategoryType> clone()
AbstractCloneableSerializable
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.clone
in interface CloneableSerializable
clone
in class AbstractCloneableSerializable
public java.util.Set<CategoryType> getCategories()
Categorizer
getCategories
in interface Categorizer<java.util.Collection<InputType>,CategoryType>
public double computeEvidenceProbabilty(java.util.Collection<InputType> inputs)
inputs
- Inputs for which to compute the probability.public double computePosterior(java.util.Collection<InputType> inputs, CategoryType category)
inputs
- Inputs to compute the posterior.category
- Category to compute the posterior.public double computeConditionalProbability(java.util.Collection<InputType> inputs, CategoryType category)
inputs
- Inputs to compute the class conditional.category
- Category to compute the class conditional.public void update(java.util.Collection<InputType> inputs, CategoryType category)
inputs
- Inputs to update.category
- Category to update.public double computeConjuctiveProbability(java.util.Collection<InputType> inputs, CategoryType category)
inputs
- Inputs for which to compute the conjunctive probability.category
- Category for which to compute the conjunctive probability.public CategoryType evaluate(java.util.Collection<InputType> inputs)
Evaluator
evaluate
in interface Evaluator<java.util.Collection<InputType>,CategoryType>
inputs
- The input to evaluate.public DefaultWeightedValueDiscriminant<CategoryType> evaluateWithDiscriminant(java.util.Collection<InputType> input)
DiscriminantCategorizer
evaluateWithDiscriminant
in interface DiscriminantCategorizer<java.util.Collection<InputType>,CategoryType,java.lang.Double>
input
- The input value to categorize with a discriminatepublic double getConditionalProbability(int index, InputType input, CategoryType category)
index
- Index to compute.input
- Input value to assume.category
- Category value to assume.public double getPriorProbability(CategoryType category)
category
- Category to return the prior probability of.public int getInputDimensionality()
public void setInputDimensionality(int inputDimensionality)
inputDimensionality
- Assumed dimensionality of the inputs.