emolib.classifier.machinelearning
Class NaiveBayes

java.lang.Object
  extended by emolib.util.proc.TextDataProcessor
      extended by emolib.classifier.Classifier
          extended by emolib.classifier.machinelearning.NaiveBayes
All Implemented Interfaces:
Configurable, DataProcessor

public class NaiveBayes
extends Classifier

The NaiveBayes is a Bayesian classifier operating in the circumplex.

The NaiveBayes assumes that the features are conditionally independent, and models their distribution according to a given density form, e.g., the Gaussian/normal.

Author:
Alexandre Trilla (atrilla@salle.url.edu)

Field Summary
static java.lang.String PROP_EXTERNAL_FILE
          Property to indicate a pre-trained classifier.
static java.lang.String PROP_NUM_EMO_DIMS
          Property to determine the number of emotional dimensions the NaiveBayes deals with.
static java.lang.String PROP_PRIORS
          Property to account for prior probabilities.
 
Constructor Summary
NaiveBayes()
          Main constructor of this classifier.
 
Method Summary
 java.lang.String getCategory(FeatureBox inputFeatures)
          The function that decides the most appropriate emotional category.
 java.util.ArrayList<java.lang.String> getEmotionCategories()
          Function to retrieve the emotion categories.
 java.util.ArrayList<ClassConditionalDensity> getLikelihoodActivations()
          Function to retrieve the likelihood distributions for activation from this NB.
 java.util.ArrayList<ClassConditionalDensity> getLikelihoodControls()
          Function to retrieve the likelihood distributions for control from this NB.
 java.util.ArrayList<ClassConditionalDensity> getLikelihoodValences()
          Function to retrieve the likelihood distributions for valence from this NB.
 float getPosteriorProbability(java.lang.String theClass, FeatureBox theFeatures)
          Open function to retrieve the posterior probabilities of having a single class given a bunch of features.
 java.lang.String getTypeOfLikelihoodDistribution()
          Method to get the type of class-conditional densities.
 void initialize()
          Method to initialize the Classifier.
 void load(java.lang.String path)
          Generic function to load a previously saved classifier.
 void newProperties(PropertySheet ps)
          This method is called when this configurable component has new data.
 void register(java.lang.String name, Registry registry)
          Register my properties.
 void resetExamples()
          Method to reset the classifier and flush the training examples.
 void save(java.lang.String path)
          Generic method to save the fully fledged classifier into a given file path.
 void setAccountForPriors(boolean flag)
          Method to set the NB to account for prior probabilities.
 void setNumberOfEmotionalDimensions(int numDims)
          Method to set the number of emotional dimensions.
 void setTypeOfLikelihoodDistribution(java.lang.String type)
          Method to set the type of class-conditional densities.
 void trainingProcedure()
          Void method to train required by the Classifier class.
 
Methods inherited from class emolib.classifier.Classifier
applyClassification, getData, getListOfExampleCategories, getListOfExampleFeatures, inputTrainingExample, train
 
Methods inherited from class emolib.util.proc.TextDataProcessor
flush, getName, getPredecessor, setPredecessor, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROP_NUM_EMO_DIMS

public static final java.lang.String PROP_NUM_EMO_DIMS
Property to determine the number of emotional dimensions the NaiveBayes deals with.

See Also:
Constant Field Values

PROP_EXTERNAL_FILE

public static final java.lang.String PROP_EXTERNAL_FILE
Property to indicate a pre-trained classifier.

See Also:
Constant Field Values

PROP_PRIORS

public static final java.lang.String PROP_PRIORS
Property to account for prior probabilities.

See Also:
Constant Field Values
Constructor Detail

NaiveBayes

public NaiveBayes()
Main constructor of this classifier.

Method Detail

register

public void register(java.lang.String name,
                     Registry registry)
              throws PropertyException
Description copied from interface: Configurable
Register my properties. This method is called once early in the time of the component, shortly after the component is constructed. This component should register any configuration properties that it needs to register. If this configurable extends another configurable, super.register should also be called

Specified by:
register in interface Configurable
Overrides:
register in class Classifier
Parameters:
name - the name of the component
registry - the registry for this component
Throws:
PropertyException

newProperties

public void newProperties(PropertySheet ps)
                   throws PropertyException
Description copied from interface: Configurable
This method is called when this configurable component has new data. The component should first validate the data. If it is bad the component should return false. If the data is good, the component should record the the data internally and return true.

Specified by:
newProperties in interface Configurable
Overrides:
newProperties in class Classifier
Parameters:
ps - a property sheet holding the new data
Throws:
PropertyException - if there is a problem with the properties.

initialize

public void initialize()
Method to initialize the Classifier.

Specified by:
initialize in interface DataProcessor
Overrides:
initialize in class Classifier

setNumberOfEmotionalDimensions

public void setNumberOfEmotionalDimensions(int numDims)
Method to set the number of emotional dimensions.

Parameters:
numDims - The number of emotional dimensions.

setAccountForPriors

public void setAccountForPriors(boolean flag)
Method to set the NB to account for prior probabilities.

Parameters:
flag - The boolean flag.

setTypeOfLikelihoodDistribution

public void setTypeOfLikelihoodDistribution(java.lang.String type)
Method to set the type of class-conditional densities. By default this NB class assumes normal distributions.

Parameters:
type - The distribution.

getTypeOfLikelihoodDistribution

public java.lang.String getTypeOfLikelihoodDistribution()
Method to get the type of class-conditional densities. By default this NB class assumes normal distributions.

Returns:
The type of distribution.

getLikelihoodValences

public java.util.ArrayList<ClassConditionalDensity> getLikelihoodValences()
Function to retrieve the likelihood distributions for valence from this NB.

Returns:
The array of likelihood distributions for valence.

getLikelihoodActivations

public java.util.ArrayList<ClassConditionalDensity> getLikelihoodActivations()
Function to retrieve the likelihood distributions for activation from this NB.

Returns:
The array of likelihood distributions for activation.

getLikelihoodControls

public java.util.ArrayList<ClassConditionalDensity> getLikelihoodControls()
Function to retrieve the likelihood distributions for control from this NB.

Returns:
The array of likelihood distributions for control.

getPosteriorProbability

public float getPosteriorProbability(java.lang.String theClass,
                                     FeatureBox theFeatures)
Open function to retrieve the posterior probabilities of having a single class given a bunch of features. This function implements the Bayes Theorem.

Parameters:
theClass - The class.
theFeatures - The features.
Returns:
The associated posterior probability P(c|x).

getCategory

public java.lang.String getCategory(FeatureBox inputFeatures)
Description copied from class: Classifier
The function that decides the most appropriate emotional category. This is required for any classifier. The classifier in question has to previously run any training algorithm in order to provide the required prediction.

Specified by:
getCategory in class Classifier
Parameters:
inputFeatures - The input emotional features.
Returns:
The most appropriate emotional category.

getEmotionCategories

public java.util.ArrayList<java.lang.String> getEmotionCategories()
Function to retrieve the emotion categories. This is used for integration purposes. Normally NB is a basic classifier, prone to be enhanced by dome method.


trainingProcedure

public void trainingProcedure()
Void method to train required by the Classifier class.

Specified by:
trainingProcedure in class Classifier

save

public void save(java.lang.String path)
Description copied from class: Classifier
Generic method to save the fully fledged classifier into a given file path. It is recommended to use a plain text file (such as XML) to save the classifier's configuration since it's readable directly.

Specified by:
save in class Classifier
Parameters:
path - The file path to save the classifier.

load

public void load(java.lang.String path)
Description copied from class: Classifier
Generic function to load a previously saved classifier. This function should be consistent with the design followed in the saving procedure.

Specified by:
load in class Classifier
Parameters:
path - The path of the file which contains the previously saved classifier.

resetExamples

public void resetExamples()
Description copied from class: Classifier
Method to reset the classifier and flush the training examples. This method only makes sense if the classifier in question is trainable and already has some training examples.

Overrides:
resetExamples in class Classifier