frog
Class GestureHMM

java.lang.Object
  extended by frog.GestureHMM
All Implemented Interfaces:
GestureModel, Serializable

public class GestureHMM
extends Object
implements GestureModel, Serializable

GestureHMM is a modeling class that represents a gesture. As a model, it requires data (gesture instances) as well as parameters for training. GestureHMM utilizes a statistical HMM (as its name suggests) model as well as a Baum-Welch training method.

Author:
Team Better Recognize
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface frog.GestureModel
GESTUREHMM, NUM_TYPES_SUPPORTED
 
Constructor Summary
GestureHMM(String n)
          Constructs a GestureHMM with a name and default training parameters.
GestureHMM(String n, byte[] iconBuf)
          Constructs a GestureHMM with a name and image.
GestureHMM(String n, GestureHMMParameters gParams)
          Constructs a GestureHMM with a name and training parameters.
GestureHMM(String n, GestureHMMParameters gParams, byte[] iconBuf)
          Constructs a GestureHMM with a name, training parameters, and an image.
GestureHMM(String n, GestureHMMParameters gParams, KmeansParameters kParams)
          Constructs a GestureHMM with a name, training parameters, and quantizer parameters (Kmeans in particular).
GestureHMM(String n, GestureHMMParameters gParams, KmeansParameters kParams, byte[] iconBuf)
          Constructs a GestureHMM with a name, training parameters, a gesture set, and an image.
GestureHMM(String n, GestureHMMParameters gParams, KmeansParameters kParams, Vector<Vector<Accel3D>> instances)
          Constructs a GestureHMM with a name, training parameters, quantizer parameters (Kmeans in particular), and a training set.
GestureHMM(String n, GestureHMMParameters gParams, KmeansParameters kParams, Vector<Vector<Accel3D>> instances, byte[] iconBuf)
          Constructs a GestureHMM with a name, training parameters, a gesture set, and an image.
GestureHMM(String n, GestureHMMParameters gParams, Vector<Vector<Accel3D>> instances)
          Constructs a GestureHMM with a name, training parameters, as well as a gesture set.
GestureHMM(String n, GestureHMMParameters gParams, Vector<Vector<Accel3D>> instances, byte[] iconBuf)
          Constructs a GestureHMM with a name, training parameters, a gesture set, and an image.
GestureHMM(String n, Vector<Vector<Accel3D>> instances)
          Constructs a GestureHMM with a name and gesture set as well as default training parameters.
 
Method Summary
 boolean addAccel(int inum, Accel3D acc)
          Adds an additional Accel3D to the end of a gesture instance.
 void addInstance(Vector<Accel3D> instance)
          Adds an entire gesture instance to the gesture set.
 void clearStats()
          Clears all saved statistics associated with this GestureModel
 void correct()
          Signifies a correct recognition event to the GestureModel.
 double getAverageRecognitionProbability()
          Returns the average certainty currently associated with this GestureModel.
 double getDefaultProbability()
          For GestureHMM, default probability is obtained by averaging the probabilities with which each instance in the set used to create this model match the model.
 BufferedImage getIcon()
          Returns the icon of this gesture as a BufferedImage.
 String getName()
          Returns the name associated with this GestureModel.
 int getNumCorrect()
          Accessor for the number correct statistic.
 int getNumIncorrect()
          Accessor for the number incorrect statistic.
 int getNumNotRecognized()
          Accessor for the number not recognized statistic.
 int getNumStates()
          Returns the number of hidden states in this GestureHMM.
 double getProbability(Vector<Accel3D> instance)
          For GestureHMM, probability is computed using the forward algorithm.
 Vector<Vector<Accel3D>> getTrainingSet()
          Accessor for the training set of gesture instances associated with this GestureModel
 double getTrainingThreshold()
          Returns the training threshold of this GestureHMM.
 int getType()
          Accessor for the GestureModel type index.
 void incorrect()
          Signifies an incorrect recognition event to the GestureModel.
 void matchedWithProbability(double prob)
          Signifies a recognition event that occurred with a given probability.
 void notRecognized()
          Signifies an unrecognized recognition event to the GestureModel.
 boolean removeAccel(int inum, int anum)
          Removes an acceleration value from the gesture set.
 boolean removeInstance(int inum)
          Removes a gesture instance from the gesture set.
 void setIcon(byte[] imageBuffer)
          Associates a byte array image with the GestureModel
 void setName(String n)
          Associates a representative name with this GestureModel
 boolean train()
          Trains the GestureModel, constructing everything necessary for recognition to take place.
 boolean train(GestureHMMParameters gParams)
          Trains the GestureHMM with a specified set of training parameters.
 boolean train(GestureHMMParameters gParams, KmeansParameters kParams)
          Trains the GestureHMM with a specified set of training parameters as well as a specified set of quantizer parameters.
 boolean train(KmeansParameters params)
          Trains the GestureHMM with a specified set of quantizer parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GestureHMM

public GestureHMM(String n)
Constructs a GestureHMM with a name and default training parameters.

Parameters:
n - a name to associate with the GestureHMM

GestureHMM

public GestureHMM(String n,
                  Vector<Vector<Accel3D>> instances)
Constructs a GestureHMM with a name and gesture set as well as default training parameters.

Parameters:
n - a name to associate with the GestureHMM
instances - the gesture set for training the GestureHMM

GestureHMM

public GestureHMM(String n,
                  GestureHMMParameters gParams)
Constructs a GestureHMM with a name and training parameters.

Parameters:
n - a name to associate with the GestureHMM
gParams - HMM parameters for training

GestureHMM

public GestureHMM(String n,
                  GestureHMMParameters gParams,
                  Vector<Vector<Accel3D>> instances)
Constructs a GestureHMM with a name, training parameters, as well as a gesture set.

Parameters:
n - a name to associate with the GestureHMM
gParams - HMM parameters for training
instances - the gesture set for training the GestureHMM

GestureHMM

public GestureHMM(String n,
                  GestureHMMParameters gParams,
                  KmeansParameters kParams)
Constructs a GestureHMM with a name, training parameters, and quantizer parameters (Kmeans in particular).

Parameters:
n - a name to associate with the GestureHMM
gParams - HMM parameters for training
kParams - Kmeans parameters for training the quantizer

GestureHMM

public GestureHMM(String n,
                  GestureHMMParameters gParams,
                  KmeansParameters kParams,
                  Vector<Vector<Accel3D>> instances)
Constructs a GestureHMM with a name, training parameters, quantizer parameters (Kmeans in particular), and a training set.

Parameters:
n - a name to associate with the GestureHMM
gParams - HMM parameters for training
kParams - Kmeans parameters for training the quantizer
instances - the gesture set for training the GestureHMM

GestureHMM

public GestureHMM(String n,
                  byte[] iconBuf)
           throws IOException
Constructs a GestureHMM with a name and image.

Parameters:
n - a name to associate with the GestureHMM
iconBuf - the byte array image to associate with the GestureHMM
Throws:
IOException - thrown if image reading fails

GestureHMM

public GestureHMM(String n,
                  GestureHMMParameters gParams,
                  byte[] iconBuf)
           throws IOException
Constructs a GestureHMM with a name, training parameters, and an image.

Parameters:
n - a name to associate with the GestureHMM
gParams - HMM parameters for training
iconBuf - the byte array image to associate with the GestureHMM
Throws:
IOException - thrown if image reading fails

GestureHMM

public GestureHMM(String n,
                  GestureHMMParameters gParams,
                  Vector<Vector<Accel3D>> instances,
                  byte[] iconBuf)
           throws IOException
Constructs a GestureHMM with a name, training parameters, a gesture set, and an image.

Parameters:
n - a name to associate with the GestureHMM
gParams - HMM parameters for training
instances - the gesture set for training the GestureHMM
iconBuf - the byte array image to associate with the GestureHMM
Throws:
IOException - thrown if image reading fails

GestureHMM

public GestureHMM(String n,
                  GestureHMMParameters gParams,
                  KmeansParameters kParams,
                  byte[] iconBuf)
           throws IOException
Constructs a GestureHMM with a name, training parameters, a gesture set, and an image.

Parameters:
n - a name to associate with the GestureHMM
gParams - HMM parameters for training
kParams - Kmeans parameters for training the quantizer
iconBuf - the byte array image to associate with the GestureHMM
Throws:
IOException - thrown if image reading fails

GestureHMM

public GestureHMM(String n,
                  GestureHMMParameters gParams,
                  KmeansParameters kParams,
                  Vector<Vector<Accel3D>> instances,
                  byte[] iconBuf)
           throws IOException
Constructs a GestureHMM with a name, training parameters, a gesture set, and an image.

Parameters:
n - a name to associate with the GestureHMM
gParams - HMM parameters for training
kParams - Kmeans parameters for training the quantizer
instances - the gesture set for training the GestureHMM
iconBuf - the byte array image to associate with the GestureHMM
Throws:
IOException - thrown if image reading fails
Method Detail

addAccel

public boolean addAccel(int inum,
                        Accel3D acc)
Description copied from interface: GestureModel
Adds an additional Accel3D to the end of a gesture instance.

Specified by:
addAccel in interface GestureModel
Parameters:
inum - The index of the gesture instance to modify
acc - The Accel3D to insert
Returns:
a boolean signifying success or failure of the insertion

addInstance

public void addInstance(Vector<Accel3D> instance)
Description copied from interface: GestureModel
Adds an entire gesture instance to the gesture set.

Specified by:
addInstance in interface GestureModel
Parameters:
instance - The instance to insert

clearStats

public void clearStats()
Description copied from interface: GestureModel
Clears all saved statistics associated with this GestureModel

Specified by:
clearStats in interface GestureModel

correct

public void correct()
Description copied from interface: GestureModel
Signifies a correct recognition event to the GestureModel. Statistics for the model are updated accordingly.

Specified by:
correct in interface GestureModel

getDefaultProbability

public double getDefaultProbability()
For GestureHMM, default probability is obtained by averaging the probabilities with which each instance in the set used to create this model match the model. In other words, it average the value of getProbability obtained with each gesture instance in the training set.

Specified by:
getDefaultProbability in interface GestureModel
Returns:
the default probability of this model.

getIcon

public BufferedImage getIcon()
Description copied from interface: GestureModel
Returns the icon of this gesture as a BufferedImage.

Specified by:
getIcon in interface GestureModel
Returns:
the icon of this gesture; or null if the gesture has no icon.

getName

public String getName()
Description copied from interface: GestureModel
Returns the name associated with this GestureModel. (e.g. a model for a circle might appropriately be named "Circle")

Specified by:
getName in interface GestureModel
Returns:
the name of the GestureModel.

getNumCorrect

public int getNumCorrect()
Description copied from interface: GestureModel
Accessor for the number correct statistic. This value is entirely dependent on calls to GestureModel.correct()

Specified by:
getNumCorrect in interface GestureModel
Returns:
the saved number of correct recognition events.

getNumIncorrect

public int getNumIncorrect()
Description copied from interface: GestureModel
Accessor for the number incorrect statistic. This value is entirely dependent on calls to GestureModel.incorrect()

Specified by:
getNumIncorrect in interface GestureModel
Returns:
the saved number of incorrect recognition events.

getNumNotRecognized

public int getNumNotRecognized()
Description copied from interface: GestureModel
Accessor for the number not recognized statistic. This value is entirely dependent on calls to GestureModel.notRecognized()

Specified by:
getNumNotRecognized in interface GestureModel
Returns:
the saved number of unrecognized recognition events.

getNumStates

public int getNumStates()
Returns the number of hidden states in this GestureHMM.

Returns:
the number of hidden states in this GestureHMM.

getProbability

public double getProbability(Vector<Accel3D> instance)
For GestureHMM, probability is computed using the forward algorithm.

Specified by:
getProbability in interface GestureModel
Parameters:
instance - the series of acceleration vectors representing a single gesture instance
Returns:
the probability that the instance matches this model

getTrainingSet

public Vector<Vector<Accel3D>> getTrainingSet()
Description copied from interface: GestureModel
Accessor for the training set of gesture instances associated with this GestureModel

Specified by:
getTrainingSet in interface GestureModel
Returns:
the model's gesture set

getTrainingThreshold

public double getTrainingThreshold()
Returns the training threshold of this GestureHMM.

Returns:
the training threshold of this GestureHMM.

incorrect

public void incorrect()
Description copied from interface: GestureModel
Signifies an incorrect recognition event to the GestureModel. Statistics for the model are updated accordingly.

Specified by:
incorrect in interface GestureModel

notRecognized

public void notRecognized()
Description copied from interface: GestureModel
Signifies an unrecognized recognition event to the GestureModel. Statistics for the model are updated accordingly.

Specified by:
notRecognized in interface GestureModel

removeAccel

public boolean removeAccel(int inum,
                           int anum)
Description copied from interface: GestureModel
Removes an acceleration value from the gesture set.

Specified by:
removeAccel in interface GestureModel
Parameters:
inum - the index of the instance to access
anum - the index of the acceleration to remove
Returns:
a boolean signifying success or failure of the deletion

removeInstance

public boolean removeInstance(int inum)
Description copied from interface: GestureModel
Removes a gesture instance from the gesture set.

Specified by:
removeInstance in interface GestureModel
Parameters:
inum - the index of the instance to remove
Returns:
a boolean signifying success or failure of the deletion

setName

public void setName(String n)
Description copied from interface: GestureModel
Associates a representative name with this GestureModel

Specified by:
setName in interface GestureModel
Parameters:
n - the name to associate

train

public boolean train()
Description copied from interface: GestureModel
Trains the GestureModel, constructing everything necessary for recognition to take place.

Specified by:
train in interface GestureModel

train

public boolean train(GestureHMMParameters gParams)
Trains the GestureHMM with a specified set of training parameters. The training parameters associated with the GestureHMM are set to the new values in gParams.

Parameters:
gParams - the training parameters
Returns:
a boolean indicating whether training took place or not. Training will not occur if the gesture set is empty.

train

public boolean train(GestureHMMParameters gParams,
                     KmeansParameters kParams)
Trains the GestureHMM with a specified set of training parameters as well as a specified set of quantizer parameters. The Quantizer for the GestureHMM is set accordingly and the training parameters associated with the GestureHMM are set to the new values in gParams.

Parameters:
gParams - the training parameters
kParams - the Kmeans parameters
Returns:
a boolean indicating whether training took place or not. Training will not occur if the gesture set is empty.

train

public boolean train(KmeansParameters params)
Trains the GestureHMM with a specified set of quantizer parameters. The Quantizer for the GestureHMM is set accordingly.

Parameters:
params - The K-means parameters.
Returns:
A boolean indicating whether training took place or not. Training will not occur if the gesture set is empty.

setIcon

public void setIcon(byte[] imageBuffer)
             throws IOException
Description copied from interface: GestureModel
Associates a byte array image with the GestureModel

Specified by:
setIcon in interface GestureModel
Parameters:
imageBuffer - the byte array image
Throws:
IOException - thrown if image reading fails

getAverageRecognitionProbability

public double getAverageRecognitionProbability()
Description copied from interface: GestureModel
Returns the average certainty currently associated with this GestureModel. The average certainty is calculated based on all calls made to GestureModel.matchedWithProbability(double).

Specified by:
getAverageRecognitionProbability in interface GestureModel
Returns:
the average recognition probability (certainty)

matchedWithProbability

public void matchedWithProbability(double prob)
Description copied from interface: GestureModel
Signifies a recognition event that occurred with a given probability. This updates the average recognition probability of the GestureModel, as accessed by GestureModel.getAverageRecognitionProbability()

Specified by:
matchedWithProbability in interface GestureModel
Parameters:
prob - the probability (0-1) with which the match occurred

getType

public int getType()
Description copied from interface: GestureModel
Accessor for the GestureModel type index. Should return the value as specified in the GestureModel interface.

Specified by:
getType in interface GestureModel
Returns:
the GestureModel type index.