## 6 Federated Learning for Early Health Prediction
### Federated Learning Methodology
The weighted averaging approach can be represented mathematically as follows:  
\[W=\sum_{i=1}^{N}\alpha_{i}\cdot w_{i}\]  
Here:  
* \(\alpha_{i}\) represents the weight assigned to the edge device \(i\). Factors such as the amount of locally available data and the computational capacity of the edge device are considered in determining these weights. * \(\sum\) represents the sum of the weighted local models across all edge devices. In this method, the local models are consolidated through the use of weighted averaging, where each edge device's individual input to the global model is adjusted in proportion to its corresponding weight [83]. In this way, edge devices with more relevant or accurate data can impact the global model more. Algorithm 2 below shows how the weighted averaging method can be used in federated learning with edge devices. In Algorithm 1, federated learning with averaging, the gradient updates (\(\
abla F(w_{i})\)) received from each edge device \(i\) are equally weighted during aggregation (computation of the aggregate gradient update as \(\Delta w_{i}=\frac{1}{N}\
abla F(w_{i})\). This means that each local model's contribution to the global model update is treated identically. ```
1:Global model \(W\), Edge devices \(\{1,2,\dots,N\}\), Learning rate \(\eta\), Rounds \(T\)
2:Updated global model \(W\)
3:Initialize global model \(W\)
4:for\(t=1\) to \(T\)do
5: Send global model \(W\) to all edge devices
6:for each edge device \(i\) in \(\{1,2,\dots,N\}\)do
7: Receive local model \(w_{i}\) from edge device \(i\)
8: Compute gradient \(\
abla F(w_{i})\) on local model \(w_{i}\)
9:endfor
10: Initialize aggregated gradient \(\Delta W=0\)
11:for each edge device \(i\) in \(\{1,2,\dots,N\}\)do
12: Compute gradient update \(\Delta w_{i}=\frac{1}{N}\
abla F(w_{i})\)
13: Aggregate gradient updates: \(\Delta W=\Delta W+\Delta w_{i}\)
14:endfor
15: Update global model: \(W=W-\eta\cdot\Delta W\)
16:endfor
17:Return Updated global model \(W\)
```  
**Algorithm 1** Federated Learning with Averaging  
```
1:Global model \(W\), Edge devices \(\{1,2,\dots,N\}\), Learning rate \(\eta\), Rounds \(T\)
2:Updated global model \(W\)
3:Initialize global model \(W\)
4:for\(t=1\) to \(T\)do
5: Send global model \(W\) to all edge devices
6:for each edge device \(i\) in \(\{1,2,\dots,N\}\)do
7: Receive local model \(w_{i}\) from edge device \(i\)
8: Compute gradient \(\
abla F(w_{i})\) on local model \(w_{i}\)
9: Compute weight \(\alpha_{i}\) based on device-specific factors
10:endfor
11: Initialize aggregated gradient \(\Delta W=0\)
12:for each edge device \(i\) in \(\{1,2,\dots,N\}\)do
13: Compute weighted gradient \(\Delta w_{i}=\alpha_{i}\cdot\
abla F(w_{i})\)
14: Aggregate weighted gradient: \(\Delta W=\Delta W+\Delta w_{i}\)
15:endfor
16: Update global model: \(W=W-\eta\cdot\Delta W\)
17:endfor
18:Return Updated global model \(W\)
```  
**Algorithm 2** Federated Learning with Weighted AveragingIn Algorithm 2, federated learning with weighted averaging, we introduce the concept of device-specific factors or weights, denoted as \(\alpha_{i}\), for each edge device \(i\). These factors are based on device-specific characteristics or criteria. The local models' gradient updates are multiplied by their respective weights before aggregation (weighted gradient \(\Delta w_{i}=\alpha_{i}\cdot\
abla F(w_{i})\)), and the aggregate weighted gradient is computed as \(\Delta W=\Delta W+\Delta w_{i}\). This allows for individualized contributions to the global model, accounting for device-specific considerations. Therefore, Algorithm 2 incorporates a level of customization not present in Algorithm 1. By introducing device-specific factors, it accommodates the potential variations among edge devices. This customization can be based on factors such as device capabilities, data quality, or performance history. Doing so provides a mechanism to incorporate this diversity into the federated learning process. _Secure aggregation_ methods emphasize privacy and security during the aggregation process.