# Double-Scale Adaptive Transmission in Time-Varying Channel for Underwater Acoustic Sensor Networks
## 4 Double-Scale Channel State Prediction
### Large-Scale Channel State Prediction
#### 4.1.1 \(k\)-Nearest Neighbor Prediction Algorithm with Sliding Window  
Large-scale channel state is represented as the average channel state in a large-scale epoch, as shown in Figure 5. Large-scale channel state of epoch \(j\) is  
\[h_{j}^{L}=\frac{1}{N_{large}}\sum_{i=1}^{N_{large}}h_{i}^{S}, \tag{12}\]  
where \(N_{large}\) is the number of slots in a large-scale epoch. \(h_{i}^{S}\) is the channel state of the \(i\)-th slot during the epoch \(j\) in dB. For the convenience of expression, the notation \(h_{j}\) is used to signify \(h_{j}^{L}\) in Section 4.1.  
Assuming that the current time is in the \(u\)-th large-scale epoch, and the stored historical series of large-scale channel state can be represented as  
\[\mathbf{H}^{L}=[h_{1},h_{2},\dots,h_{u}], \tag{13}\]  
where \(h_{i}\) denotes the large-scale channel state in epoch \(i\).  
The scheme of large-scale channel prediction is shown in Algorithm 1. The input elements of the algorithm include the training set which consists of training vectors and a test vector. And the output of the algorithm is the predicted large-scale channel state after \(v\)-th epochs.  
The training set \(\mathbf{Y}=[\mathbf{S}_{n},\mathbf{S}_{n+1},\dots,\mathbf{S}_{u-v}]\) contains a group of training vectors and their labels. Training vectors are obtained from \(\mathbf{H}^{L}\) by a sliding window with a length of \(n\), which is the order of the prediction model, as shown in Figure 5b. The label is the \(v\)-th value after the corresponding vector in \(\mathbf{H}^{L}\). Training vector \(\mathbf{S}_{i}\) and its label \(h_{i+v}\) is given as  
\[\mathbf{S}_{i}=[h_{i-n+1},h_{i-n+2},\dots,h_{i-1},h_{i}]\sim h_{i+v},i\in[n,u- v]. \tag{14}\]  
Test vector \(\mathbf{S}_{u}\) contains channel state of \(n\) large-scale epochs before current large-scale epoch,  
\[\mathbf{S}_{u}=[h_{u-n+1},h_{u-n+2},\dots,h_{u-1},h_{u}]. \tag{15}\]  
Firstly, each training vector is matched according to its last value. In detail, training vector \(\mathbf{S}_{i}\) is selected if the last values of \(\mathbf{S}_{i}\) and \(\mathbf{S}_{u}\) are similar, meeting the following condition,  
\[|h_{i}-h_{u}|\leq\frac{h_{max}-h_{min}}{M}. \tag{16}\]If this condition is not satisfied, \(\mathbf{S}_{i}\) is filtered out. Most of the training vectors are filtered out by this condition, so the computational complexity is greatly reduced.  
To reduce the computational complexity, the L1 metric is calculated as the distance between \(\mathbf{S}_{i}\) and \(\mathbf{S}_{u}\). The L1 metric is represented as  
\[D_{\mathbf{S}_{i}\mathbf{S}_{u}}=||\mathbf{S}_{i}-\mathbf{S}_{u}||_{1}. \tag{17}\]  
Then, \(k\) nearest neighbors \([\mathbf{c}_{1},\mathbf{c}_{2}...\mathbf{c}_{k}]\) are chosen with labels \(\{h_{\text{P}}^{c_{1}},h_{\text{P}}^{c_{2}},\ldots,h_{\text{P}}^{c_{k}}\}\) as \(k\) prediction values. For example, in Figure 5, nearest neighbors \(\mathbf{v}_{1}\) and \(\mathbf{v}_{2}\) are chosen for test vector \(\mathbf{v}_{3}\).  
Inverse distance weight of chosen vector \(\mathbf{c}_{j}\) is calculated as  
Figure 5: Channel state and large-scale channel state prediction method. (**a**) Original channel state. (**b**) Large-scale channel state and diagram of \(k\)-nearest neighbor algorithm with sliding window. \(\mathbf{v}_{3}\) is the test vector. \(\mathbf{v}_{1}\) and \(\mathbf{v}_{2}\) are nearest neighbors chosen from training vectors.  
\[w_{c_{j}}=\frac{1/D_{c_{i}\mathcal{S}_{u}}}{\sum_{m=1}^{k}1/D_{c_{m}\mathcal{S}_{ u}}}. \tag{18}\]  
Finally, the predicted channel state is calculated with inverse distance weight, which is represented as  
\[\hat{h}_{n+v}=\sum_{m=1}^{k}w_{c_{m}}h_{v}^{c_{m}}. \tag{19}\]