# A Hierarchical Federated Learning Algorithm Based on Time Aggregation in Edge Computing Environment
## 3 Dynamic Weighted Hierarchical Federated Learning Algorithm  
### Federated Average Algorithm  
The conventional federated learning framework typically consists of a two-tier client-server structure, comprising a group of client devices and a centralized server. Assuming that the client device \(\mathcal{N}=\{i|i=1,2,\ldots,N\}\) uses its own dataset \(\{D_{i}|i=1,2,\ldots,N\}\) to train locally, and produces a group of machine learning models \(\mathit{Model}_{local}=\{M_{i}|i=1,2,\ldots,N\}\) with different emphases, the central server integrates all of the \(\mathit{Model}_{local}\) parameters or gradients of the joint training, and finally produces a global model \(\mathit{Model}_{global}\) that integrates the data characteristics of all parties. The global model obtained through federated learning can provide local users with higher-accuracy services because it contains model information that each participating client lacks or has under-trained. In contrast to the previous training mode of data integration, federated learning does not require user data to be uploaded centrally. Instead, it is trained locally, and the objective function is optimized through multiple interactions between local model parameters and the global model. Ultimately, a joint model that performs nearly as well as the centralized training benchmark model is obtained. The optimization objective function is expressed as:  
\[\min_{\omega}F(\omega)=\sum_{i=1}^{N}p_{i}F_{i}(\omega), \tag{1}\] \begin{table}
\begin{tabular}{c c c} \hline \hline
**Algorithm** & **Advantages** & **Disadvantages** \\ \hline FedAvg & Reduced communication costs. & Sacrifices in model \\  & & convergence and accuracy. \\ \hline FedSGD & Computationally efficient. & Large communication overhead. \\ \hline FedCS & Improves overall convergence speed. & Does not work well in complex structures \\  & & and with heterogeneous sample data. \\ \hline L2 GD & Handles heterogeneous data successfully. & Increases model complexity \\  & & and associated costs. \\ \hline FedPer & Provides a precise & Affects the convergence speed \\  & personalization method. & and accuracy of the model. \\ \hline PerFit & Provides personalized services, enabling & Increases model complexity \\  & clients to flexibly create models & and associated costs. \\ \hline  & & Final model may not achieve expected \\  & & accuracy or even fail to \\  & & converge when the q is non-IID. \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Comparison of federated learning algorithms. where \(N\) is the number of clients participating in training, \(p_{i}\) is the probability that client \(i\) is chosen to participate in the global model training, \(p_{i}\geq 0\) and \(\sum_{i=1}^{N}p_{i}=1\). Generally, all client devices have an equal chance of being randomly selected to participate in training. Specifically, \(p_{i}\) is usually uniformly distributed. \(F_{i}(\omega)\) is the predicted loss of the model parameter error on \(\omega\) of the \(i\)-th client device on its local datasets \(D_{i}=\{\big{(}x_{j},y_{j}\big{)}\}_{j=1}^{|D_{i}|}\), where \(x_{j}\) denotes the \(j\)-th input sample of the device, and the corresponding labeled output is \(y_{j}\). \(F_{i}(\omega)\) usually depends on the predefined specific loss function \(\ell(\cdot)\), namely \(F_{i}(\omega)=\frac{1}{|D_{i}|}\sum_{j\in D_{i}}\ell\big{(}x_{j},y_{j},\omega \big{)}\), where \(|D_{i}|\) is the size of the dataset \(D_{i}\). During the federated learning training process, a global maximum number of iterations \(T\) is set. The training will end and the final optimized global model will be output when the model converges or reaches the maximum number of iterations. The most classic and widely recognized algorithm for federated learning is the federated average (FedAvg) algorithm. It is based on the conventional two-tier federated learning architecture and is used as the benchmark comparison algorithm in current studies on federated learning.