|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.classify.TrainableClassifier
de.fu_berlin.ties.classify.MoonClassifier
public class MoonClassifier
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
FeatureTransformer
s 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.
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 |
---|
public static final String CONFIG_DIR
Constructor Detail |
---|
public MoonClassifier(Set<String> allValidClasses) throws ProcessingException
allValidClasses
- the set of all valid classes
ProcessingException
- if an I/O error occurs during initializationpublic MoonClassifier(Set<String> allValidClasses, TiesConfiguration config) throws ProcessingException
allValidClasses
- the set of all valid classesconfig
- contains configuration properties
ProcessingException
- if an I/O error occurs during initializationpublic MoonClassifier(Set<String> allValidClasses, FeatureTransformer trans, TiesConfiguration config) throws ProcessingException
allValidClasses
- the set of all valid classestrans
- the last transformer in the transformer chain to use, or
null
if no feature transformers should be usedconfig
- contains configuration properties
ProcessingException
- if an I/O error occurs during initializationMethod Detail |
---|
protected PredictionDistribution doClassify(FeatureVector features, Set candidateClasses, ContextMap context) throws ProcessingException
doClassify
in class TrainableClassifier
features
- the feature vector to considercandidateClasses
- an array of the classes that are allowed for
this itemcontext
- used to store context information to be used for training
PredictionDistribution.best()
to get the most probably class;
this classifier returns only the best prediction, so
PredictionDistribution.size()
will be 1
ProcessingException
- if an I/O error occurs during communication
with the external programprotected void doTrain(FeatureVector features, String targetClass, ContextMap context) throws ProcessingException
doTrain
in class TrainableClassifier
features
- the feature vector to considertargetClass
- the class of this feature vectorcontext
- 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
ProcessingException
- if an error occurs during trainingpublic void reset() throws ProcessingException
reset
in class TrainableClassifier
ProcessingException
- if an error occurs during resetpublic ObjectElement toElement() throws UnsupportedOperationException
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.
toElement
in interface XMLStorable
toElement
in class TrainableClassifier
UnsupportedOperationException
- always thrown by this
implementationprotected boolean trainOnErrorHook(PredictionDistribution predDist, FeatureVector features, String targetClass, Set candidateClasses, ContextMap context) throws ProcessingException
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
.
trainOnErrorHook
in class TrainableClassifier
predDist
- the prediction distribution returned by
TrainableClassifier.classify(FeatureVector, Set)
features
- the feature vector to considertargetClass
- 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
false
; subclasses
can return true
to signal that any error-driven learning was
already handled
ProcessingException
- if an error occurs during trainingpublic String toString()
toString
in class TrainableClassifier
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |