public static class SparseAveragedPerceptron.AveragedWeightVector extends SparseWeightVector
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.| Modifier and Type | Field and Description |
|---|---|
edu.illinois.cs.cogcomp.core.datastructures.vectors.DVector |
averagedWeights
Together with
SparseWeightVector.weights, this vector provides enough information
to reconstruct the average of all weight vectors arrived at during the course of
learning. |
protected int |
examples
Counts the total number of training examples this vector has seen.
|
defaultCapacity, defaultWeight, weights| Constructor and Description |
|---|
AveragedWeightVector()
Simply instantiates the weight vectors.
|
AveragedWeightVector(double[] w)
Simply initializes the weight vectors.
|
AveragedWeightVector(edu.illinois.cs.cogcomp.core.datastructures.vectors.DVector w)
Simply initializes the weight vectors.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
clone()
Returns a copy of this
AveragedWeightVector. |
void |
correctExample()
Increments the
examples variable. |
double |
dot(int[] exampleFeatures,
double[] exampleValues)
Takes the dot product of this
AveragedWeightVector with the argument vector,
using the hard coded default weight. |
double |
dot(int[] exampleFeatures,
double[] exampleValues,
double defaultW)
Takes the dot product of this
AveragedWeightVector with the argument vector,
using the specified default weight when one is not yet present in this vector. |
SparseWeightVector |
emptyClone()
Returns a new, empty weight vector with the same parameter settings as this one.
|
double |
getAveragedWeight(int featureIndex,
double defaultW)
Returns the averaged weight of the given feature.
|
int |
getExamples()
Returns the
examples variable. |
void |
read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
Reads the representation of a weight vector with this object's run-time type from the
given stream, overwriting the data in this object.
|
void |
scaledAdd(int[] exampleFeatures,
double[] exampleValues,
double factor)
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.
|
void |
scaledAdd(int[] exampleFeatures,
double[] exampleValues,
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(int[] exampleFeatures,
double[] exampleValues)
Takes the dot product of the regular, non-averaged, Perceptron weight vector with the
given vector, using the hard coded default weight.
|
double |
simpleDot(int[] exampleFeatures,
double[] exampleValues,
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.
|
protected void |
updateAveragedWeight(int featureIndex,
double w)
Adds a new value to the current averaged weight indexed by the supplied feature index.
|
void |
write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
Writes the weight vector's internal representation in binary form.
|
void |
write(PrintStream out)
Outputs the contents of this
SparseWeightVector into the specified
PrintStream. |
void |
write(PrintStream out,
Lexicon lex)
Outputs the contents of this
SparseWeightVector into the specified
PrintStream. |
clear, getWeight, getWeight, pairwiseMultiply, readWeightVector, scaledAdd, scaledMultiply, scaledMultiply, setWeight, setWeight, size, toString, toString, toStringJustWeights, toStringJustWeightspublic edu.illinois.cs.cogcomp.core.datastructures.vectors.DVector averagedWeights
SparseWeightVector.weights, this vector provides enough information
to reconstruct the average of all weight vectors arrived at during the course of
learning.protected int examples
public AveragedWeightVector()
public AveragedWeightVector(double[] w)
w - An array of weights.public AveragedWeightVector(edu.illinois.cs.cogcomp.core.datastructures.vectors.DVector w)
w - A vector of weights.public void correctExample()
examples variable.public int getExamples()
examples variable.public double getAveragedWeight(int featureIndex,
double defaultW)
featureIndex - The feature index.defaultW - The default weight.public double dot(int[] exampleFeatures,
double[] exampleValues)
AveragedWeightVector with the argument vector,
using the hard coded default weight.dot in class SparseWeightVectorexampleFeatures - The example's array of feature indices.exampleValues - The example's array of feature values.public double dot(int[] exampleFeatures,
double[] exampleValues,
double defaultW)
AveragedWeightVector with the argument vector,
using the specified default weight when one is not yet present in this vector.dot in class SparseWeightVectorexampleFeatures - The example's array of feature indices.exampleValues - The example's array of feature values.defaultW - The default weight.public double simpleDot(int[] exampleFeatures,
double[] exampleValues)
exampleFeatures - The example's array of feature indices.exampleValues - The example's array of feature values.public double simpleDot(int[] exampleFeatures,
double[] exampleValues,
double defaultW)
exampleFeatures - The example's array of feature indices.exampleValues - The example's array of feature values.defaultW - An initial weight for new features.public void scaledAdd(int[] exampleFeatures,
double[] exampleValues,
double factor)
scaledAdd in class SparseWeightVectorexampleFeatures - The example's array of feature indices.exampleValues - The example's array of feature values.factor - The scaling factor.public void scaledAdd(int[] exampleFeatures,
double[] exampleValues,
double factor,
double defaultW)
scaledAdd in class SparseWeightVectorexampleFeatures - The example's array of feature indices.exampleValues - The example's array of feature values.factor - The scaling factor.defaultW - An initial weight for new features.protected void updateAveragedWeight(int featureIndex,
double w)
featureIndex - The feature index.w - The value to add to the current weight.public void write(PrintStream out)
SparseWeightVector into the specified
PrintStream. The string representation starts with a "Begin"
annotation, ends with an "End" annotation, and without a
Lexicon passed as a parameter, the weights are simply printed in the order
of their integer indices.write in class SparseWeightVectorout - The stream to write to.public void write(PrintStream out, Lexicon lex)
SparseWeightVector into the specified
PrintStream. The string representation starts with a "Begin"
annotation, ends with an "End" annotation, and lists each feature with its
corresponding weight on the same, separate line in between.write in class SparseWeightVectorout - The stream to write to.lex - The feature lexicon.public void write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
write in class SparseWeightVectorout - The output stream.public void read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
This method is appropriate for reading weight vectors as written by
write(ExceptionlessOutputStream).
read in class SparseWeightVectorin - The input stream.public Object clone()
AveragedWeightVector.clone in class SparseWeightVectorAveragedWeightVector.public SparseWeightVector emptyClone()
emptyClone in class SparseWeightVectorCopyright © 2016. All rights reserved.