Class BaumWelch

All Implemented Interfaces:
RandomNumberGenerator, Seedable

public class BaumWelch extends DiscreteHMM
This implementation trains an HMM model by observations using the Baum–Welch algorithm.
See Also:
    • L. R. Welch, "Hidden Markov models and the Baum-Welch algorithm," IEEE Information Theory Society Newsletter Volume 53, pp. 1, 10-13, Dec 2003.
    • Wikipedia: Baum-Welch algorithm
  • Constructor Details

    • BaumWelch

      public BaumWelch(int[] observations, DiscreteHMM model0, int nIteraions)
      Constructs an HMM model by training an initial model using the Baum–Welch algorithm.
      Parameters:
      observations - an integer array of observation symbols (length = T). Each symbol is a positive integer less than or equal to M (the number of observation symbols per state).
      model0 - an initial model
      nIteraions - the number of iterations
  • Method Details

    • train

      public static DiscreteHMM train(int[] observations, DiscreteHMM model0)
      Constructs a trained (discrete) hidden Markov model, one iteration.
      Parameters:
      observations - an integer array of observation symbols (length = T). Each symbol is a positive integer less than or equal to M (the number of observation symbols per state).
      model0 - the initial hidden Markov model
      Returns:
      a trained (discrete) hidden Markov model
    • xi

      public static Matrix[] xi(HiddenMarkovModel model, int[] observations, ForwardBackwardProcedure fb)
      Gets the ξ matrices, where for 1 ≤ t ≤ T - 1, the t-th entry of ξ is an (N * N) matrix, for which the (i, j)-th entry is ξt(i, j). ξt(i, j) is the probability of the system being in state si at time t and state sj at time t+1 and the observations, given the model.
      ξt(i, j) = P(qt = si, qt+1 = sj, Ω | λ)
      This implementation works for both unscaled and scaled alpha-beta probabilities in terms of transition probability estimation. The actual value for the unscaled fwd-bwd probabilities computed using scaled alpha-beta differ by a factor of L(x) the likelihood of observations. But this term appears in both the numerator and denominator so they cancel out. See eq. 18 in hmm-scaling-implementation.
      Parameters:
      model - an HMM model
      observations - an array of observations (length = T).
      fb - the alpha-beta
      Returns:
      the ξ matrices, one for each time; the 0-th entry is not used to match the time index
    • gamma

      public static Vector[] gamma(HiddenMarkovModel model, int[] observations, Matrix[] xi)
      Gets the (T-1 * N) γ matrix, where the (t, i)-th entry is γt(i). γ is the probability of the system in state si and the observations, given the model.
      γt(i) = P(qt = si, Ω | λ)
      Parameters:
      model - an HMM model
      observations - an array of observations (length = T).
      xi - the ξ matrices; the 0-th entry is not used to match the time index
      Returns:
      the gamma matrix