## 3 Network Handover Algorithm Based on Location Prediction
### Movement Prediction  
In this section, clusters generated from clustering important location points in Section 3.2 are utilized as hidden states, and the HMM predicts user movement trajectories. The parameters of the HMM are defined as follows:  
Hidden state sequence \(C\): Hidden state sequences are generated by clustering historical grid trajectory sequences \(\{C_{1},C_{2},\ldots C_{m}\}\). Observed state sequence \(O\): Define the sequence of grid trajectories \(\{g_{1},g_{2},\ldots g_{n}\}\) as the observation state. The state transfer probability matrix \(A\):  
\[A=\left[ \begin{matrix}a_{11}&a_{12}&\ldots&a_{1m}\\ a_{12}&\ldots&\ldots&a_{12}\\ \ldots&a_{ij}&a_{ii}&\ldots\\ a_{m1}&a_{m2}&\ldots&a_{mm}\end{matrix} \right],\sum_{j=1}^{m}a_{ij}=1 \tag{13}\]  
where \(a_{ij}\) represents the state transfer probability between hidden states \(C_{i}\) and \(C_{j}\). To satisfy the constraints of the state transfer probability matrix \(A\), \(a_{ij}^{\prime}\) is first normalized, and then \(a_{ij}\) is calculated. \[a_{ij}^{\prime}=[\beta_{a}^{(ij)},\beta_{st}^{(ij)},\beta_{dis}^{(ij)}] \begin{bmatrix} \omega_{a}\\ \omega_{st}\\ \omega_{dis}\end{bmatrix}  \tag{14}\]  
where \(\beta_{a}^{(ij)}\) denotes the normalized angular eigenvalue between \(C_{i}\) and \(C_{j}\), \(\beta_{st}^{(ij)}\) represents the residence time eigenvalue of \(C_{i}\), \(\beta_{dis}^{(ij)}\) is the reciprocal of the Euclidean distance between \(C_{i}\) and \(C_{j}\), and \( \begin{bmatrix}\omega_{a}\\ \omega_{st}\\ \omega_{dis}\end{bmatrix} \) denotes the weight set for the three eigenvalues. Observation probability matrix \(B\):  
\[B= \begin{bmatrix}b_{11}&b_{12}&\cdots&b_{1n}\\ b_{21}&\cdots&\cdots&b_{2n}\\ \cdots&b_{ij}&b_{ii}&\cdots\\ b_{m1}&b_{m2}&\cdots&b_{mn}\end{bmatrix} ,\sum_{j=1}^{n}b_{ij}=1 \tag{15}\]  
where \(b_{ij}\) is the transfer probability between grid cells and the clusters of the hidden state sequences, to satisfy the constraints of the state transfer probability matrix \(B\), \(b_{ij}^{\prime}\) is first normalized, and then \(b_{ij}\) is obtained. \[b_{ij}^{\prime}= \begin{cases}1,\delta_{j}\in C_{i}\\ \begin{bmatrix}\gamma_{a}^{(ij)},\gamma_{dis}^{(ij)}\end{bmatrix}\begin{bmatrix} w_{a}\\ w_{dis}\end{bmatrix},\delta_{j}\
otin C_{i}\end{cases}  \tag{16}\]  
where \(g_{j}\) is the grid cell, \(\gamma_{a}^{(ij)}\) is the eigenvalue of the normalized angle between \(C_{i}\) and \(g_{j}\), and \(\gamma_{dis}^{(ij)}\) is the inverse of the Euclidean distance between \(C_{i}\) and \(g_{j}\). Initial state probability matrix \(\lambda=[0,\ldots,\frac{1}{k},0,\frac{1}{k},\ldots,0]^{T}\), the \(k\) clusters neighboring indoor entrances are selected and their initial states are set to be uniformly distributed with an initial state probability of \(\frac{1}{k}\) and the rest of the state probabilities are zero. After determining the parameters of each part of the HMM, we train the model using the Baum-Welch algorithm [25]. In user movement, the user may stay at a specific location for a long time, resulting in the continuous trajectory points projected to the same cluster. The state transfer probability \(a_{ij}\) of the classical HMM may become zero, which will cause the prediction failure, and this problem can be solved by introducing a smoothing factor \(\varepsilon_{a}\). The user dwell time obeys a long-tailed distribution. Find the maximum dwell time for all grids in cluster \(C_{t}\), as shown in the following equation. \[stoptime(C_{t})=\max_{1\leq v\leq k}(stoptime(g_{tv})) \tag{17}\]  
where \(g_{tv}\) denotes the grid point \(v\) in Cluster \(C_{t}\), \(k\) is the number of grid points in Cluster \(C_{t}\). \(stoptime(C_{t})\) denotes the maximum value of dwell time for all grid points \(g_{tv}\) in Cluster \(C_{t}\). The residence time is mapped using a mapping function \(L\)ogistic in the range of [0,1] as follows:  
\[\varepsilon_{a}=\text{Logistic}(stoptime(C_{t})),0<\varepsilon_{a}\leq\max(a _{tz}) \tag{18}\]  
The smoothing factor \(\varepsilon_{a}\) dynamically adjusts the state transfer probability.