|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectLBJ2.classify.Classifier
LBJ2.learn.Learner
LBJ2.learn.LinearThresholdUnit
public abstract class LinearThresholdUnit
A LinearThresholdUnit is a Learner for binary
classification in which a score is computed as a linear function a
weight vector and the input example, and the decision is made by
comparing the score to some threshold quantity. Deriving a linear
threshold algorithm from this class gives the programmer more flexible
access to the score it computes as well as its promotion and demotion
methods (if it's on-line).
On-line, mistake driven algorithms derived from this class need only
override the promote(Object), and demote(Object)
methods, assuming the score returned by the score(Object) method
need only be compared with threshold to make a prediction.
Otherwise, the classify(Object) method also needs to be
overridden. If the algorithm is not mistake driven, the
learn(Object) method needs to be overridden as well.
It is assumed that Learner.labeler is a single discrete
classifier that produces the same feature for every example object and
that the values that feature may take are available through the
Classifier.allowableValues() method. The first value returned
from Classifier.allowableValues() is treated as "negative", and it
is assumed there are exactly 2 allowable values. Assertions will produce
error messages if these assumptions do not hold.
Fitting a "thick separator" instead of just a hyperplane is also supported through this class.
This algorithm's user-configurable parameters are stored in member
fields of this class. They may be set via either a constructor that names
each parameter explicitly or a constructor that takes an instance of
Parameters as input.
The documentation in each member field in this class indicates the default
value of the associated parameter when using the former type of
constructor. The documentation of the associated member field in the
Parameters class
indicates the default value of the parameter when using the latter type of
constructor.
| Nested Class Summary | |
|---|---|
static class |
LinearThresholdUnit.Parameters
Simply a container for all of LinearThresholdUnit's configurable
parameters. |
| Field Summary | |
|---|---|
protected java.lang.String[] |
allowableValues
The label producing classifier's allowable values. |
protected double |
bias
The bias is stored here rather than as an element of the weight vector. |
static double |
defaultInitialWeight
Default for initialWeight. |
static double |
defaultThickness
Default for positiveThickness. |
static double |
defaultThreshold
Default for threshold. |
static SparseWeightVector |
defaultWeightVector
Default for weightVector. |
protected double |
initialWeight
The weight associated with a feature when first added to the vector; default defaultInitialWeight. |
protected double |
negativeThickness
The thickness of the hyperplane on the negative side; default equal to positiveThickness. |
protected double |
positiveThickness
The thickness of the hyperplane on the positive side; default defaultThickness. |
protected double |
threshold
The score is compared against this value to make predictions; default defaultThreshold. |
protected SparseWeightVector |
weightVector
The LTU's weight vector; default is an empty vector. |
| Fields inherited from class LBJ2.learn.Learner |
|---|
extractor, labeler |
| Fields inherited from class LBJ2.classify.Classifier |
|---|
containingPackage, name |
| Constructor Summary | |
|---|---|
protected |
LinearThresholdUnit(java.lang.String n)
Default constructor. |
protected |
LinearThresholdUnit(java.lang.String n,
double t)
Initializing constructor. |
protected |
LinearThresholdUnit(java.lang.String n,
double t,
double pt)
Initializing constructor. |
protected |
LinearThresholdUnit(java.lang.String n,
double t,
double pt,
double nt)
Initializing constructor. |
protected |
LinearThresholdUnit(java.lang.String n,
double t,
double pt,
double nt,
SparseWeightVector v)
Initializing constructor. |
protected |
LinearThresholdUnit(java.lang.String n,
LinearThresholdUnit.Parameters p)
Initializing constructor. |
| Method Summary | |
|---|---|
java.lang.String[] |
allowableValues()
Returns the array of allowable values that a feature returned by this classifier may take. |
FeatureVector |
classify(java.lang.Object example)
The default evaluation method simply computes the score for the example and returns a DiscreteFeature set to either the second value
from the label classifier's array of allowable values if the score is
greater than or equal to threshold or the first otherwise. |
abstract void |
demote(java.lang.Object example)
If the LinearThresholdUnit is mistake driven, this method
should be overridden and used to update the internal representation when
a mistake is made on a negative example. |
void |
forget()
Resets the weight vector to associate the default weight with all features. |
double |
getInitialWeight()
Returns the current value of the initialWeight variable. |
double |
getNegativeThickness()
Returns the current value of the negativeThickness variable. |
double |
getPositiveThickness()
Returns the current value of the positiveThickness variable. |
double |
getThreshold()
Returns the current value of the threshold variable. |
void |
learn(java.lang.Object example)
The default training algorithm for a linear threshold unit consists of evaluating the example object with the score(Object) method and
threshold, checking the result of evaluation against the label,
and, if they are different, promoting when the label is positive or
demoting when the label is negative. |
abstract void |
promote(java.lang.Object example)
If the LinearThresholdUnit is mistake driven, this method
should be overridden and used to update the internal representation when
a mistake is made on a positive example. |
double |
score(java.lang.Object example)
Computes the score for the specified example vector which will be thresholded to make the binary classification. |
ScoreSet |
scores(java.lang.Object example)
An LTU returns two scores; one for the negative classification and one for the positive classification. |
void |
setInitialWeight(double w)
Sets the initialWeight member variable to the specified value. |
void |
setLabeler(Classifier l)
Sets the labels list. |
void |
setNegativeThickness(double t)
Sets the negativeThickness member variable to the specified
value. |
void |
setPositiveThickness(double t)
Sets the positiveThickness member variable to the specified
value. |
void |
setThickness(double t)
Sets the positiveThickness and negativeThickness
member variables to the specified value. |
void |
setThreshold(double t)
Sets the threshold member variable to the specified value. |
| Methods inherited from class LBJ2.learn.Learner |
|---|
doneLearning, getExtractor, getLabeler, learn, save, setExtractor, write |
| Methods inherited from class LBJ2.classify.Classifier |
|---|
binaryRead, binaryRead, binaryRead, binaryRead, binaryWrite, binaryWrite, classify, clone, discreteValue, discreteValueArray, getCompositeChildren, getInputType, getOutputType, realValue, realValueArray, test, toString, valueIndexOf |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final double defaultInitialWeight
initialWeight.
public static final double defaultThreshold
threshold.
public static final double defaultThickness
positiveThickness.
public static final SparseWeightVector defaultWeightVector
weightVector.
protected SparseWeightVector weightVector
protected double initialWeight
defaultInitialWeight.
protected double threshold
defaultThreshold.
protected double bias
protected double positiveThickness
defaultThickness.
protected double negativeThickness
positiveThickness.
protected java.lang.String[] allowableValues
| Constructor Detail |
|---|
protected LinearThresholdUnit(java.lang.String n)
n - The name of the classifier.
protected LinearThresholdUnit(java.lang.String n,
double t)
n - The name of the classifier.t - The desired value for the threshold.
protected LinearThresholdUnit(java.lang.String n,
double t,
double pt)
n - The name of the classifier.t - The desired value for the threshold.pt - The desired thickness.
protected LinearThresholdUnit(java.lang.String n,
double t,
double pt,
double nt)
n - The name of the classifier.t - The desired value for the threshold.pt - The desired positive thickness.nt - The desired negative thickness.
protected LinearThresholdUnit(java.lang.String n,
double t,
double pt,
double nt,
SparseWeightVector v)
n - The name of the classifier.t - The desired value for the threshold.pt - The desired positive thickness.nt - The desired negative thickness.v - An initial weight vector.
protected LinearThresholdUnit(java.lang.String n,
LinearThresholdUnit.Parameters p)
LinearThresholdUnit.Parameters object.
n - The name of the classifier.p - The settings of all parameters.| Method Detail |
|---|
public void setLabeler(Classifier l)
setLabeler in class Learnerl - A new label producing classifier.public double getInitialWeight()
initialWeight variable.
initialWeight variable.public void setInitialWeight(double w)
initialWeight member variable to the specified value.
w - The new value for initialWeight.public double getThreshold()
threshold variable.
threshold variable.public void setThreshold(double t)
threshold member variable to the specified value.
t - The new value for threshold.public double getPositiveThickness()
positiveThickness variable.
positiveThickness variable.public void setPositiveThickness(double t)
positiveThickness member variable to the specified
value.
t - The new value for positiveThickness.public double getNegativeThickness()
negativeThickness variable.
negativeThickness variable.public void setNegativeThickness(double t)
negativeThickness member variable to the specified
value.
t - The new value for negativeThickness.public void setThickness(double t)
positiveThickness and negativeThickness
member variables to the specified value.
t - The new thickness value.public java.lang.String[] allowableValues()
allowableValues in class Classifiernew String[]{ "*", "*" } is returned, which
indicates to the compiler that classifiers derived from this
learner will return features that take one of two values that
are specified in the source code. Otherwise, the allowable
values of the labeler are returned.public void learn(java.lang.Object example)
score(Object) method and
threshold, checking the result of evaluation against the label,
and, if they are different, promoting when the label is positive or
demoting when the label is negative.
This method does not call classify(Object); it calls
score(Object) directly.
learn in class Learnerexample - The example object.public ScoreSet scores(java.lang.Object example)
score(Object) minus the
threshold, and the score for the negative classification is the
opposite of the positive classification's score.
scores in class Learnerexample - The object to make decisions about.
public FeatureVector classify(java.lang.Object example)
DiscreteFeature set to either the second value
from the label classifier's array of allowable values if the score is
greater than or equal to threshold or the first otherwise.
classify in class Classifierexample - The example to be evaluated.
public double score(java.lang.Object example)
example - The example object.
public void forget()
forget in class Learnerpublic abstract void promote(java.lang.Object example)
LinearThresholdUnit is mistake driven, this method
should be overridden and used to update the internal representation when
a mistake is made on a positive example.
example - The example object.public abstract void demote(java.lang.Object example)
LinearThresholdUnit is mistake driven, this method
should be overridden and used to update the internal representation when
a mistake is made on a negative example.
example - The example object.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||