# Lightweight Anomaly Detection in Digit Recognition Using Federated Learning
## 7 Experimental Results and Analysis
### Federated Learning Scenario 1: Non-IID--Single Digit per Device  
To evaluate FL with the implemented AEs, it is important to select representative models that balance AD quality, training and inference speed, and resource usage. Since all seven candidate models exhibited comparable performance in AD, several criteria could be used to guide model selection. For instance, one might prioritize  
* Training time--to reduce energy consumption and improve convergence speed during FL rounds. * Inference time--if real-time detection is critical. * Memory footprint--for devices with severe RAM/Flash limitations. In our experiments, we opted to prioritize training efficiency as FL involves multiple rounds of local training on constrained hardware. Since all the models demonstrated comparable AD performance, choosing the fastest models in terms of training time allows us to minimize energy consumption and reduce the duration of each FL round. Thus, we selected the three models with the shortest training time during ESP32-based evaluation from the previous subsection. The selected models are as follows:  
* Model 1: Single hidden layer with 16 neurons--architecture: [196, 16, 196]. * Model 2: Single hidden layer with 32 neurons--architecture: [196, 32, 196]. * Model 3: Single hidden layer with 64 neurons--architecture: [196, 64, 196]. Each model undergoes multiple FL rounds, interleaved with local training phases. The training progression follows this sequence: _Training 0 \(\rightarrow\) Federated 0 \(\rightarrow\) Training 1 \(\rightarrow\) Federated 1 \(\rightarrow\)\(\ldots\)\(\rightarrow\) Federated \(n\)\(\rightarrow\) Training \(n\)\(+\)1_, where \(n\) is determined by the dual-phase early stopping mechanism adapted for FL, as previously described. All early stopping parameters used at the global level were kept consistent with the local early stopping configuration, except for the second-phase patience, which was set to a stricter value of zero. This means that even a single round without improvement was sufficient to trigger the voting for stopping. For all three selected models, convergence was consistently reached after two federated rounds (_Federated 0  and Federated 1_). This means that, after receiving the global model for the second time and performing additional local training, the majority of devices voted to stop training. Following that, each device sent its local model and stop decision back to the server. Although the stopping condition was met, we performed one final aggregation round for evaluation purposes, bringing the total to three federated rounds (_Federated 3_). To maintain consistency, all the training configurations were kept the same as in the previous experiment. The only difference was that the number of training epochs was limited for each model during every local training phase. Specifically, Model 1 and Model 2 were each trained for 20 epochs, while Model 3 was trained for 10 epochs. These values were selected based on the results from the previous experiment, where the full duration of training was evaluated for each model. We used approximately one-third of the total number of epochs required to reach convergence in standalone training on the ESP32. This strategy allows each model to gain meaningful weight updates while still keeping training incomplete for federated learning. The F1 scores, measured after each phase, are presented in Figure 7, illustrating how AD performance evolves per digit across training and federated rounds. This scenario represents a highly non-IID setting, where each ESP32-CAM device is trained exclusively on a single digit class from the dataset. After the initial local training round (_Training 0_), the F1 scores varied significantly across devices depending on the digit each device was trained on. However, after the first federated aggregation (_Federated 0_) was applied, the scores became more aligned across the devices, with only slight differences caused by the locally determined anomaly thresholds.