## 4 Statistical Methodology for Federated Learning
### Federated Averaging  
The Federated Averaging (FedAvg) algorithm is a key methodology in the field of federated learning [24], a distributed learning paradigm that allows the training of machine learning models without having to centralize the data. In this approach, several devices or clients, which can be smartphones, IoT sensors, or other edge computing entities, locally train a copy of the model using their own private data. The FedAvg process works using five macro-points:  
1. Initialization: The central server initializes the global model with initial weights and distributes it to all participating clients.
2. Local Training: Each client receives the global model and trains it locally on its data for a predefined number of epochs or iterations. This local training produces an updated set of weights specific to each client.
3. Sending Weights: Clients send their updated weights to the central server. During this process, only the model weights are transferred, while the raw data remain on local devices, thus preserving user privacy in a broad way.
4. Aggregation: The central server collects all updated weights from clients and calculates the weighted average of these weights to update the global model. Weighting can take into account the amount of local training data from each client, ensuring that clients with more data have a greater influence on updating the model.
5. Iteration: This process of deploying the global model, training locally, dispatching weights, and aggregating is repeated for a predefined number of rounds until the global model reaches a desired convergence or performance level.  
This is described with more detail--such as averaging formula--in Algorithm 1. The Federated Averaging algorithm's formula is  
\[w_{t+1}=\sum_{k=1}^{K}\frac{n_{k}}{n}w_{t+1}^{k}\]  
where \(w_{t+1}\) is the weight vector of the updated global model; \(K\) is the total number of participating devices; \(n_{k}\) is the number of data samples on the device \(k\); \(n=\sum_{k=1}^{K}n_{k}\) is the total number of data samples across all devices; \(w_{t+1}^{k}\) is the weight vector of the local model updated by the device \(k\) per round \(t+1\).  
This approach is particularly effective in heterogeneous and dynamic environments, such as those characterized by the use of IoT devices and edge computing described in this paper, as it reduces the need to transfer large volumes of data across the network and addresses issues related to data privacy and security data. Furthermore, the aggregation of weights allows to obtain a robust and generalized global model, exploiting the diversity of the data distributed among clients. The privacy is not automatically maintained by default, to introduce it, we need to implement advanced techniques such as Differential Privacy, which we will highlight in detail in Section 4.2.  
```
Data: Initial global model \(w_{0}\), number of clients \(K\), number of rounds \(T\) Result: Updated global model \(w_{T}\) forachround \(t=1,2,\ldots,T\)do forachclient \(k=1,2,\ldots,K\)inparalleldo \(w_{t+1}^{k}\leftarrow\text{Client Update}(k,w_{t})\) ; // Client \(k\) update the model \(w_{t+1}\leftarrow\frac{1}{K}\sum_{k=1}^{K}w_{t+1}^{k}\) ; // Weight Averaging
```  
**Algorithm 1**FedAvg: Federated Averaging Algorithm