LBJ2.learn
Class NaiveBayes.NaiveBayesVector

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

protected class NaiveBayes.NaiveBayesVector
extends SparseWeightVector

Keeps track of all the counts associated with a given label. Features are associated with NaiveBayes.Counts. 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.

RealFeatures are ignored by this vector - no counts will be associated with them.

See Also:
Serialized Form

Nested Class Summary
protected  class NaiveBayes.NaiveBayesVector.NaiveBayesIterator
          This class simultaneously iterates over the features in a given vector and their corresponding weights from a NaiveBayes.NaiveBayesVector.
 
Nested classes/interfaces inherited from class LBJ2.learn.SparseWeightVector
SparseWeightVector.WeightIterator
 
Field Summary
protected  NaiveBayes.Count priorCount
          The prior count is the number of times either scaledAdd method has been called.
 
Fields inherited from class LBJ2.learn.SparseWeightVector
defaultWeight, weights
 
Constructor Summary
NaiveBayes.NaiveBayesVector()
          Simply instantiates SparseWeightVector.weights.
NaiveBayes.NaiveBayesVector(java.util.HashMap w)
          Simply initializes SparseWeightVector.weights.
 
Method Summary
 java.lang.Object clone()
          Returns a copy of this NaiveBayesVector in which the SparseWeightVector.weights variable has been cloned deeply.
 double dot(FeatureVector example)
          Takes the dot product of this vector with the given vector, using the hard coded smoothing weight.
 double dot(FeatureVector example, 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.
 NaiveBayes.Count getPrior()
          Returns the prior count of the prediction value associated with this vector.
 void scaledAdd(FeatureVector example, double factor, double defaultW)
          This method is similar to the implementation in SparseWeightVector except that the factor and defaultW arguments are ignored and NaiveBayes.NaiveBayesVector.NaiveBayesIterator.incrementCount(double) is called instead of SparseWeightVector.WeightIterator.setWeight(double).
 java.lang.String toString()
          Converts this NaiveBayesVector 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, scaledAdd, scaledAdd, write
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

priorCount

protected NaiveBayes.Count priorCount
The prior count is the number of times either scaledAdd method has been called.

Constructor Detail

NaiveBayes.NaiveBayesVector

public NaiveBayes.NaiveBayesVector()
Simply instantiates SparseWeightVector.weights.


NaiveBayes.NaiveBayesVector

public NaiveBayes.NaiveBayesVector(java.util.HashMap w)
Simply initializes SparseWeightVector.weights.

Parameters:
w - A map of weights.
Method Detail

getPrior

public NaiveBayes.Count getPrior()
Returns the prior count of the prediction value associated with this vector.


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.

dot

public double dot(FeatureVector example)
Takes the dot product of this vector with the given vector, using the hard coded smoothing weight.

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

dot

public double dot(FeatureVector example,
                  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. Here, weights are taken as log(feature count / prior count). The output of this method is related to the empirical probability of the example e as follows:

exp(dot(e)) / (sum of all labels' prior counts)) =
P(e's label && e)

Overrides:
dot in class SparseWeightVector
Parameters:
example - A vector of features extracted from an example object.
defaultW - The default weight.
Returns:
The computed dot product.

scaledAdd

public void scaledAdd(FeatureVector example,
                      double factor,
                      double defaultW)
This method is similar to the implementation in SparseWeightVector except that the factor and defaultW arguments are ignored and NaiveBayes.NaiveBayesVector.NaiveBayesIterator.incrementCount(double) is called instead of SparseWeightVector.WeightIterator.setWeight(double).

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

toString

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

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

clone

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

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