ir.classifiers
Class PerceptronUnit

java.lang.Object
  extended by ir.classifiers.PerceptronUnit

public class PerceptronUnit
extends java.lang.Object

An individual perceptron object used by the Perceptron classifier Includes methods for classifying an Example and training the unit to fire only for a given category of examples.


Field Summary
protected  java.lang.String[] categories
          Array of categories (classes) in the data
 boolean debug
          Flag for debug print statements
 double learningRate
          The learning rate for weight updating
 int maxEpochs
          Maximum number of training epochs allowed
protected  double threshold
          The threshold of the perceptron.
protected  HashMapVector weights
          The weights of the perceptron.
 
Constructor Summary
PerceptronUnit(java.lang.String[] categories, boolean debug)
          Create an PerceptronUnit with these attributes
 
Method Summary
 double classify(Example example)
          Classify an example using the perceptron and return the amount by which the net input exceeds the threshold as a measure of confidence of the prediction of being positive for this perceptron
 void clear()
          Clear the weights and threshold all back to zero
 void trainCategory(java.util.List trainExamples, int category)
          Trains the perceptron to only fire for examples in the given category, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threshold

protected double threshold
The threshold of the perceptron. The net input must exceed this threshold in order for the neuron to fire


weights

protected HashMapVector weights
The weights of the perceptron. Since the weight vector is sparse, most entries are zero, a HashMapVector is used to store the weights for the non-zero features (tokens). See ir.vsr.HashMapVector.


maxEpochs

public int maxEpochs
Maximum number of training epochs allowed


learningRate

public double learningRate
The learning rate for weight updating


categories

protected java.lang.String[] categories
Array of categories (classes) in the data


debug

public boolean debug
Flag for debug print statements

Constructor Detail

PerceptronUnit

public PerceptronUnit(java.lang.String[] categories,
                      boolean debug)
Create an PerceptronUnit with these attributes

Parameters:
categories - The array of Strings containing the category names
debug - Flag to turn on detailed output
Method Detail

clear

public void clear()
Clear the weights and threshold all back to zero


classify

public double classify(Example example)
Classify an example using the perceptron and return the amount by which the net input exceeds the threshold as a measure of confidence of the prediction of being positive for this perceptron


trainCategory

public void trainCategory(java.util.List trainExamples,
                          int category)
Trains the perceptron to only fire for examples in the given category, i.e. examples in the given category should be treated as positive examples for this perceptron and examples in all other categories should be treated as negative