Package dev.nm.stat.hmm.discrete
Class BaumWelch
java.lang.Object
dev.nm.stat.markovchain.SimpleMC
dev.nm.stat.hmm.HMMRNG
dev.nm.stat.hmm.HiddenMarkovModel
dev.nm.stat.hmm.discrete.DiscreteHMM
dev.nm.stat.hmm.discrete.BaumWelch
- All Implemented Interfaces:
RandomNumberGenerator
,Seedable
This implementation trains an HMM model by observations using the Baum–Welch
algorithm.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBaumWelch
(int[] observations, DiscreteHMM model0, int nIteraions) Constructs an HMM model by training an initial model using the Baum–Welch algorithm. -
Method Summary
Modifier and TypeMethodDescriptionstatic Vector[]
gamma
(HiddenMarkovModel model, int[] observations, Matrix[] xi) Gets the (T-1 * N) γ matrix, where the (t, i)-th entry is γt(i).static DiscreteHMM
train
(int[] observations, DiscreteHMM model0) Constructs a trained (discrete) hidden Markov model, one iteration.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).Methods inherited from class dev.nm.stat.hmm.discrete.DiscreteHMM
B, density, nSymbols
Methods inherited from class dev.nm.stat.hmm.HiddenMarkovModel
logProbability, logProbability, logProbability
Methods inherited from class dev.nm.stat.hmm.HMMRNG
next, nextDouble, seed
-
Constructor Details
-
BaumWelch
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 modelnIteraions
- the number of iterations
-
-
Method Details
-
train
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
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 modelobservations
- 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
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 modelobservations
- 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
-