Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

edu.berkeley.guir.quill.gesturelib
Class Classifier  view Classifier download Classifier.java

java.lang.Object
  extended byedu.berkeley.guir.quill.gesturelib.Classifier

public class Classifier
extends java.lang.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.

This software is distributed under the Berkeley Software License.


Nested 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
           
private static java.lang.Class[] DEFAULT_FEATURE_CLASSES
           
protected  GestureCategory dotCategory
           
protected  java.util.List enabledCategories
           
protected static double EPSILON
           
protected  java.lang.Class[] featureClasses
           
protected  java.util.BitSet featuresUsed
           
protected  GestureSet gestureSet
           
protected  double[][] meanFeatureValues
           
static java.lang.String MISRECOGNIZED_PROP
          Set on gestures that are misrecognized, with a Result value
protected  edu.berkeley.guir.quill.util.CollectionListener myCollectionListener
           
protected  java.beans.PropertyChangeListener myPropChangeListener
           
protected  java.beans.PropertyChangeSupport propChangeSupport
           
protected  boolean trained
           
static java.lang.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(java.beans.PropertyChangeListener listener)
           
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.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(java.io.PrintStream out)
           
 void dumpMFV(java.io.PrintStream out)
          Return a matrix where A[Ci][Cj] is a Vector of category Ci examples (i.e.
 void dumpRelativeVariance(java.io.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 java.lang.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, java.lang.Class featureClass)
           
protected  Feature getFeature(GestureCategory gc, int gIndex, int fIndex)
           
 java.lang.Class[] getFeatureClasses()
           
 java.util.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, java.lang.String categoryName)
          Use the weights for the category to get normalized distance of the gesture from the category.
 java.util.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(java.beans.PropertyChangeListener listener)
           
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
           
 void setFeatureClasses(java.lang.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
 java.util.List testRecognition(GestureContainer container)
           
 java.util.List testRecognition(java.util.Iterator iter)
          iter should contain Gestures or GestureContainers.
 java.util.List testRecognition(java.util.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 java.lang.String TRAINED_PROP
a Boolean property indicating whether the classifier is trained or not

See Also:
Constant Field Values

MISRECOGNIZED_PROP

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

See Also:
Constant Field Values

DEFAULT_FEATURE_CLASSES

private static final java.lang.Class[] DEFAULT_FEATURE_CLASSES

featureClasses

protected java.lang.Class[] featureClasses

EPSILON

protected static final double EPSILON
See Also:
Constant Field Values

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 java.util.BitSet featuresUsed

enabledCategories

protected java.util.List enabledCategories

myCollectionListener

protected edu.berkeley.guir.quill.util.CollectionListener myCollectionListener

myPropChangeListener

protected java.beans.PropertyChangeListener myPropChangeListener

propChangeSupport

protected transient java.beans.PropertyChangeSupport propChangeSupport
Constructor Detail

Classifier

public Classifier()

Classifier

public Classifier(GestureSet gs)
Does not automatically train.

Method Detail

setFeatureClasses

public void setFeatureClasses(java.lang.Class[] featureClasses)

getFeatureClasses

public java.lang.Class[] getFeatureClasses()

getDefaultFeatureClasses

public static java.lang.Class[] getDefaultFeatureClasses()

getWeights

public double[][] getWeights()

setGestureSet

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


getGestureSet

public GestureSet getGestureSet()

getFeaturesUsed

public java.util.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,
                             java.lang.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 java.lang.InterruptedException

train

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


fixClassifier

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

classify

public Classifier.Result classify(Gesture gesture)
                           throws TrainingException,
                                  java.lang.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 java.util.List testRecognition(GestureContainer container)
                               throws java.lang.InterruptedException,
                                      TrainingException

testRecognition

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


testRecognition

public java.util.List testRecognition(java.util.Iterator iter,
                                      boolean onlyEnabled)
                               throws java.lang.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 java.lang.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,
                                                java.lang.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 java.util.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(java.io.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(java.io.PrintStream out)

dumpRelativeVariance

public void dumpRelativeVariance(java.io.PrintStream out)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)