# A Simplified Matrix Formulation for Sensitivity Analysis of Hidden Markov Models
## 2 Background
### Hidden Markov Models
#### 2.1.2 Recursive Probability Expressions  
In order to establish the sensitivity functions for HMMs directly from the model's representation, the recursive probability expression for the Forward-Backward algorithm should be investigated. The repetitive character of the model parameters in the Forward-Backward algorithm is used to drive the sensitivity functions. Consequently, in this section the recursive expressions of the Forward-Backward algorithm [29; 31] are reviewed briefly.  
FilteringThe _filter probability_ is \(p(x_{v}^{t},\mathbf{y}_{\mathbf{e}}^{t})\) for a specific state \(v\) of \(X\). This probability is the same as the forward probability \(F(v,t)\) in the Forward-Backward algorithm. For time slice \(t=1\), we simply have that  
\[p(x_{v}^{1},\mathbf{y}_{\mathbf{e}}^{1})=p(\mathbf{y}_{\mathbf{e}}^{1}|x_{v}^{ 1}).p(x_{v}^{1})=o_{v,\mathbf{e}^{1}}.\gamma_{v},\]  
where \(\mathbf{e}^{1}\) corresponds to the symbol of \(Y\) that is observed at time \(1\). For time slices \(t>1\), we exploit the fact that \(Y^{t}\) is independent of \(Y^{1},...,Y^{t-1}\), given \(X^{t}\), written \(Y^{t}\perp Y^{1:t-1}|X^{t}\). Then,  
\[p(x_{v}^{t},\mathbf{y}_{\mathbf{e}}^{1:t})=p(x_{v}^{t},\mathbf{y}_{\mathbf{e}} ^{1:t-1},\mathbf{y}_{\mathbf{e}}^{t})=p(\mathbf{y}_{\mathbf{e}}^{t}|x_{v}^{t} ).p(x_{v}^{t},\mathbf{y}_{\mathbf{e}}^{1:t-1})\]  
The first factor in the above product corresponds to \(o_{v,\mathbf{e}^{1}}\); conditioning the second factor on the \(n\) states of \(X^{t-1}\), we find with \(X^{t}\perp Y^{1:t-1}|X^{t-1}\) that  
\[p(x_{v}^{t},\mathbf{y}_{\mathbf{e}}^{1:t-1})=\sum_{z=1}^{n}p(x_{v}^{t}|x_{z}^{ t-1}).p(x_{z}^{t-1},\mathbf{y}_{\mathbf{e}}^{1:t-1})=\sum_{z=1}^{n}a_{z,v}.p(x_{z}^{ t-1},\mathbf{y}_{\mathbf{e}}^{1:t-1})\]  
Taken together, we find for \(F(v,t)=p(x_{v}^{t},\mathbf{y}_{\mathbf{e}}^{1:t})\) the recursive expression  
\[F(v,t)=\begin{cases}o_{v,\mathbf{e}^{1}}.\gamma_{v}&\text{ if }t=1\\ o_{v,\mathbf{e}^{1}}.\sum_{z=1}^{n}a_{z,v}.F(z,t-1)&\text{ if }t>1\end{cases} \tag{2}\]  
PredictionThe _prediction probability_\(p(x_{v}^{t},\mathbf{y}_{\mathbf{e}}^{1:T})\) for \(t>T\) can be handled by the the Forward-Backward algorithm by computing \(F(v,t)\) with an empty set of evidence for \(Y^{T+1:t}\). It can be implemented by replacing the term \(o_{v,\mathbf{e}^{1}}\) by \(1\) for \(t>T\) in Equation (2). As a result, for \(T=0\), the _prediction probability_\(p(x_{v}^{t},\mathbf{y}_{\mathbf{e}}^{1:T})\) becomes the prior probability \(p(x_{v}^{t})\). The prediction task can be seen as a special case of the filtering task.  
SmoothingFinally, we consider a _smoothing probability_\(p(x_{v}^{t},\mathbf{y}_{\mathbf{e}}^{1:T})\) with \(t<T\). Using \(Y^{t+1:T}\perp Y^{1:t}|X^{t}\) we find that  
\[p(x_{v}^{t},\mathbf{y}_{\mathbf{e}}^{1:T})=p(x_{v}^{t},\mathbf{y}_{\mathbf{e} }^{1:t},\mathbf{y}_{\mathbf{e}}^{1+1:T})=p(\mathbf{y}_{\mathbf{e}}^{t+1:T}|x_{ v}^{t}).p(x_{v}^{  
Taken together, we find for \(B(v,t)=p(\mathbf{y}_{\mathbf{e}}^{t+1:\mathbf{T}}|x_{v}^{t})\) the recursive expression  
\[B(v,t)=\begin{cases}\sum_{z=1}^{n}o_{z,\mathbf{e}}\mathbf{r}^{t,z}\mathbf{r}_{0,z}&\text{if $t=1$}\\ \sum_{z=1}^{n}o_{z,\mathbf{e}}\mathbf{e}^{t+1}\mathbf{r}_{0,z}\mathbf{.}B(z,t+ 1)&\text{if $t>1$}\end{cases} \tag{3}\]  
In this work, we present the sensitivity of the HMM for filtering and smoothing probabilities for transition, initial and observation parameter variation. Therefore, the above discussion on the recursive probability expression for the filtering probability, Equation (2), and smoothing probability Equation (3), will be used to formulate our algorithm.