# A Hierarchical Federated Learning Algorithm Based on Time Aggregation in Edge Computing Environment
## 5 Simulation and Analysis  
The parameters of the FedEdge algorithm used in this simulation are reported in Table 2. We varied the distribution of data across clients to include IID, non-IID(2), and non-IID(5) distributions. We set the total number of clients, \(N\), to 100, with a subset of 5 clients participating in each round of training. We also employed \(M\) edge servers. We conducted separate experiments using the MNIST and CIFAR-10 datasets, respectively, with a total of 20 and 200 global training iterations, \(T\). At each training iteration, each participating client performed \(E\) local training iterations with a batch size of 64 and a learning rate of \(\eta\) set to 0.01. For non-IID datasets, we use a completely random method to partition the dataset. Figures 5 and 6 show the experimental comparison results of the dynamic and average weighted aggregation methods using the MNIST and CIFAR-10 datasets, respectively. The \begin{table}
\begin{tabular}{c c} \hline \hline
**Parameters** & **Value** \\ \hline Total clients \(N\) & 100 \\ Number of participating clients \(C\) & 5 \\ Number of edge servers \(M\) & 1 \\ Global training iterations \(T\) & 20 (MNIST)/200 (CIFAR-10) \\ Local training iterations \(E\) & 5 \\ Batch\_size & 64 \\ Learning rate \(\eta\) & 0.01 \\ Distribution & IID, non-IID(2), non-IID(5) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Simulation parameters. x-axis represents the global training round, and the y-axis represents the global model's classification accuracy after each global aggregation. Figure 5 compares the effects of two algorithms on the MNIST dataset after 20 rounds of training. The model's accuracy is highest when the q is IID, and it fluctuates more when the client's data distribution differs greatly. For non-IID data with two classifications, the model accuracy obtained with the dynamic weighting algorithm is higher than that obtained with the FedAvg algorithm. For non-IID data with five classifications, the accuracy of the model trained with the dynamic weighting algorithm is similar to that trained with the FedAvg algorithm, but with less fluctuation. In summary, the proposed federated learning algorithm based on dynamic weighted aggregation can achieve excellent results for both IID and non-IID cases in the MNIST dataset. Figure 6 compares two federated learning algorithm model effects after 200 training rounds on the CIFAR-10 dataset. The complexity of CIFAR-10 leads to longer convergence times and more model fluctuation between rounds than MNIST. Under IID conditions, the best classification accuracy is 65%. The training model effect is unsatisfactory under non-IID conditions. Nevertheless, dynamic weighted aggregation of local model parameters outperforms direct average weighted aggregation overall, irrespective of whether the non-IID case has two or five classifications. Figure 5: Effect of dynamic weighting and average weighting algorithms on MNIST. Figure 6: Effect of dynamic weighting and average weighting algorithms on CIFAR-10. The efficient hierarchical federated learning algorithm is evaluated on the MNIST dataset using confusion matrices for IID and non-IID(5) data distributions. The CNN model performs well on both distributions, with a slightly higher classification deviation observed in the non-IID case. Figures 7 and 8 show the classification results. Figures 9 and 10 compare the classification accuracy of the FedAvg and FedEdge algorithms on the MNIST dataset after 60 rounds of global training, under IID and non-IID conditions. The FedEdge algorithm achieves the same accuracy in less time than the FedAvg algorithm, as it performs edge aggregation in each iteration without waiting for all clients to finish training. The proposed algorithm reduces training time by 37.3% and achieves good accuracy when classifying handwritten datasets, improving training efficiency by about 30-40%. In the non-IID case, the accuracy of the model fluctuates greatly due to the different distributions of training data used in each round of aggregation.