# A Simplified Matrix Formulation for Sensitivity Analysis of Hidden Markov Models
## 3 Sensitivity Analysis of Filtering Probability
### Transition Parameter Variation
#### 3.1.1 Transition Matrix Decomposition and Observation Matrix Representation  
In the proposed algorithm, to calculate the coefficients in a series of Forward matrices \(F^{k}\), \(k=1,...,t\), the Transition Matrix \(A\) is divided into \(\bar{A}\) and \(\widehat{A}\) that are independent of and dependent on \(\theta_{a}\), respectively, for mathematical convenience. The matrices \(\bar{A}\) and \(\widehat{A}\) are computed based on the proportional co-variation assumption shown in Equation (4). Let us explain the decomposition considering an HMM with an \(n\times n\) Transition Matrix \(A\) with the transition parameter \(\theta_{a}=a_{r,s}=a_{n,1}=p(x_{1}^{t}|x_{n}^{t-1})\). This makes the transition matrix \(A\) a function of \(\theta_{a}\), and, with the proportional co-variation assumption shown in Equation (4), it becomes  
\[A(\theta_{a})=\left[\begin{array}{cccc}a_{1,1}&a_{1,2}&\cdots&a_{1,n}\\ a_{2,1}&a_{2,2}&\cdots&a_{2,n}\\ \vdots&\vdots&\ddots&\vdots\\ \theta_{a}&a_{n,2}\frac{1-\theta_{a}}{1-a_{n,1}}&\cdots&a_{n,n}\frac{1-\theta _{a}}{1-a_{n,1}}\end{array}\right]\]  
This matrix is divided into \(\bar{A}\) and \(\widehat{A}\) that are independent of and dependent on \(\theta_{a}\), respectively, as follows, and such that \(A(\theta_{a})=\bar{A}+\widehat{A}(\theta_{a})\).  
\[\tilde{A}=\left[\begin{array}{ccccc}a_{1,1}&a_{1,2}&\cdots&a_{1,n}\\ a_{2,1}&a_{2,2}&\cdots&a_{2,n}\\ \vdots&\vdots&\ddots&\vdots\\ 0&\frac{a_{n,2}}{1-a_{n,1}}&\cdots&\frac{a_{n,n}}{1-a_{n,1}}\end{array}\right] \quad\text{and}\quad\widehat{A}(\theta_{a})=\left[\begin{array}{ccccc}0&0& \cdots&0\\ 0&0&\cdots&0\\ \vdots&\vdots&\ddots&\vdots\\ 1&\frac{-a_{n,2}}{1-a_{n,1}}&\cdots&\frac{-a_{n,n}}{1-a_{n,1}}\end{array} \right]\cdot\theta_{a}\]  
In short, this decomposition can be represented in the algorithm simply as \(\tilde{A}\) and \(\widehat{A}\) that are independent of and dependent on \(\theta_{a}\), respectively.  
In the simplified matrix representation, the Observation Matrix \(O\) is represented as an \(n\times n\) diagonal matrices \(O^{t}\) whose \(v^{th}\) diagonal entry is \(P(y^{t}_{e}|x^{t}_{v})\) for each state \(v\) and whose other entries are \(0\) at the time \(t\) of the observation sequence [31]. Let us explain this representation by considering the HMM with an \(n\times m\) Observation Matrix \(O\). Given the following sequence of observations: \(y^{1}_{2},y^{2}_{1}\) and \(y^{3}_{3}\), the corresponding diagonal matrices become  
\[O^{1}=\left[\begin{array}{ccccc}o_{1,2}&0&\cdots&0\\ 0&o_{2,2}&\cdots&0\\ \vdots&\vdots&\ddots&\vdots\\ 0&0&\cdots&o_{n,2}\end{array}\right]=diag(O_{;2}),\quad O^{2}=diag(O_{;1}) \text{ and}\quad O^{3}=diag(O_{;3})\]  
.1.2 SMF for Sensitivity Analysis of the Filtering Probability to the Transition Parameter Variation  
In the Simplified Matrix Representation (SMF), the sensitivity function \(p(x^{t}_{v},\mathbf{y^{1:}_{e}})(\theta_{a})\) shown in Equation (7) can be written as a simple matrix-vector multiplication. It follows that for \(t=1\) we have the constant \(p(x^{1}_{v},\mathbf{y^{1}_{e}})(\theta_{a})=\sigma_{v,\mathbf{e}}\cdot\gamma_ {v}\), which becomes \(p(X^{1},\mathbf{y^{1}_{e}})(\theta_{a})=O^{1}\Gamma^{\intercal}\) in the SMF. For \(t>1\), we have  
\[p(x^{t}_{v},\mathbf{y^{1:}_{e}})(\theta_{a})=\sigma_{v,\mathbf{e}}\cdot\sum_{ z=1}^{n}a_{z,v}(\theta_{a})\cdot p(x^{t-1}_{v},\mathbf{y^{1:}_{e}})(\theta_{a})\]  
which is represented in SMF as  
\[p(X^{t},\mathbf{y^{t}_{e}})(\theta_{a})=O^{t}A(\theta_{a})^{\intercal}p(X^{t- 1},\mathbf{y^{1:}_{e}})(\theta_{a})\]  
The overall procedure of computing the sensitivity coefficients of \(p(X^{t},\mathbf{y^{t}_{e}})(\theta_{a})\) using the SMF is described in the following algorithm.