# FL-LoRaMAC: A Novel Framework for Enabling On-Device Learning for LoRa-Based IoT Applications
## 5 Simulation Details and Parameter Selection
### Selection of Hyper-Parameters  
The selection of model parameters is a critical issue that must be based on the trained model performance, cost of communicating data and/or parameters of the model, and computation complexity. Wherever pertinent, the model training measures, namely recall, precision, and accuracy, were used for evaluating the model's performance to make predictions.  
_Recall_ is defined as the ratio between the number of samples correctly predicted as positive to the total number of positive samples. In the case of ECG anomaly detection, recall can be formulated as  
\[Recall=\frac{Number\ of\ samples\ correctly\ predicted\ as\ abnormal}{Total\ abnormal\ samples} \tag{1}\]  
_Precision_ is defined as the ratio of positive samples to the total number of positive predictions that the model made. In the case of ECG anomaly detection, precision can be formulated as  
\[Precision=\frac{Total\ number\ of\ abnormal\ samples}{Number\ of\ samples\ predicted\ to\ be\ abnormal} \tag{2}\]  
Finally, _accuracy_ is defined as the ratio of the total number of correct predictions to the total number of predictions. In the case of ECG anomaly detection, _accuracy_ can be formulated as  
\[Accuracy=\frac{Number\ of\ samples\ correctly\ predicted\ ( abnormal\ or\ normal)}{Total\ number\ of\ predictions} \tag{3}\]  
The autoencoder applied to the ML model consisted of three fully connected layers with 140 neurons in the input layer, 32 neurons in the hidden layer, and 140 neurons in the output layer. These parameters were chosen experimentally to achieve an acceptable performance. The mean absolute error (MAE) function was used to compute the training losses and ADAM was used as the optimizer to update network weights during training.  
For FL, we used the same autoencoder model as described above. The model had a total of 9132 parameters. The dataset was divided equally among five devices. To achieve comparable performance to machine learning, the FL model required three communication rounds with 100 epochs in each communication round. Hence, these parameters were used for all FL simulations.  
Figure 9: Illustration of dataset division.  
When the PCA dimensionality reduction algorithm is applied in FL, it essentially reduces the 140 data points in the dataset to a smaller number of PCA components. This reduces the number of neurons in the input and output layers, resulting in the reduction in the number of model parameters. This in turn reduces the communication cost; however, it may reduce the model performance. Hence, we next focus on the selection of the appropriate number of PCA components, which are obtained from simulations. The volume of data required for FL with PCA and the corresponding model performance in terms of recall, precision, and accuracy with different communication rounds and different numbers of PCA components, as determined from simulations, are tabulated in Table 2. It is observed that the trained model performance measures (recall, precision, and accuracy) are consistently above 95% with 100 epochs and 20 PCA components with a sufficient reduction in the volume of data; hence, we select these parameters (indicated in boldface in Table 2).  
In summary, the model parameters used for FL with the PCA dimensionality reduction algorithms are listed in Table 3. Unless otherwise specified, these values are used for all performance evaluations of FL-LoRaMAC.