HiddenMarkovClassifierLearning Class 
Namespace: Accord.Statistics.Models.Markov.Learning
public class HiddenMarkovClassifierLearning : BaseHiddenMarkovClassifierLearning<HiddenMarkovClassifier, HiddenMarkovModel, GeneralDiscreteDistribution, int>
The HiddenMarkovClassifierLearning type exposes the following members.
Name  Description  

HiddenMarkovClassifierLearning 
Creates a new instance of the learning algorithm for a given
Markov sequence classifier using the specified configuration
function.

Name  Description  

Algorithm  Obsolete.
Obsolete.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
Classifier 
Gets the classifier being trained by this instance.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
Empirical 
Gets or sets a value indicating whether the class priors
should be estimated from the data, as in an empirical Bayes method.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
Learner 
Gets or sets the configuration function specifying which
training algorithm should be used for each of the models
in the hidden Markov model set.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
LogLikelihood 
Gets the loglikelihood at the end of the training.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
ParallelOptions 
Gets or sets the parallelization options for this algorithm.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
Rejection 
Gets or sets a value indicating whether a threshold model
should be created or updated after training to support rejection.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
Smoothing 
Gets or sets the smoothing kernel's sigma
for the threshold model.
 
Token 
Gets or sets a cancellation token that can be used to
stop the learning algorithm while it is running.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.) 
Name  Description  

ComputeError 
Compute model error for a given data set.
 
CreateThresholdTopology 
Creates the state transition topology for the threshold model. This
method can be used to help in the implementation of the Threshold
abstract method which has to be defined for implementers of this class.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
Equals  Determines whether the specified object is equal to the current object. (Inherited from Object.)  
Finalize  Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)  
GetHashCode  Serves as the default hash function. (Inherited from Object.)  
GetType  Gets the Type of the current instance. (Inherited from Object.)  
Learn 
Learns a model that can map the given inputs to the given outputs.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
MemberwiseClone  Creates a shallow copy of the current Object. (Inherited from Object.)  
OnGenerativeClassModelLearningFinished 
Raises the [E:GenerativeClassModelLearningFinished] event.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
OnGenerativeClassModelLearningStarted 
Raises the [E:GenerativeClassModelLearningStarted] event.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
Run(Int32, Int32)  Obsolete.
Trains each model to recognize each of the output labels.
 
RunT(T, Int32)  Obsolete.
Trains each model to recognize each of the output labels.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
Threshold 
Creates a new threshold model
for the current set of Markov models in this sequence classifier.
(Overrides BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservationThreshold.)  
ToString  Returns a string that represents the current object. (Inherited from Object.) 
Name  Description  

ClassModelLearningFinished 
Occurs when the learning of a class model has finished.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.)  
ClassModelLearningStarted 
Occurs when the learning of a class model has started.
(Inherited from BaseHiddenMarkovClassifierLearningTClassifier, TModel, TDistribution, TObservation.) 
Name  Description  

HasMethod 
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)  
IsEqual  Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices. (Defined by Matrix.)  
ToT  Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)  
ToT  Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by Matrix.) 
This class acts as a teacher for classifiers based on discrete hidden Markov models. The learning algorithm uses a generative approach. It works by training each model in the generative classifier separately.
This class implements discrete classifiers only. Discrete classifiers can be used whenever the sequence of observations is discrete or can be represented by discrete symbols, such as class labels, integers, and so on. If you need to classify sequences of other entities, such as real numbers, vectors (i.e. multivariate observations), then you can use genericdensity hidden Markov models. Those models can be modeled after any kind of probability distribution implementing the IDistribution interface.
For a more thorough explanation on hidden Markov models with practical examples on gesture recognition, please see Sequence Classifiers in C#, Part I: Hidden Markov Models [1].
[1]: http://www.codeproject.com/Articles/541428/SequenceClassifiersinCsharpPartIHiddenMarko
The following example shows how to create a hidden Markov model sequence classifier to classify discrete sequences into two disjoint labels: labels for class 0 and labels for class 1. The training data is separated in inputs and outputs. The inputs are the sequences we are trying to learn, and the outputs are the labels associated with each input sequence.
In this example we will be using the BaumWelch algorithm to learn each model in our generative classifier; however, any other unsupervised learning algorithm could be used.
// Declare some testing data int[][] inputs = new int[][] { new int[] { 0,1,1,0 }, // Class 0 new int[] { 0,0,1,0 }, // Class 0 new int[] { 0,1,1,1,0 }, // Class 0 new int[] { 0,1,0 }, // Class 0 new int[] { 1,0,0,1 }, // Class 1 new int[] { 1,1,0,1 }, // Class 1 new int[] { 1,0,0,0,1 }, // Class 1 new int[] { 1,0,1 }, // Class 1 }; int[] outputs = new int[] { 0,0,0,0, // First four sequences are of class 0 1,1,1,1, // Last four sequences are of class 1 }; // We are trying to predict two different classes int classes = 2; // Each sequence may have up to two symbols (0 or 1) int symbols = 2; // Nested models will have two states each int[] states = new int[] { 2, 2 }; // Creates a new Hidden Markov Model Classifier with the given parameters HiddenMarkovClassifier classifier = new HiddenMarkovClassifier(classes, states, symbols); // Create a new learning algorithm to train the sequence classifier var teacher = new HiddenMarkovClassifierLearning(classifier, // Train each model until the loglikelihood changes less than 0.001 modelIndex => new BaumWelchLearning(classifier.Models[modelIndex]) { Tolerance = 0.001, Iterations = 0 } ); // Train the sequence classifier teacher.Learn(inputs, outputs); // Obtain classification labels for the output int[] predicted = classifier.Decide(inputs); // Obtain prediction scores for the outputs double[] lls = classifier.LogLikelihood(inputs);
It is also possible to learn a hidden Markov classifier with support for rejection. When a classifier is configured to use rejection, it will be able to detect when a sample does not belong to any of the classes that it has previously seen.
// Declare some testing data int[][] inputs = new int[][] { new int[] { 0,0,1,2 }, // Class 0 new int[] { 0,1,1,2 }, // Class 0 new int[] { 0,0,0,1,2 }, // Class 0 new int[] { 0,1,2,2,2 }, // Class 0 new int[] { 2,2,1,0 }, // Class 1 new int[] { 2,2,2,1,0 }, // Class 1 new int[] { 2,2,2,1,0 }, // Class 1 new int[] { 2,2,2,2,1 }, // Class 1 }; int[] outputs = new int[] { 0,0,0,0, // First four sequences are of class 0 1,1,1,1, // Last four sequences are of class 1 }; // We are trying to predict two different classes int classes = 2; // Each sequence may have up to 3 symbols (0,1,2) int symbols = 3; // Nested models will have 3 states each int[] states = new int[] { 3, 3 }; // Creates a new Hidden Markov Model Classifier with the given parameters HiddenMarkovClassifier classifier = new HiddenMarkovClassifier(classes, states, symbols); // Create a new learning algorithm to train the sequence classifier var teacher = new HiddenMarkovClassifierLearning(classifier, // Train each model until the loglikelihood changes less than 0.001 modelIndex => new BaumWelchLearning(classifier.Models[modelIndex]) { Tolerance = 0.001, Iterations = 0 } ); // Enable support for sequence rejection teacher.Rejection = true; // Train the sequence classifier teacher.Learn(inputs, outputs); // Obtain prediction classes for the outputs int[] prediction = classifier.Decide(inputs); // Obtain prediction scores for the outputs double[] lls = classifier.LogLikelihood(inputs);