de.fu_berlin.ties.classify
Class MoonClassifier

java.lang.Object
  extended by de.fu_berlin.ties.classify.TrainableClassifier
      extended by de.fu_berlin.ties.classify.MoonClassifier
All Implemented Interfaces:
Classifier, XMLStorable

public class MoonClassifier
extends TrainableClassifier

A proxy to the MoonFilter classifier written by Christian Siefkes. The moonrunner.lua must be installed and in the path. Note that using this classifier with FeatureTransformers is probably a bad idea since OSB is already integrated into MoonFilter.

Any configured "classifier.moon.param.NAME = VALUE" pairs will be passed to the MoonFilter for configuring itself (e.g., you can specify "classifier.moon.param.buckets = NUMBER" to modify the number of buckets in the database files).

Instances of this class are thread-safe. For efficient use with MultiBinaryClassifier and OneAgainstTheRestClassifier, the used moonrunner.lua is a static singleton that is shared by all instances.

Version:
$Revision: 1.14 $, $Date: 2006/12/02 15:33:54 $, $Author: siefkes $
Author:
Christian Siefkes

Field Summary
static String CONFIG_DIR
          Configuration key: the directory to run the classifier in (optional, defaults to current working directory).
 
Fields inherited from class de.fu_berlin.ties.classify.TrainableClassifier
ATTRIB_CLASSES, ATTRIB_TRAIN_ALL, ELEMENT_MAIN, META_CLASSIFIER, MULTI_CLASSIFIER, OAR_CLASSIFIER, TIE_CLASSIFIER
 
Fields inherited from interface de.fu_berlin.ties.classify.Classifier
CONFIG_CLASSIFIER
 
Constructor Summary
MoonClassifier(Set<String> allValidClasses)
          Creates a new instance based on the standard configuration.
MoonClassifier(Set<String> allValidClasses, FeatureTransformer trans, TiesConfiguration config)
          Creates a new instance based on the provided arguments.
MoonClassifier(Set<String> allValidClasses, TiesConfiguration config)
          Creates a new instance based on the provided configuration.
 
Method Summary
protected  PredictionDistribution doClassify(FeatureVector features, Set candidateClasses, ContextMap context)
          Classifies an item that is represented by a feature vector by choosing the most probable class among a set of candidate classes.
protected  void doTrain(FeatureVector features, String targetClass, ContextMap context)
          Incorporates an item that is represented by a feature vector into the classification model. Currently this method is not implemented since Moonfilter needs to know the list of active classes.
 void reset()
          Resets the classifer, completely deleting the prediction model.
 ObjectElement toElement()
          Stores all relevant fields of this object in an XML element for serialization. An equivalent object can be created by calling ObjectElement.createObject(org.dom4j.Element, Class) on the created element. Subclasses of TrainableClassifier should extend this method and the corresponding constructor from Element to ensure (de)serialization works as expected. Currently, this classifier does not support XML serialization, throwing an UnsupportedOperationException instead.
 String toString()
          Returns a string representation of this object.
protected  boolean trainOnErrorHook(PredictionDistribution predDist, FeatureVector features, String targetClass, Set candidateClasses, ContextMap context)
          Subclasses can implement this hook for more refined error-driven learning.
 
Methods inherited from class de.fu_berlin.ties.classify.TrainableClassifier
classify, createClassifier, createClassifier, createClassifier, createClassifier, createClassifier, destroy, doTrainOnError, getAllClasses, getConfig, shouldTrain, train, trainOnError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONFIG_DIR

public static final String CONFIG_DIR
Configuration key: the directory to run the classifier in (optional, defaults to current working directory).

See Also:
Constant Field Values
Constructor Detail

MoonClassifier

public MoonClassifier(Set<String> allValidClasses)
               throws ProcessingException
Creates a new instance based on the standard configuration.

Parameters:
allValidClasses - the set of all valid classes
Throws:
ProcessingException - if an I/O error occurs during initialization

MoonClassifier

public MoonClassifier(Set<String> allValidClasses,
                      TiesConfiguration config)
               throws ProcessingException
Creates a new instance based on the provided configuration.

Parameters:
allValidClasses - the set of all valid classes
config - contains configuration properties
Throws:
ProcessingException - if an I/O error occurs during initialization

MoonClassifier

public MoonClassifier(Set<String> allValidClasses,
                      FeatureTransformer trans,
                      TiesConfiguration config)
               throws ProcessingException
Creates a new instance based on the provided arguments.

Parameters:
allValidClasses - the set of all valid classes
trans - the last transformer in the transformer chain to use, or null if no feature transformers should be used
config - contains configuration properties
Throws:
ProcessingException - if an I/O error occurs during initialization
Method Detail

doClassify

protected PredictionDistribution doClassify(FeatureVector features,
                                            Set candidateClasses,
                                            ContextMap context)
                                     throws ProcessingException
Classifies an item that is represented by a feature vector by choosing the most probable class among a set of candidate classes.

Specified by:
doClassify in class TrainableClassifier
Parameters:
features - the feature vector to consider
candidateClasses - an array of the classes that are allowed for this item
context - used to store context information to be used for training
Returns:
the result of the classification; you can call PredictionDistribution.best() to get the most probably class; this classifier returns only the best prediction, so PredictionDistribution.size() will be 1
Throws:
ProcessingException - if an I/O error occurs during communication with the external program

doTrain

protected void doTrain(FeatureVector features,
                       String targetClass,
                       ContextMap context)
                throws ProcessingException
Incorporates an item that is represented by a feature vector into the classification model. Currently this method is not implemented since Moonfilter needs to know the list of active classes.

Specified by:
doTrain in class TrainableClassifier
Parameters:
features - the feature vector to consider
targetClass - the class of this feature vector
context - can be used to transport implementation-specific contextual information between the TrainableClassifier.doClassify(FeatureVector, Set, ContextMap), TrainableClassifier.doTrain(FeatureVector, String, ContextMap), and TrainableClassifier.trainOnErrorHook(PredictionDistribution, FeatureVector, String, Set, ContextMap) methods
Throws:
ProcessingException - if an error occurs during training

reset

public void reset()
           throws ProcessingException
Resets the classifer, completely deleting the prediction model.

Specified by:
reset in class TrainableClassifier
Throws:
ProcessingException - if an error occurs during reset

toElement

public ObjectElement toElement()
                        throws UnsupportedOperationException
Stores all relevant fields of this object in an XML element for serialization. An equivalent object can be created by calling ObjectElement.createObject(org.dom4j.Element, Class) on the created element. Subclasses of TrainableClassifier should extend this method and the corresponding constructor from Element to ensure (de)serialization works as expected. Currently, this classifier does not support XML serialization, throwing an UnsupportedOperationException instead.

Specified by:
toElement in interface XMLStorable
Overrides:
toElement in class TrainableClassifier
Returns:
the created XML element
Throws:
UnsupportedOperationException - always thrown by this implementation

trainOnErrorHook

protected boolean trainOnErrorHook(PredictionDistribution predDist,
                                   FeatureVector features,
                                   String targetClass,
                                   Set candidateClasses,
                                   ContextMap context)
                            throws ProcessingException
Subclasses can implement this hook for more refined error-driven learning. It is called from the TrainableClassifier.trainOnError(FeatureVector, String, Set) method after classifying. This method can do any necessary training itself and return true to signal that no further action is necessary. This implementation is just a placeholder that always returns false.

Overrides:
trainOnErrorHook in class TrainableClassifier
Parameters:
predDist - the prediction distribution returned by TrainableClassifier.classify(FeatureVector, Set)
features - the feature vector to consider
targetClass - the expected class of this feature vector; must be contained in the set of candidateClasses
candidateClasses - an set of classes that are allowed for this item (the actual targetClass must be one of them)
context - can be used to transport implementation-specific contextual information between the TrainableClassifier.doClassify(FeatureVector, Set, ContextMap), TrainableClassifier.doTrain(FeatureVector, String, ContextMap), and TrainableClassifier.trainOnErrorHook(PredictionDistribution, FeatureVector, String, Set, ContextMap) methods
Returns:
this implementation always returns false; subclasses can return true to signal that any error-driven learning was already handled
Throws:
ProcessingException - if an error occurs during training

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class TrainableClassifier
Returns:
a textual representation


Copyright © 2003-2007 Christian Siefkes. All Rights Reserved.