Chapter 7. Examples

Table of Contents

7.1. Building a HMM
7.2. Multivariate gaussian distributions
7.3. Learning
7.3.1. K-Means
7.3.2. Baum-Welch
7.4. Data file reading

7.1. Building a HMM

This code:

Hmm<ObservationInteger> hmm =
     new Hmm<ObservationInteger>(5, OpdfIntegerFactory(10));

...creates a HMM with 5 states and observation distributions that handles integers ranging from 0 to 9 (included). The state transition functions and initial probabilities are uniformly distributed. The distribution associated with each state is given by the result of the factor() method applied to the factory object (in this case, it returns a uniform distribution between 0 and 9).

This program fragment:

Hmm<ObservationInteger> hmm =
     new Hmm<ObservationInteger>(2, new OpdfIntegerFactory(2));

...creates a HMM with 2 states and default parameters.

It could be followed by a piece of code setting those parameters to known values:

hmm.setPi(0, 0.95);
hmm.setPi(1, 0.05);

hmm.setOpdf(0, new OpdfInteger(new double[] {0.95, 0.05}));
hmm.setOpdf(1, new OpdfInteger(new double[] {0.2, 0.8}));

hmm.setAij(0, 1, 0.05);
hmm.setAij(0, 0, 0.95);
hmm.setAij(1, 0, 0.1);
hmm.setAij(1, 1, 0.9);

...in order to get a valid HMM.