7.3. Learning

7.3.1. K-Means

This example finds a HMM that fits the sequences sequences (this argument is a List of List of observations). This HMM has 3 states and uses the distributions build by {\tt OpdfIntegerFactory(4)}.

KMeansLearner<ObservationInteger> kml =
     new KMeansLearner<ObservationInteger>(3,
          new OpdfIntegerFactory(4), sequences);
Hmm<ObservationInteger> initHmm = kml.iterate();

The iterate() function can be called several times to get better and better HMM models. The learn() method applies iterate() until a fix point is reached.

7.3.2. Baum-Welch

This example is similar to the one given in Section 7.3.1:

OpdfIntegerFactory factory = new OpdfIntegerFactory(4);
BaumWelchLearner<ObservationInteger> bwl =
     new BaumWelchLearner<ObservationInteger>(3, factory);
Hmm<ObservationInteger> learntHmm = bwl.learn(initHmm, sequences);

The learn(hmm) method iterates the algorithm a certain number of times. Its first argument is an estimation of the resulting HMM (it could be found using an iteration of the k-Means algorithm, see how initHmm has been computed in Section 7.3.1).