public class RandomWeightVector extends SparseWeightVector
RandomWeightVector
, all the
features in the feature vector will now have random weights associated with them in weight
vector. If a SparseWeightVector.scaledAdd(int[],double[])
is performed, any features in the feature vector
lacking a corresponding weight in the weight vector will have a random one assigned before the
addition is performed. This is usually not an issue for most algorithms, since dot products are
usually performed before deciding how to add, which means all the weights for that feature vector
will already be set when the addition is performed. Thus, it will simply appear to the algorithm
that this vector had independent, identically distributed random values for all its dimensions
when first created.
The random numbers generated by this class are Gaussian with mean 0 and with a user-configurable standard deviation.
Modifier and Type | Field and Description |
---|---|
protected static double |
defaultStddev
Default value for
stddev . |
protected int |
instanceNumber
Remembers the instance number of this instance.
|
protected Random |
random
The random number generator for this instance.
|
protected double |
stddev
The random numbers that are generated by this class are Gaussian with mean 0 and standard
deviation defined by this variable.
|
defaultCapacity, defaultWeight, weights
Constructor and Description |
---|
RandomWeightVector()
Sets a default standard deviation.
|
RandomWeightVector(double s)
Sets the specified standard deviation.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Empties the weight map and resets the random number generator.
|
SparseWeightVector |
emptyClone()
Returns a new, empty weight vector with the same parameter settings as this one.
|
double |
getWeight(int featureIndex,
double defaultW)
Returns the double precision value for the given feature, or sets a random one and returns it
if one did not already exist.
|
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 |
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 vector into the specified
PrintStream . |
void |
write(PrintStream out,
Lexicon lex)
Outputs the contents of this vector into the specified
PrintStream . |
clone, dot, dot, getWeight, pairwiseMultiply, readWeightVector, scaledAdd, scaledAdd, scaledAdd, scaledMultiply, scaledMultiply, setWeight, setWeight, size, toString, toString, toStringJustWeights, toStringJustWeights
protected static final double defaultStddev
stddev
.protected double stddev
protected int instanceNumber
protected Random random
public RandomWeightVector()
public RandomWeightVector(double s)
s
- The standard deviation.public double getWeight(int featureIndex, double defaultW)
getWeight
in class SparseWeightVector
featureIndex
- The feature indexdefaultW
- Unused.public void clear()
SparseWeightVector.dot(int[],double[],double)
and SparseWeightVector.scaledAdd(int[],double[],double,double)
are
made in the same order.clear
in class SparseWeightVector
public void write(PrintStream out)
PrintStream
. The string
representation is the same as in the super class, except the "Begin"
annotation
line also contains the value of stddev
in parentheses.write
in class SparseWeightVector
out
- The stream to write to.public void write(PrintStream out, Lexicon lex)
PrintStream
. The string
representation is the same as in the super class, except the "Begin"
annotation
line also contains the value of stddev
in parentheses.write
in class SparseWeightVector
out
- The stream to write to.lex
- The feature lexicon.public void write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
write
in class SparseWeightVector
out
- 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 SparseWeightVector
in
- The input stream.public SparseWeightVector emptyClone()
emptyClone
in class SparseWeightVector
Copyright © 2016. All rights reserved.