UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.gesture
Class Classifier

java.lang.Object
  |
  +--edu.berkeley.guir.lib.gesture.Classifier
Direct Known Subclasses:
RubineClassifier

public class Classifier
extends Object

Gesture classifier/recogizer, using Dean Rubine's algorithm, with guidance from Rob Miller's C++ port, which is part of the Amulet package. Note: for performance reasons, the Classifier does not retrain automatically when the underlying GestureSet changes. It will retrain automatically the next time it needs to (e.g., for classify()). Known bugs: training may take some time, but train() does not check to see if its thread gets interrupted.


Inner Class Summary
 class Classifier.FeatureDirection
           
protected  class Classifier.MyCollectionListener
           
protected  class Classifier.MyPropChangeListener
           
 class Classifier.Result
          Used to return the results of a classification.
 
Field Summary
protected  double[][] ccm
           
protected  double[][] ccmInv
           
protected  GestureCategory dotCategory
           
protected  List enabledCategories
           
protected static double EPSILON
           
protected  Class[] featureClasses
           
protected  BitSet featuresUsed
           
protected  GestureSet gestureSet
           
protected  double[][] meanFeatureValues
           
static String MISRECOGNIZED_PROP
          Set on gestures that are misrecognized, with a Result value
protected  CollectionListener myCollectionListener
           
protected  PropertyChangeListener myPropChangeListener
           
protected  PropertyChangeSupport propChangeSupport
           
protected  boolean trained
           
static String TRAINED_PROP
          a Boolean property indicating whether the classifier is trained or not
protected  double[][] weights
           
 
Constructor Summary
Classifier()
           
Classifier(GestureSet gs)
          Does not automatically train.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
           
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
           
 double categoryDistance(GestureCategory categoryA, GestureCategory categoryB)
          Return the square of the distance between the two categories (which must in the GestureSet).
 double categoryDistance(int categoryA, int categoryB)
          Return the square of the distance between the two categories.
protected  void checkForInterrupt()
           
 Classifier.Result classify(Gesture gesture)
          Determine which GestureCategory the Gesture is most likely a member of, and return an appropriate Result.
 Classifier.Result classifyWithoutTraining(Gesture gesture)
          Only call this if you know the GestureSet the classifier is using hasn't changed since the last time classify() or train() was called.
protected  double[][] computeCovarianceMatrix(GestureCategory gestureCategory, double[] meanFeatureVector)
          Compute and return covariance matrix and fill in the mean feature value array (if provided) (Note: only upper triangular part computed)
 double distanceToCategory(Gesture gesture, GestureCategory category)
           
 double distanceToCategory(Gesture gesture, int catIndex)
           
 void dump(PrintStream out)
           
 void dumpMFV(PrintStream out)
          Return a matrix where A[Ci][Cj] is a Vector of category Ci examples (i.e.
 void dumpRelativeVariance(PrintStream out)
           
 int findPrincipleComponent(double[] featureVals)
          Return the index of the largest component of featureVals, using the current training weights.
 Classifier.FeatureDirection findPrincipleFeature(int catA, int catB)
          Find the feature class on which catA and catB differ most (based on current weights).
protected  boolean fixClassifier(double[][] ccm, double[][] ccmInv)
           
static Class[] getDefaultFeatureClasses()
           
 double[] getDistancesByFeature(int catA, int catB)
          Use the current weights to get normalized distances along each feature between two categories.
protected  Feature getFeature(GestureCategory gc, int gIndex, Class featureClass)
           
protected  Feature getFeature(GestureCategory gc, int gIndex, int fIndex)
           
 Class[] getFeatureClasses()
           
 BitSet getFeaturesUsed()
          Features actually used in current classification (null if untrained)
 GestureSet getGestureSet()
           
 double[] getNormalizedDistancesByFeature(Gesture gesture, GestureCategory gc)
          Use the weights for the category to get normalized distance of the gesture from the category.
 double[] getNormalizedDistancesByFeature(Gesture gesture, int categoryIndex)
          Use the weights for the category to get normalized distance of the gesture from the category.
 double[] getNormalizedDistancesByFeature(Gesture gesture, String categoryName)
          Use the weights for the category to get normalized distance of the gesture from the category.
 List getTrainingCategories()
          Returns an unmodifiable List of the categories that were used to train the classifier.
 double[][] getWeights()
           
 boolean isTrained()
           
 double MahalanobisDistance(double[] v, double[] u)
          Return the square of the distance between the two vectors.
static double MahalanobisDistance(double[] v, double[] u, double[][] sigma)
          Return the square of the distance between the two vectors, using the specified dispersion matrix.
 void removePropertyChangeListener(PropertyChangeListener listener)
           
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
           
 void setFeatureClasses(Class[] featureClasses)
           
 void setGestureSet(GestureSet gs)
          Does not automatically train.
protected  void setTrained(boolean isTrained)
           
 boolean testRecognition(Gesture gesture)
          return true iff the gesture was correctly recognized
 List testRecognition(GestureContainer container)
           
 List testRecognition(Iterator iter)
          iter should contain Gestures or GestureContainers.
 List testRecognition(Iterator iter, boolean onlyEnabled)
          iter should contain Gestures or GestureContainers.
 void train()
          (Re)trains the current Classifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRAINED_PROP

public static final String TRAINED_PROP
a Boolean property indicating whether the classifier is trained or not

MISRECOGNIZED_PROP

public static final String MISRECOGNIZED_PROP
Set on gestures that are misrecognized, with a Result value

featureClasses

protected Class[] featureClasses

EPSILON

protected static final double EPSILON

gestureSet

protected GestureSet gestureSet

weights

protected double[][] weights

meanFeatureValues

protected double[][] meanFeatureValues

ccm

protected double[][] ccm

ccmInv

protected double[][] ccmInv

dotCategory

protected GestureCategory dotCategory

trained

protected boolean trained

featuresUsed

protected BitSet featuresUsed

enabledCategories

protected List enabledCategories

myCollectionListener

protected CollectionListener myCollectionListener

myPropChangeListener

protected PropertyChangeListener myPropChangeListener

propChangeSupport

protected transient PropertyChangeSupport propChangeSupport
Constructor Detail

Classifier

public Classifier()

Classifier

public Classifier(GestureSet gs)
Does not automatically train.
Method Detail

setFeatureClasses

public void setFeatureClasses(Class[] featureClasses)

getFeatureClasses

public Class[] getFeatureClasses()

getDefaultFeatureClasses

public static Class[] getDefaultFeatureClasses()

getWeights

public double[][] getWeights()

setGestureSet

public void setGestureSet(GestureSet gs)
Does not automatically train.

getGestureSet

public GestureSet getGestureSet()

getFeaturesUsed

public BitSet getFeaturesUsed()
Features actually used in current classification (null if untrained)

getFeature

protected Feature getFeature(GestureCategory gc,
                             int gIndex,
                             int fIndex)

getFeature

protected Feature getFeature(GestureCategory gc,
                             int gIndex,
                             Class featureClass)

computeCovarianceMatrix

protected double[][] computeCovarianceMatrix(GestureCategory gestureCategory,
                                             double[] meanFeatureVector)
Compute and return covariance matrix and fill in the mean feature value array (if provided) (Note: only upper triangular part computed)

setTrained

protected void setTrained(boolean isTrained)

isTrained

public boolean isTrained()

checkForInterrupt

protected void checkForInterrupt()
                          throws InterruptedException

train

public void train()
           throws TrainingException,
                  InterruptedException
(Re)trains the current Classifier.

fixClassifier

protected boolean fixClassifier(double[][] ccm,
                                double[][] ccmInv)

classify

public Classifier.Result classify(Gesture gesture)
                           throws TrainingException,
                                  InterruptedException
Determine which GestureCategory the Gesture is most likely a member of, and return an appropriate Result. Resturns null if no GestureSet has been assigned, or if the GestureSet has no members.

classifyWithoutTraining

public Classifier.Result classifyWithoutTraining(Gesture gesture)
Only call this if you know the GestureSet the classifier is using hasn't changed since the last time classify() or train() was called. See classify() for return value information.

testRecognition

public List testRecognition(GestureContainer container)
                     throws InterruptedException,
                            TrainingException

testRecognition

public List testRecognition(Iterator iter)
                     throws InterruptedException,
                            TrainingException
iter should contain Gestures or GestureContainers. returns the misrecognized Gestures. If all are correctly recognized, returns an empty List.

testRecognition

public List testRecognition(Iterator iter,
                            boolean onlyEnabled)
                     throws InterruptedException,
                            TrainingException
iter should contain Gestures or GestureContainers. returns the misrecognized Gestures. If all are correctly recognized, returns an empty List. If onlyEnabled is true, skip GestureObjects that aren't enabled.

testRecognition

public boolean testRecognition(Gesture gesture)
                        throws InterruptedException,
                               TrainingException
return true iff the gesture was correctly recognized

categoryDistance

public double categoryDistance(GestureCategory categoryA,
                               GestureCategory categoryB)
Return the square of the distance between the two categories (which must in the GestureSet). If the classifier is not trained, it throws an IllegalStateException.

categoryDistance

public double categoryDistance(int categoryA,
                               int categoryB)
Return the square of the distance between the two categories. If the classifier is not trained, it throws an IllegalStateException.

distanceToCategory

public double distanceToCategory(Gesture gesture,
                                 GestureCategory category)

distanceToCategory

public double distanceToCategory(Gesture gesture,
                                 int catIndex)

getNormalizedDistancesByFeature

public double[] getNormalizedDistancesByFeature(Gesture gesture,
                                                String categoryName)
Use the weights for the category to get normalized distance of the gesture from the category. This distance is not comparable with the mahalanobis distance (I don't think).

getNormalizedDistancesByFeature

public double[] getNormalizedDistancesByFeature(Gesture gesture,
                                                GestureCategory gc)
Use the weights for the category to get normalized distance of the gesture from the category. This distance is not comparable with the mahalanobis distance (I don't think).

getNormalizedDistancesByFeature

public double[] getNormalizedDistancesByFeature(Gesture gesture,
                                                int categoryIndex)
Use the weights for the category to get normalized distance of the gesture from the category. This distance is not comparable with the mahalanobis distance (I don't think). categoryIndex is the index into the enabled classes that the classifier has.

getDistancesByFeature

public double[] getDistancesByFeature(int catA,
                                      int catB)
Use the current weights to get normalized distances along each feature between two categories. This distance is not comparable with the mahalanobis distance (I don't think). catA and catB are indices into the enabled classes that the classifier has.

getTrainingCategories

public List getTrainingCategories()
Returns an unmodifiable List of the categories that were used to train the classifier.

MahalanobisDistance

public double MahalanobisDistance(double[] v,
                                  double[] u)
Return the square of the distance between the two vectors.

MahalanobisDistance

public static double MahalanobisDistance(double[] v,
                                         double[] u,
                                         double[][] sigma)
Return the square of the distance between the two vectors, using the specified dispersion matrix.

findPrincipleComponent

public int findPrincipleComponent(double[] featureVals)
Return the index of the largest component of featureVals, using the current training weights. (If all features were weighted equally, we'd be in normal Euclidean space and this would simply be the largest feature value.)

findPrincipleFeature

public Classifier.FeatureDirection findPrincipleFeature(int catA,
                                                        int catB)
Find the feature class on which catA and catB differ most (based on current weights). catA and catB are the indices of categories in the current enabled categories list.

dumpMFV

public void dumpMFV(PrintStream out)
Return a matrix where A[Ci][Cj] is a Vector of category Ci examples (i.e. Gestures) that are classified as Cj.

dump

public void dump(PrintStream out)

dumpRelativeVariance

public void dumpRelativeVariance(PrintStream out)

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)

Copyright Information