protected class NaiveBayes.NaiveBayesVector extends SparseWeightVector
NaiveBayes.Count
s. Those not appearing in this vector are assumed to have a count of
0. The invocation of either of the scaledAdd
methods increments the prior count
for the label.
RealFeature
s' strengths are ignored by this vector; they are assumed to be equal to
1, as if the feature were an active Boolean feature.
Modifier and Type | Field and Description |
---|---|
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector |
counts
The counts in the vector indexed by their
Lexicon key. |
protected NaiveBayes.Count |
priorCount
The prior count is the number of times either
scaledAdd method has been
called. |
defaultCapacity, defaultWeight, weights
Constructor and Description |
---|
NaiveBayesVector()
Simply instantiates
counts . |
NaiveBayesVector(NaiveBayes.Count[] w)
Simply initializes
counts . |
NaiveBayesVector(edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector w)
Simply initializes
counts . |
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Returns a copy of this
NaiveBayesVector . |
double |
dot(int[] exampleFeatures,
double[] exampleValues)
Takes the dot product of this vector with the given vector, using the hard coded
smoothing weight.
|
double |
dot(int[] exampleFeatures,
double[] exampleValues,
double defaultW)
Takes the dot product of this vector with the given vector, using the specified default
weight when encountering a feature that is not yet present in this vector.
|
SparseWeightVector |
emptyClone()
Returns a new, empty weight vector with the same parameter settings as this one.
|
double |
getCount(int featureIndex)
Returns the count of the given feature.
|
NaiveBayes.Count |
getPrior()
Returns the prior count of the prediction value associated with this vector.
|
double |
getWeight(int featureIndex,
double defaultW)
Returns the weight of the given feature
|
void |
incrementCount(int featureIndex,
double factor)
Increments the count of the given feature.
|
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)
This method is similar to the implementation in
SparseWeightVector except that
incrementCount(int,double) is called instead of
SparseWeightVector.setWeight(int,double) . |
void |
scaledAdd(int[] exampleFeatures,
double[] exampleValues,
double factor,
double defaultW)
This method is similar to the implementation in
SparseWeightVector except that
the defaultW argument is ignored and
incrementCount(int,double) is called instead of
SparseWeightVector.setWeight(int,double) . |
void |
setWeight(int f,
double w)
This method is overridden to do nothing; use
incrementCount(int,double) instead. |
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 . |
clear, getWeight, pairwiseMultiply, readWeightVector, scaledAdd, scaledMultiply, scaledMultiply, setWeight, size, toString, toString, toStringJustWeights, toStringJustWeights
protected edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector counts
Lexicon
key.protected NaiveBayes.Count priorCount
scaledAdd
method has been
called.public NaiveBayesVector()
counts
.public NaiveBayesVector(NaiveBayes.Count[] w)
counts
.w
- An array of counts.public NaiveBayesVector(edu.illinois.cs.cogcomp.core.datastructures.vectors.OVector w)
counts
.w
- A vector of counts.public NaiveBayes.Count getPrior()
public double dot(int[] exampleFeatures, double[] exampleValues)
dot
in class SparseWeightVector
exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.public double dot(int[] exampleFeatures, double[] exampleValues, double defaultW)
dot
in class SparseWeightVector
exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.defaultW
- The default weight.public double getCount(int featureIndex)
featureIndex
- The feature index.public double getWeight(int featureIndex, double defaultW)
getWeight
in class SparseWeightVector
featureIndex
- The feature index.defaultW
- The default count.public void setWeight(int f, double w)
incrementCount(int,double)
instead.setWeight
in class SparseWeightVector
f
- Unused.w
- Unused.public void incrementCount(int featureIndex, double factor)
featureIndex
- The index of the feature to update.factor
- The factor by which to increment.public void scaledAdd(int[] exampleFeatures, double[] exampleValues, double factor)
SparseWeightVector
except that
incrementCount(int,double)
is called instead of
SparseWeightVector.setWeight(int,double)
.scaledAdd
in class SparseWeightVector
exampleFeatures
- 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)
SparseWeightVector
except that
the defaultW
argument is ignored and
incrementCount(int,double)
is called instead of
SparseWeightVector.setWeight(int,double)
.scaledAdd
in class SparseWeightVector
exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.factor
- The scaling factor.defaultW
- Unused.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 priorCount
in parentheses. In
addition, this method has access to the lexicon, so the output of this method is
equivalent to that of write(PrintStream,Lexicon)
.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 priorCount
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)
SparseWeightVector.write(ExceptionlessOutputStream)
and does
not output its class name or the contents of SparseWeightVector.weights
since
there shouldn't be any.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 Object clone()
NaiveBayesVector
.clone
in class SparseWeightVector
NaiveBayesVector
.public SparseWeightVector emptyClone()
emptyClone
in class SparseWeightVector
Copyright © 2016. All rights reserved.