# A Simplified Matrix Formulation for Sensitivity Analysis of Hidden Markov Models
## 3 Sensitivity Analysis of Filtering Probability
### Filtering Sensitivity Function Example  
The proposed algorithm is illustrated by the following example. The example is also used to illustrate the computations in the Coefficient-Matrix-Fill procedure in [26]. The computed coefficients using the proposed algorithm are the same as those computed using the Coefficient-Matrix-Fill procedure. However, the proposed algorithm is simplified and works for any number of hidden states and evidence (observation) variables. It is also efficient in terms of computational time as the length of the observation sequence increases. **Example 1**. : _Consider an HMM with binary-valued hidden state \(X\) and binary-valued evidence variable \(Y\). Let \(\Gamma=[0.20,0.80]\) be the initial vector for \(X^{1}\). The transition matrix \(A\) and observation matrix \(O\) be as follows:_  
\[A=\left[ \begin{array}{cc}0.95&0.05\\ 0.15&0.85\end{array} \right]\quad\text{and}\quad O=\left[ \begin{array}{cc}0. 75&0.25\\ 0.90&0.10\end{array} \right]\]  
_Let us compute the sensitivity functions for the filtering probability using Algorithm 1 for the two states of \(X^{t}\) as a function of transition parameter \(\theta_{a}=a_{2,1}=p(x_{1}^{t}|x_{2}^{t-1})=0.15\) given the following sequence of observations: \(y_{2}^{1},y_{1}^{2}\) and \(y_{1}^{3}\)._  
_The simplified matrix formulation procedure divides the Transition Matrix \(A\) into \(\bar{A}\) and \(\widehat{A}\) :_  
\[A=\left[ \begin{array}{cc}0.95&0.05\\ \theta_{a}&1-\theta_{a}\end{array} \right],\quad\bar{A}=\left[ \begin{array}{ cc}0.95&0.05\\ 0&1\end{array} \right]\quad\text{and}\quad\widehat{A}=\left[ \begin{array}{cc} 0&0\\ 1&-1\end{array} \right]\]  
_For the observation sequence given, \(y_{2}^{1},y_{1}^{2}\) and \(y_{1}^{3}\), the diagonal matrices become_  
\[O^{1}=\left[ \begin{array}{cc}0.25&0\\ 0&0.10\end{array} \right],\quad O^{2}=\left[ \begin{array}{cc}0.75&0\\ 0&0.90\end{array} \right]\quad\text{and}\quad O^{3}=\left[ \begin{array}{cc}0. 75&0\\ 0&0.90\end{array} \right]\]  
_The coefficients for the sensitivity functions are computed by the proposed procedure using the forward matrices that are constructed as follows:_  
\[F^{1}=O^{1}*\Gamma^{\prime}=\left[ \begin{array}{cc}0.25&0\\ 0&0.10\end{array} \right]\times\left[ \begin{array}{cc}0.20\\ 0.80\end{array} \right]=\left[ \begin{array}{cc}0.05\\ 0.08\end{array} \right]\]  
_Then, \(F^{2}=Ftmp_{1}+Ftmp_{2}\), where the temporary matrices \(Ftmp_{1}\) and \(Ftmp_{2}\) are computed as follows:_  
\[Ftmp_{1} =\left[O^{2}*\bar{A}^{\prime}*F^{1},zeros(2,1)\right]\] \[=\left[ \begin{array}{cc}0.75&0\\ 0&0.90\end{array} \right]\times\left[ \begin{array}{cc}0.95&0\\ 0.05&1\end{array} \right]\times\left[ \begin{array}{cc}0.05\\ 0.08\end{array} \right]{}^{\prime}\left[ \begin{array}{cc}0\\ 0\end{array} \right]\right]\] \[=\left[ \begin{array}{cc}0.0356&0\\ 0.0743&0\end{array} \right]\] \[Ftmp_{2} =\left[zeros(2,1),O^{2}*\widehat{A}^{\prime}*F^{1}\right]\] \[=\left[ \begin{array}{cc}0&0.060\\ 0&-0.072\end{array} \right]\]\[F^{2}=Ftmp_{1}+Ftmp_{2}=\left[ \begin{array}{cc}0.0356&0.060\\ 0.0743&-0.072\end{array} \right],\]  
_and finally, for \(F^{3}\):_  
\[ \begin{split} Ftmp_{1}&=[O^{3}*\bar{A}^{\prime}*F^{2},zeros(2,1)] \\ &=\left[\begin{array}{cc}0.75&0\\ 0&0.90\end{array}\right]\times\left[\begin{array}{cc}0.95&0\\ 0.05&1\end{array}\right]\times\left[\begin{array}{cc}0.0356&0.060\\ 0.0743&-0.072\end{array}\right],\left[\begin{array}{c}0\\ 0\end{array}\right]\right]\\ &=\left[\begin{array}{cc}0.0254&0.0428&0\\ 0.0684&-0.0621&0\end{array}\right]\\ Ftmp_{2}&=[zeros(2,1),O^{3}*\bar{A}^{\prime}*F^{2}]\\ &=\left[\begin{array}{cc}\left[\begin{array}{cc}0\\ 0\end{array}\right],\left[\begin{array}{cc}0.75&0\\ 0&0.90\end{array}\right]\times\left[\begin{array}{cc}0&1\\ 0&-1\end{array}\right]\times\left[\begin{array}{cc}0.0356&0.060\\ 0.0743&-0.072\end{array}\right]\right]\\ &=\left[\begin{array}{cc}0&0.0557&-0.0540\\ 0&-0.0668&0.0648\end{array}\right]\\ F^{3}&=Ftmp_{1}+Ftmp_{2}=\left[\begin{array}{cc}0.0254&0.0984&-0.0540\\ 0.0684&-0.1289&0.0648\end{array}\right]\end{split}