emolib.classifier.machinelearning
Class KNearestNeighbour

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

public class KNearestNeighbour
extends Classifier

The KNearestNeighbour is an example-based classifier that uses the k-Nearest Neighbour method.

Computes the `k' nearest elements according to a distance measure (e.g., euclidean) in the feature space (e.g., the circumplex). Decides the resulting affective category according to the majority vote among these `k' elements. The number of emotional dimensions of use has to be specified.

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

Field Summary
static java.lang.String PROP_NUM_EMO_DIMS
          Property to determine the number of emotional dimensions the KNN deals with.
 
Constructor Summary
KNearestNeighbour()
          Main constructor of this example-based classifier.
 
Method Summary
 java.lang.String getCategory(FeatureBox inputFeatures)
          The function that decides the most appropriate emotional category.
 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 save(java.lang.String path)
          Generic method to save the fully fledged classifier into a given file path.
 void setNumberOfEmotionalDimensions(int numDims)
          Method to set the number of emotional dimensions.
 void setNumberOfNeighbours(int number)
          Method to set the number of neighbors to consider (k) when evaluating this classifier.
 void trainingProcedure()
          Void method to train required by the Classifier class.
 
Methods inherited from class emolib.classifier.Classifier
applyClassification, getData, getListOfExampleCategories, getListOfExampleFeatures, initialize, inputTrainingExample, resetExamples, 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 KNN deals with.

See Also:
Constant Field Values
Constructor Detail

KNearestNeighbour

public KNearestNeighbour()
Main constructor of this example-based 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.

setNumberOfEmotionalDimensions

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

Parameters:
numDims - The number of emotional dimensions.

setNumberOfNeighbours

public void setNumberOfNeighbours(int number)
Method to set the number of neighbors to consider (k) when evaluating this classifier. If this method is not invoked the k-NN takes one neighbor (k=1).

Parameters:
number - The number of neighbors.

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.

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.