# A Hierarchical Federated Learning Algorithm Based on Time Aggregation in Edge Computing Environment
## 4 Hierarchical Federated Learning Algorithm Based on Time-Effective Aggregation
The details are as follows:  
\[\omega^{t}_{(m,S^{\prime})} = \sum_{k^{\prime}=1}^{S^{\prime}}\alpha_{k^{\prime}}\omega^{t-1}_{ k^{\prime}} \tag{17}\] \[\omega^{t}_{(m,S^{\prime\prime})} = \sum_{k^{\prime\prime}=1}^{S^{\prime\prime}}\alpha_{k^{\prime \prime}}\omega^{t-1}_{k^{\prime\prime}}, \tag{18}\]  
where \(\omega^{t}_{(m,S^{\prime})}\) is the model parameter obtained by dynamic weighted aggregation of the client devices participating in the \(t\)-th round of training on edge server \(m\), and \(\omega^{t}_{(m,S^{\prime\prime})}\) refers to the aggregation of obsolete local model parameters for the \(t\)-th round of edge server \(m\). These local model parameters are obtained by the client devices through training on the obsolete global model, where \(\alpha_{k^{\prime}}\) and \(\alpha_{k^{\prime\prime}}\) are defined as in Equation (14). Group weighted edge aggregation. After obtaining the two sets of grouping aggregation results, \(\omega^{t}_{(m,S^{\prime})}\) and \(\omega^{t}_{(m,S^{\prime\prime})}\), these sets must be weighted and combined. A relatively small weight needs to be given to the relatively stale model to reduce the effect of obsolescence on convergence. The edge aggregation model \(\omega^{t}_{m}\) for the \(t\)-th round of the edge server \(m\) is defined as follows:  
\[\omega^{t}_{m}=\big{(}1-\lambda^{t}\big{)}\omega^{t}_{(m,S^{\prime})}+\lambda^ {t}\omega^{t}_{(m,S^{\prime\prime})}, \tag{19}\]  
where \(\lambda^{t}\) is the dynamic weighting factor determined using the average obsolescence \(\epsilon_{t}\) of the local models of \(\mathcal{S}^{\prime\prime}_{m}\). \(\lambda^{t}\) is defined as:  
\[\lambda^{t}=\frac{|S^{\prime\prime}|}{|S^{\prime}|+|S^{\prime\prime}|}\exp( \epsilon_{t}). \tag{20}\]  
Global synchronization aggregation  
The time difference for edge servers to complete edge aggregation is insignificant, as the edge waiting time is set at the edge. This enables the central server to use the synchronous aggregation method. Once all of the edge model parameters \(\omega^{t}_{m}\) have arrived at the central server, the global aggregation is performed using the average weighted algorithm to update the global model parameters. The calculation process for the global model parameters is as follows:  
\[\omega^{t}=\frac{\sum_{m\in M}|D_{m}|\omega^{t}_{m}}{|D|}. \tag{21}\]The overall training time of federated learning can be significantly shortened, and model training efficiency can be improved using this hierarchical grouping and time-effective aggregation method. At the same time, the dual-weighting method is used to ensure the accuracy of the global model. Figure 4 vividly illustrates the above aggregation ideas. The proposed hierarchical federated learning algorithm, based on an efficient aggregation mechanism, is presented in Algorithm 2. It is noteworthy that, in contrast to the direct aggregation method used by the central server in Algorithm 1, the edge server process in Algorithm 2 first performs semi-asynchronous edge aggregation of the local model. This hierarchical aggregation method can effectively reduce the number of model parameters that the central server process needs to receive. To improve training efficiency, the edge server process has a waiting time set, enabling edge aggregation to be performed without waiting for all participating client devices to complete local training. This reduces idle waiting time on both the edge and central servers, allowing as many training rounds as possible to be conducted concurrently, and speeding up the global model's convergence. To ensure the model's training effect, the local model parameters arriving at the edge server in each round are grouped, and the two groups of model parameters are weighted to balance the local model's contribution to the global model. Figure 4: Schematic diagram of group-weighted aggregation.