# Adaptive Modulation Scheme for Soft-Switching Hybrid FSO/RF Links Based on Machine Learning
## 3 Threshold Estimation and Data Set Generation by Machine Learning
### Construction of the Random Forest Algorithm Model  
The random forest algorithm is an ensemble model suitable for classification problems, consisting of multiple decision trees. When training data are input into the model, a subset is randomly selected along with some of its feature attributes to build multiple small decision trees. When unknown data are input, predictions are made for each decision tree, and the final prediction is obtained through a voting process based on the predictions of the decision trees. In this experiment, 500 decision trees are selected, each with a maximum depth of 3.  
The model works in two phases: the training part and the testing part. The training part includes defining the optimal range of multiple modulations based on a given target BER and \(S_{1}\). Then, their corresponding LB threshold set \(S_{2}\) can be calculated to allocate the channel state set \(D_{i,i=1,2\cdots N}\). The FSO link has three modulation modes, including L-ary pulse-phase modulation (L-PPM), M-ary phase shift keying (M-PSK), and M-ary quadrature amplitude modulation (M-QAM). The RF link operates predominantly in twomodulation modes: M-PSK and M-QAM. In Algorithm 1, the details of calculating link budget by switching modulation is provided.  
```
Input:\(parameter_{1}\), \(parameter_{2}\), \(\cdots\), \(parameter_{n}\) (\(1\), \(2\), \(\cdots\), n for modulation mode.) Result: An optimum spanning random forest model, LinkBudget Data: Weather set \(S_{1}\) /* Now this is an if\(\cdots\)else conditional loop */
1 for i = 1:length (rainfall rate (R) or visibility (V)) if0<R(i)/V(i)\(\leq parameter_{1}\)then
2 Modulation1;
3 elseif\(parameter_{1}<R\)(i)/V(i)\(\leq parameter_{2}\)then
4 Modulation2;
5 elseif\(parameter_{n-1}<R\)(i)/V(i)\(\leq parameter_{n}\)then
6 Modulation\(n\);
7
8 elseifR(i)/V(i)\(>parameter_{n}\)then
9 Outage;
10 Substituting of \(parameter_{1}\), \(parameter_{2}\), \(\cdots\), \(parameter_{n}\) into the formula of the LinkBudget results in \(LB_{1}\), \(LB_{2}\), \(\cdots\), \(LB_{n}\). Determine the total number of each modulation, along with the number of correct and incorrect judgments.
```  
**Algorithm 1**Link budget switching scheme  
For the channel state of each modulation (\(D_{i,i=1,2\cdots N}\)) and the proper target BER (\(P_{e,obj}\)), set \(S_{1}\) is taken into account to construct a relational graph that delineates the correlation between the weather parameter and the average BER (\(\overline{P}_{e}\)) across different modulations. The relational graph as shown in Figure 2 is divided into some areas representing the optimum modulation range when \(\overline{P}_{e}\) is smaller than \(P_{e,obj}\), and the \(LB_{thi,i=1,2\cdots N}\) is calculated when \(\overline{P}_{e}\) is equal to \(P_{e,obj}\). And we calculate the LB from arbitrary weather data. A comparison between \(LB\) and \(LB_{thi,i=1,2\cdots N}\) determines the channel state (\(S_{2}\)). If it is less than the minimum threshold (\(LB_{thi,min}\)), the communication is interrupted. If it is between \(LB_{thi}\) and \(LB_{thi+1}\), the channel state of the current weather is \(D_{i}\).  
The second component focuses on constructing a random forest model that utilizes the weather set (\(S_{1}\)) and channel state set (\(S_{2}\)). Within the training phase, multiple channel states are formulated as the output labels for the decision trees. The optimal channel state can be obtained by inputting data from real-time weather into the random forest model, but it requires in-depth analysis to determine whether \(\overline{P}_{e}\) of the channel state (\(D_{i+1}\)) under current weather data is less than \(P_{e,obj}\). In cases where \(\overline{P}_{e}\) exceeds \(P_{e,obj}\), the LB threshold is  
Figure 2: Optimum modulation range.  
fine-tuned iteratively until it descends below \(P_{e,obj}\). This iterative process is performed to produce the channel state congruent with the channel state set (\(S_{2}\)) established during the training phase.