# HMM Adaptation for Improving a Human Activity Recognition System
## 3 HAR System Overview
The joint probability that \(O\) is generated by the model \(M\) moving through the state sequence \(X\) is calculated simply as the product of the transition probabilities and the output probabilities:  
\[P(O,X/M)=a_{12}b_{2}(O_{1})a_{23}b_{3}(O_{2})a_{33}b_{3}(O_{3})... \tag{1}\]  
In a real application, only the observation sequence \(\mathrm{O}\) is known and the underlying state sequence \(X\) is hidden. In this case, the required likelihood is computed by considering only the most likely state sequence. The main parameters of every model are \(a_{ij}\) and \(b_{j}(O_{t})\). The output distribution \(b_{j}(O_{t})\) can be modeled by using Gaussian mixtures, reducing the model parameters to the mean and variance of every Gaussian distribution. The model parameters can be determined automatically through a robust and efficient re-estimation procedure (estimation maximization, EM) considering a set of training examples corresponding to a particular activity:  
1. Initialize all Gaussian distributions with the mean and variance computed throughout the whole dataset. 2. Calculate the forward and backward probabilities for all states \(j\) and times \(t\). 3. For each state \(j\) and time \(t\), use the probability \(\mathit{Lj}(t)\) and the current observation vector \(O_{t}\) to update the accumulators for that state. 4. Use the final accumulator values to calculate new parameter values. 5. If the value of \(P=P(O/M)\) for this iteration is not higher than the value at the previous iteration, then stop; otherwise, repeat the aforementioned steps using the new re-estimated parameter values (from step 2). In the estimation maximization (EM) algorithm, the main target is to maximize the likelihood of an activity respect to its HMM: Maximum Likelihood Estimation (MLE). In some applications, it  
Figure 2: Example of a Hidden Markov Model. is possible to consider a discriminative training procedure. In this procedure, the main target is to maximize the differences between models. The HTK toolkit includes a tool for training HMMs in a discriminative way. In this work, the Maximum Mutual Information Estimation (MMIE) discriminative procedure has also been evaluated [32]. In this procedure, the main difference compared to MLE is the objective function to be optimized. In the case of the MMIE, the function to maximize is:  
\[F_{MMIE}=\sum_{i=activities}\log\frac{P(O_{i},X_{i}/M_{i})}{\sum\limits_{n= activities\,sequences}P(O_{i},X_{n}/M_{i})} \tag{2}\]  
The first term in the numerator is identical to the objective function for the MLE. In order to maximize Equation (2), the numerator must be increased while the denominator is decreased. Similar to the MLE, the MMIE has the target to maximize the likelihood of each observation given by the training sequences. In addition, the MMIE has a denominator term that can be reduced by decreasing the probabilities of other possible activity sequences. In conclusion, the MMIE attempts make the correct hypothesis more probable, and at the same time, it tries to make incorrect hypotheses less probable. Continuous activity recognition and segmentation involves connecting several HMMs in sequence. In the HTK toolkit, the Viterbi algorithm is expanded to allow several models to be connected in the search space: the last state of every model is connected with the first state of all models (Figure 3). Each model in the sequence corresponds directly to its activity.