LBJ2.learn
Class SparseWeightVector.WeightIterator

java.lang.Object
  extended by LBJ2.learn.SparseWeightVector.WeightIterator
Direct Known Subclasses:
NaiveBayes.NaiveBayesVector.NaiveBayesIterator, SparseAveragedPerceptron.AveragedWeightVector.AveragedWeightIterator
Enclosing class:
SparseWeightVector

protected class SparseWeightVector.WeightIterator
extends java.lang.Object

This class simultaneously iterates over the features in the given vector and their corresponding weights from a SparseWeightVector. Member methods give read and write access to the weight that an object of this class currently points to, and changes are reflected in the SparseWeightVector.


Field Summary
protected  int arrayIndex
          Pointer into weightArray.
protected  Feature currentFeature
          The feature corresponding to the current weight.
protected  java.util.Iterator I
          Iterates through the features corresponding to the weights to be iterated over for the current composite child.
protected  boolean isDiscrete
          true iff the current feature is discrete.
protected  FeatureVector vector
          The feature vector to iterate through.
protected  double[] weightArray
          The array of weights, if applicable.
 
Constructor Summary
SparseWeightVector.WeightIterator(FeatureVector example)
          This constructor selects a slice of weights from the SparseWeightVector representing all those weights corresponding to features in the given vector.
 
Method Summary
 Feature getCurrentFeature()
          Returns the feature corresponding to the current weight.
 double getCurrentFeatureStrength()
          Convenience method for determining the current feature's strength in the given example.
 java.lang.Double getWeight()
          Returns the double precision value pointed to by this iterator.
 boolean hasNext()
          Determines whether a call to next() will redirect this iterator to point to a different weight.
 void next()
          Repositions this iterator to point to the next weight in the iteration.
 void reset()
          Restart the iteration.
 void setWeight(double w)
          Modifies the weight vector.
 void setWeight(double w, double d)
          Modifies the weight vector.
 int totalFeatures()
          Returns the total number of features to iterate through.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vector

protected FeatureVector vector
The feature vector to iterate through.


I

protected java.util.Iterator I
Iterates through the features corresponding to the weights to be iterated over for the current composite child.


currentFeature

protected Feature currentFeature
The feature corresponding to the current weight.


isDiscrete

protected boolean isDiscrete
true iff the current feature is discrete.


weightArray

protected double[] weightArray
The array of weights, if applicable.


arrayIndex

protected int arrayIndex
Pointer into weightArray.

Constructor Detail

SparseWeightVector.WeightIterator

public SparseWeightVector.WeightIterator(FeatureVector example)
This constructor selects a slice of weights from the SparseWeightVector representing all those weights corresponding to features in the given vector.

Parameters:
example - A vector of features extracted from an example object.
Method Detail

totalFeatures

public int totalFeatures()
Returns the total number of features to iterate through.


hasNext

public boolean hasNext()
Determines whether a call to next() will redirect this iterator to point to a different weight.

Returns:
true iff there are more weights in the iteration.

next

public void next()
Repositions this iterator to point to the next weight in the iteration. If there is no next weight, this iterator will continue to point to the same weight as before.


reset

public void reset()
Restart the iteration.


getCurrentFeature

public Feature getCurrentFeature()
Returns the feature corresponding to the current weight.

Returns:
The feature corresponding to the current weight.

getCurrentFeatureStrength

public double getCurrentFeatureStrength()
Convenience method for determining the current feature's strength in the given example. The strength of a discrete feature is always 1, except when that feature is known to be boolean and has a value of false, in which case the strength is 0. The strength of a real feature is just its value.

Returns:
The strength of the current feature in the given example.

getWeight

public java.lang.Double getWeight()
Returns the double precision value pointed to by this iterator.

Returns:
The double precision value pointed to by this iterator, or null if the location in the weight vector pointed to by this iterator is empty.

setWeight

public void setWeight(double w)
Modifies the weight vector. Calling this method with parameter w is equivalent to calling setWeight(w, 0).

Parameters:
w - The new value for the weight pointed to by this iterator.
See Also:
setWeight(double,double)

setWeight

public void setWeight(double w,
                      double d)
Modifies the weight vector.

Parameters:
w - The new value for the weight pointed to by this iterator.
d - The default value for other weights incidentally created by this invocation.