# Robust and Accurate Wi-Fi Fingerprint Location Recognition Method Based on Deep Neural Network
## 3 Theoretical Frameworks
### The Fine Localizer
#### 3.3.2 Hidden Markov Models (HMM) Optimization  
The location of users in an indoor environment is uncertain; they may appear anywhere. At this point, users no longer need precise motion trajectory, but they do need accurate coordinates of their current position. However, as a form of absolute positioning, Wi-Fi positioning system cannot converge to a better accuracy as GPS does with the prolongation of observation time. Therefore, we construct HMM for optimization according to the temporal correlation of multiple observations at the same unknown point to improve the accuracy of static positioning and make effective use of the observation rather than simply calculating their mean location.  
HMM is a probability model related to time series. We use the current \(RSS\), \(o_{t}\), with its five prior \(RSS\), \(o_{t-5},\ldots o_{t-1}\), and five posterior \(RSS\), \(o_{t+1},\ldots,o_{t+5}\), as observations at an unknown point. We take fingerprint points as hidden state and the posterior probability calculated by DNN as observation state to structure HMM \(\lambda=(A,B,\pi)\).  
* \(A=(a_{ij}),i,j=1,2,\ldots,z\) is the hidden state transition matrix, which is made up of the transition probability among hidden states, and \(a_{ij}\) represents the probability of fingerprint point \(i\) transferring to \(j\). We set the \(a_{ij}\) of non-adjacent fingerprint points to \(0\) and to \(1\) otherwise.
* \(B=(b_{j\gamma}),j=1,2,\ldots z,\gamma=t-5,\ldots,t+5\) is the observation probability matrix, where \(b_{j\gamma}\) denotes the probability of \(o_{\gamma}\) observed at the fingerprint point \(j\). So, \(b_{j\gamma}=P(\gamma|l_{j})=cP(l_{j}|\gamma,out)\), where \(P(l_{j}|\gamma,out)\) is the posteriori probability of DNN output, and \(c=P(\gamma)/P(l_{j})\) is a constant that has nothing to do with final result.
* \(\pi\) is the prior state probability matrix. It represents the probability of the unknown point in each fingerprint point at the start time. In the system, we set the initial probability of each fingerprint point as equal, so \(\pi=[1/z,\ldots,1/z]\).  
Therefore, the static optimal posterior probability \(P(l_{i}|L,\textit{optimal}\ out)\) of the unknown point \(L\) at each fingerprint point can be calculated by the forward and backward probability of the HMM when given the \(RSS\) observations \(O=(o_{t-5},\ldots o_{t-1},o_{t},o_{t+1},\ldots,o_{t+5})\) and HMM model \(\lambda\), as follows:\[P(l_{i}|L,\text{optimal out})=P_{t}(L_{t}=l_{i},\lambda,O)=\frac{P(L_{t}=l_{i},O| \lambda)}{P(O|\lambda)}=\frac{\mu_{t}(l_{i})\rho_{t}(l_{i})}{\sum\limits_{j=1}^ {z}\mu_{t}(l_{j})\rho_{t}(l_{j})},i=1,2,3,\ldots,z \tag{23}\]  
\[\mu_{\gamma}(l_{i})=P(O_{t-5},\ldots,O_{t},L_{t}=l_{i}|\lambda)=[\sum\limits_ {j=1}^{z}\mu_{\gamma-1}(j)a_{ji}]b_{j\gamma},\gamma=t-5,\ldots,t-1,t \tag{24}\]  
\[\rho_{\gamma}(l_{i})=P(O_{t},\ldots,O_{t+5},L_{t}=l_{i}|\lambda)=\sum\limits_ {j=1}^{z}a_{ij}b_{j\gamma+1}\rho_{\gamma+1}(j),\gamma=t+5,\ldots,t+1,t \tag{25}\]  
where \(\mu_{t}(l_{i})\) represents the forward probability of unknown point \(L\) at fingerprint point \(l_{i}\) with the observation sequence \(o_{t-5},\ldots o_{t-1},o_{t}\), while \(\rho_{t}(l_{i})\) is the backward probability of the observation sequence \(o_{t},o_{t+1},\ldots,o_{t+5}\) given unknown point \(L\) at fingerprint point \(l_{i}\). Substituting Equation (23) into (8), we can calculate the optimal static coordinates of the unknown point.