# Wireless Traffic Prediction Based on a Gradient Similarity Federated Aggregation Algorithm
## 3 Proposed Framework and Methods
### Global Aggregation Based on Gradient Similarity  
The aggregation process in FL is a key part of model training, and the quality of aggregation directly affects the strength of the generalization ability of the final generated global model. The goal of central server-side model aggregation is to obtain a global model with strong generalization capability across all clients, which should balance client personalization and correlation characteristics across multiple clients. To achieve this, the global model should find a balance between capturing the personalized traffic patterns of the clients and the public shared traffic patterns. In literature research, it is found that similarity-based weighted fusion schemes have a wide range of applications in machine learning, such as natural language processing and transformers in image vision [18], where similarity knowledge can tap potential correlations among different clients, and FedGSA quantifies client similarity relationships by calculating Pearson correlation coefficients for each client gradient to guide the server-side weighting of client models for aggregation. The Pearson correlation coefficient is used to describe the degree of linear correlation between two variables, i.e., the larger the absolute value of the correlation, the stronger the correlation, and the value is \([-1,1]\). The Pearson correlation coefficient is the ratio of the covariance to the standard deviation, and the Pearson correlation coefficient for a set of data \((x,y)\) is calculated as:  
\[\rho_{x,y}=\frac{\Sigma xy-\frac{\Sigma x\Sigma y}{N}}{\sqrt{\left(\Sigma x^{2} -\frac{\left(\Sigma x\right)^{2}}{N}\right)\left(\Sigma y^{2}-\frac{\left( \Sigma y\right)^{2}}{N}\right)}} \tag{6}\]  
where \(N\) denotes the number of values of the variable. Here, we use gradient information to measure the similarity between individual client models, rather than based on the original traffic data of each client itself. The central server uses the similarity relationship between the gradients of the individual client models to guide the clients in generating personalized models, thus helping to moderate their impact on global aggregation (i.e., reduce variance), and the aggregation principle of FedGSA can be described as follows:  
Assuming \(K\) clients involved in training, after \(t\) rounds of global iterations, then in \(t+1\) rounds, each client is trained based on the quasi-global model obtained under T rounds using local data to obtain its local model parameters \(\left\{w_{k}^{t+1}\right\}_{k=1}^{K}\), and the central server in the aggregation phase has two layers of aggregation for the client models:  
The first layer of aggregation aims to capture the similarity relationship between each client and quantify the impact of each client on the global model by assigning weights to its Pearson correlation coefficients among the clients, and for each client, a personalized model is formed based on its gradient similarity relationship with other clients using Equation (7):  
\[\widetilde{w}_{k}^{t+1}=\sum_{r=1}^{K}\rho_{k,r}w_{r}^{t+1} \tag{7}\]  
The second layer performs aggregation among the personalized models: the central server generates a new round of quasi-global models based on the final aggregation of Equation (8):  
\[w_{G}^{t+1}=\frac{1}{K}\sum_{k=1}^{K}\widetilde{w}_{k}^{t+1} \tag{8}\]  
where \(\rho_{k,r}\) denotes the Pearson correlation coefficient between two models of \(K\) clients, \(\widetilde{w}_{k}^{t+1}\) denotes the new personalized model parameters of each client obtained in \(t+1\) round after the weighting operation of comparing the gradient similarity of each client in the round, and \(w_{G}^{t+1}\) denotes the quasi-global model parameters finally generated in the round.