LBJ2.learn
Class SparseAveragedPerceptron.AveragedWeightVector

java.lang.Object
  extended by LBJ2.learn.SparseWeightVector
      extended by LBJ2.learn.SparseAveragedPerceptron.AveragedWeightVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Enclosing class:
SparseAveragedPerceptron

public static class SparseAveragedPerceptron.AveragedWeightVector
extends SparseWeightVector

This implementation of a sparse weight vector associates two doubles with each Feature. The first plays the role of the usual weight vector, and the second accumulates multiples of examples on which mistakes were made to help implement the weighted average.

See Also:
Serialized Form

Nested Class Summary
protected  class SparseAveragedPerceptron.AveragedWeightVector.AveragedWeightIterator
          This class simultaneously iterates over the features in a given vector and their corresponding weights from an SparseAveragedPerceptron.AveragedWeightVector.
 
Nested classes/interfaces inherited from class LBJ2.learn.SparseWeightVector
SparseWeightVector.WeightIterator
 
Field Summary
protected  int examples
          Counts the total number of training examples this vector has seen.
 
Fields inherited from class LBJ2.learn.SparseWeightVector
defaultWeight, weights
 
Constructor Summary
SparseAveragedPerceptron.AveragedWeightVector()
          Simply instantiates SparseWeightVector.weights.
SparseAveragedPerceptron.AveragedWeightVector(java.util.HashMap w)
          Simply initializes SparseWeightVector.weights.
 
Method Summary
 java.lang.Object clone()
          Returns a copy of this AveragedWeightVector in which the SparseWeightVector.weights variable has been cloned deeply.
 void correctExample()
          Increments the examples variable.
 int getExamples()
          Returns the examples variable.
 void scaledAdd(FeatureVector example, double factor, double defaultW)
          Performs pairwise addition of the feature values in the given vector scaled by the given factor, modifying this weight vector, using the specified default weight when a feature from the given vector is not yet present in this vector.
 double simpleDot(FeatureVector example)
          Takes the dot product of the regular, non-averaged, Perceptron weight vector with the given vector, using the hard coded default weight.
 double simpleDot(FeatureVector example, double defaultW)
          Takes the dot product of the regular, non-averaged, Perceptron weight vector with the given vector, using the specified default weight when a feature is not yet present in this vector.
 java.lang.String toString()
          Converts this AveragedWeightVector into a String.
 SparseWeightVector.WeightIterator weightIterator(FeatureVector example)
          Produces an iterator that accesses the data in this vector associated with the features in the given vector.
 
Methods inherited from class LBJ2.learn.SparseWeightVector
clear, dot, dot, scaledAdd, scaledAdd, write
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

examples

protected int examples
Counts the total number of training examples this vector has seen.

Constructor Detail

SparseAveragedPerceptron.AveragedWeightVector

public SparseAveragedPerceptron.AveragedWeightVector()
Simply instantiates SparseWeightVector.weights.


SparseAveragedPerceptron.AveragedWeightVector

public SparseAveragedPerceptron.AveragedWeightVector(java.util.HashMap w)
Simply initializes SparseWeightVector.weights.

Parameters:
w - A map of weights.
Method Detail

correctExample

public void correctExample()
Increments the examples variable.


getExamples

public int getExamples()
Returns the examples variable.


weightIterator

public SparseWeightVector.WeightIterator weightIterator(FeatureVector example)
Produces an iterator that accesses the data in this vector associated with the features in the given vector.

Overrides:
weightIterator in class SparseWeightVector
Parameters:
example - A vector of features extracted from an example object.
Returns:
A weight iterator.

simpleDot

public double simpleDot(FeatureVector example)
Takes the dot product of the regular, non-averaged, Perceptron weight vector with the given vector, using the hard coded default weight.

Parameters:
example - A vector of features extracted from an example object.
Returns:
The computed dot product.

simpleDot

public double simpleDot(FeatureVector example,
                        double defaultW)
Takes the dot product of the regular, non-averaged, Perceptron weight vector with the given vector, using the specified default weight when a feature is not yet present in this vector.

Parameters:
example - A vector of features extracted from an example object.
defaultW - An initial weight for new features.
Returns:
The computed dot product.

scaledAdd

public void scaledAdd(FeatureVector example,
                      double factor,
                      double defaultW)
Performs pairwise addition of the feature values in the given vector scaled by the given factor, modifying this weight vector, using the specified default weight when a feature from the given vector is not yet present in this vector.

Overrides:
scaledAdd in class SparseWeightVector
Parameters:
example - A vector of features extracted from an example object.
factor - The scaling factor.
defaultW - An initial weight for new features.

clone

public java.lang.Object clone()
Returns a copy of this AveragedWeightVector in which the SparseWeightVector.weights variable has been cloned deeply.

Overrides:
clone in class SparseWeightVector
Returns:
A copy of this AveragedWeightVector.

toString

public java.lang.String toString()
Converts this AveragedWeightVector into a String.

Overrides:
toString in class SparseWeightVector
Returns:
A String holding a textual representation of this vector.