de.fu_berlin.ties.filter
Class TrainableFilter

java.lang.Object
  extended by de.fu_berlin.ties.filter.TrainableFilter
All Implemented Interfaces:
ElementFilter
Direct Known Subclasses:
RepresentationFilter

public abstract class TrainableFilter
extends Object
implements ElementFilter

An abstract filter that uses a trainable classifier for training. Subclasses must implement the buildFeatures(Element) method to convert elements into feature vectors suitable for the classifier.

Instances of this class are not thread-safe and must be synchronized externally, if required.

Version:
$Revision: 1.8 $, $Date: 2004/12/09 18:09:46 $, $Author: siefkes $
Author:
Christian Siefkes

Field Summary
static SortedSet<String> BOOLEAN_CLASSES
          An immutable set of the target classes for the classifier: the strings "false" and "true", in alphabetic order.
 
Constructor Summary
TrainableFilter(TiesConfiguration conf, NodeFilter positiveFilter, NodeFilter negativeFilter, Reranker rerank)
          Creates a new instance.
 
Method Summary
 boolean avoids(Element element)
          Whether the filter would avoid to filter an element, if possible.
abstract  FeatureVector buildFeatures(Element element)
          Converts an element into a feature vector to be used by the trainable classifier.
 void init(Document document)
          Resets the filter to start processing a new document.
 boolean matches(Element element)
          Decides whether an element is accepted by this filter.
 boolean prefers(Element element)
          Whether the filter would prefer to filter an element.
 String toString()
          Returns a string representation of this object.
 PredictionDistribution trainIfNecessary(Element element, boolean decision)
          Trains the correct decision for an element by calling the TrainableClassifier.trainOnError(FeatureVector, String, java.util.Set) method on the stored trainable classifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BOOLEAN_CLASSES

public static final SortedSet<String> BOOLEAN_CLASSES
An immutable set of the target classes for the classifier: the strings "false" and "true", in alphabetic order.

Constructor Detail

TrainableFilter

public TrainableFilter(TiesConfiguration conf,
                       NodeFilter positiveFilter,
                       NodeFilter negativeFilter,
                       Reranker rerank)
                throws ProcessingException
Creates a new instance.

Parameters:
conf - used to initialize the trainable classifier by calling TrainableClassifier.createClassifier(java.util.Set, TiesConfiguration)
positiveFilter - this filter is queried to decide whether this class prefersan element
negativeFilter - this filter is queried to decide whether this class avoidsan element
rerank - an optional reranker that recalculates probabilities to introduce a bias (can be used to favor recall over precision, by setting a bias > 1 for the "true" class, etc.); might be null
Throws:
ProcessingException - if the initialization of the trainable classifier fails
Method Detail

buildFeatures

public abstract FeatureVector buildFeatures(Element element)
Converts an element into a feature vector to be used by the trainable classifier.

Parameters:
element - the element to convert
Returns:
a feature vector representing the provided element

init

public void init(Document document)
Resets the filter to start processing a new document. This method must be called for each document to be procesed by this filter prior to calling ElementFilter.matches(Element)or ElementFilter.prefers(Element)on elements of this document.

Specified by:
init in interface ElementFilter
Parameters:
document - the document to process

avoids

public boolean avoids(Element element)
Whether the filter would avoid to filter an element, if possible. Any filter must be able to filter all elements, but some filters like to avoid elements of a certain type, for example.

Specified by:
avoids in interface ElementFilter
Parameters:
element - the element to consider
Returns:
true if this would prefer to avoid filtering the element; false otherwise

matches

public boolean matches(Element element)
                throws ProcessingException
Decides whether an element is accepted by this filter.

Specified by:
matches in interface ElementFilter
Parameters:
element - the element to test
Returns:
true if this filter accepts the element; false otherwise
Throws:
ProcessingException - if an error occurs during filtering

prefers

public boolean prefers(Element element)
Whether the filter would prefer to filter an element. Any filter must be able to filter all elements, but some filters prefer elements of a certain type, for example.

Specified by:
prefers in interface ElementFilter
Parameters:
element - the element to consider
Returns:
true if this would prefer to filter the element; false otherwise

toString

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

Overrides:
toString in class Object
Returns:
a textual representation

trainIfNecessary

public PredictionDistribution trainIfNecessary(Element element,
                                               boolean decision)
                                        throws ProcessingException
Trains the correct decision for an element by calling the TrainableClassifier.trainOnError(FeatureVector, String, java.util.Set) method on the stored trainable classifier. By using this method, the classifier will train itself only when necessary.

Parameters:
element - the element to train
decision - the correct decision for the element -- whether or not it should be accepted
Returns:
the prediction distribution returned by TrainableClassifier.trainOnError(FeatureVector, String, java.util.Set)
Throws:
ProcessingException - if an error occurs during training


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