T
- A feature classK
- A category classpublic abstract class Classifier<T,K>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.Map<K,java.util.Map<T,java.lang.Integer>> |
featureCountPerCategory
A dictionary mapping features to their number of occurrences in each
known category.
|
private static int |
INITIAL_CATEGORY_DICTIONARY_CAPACITY
Initial capacity of category dictionaries.
|
private static int |
INITIAL_FEATURE_DICTIONARY_CAPACITY
Initial capacity of feature dictionaries.
|
private int |
memoryCapacity
The initial memory capacity or how many classifications are memorized.
|
private java.util.Queue<Classification<T,K>> |
memoryQueue
The classifier's memory.
|
private java.util.Map<K,java.lang.Integer> |
totalCategoryCount
A dictionary mapping categories to their number of occurrences.
|
private java.util.Map<T,java.lang.Integer> |
totalFeatureCount
A dictionary mapping features to their number of occurrences.
|
Constructor and Description |
---|
Classifier()
Constructs a new classifier without any trained knowledge.
|
Modifier and Type | Method and Description |
---|---|
int |
categoryCount(K category)
Retrieves the number of occurrences of the given category.
|
abstract Classification<T,K> |
classify(java.util.Collection<T> features)
The classify method.
|
void |
decrementCategory(K category)
Decrements the count of a given category.
|
void |
decrementFeature(T feature,
K category)
Decrements the count of a given feature in the given category.
|
int |
featureCount(T feature,
K category)
Retrieves the number of occurrences of the given feature in the given
category.
|
float |
featureProbability(T feature,
K category) |
float |
featureWeighedAverage(T feature,
K category)
Retrieves the weighed average
P(feature|category) with
overall weight of 1.0 and an assumed probability of
0.5 . |
float |
featureWeighedAverage(T feature,
K category,
Classifier<T,K> calculator)
Retrieves the weighed average
P(feature|category) with
overall weight of 1.0 , an assumed probability of
0.5 and the given object to use for probability calculation. |
float |
featureWeighedAverage(T feature,
K category,
Classifier<T,K> calculator,
float weight)
Retrieves the weighed average
P(feature|category) with
the given weight and an assumed probability of 0.5 and the
given object to use for probability calculation. |
float |
featureWeighedAverage(T feature,
K category,
Classifier<T,K> calculator,
float weight,
float assumedProbability)
Retrieves the weighed average
P(feature|category) with
the given weight, the given assumed probability and the given object to
use for probability calculation. |
java.util.Set<K> |
getCategories()
Returns a
Set of categories the classifier knows about. |
int |
getCategoriesTotal()
Retrieves the total number of categories the classifier knows about.
|
java.util.Set<T> |
getFeatures()
Returns a
Set of features the classifier knows about. |
int |
getMemoryCapacity()
Retrieves the memory's capacity.
|
void |
incrementCategory(K category)
Increments the count of a given category.
|
void |
incrementFeature(T feature,
K category)
Increments the count of a given feature in the given category.
|
void |
learn(Classification<T,K> classification)
Train the classifier by telling it that the given features resulted in
the given category.
|
void |
learn(K category,
java.util.Collection<T> features)
Train the classifier by telling it that the given features resulted in
the given category.
|
void |
reset()
Resets the learned feature and category counts.
|
void |
setMemoryCapacity(int memoryCapacity)
Sets the memory's capacity.
|
private static final int INITIAL_CATEGORY_DICTIONARY_CAPACITY
private static final int INITIAL_FEATURE_DICTIONARY_CAPACITY
private int memoryCapacity
private java.util.Map<K,java.util.Map<T,java.lang.Integer>> featureCountPerCategory
private java.util.Map<T,java.lang.Integer> totalFeatureCount
private java.util.Map<K,java.lang.Integer> totalCategoryCount
private java.util.Queue<Classification<T,K>> memoryQueue
public Classifier()
public void reset()
public java.util.Set<T> getFeatures()
Set
of features the classifier knows about.Set
of features the classifier knows about.public java.util.Set<K> getCategories()
Set
of categories the classifier knows about.Set
of categories the classifier knows about.public int getCategoriesTotal()
public int getMemoryCapacity()
public void setMemoryCapacity(int memoryCapacity)
memoryCapacity
- The new memory capacity.public void incrementFeature(T feature, K category)
feature
- The feature, which count to increase.category
- The category the feature occurred in.public void incrementCategory(K category)
category
- The category, which count to increase.public void decrementFeature(T feature, K category)
feature
- The feature to decrement the count for.category
- The category.public void decrementCategory(K category)
category
- The category, which count to increase.public int featureCount(T feature, K category)
feature
- The feature, which count to retrieve.category
- The category, which the feature occurred in.public int categoryCount(K category)
category
- The category, which count should be retrieved.public float featureWeighedAverage(T feature, K category)
P(feature|category)
with
overall weight of 1.0
and an assumed probability of
0.5
. The probability defaults to the overall feature
probability.feature
- The feature, which probability to calculate.category
- The category.de.daslaboratorium.machinelearning.classifier.Classifier#featureProbability(Object, Object)
,
de.daslaboratorium.machinelearning.classifier.Classifier#featureWeighedAverage(Object, Object, IFeatureProbability, float, float)
public float featureWeighedAverage(T feature, K category, Classifier<T,K> calculator)
P(feature|category)
with
overall weight of 1.0
, an assumed probability of
0.5
and the given object to use for probability calculation.feature
- The feature, which probability to calculate.category
- The category.calculator
- The calculating object.de.daslaboratorium.machinelearning.classifier.Classifier#featureWeighedAverage(Object, Object, IFeatureProbability, float, float)
public float featureWeighedAverage(T feature, K category, Classifier<T,K> calculator, float weight)
P(feature|category)
with
the given weight and an assumed probability of 0.5
and the
given object to use for probability calculation.feature
- The feature, which probability to calculate.category
- The category.calculator
- The calculating object.weight
- The feature weight.de.daslaboratorium.machinelearning.classifier.Classifier#featureWeighedAverage(Object, Object, IFeatureProbability, float, float)
public float featureWeighedAverage(T feature, K category, Classifier<T,K> calculator, float weight, float assumedProbability)
P(feature|category)
with
the given weight, the given assumed probability and the given object to
use for probability calculation.feature
- The feature, which probability to calculate.category
- The category.calculator
- The calculating object.weight
- The feature weight.assumedProbability
- The assumed probability.public void learn(K category, java.util.Collection<T> features)
category
- The category the features belong to.features
- The features that resulted in the given category.public void learn(Classification<T,K> classification)
classification
- The classification to learn.public abstract Classification<T,K> classify(java.util.Collection<T> features)
features
- The features to classify.