## 4 Results
### Centralized Learning vs. FL Based on Edge-Fog-Cloud Architecture
#### 4.2.7 Latency Performance
Load the CSV dataset;  
Calculate the average speed of data transfer for each task;  
\(\text{BFD}\leftarrow\text{df}[\text{``Tot size''}]\) / \(\text{df}[\text{``flow\_duration''}]\);  
Determine the size of a model;  
\(\text{model\_size}\leftarrow\text{46 KB}\);  
Divide the devices into different groups;  
\(\text{num\_edge\_devices}\gets 5\);  
\(\text{num\_fog\_devices}\gets 5\);  
\(\text{num\_total\_edge\_devices\_cloud\_centric}\gets 25\);  
Assign data transfer speed to each group;  
\(\text{trnsSPD\_edge\_to\_fog}\leftarrow\text{BFD}\) / \(\text{num\_edge\_devices}\);  
\(\text{trnsSPD\_fog\_to\_cloud}\leftarrow\text{BFD}\) / \(\text{num\_fog\_devices}\);  
\(\text{trnsSPD\_edge\_to\_cloud}\leftarrow\text{BFD}\) / \(\text{num\_total\_edge\_devices\_cloud\_centric}\);  
Calculate the time taken for data transfer between different groups;  
\(\text{latency\_edge\_to\_fog}\leftarrow\text{model\_size}\) / \(\text{trnsSPD\_edge\_to\_fog}\);  
\(\text{latency\_fog\_to\_cloud}\leftarrow\text{model\_size}\) / \(\text{trnsSPD\_fog\_to\_cloud}\);  
\(\text{latency\_edge\_to\_cloud}\leftarrow\text{model\_size}\) / \(\text{trnsSPD\_edge\_to\_cloud}\);  
The algorithm is designed to model the latency, or delay, involved in communication within an IoT system. It starts by ingesting a dataset named CSV CICIoT2023, likely containing information about IoT devices and their communication patterns. The goal of the algorithm is to calculate and provide three types of latencies: latency from edge to fog, latency from fog to cloud, and latency from edge to cloud (cloud-centric). To begin the process, the algorithm loads the dataset from the CSV file. It then calculates the average  
Figure 14: Transmission speed in the CICIoT2023 dataset. data transfer speed for each task, a crucial metric for understanding the speed at which data move between devices. This is achieved by dividing the total size of data transferred by the duration of the flow. Next, the algorithm determines the size of a model, set at 46 Kb. This model size likely represents the amount of data processed or transferred by the IoT devices. The devices are categorized into different groups based on their roles or locations, with parameters indicating the number of edge devices, fog devices, and total edge devices in a cloud-centric architecture. Once the groups are established, the algorithm assigns data transfer speeds to each group. It computes the transmission speed for data transfer from edge devices to fog devices, from fog devices to the cloud, and from edge devices directly to the cloud, using previously calculated values and the number of devices in each group. Finally, the algorithm calculates the latency for data transfer between these groups. It determines the time taken for data transfer from edge devices to fog devices, from fog devices to the cloud, and from edge devices directly to the cloud using the model size and the transmission speed values for each group. With the available transmission speed, the simulation proceeds to distribute it among the devices in the architecture. It calculates the transmission speed allocated for communication links from edge to fog, fog to cloud, and edge to cloud. Subsequently, the simulation computes the time taken for communication between different layers of the architecture. These calculations are based on the model size and the allocated transmission speed for each communication link. The plots visualize the communication latency for communication from edge to fog, fog to cloud, and edge to cloud, as seen in Figure 15, Figure 16, and Figure 17, respectively. The result from the cloud-centric architecture in Figure 17 has bigger latency than edge to fog in Figure 15 and fog to cloud in Figure 16. The latency can be reduced by more than 50% when the fog-edge-cloud architecture is employed in the CIDS architecture. In edge-fog-cloud architecture, model updates are processed and aggregated locally at fog devices before being sent to the cloud server.