# Enhancing Heart Disease Prediction with Federated Learning and Blockchain Integration
## 2 Background
### Federated Learning
#### 2.2.2 Federated Averaging Algorithm  
The computation of the federated averaging algorithm is controlled by three key parameters: parameter \(\rho\), which refers to the fraction of clients that perform computations in each round; parameter \(S\), which refers to the number of training steps performed by each client on the local dataset in each round; and parameter \(M\), which refers to the size of the mini-batch used for client updates. We use \(M=\infty\) to denote that the complete local dataset is processed as a batch. In this algorithm, \(\rho\) controls the global batch size. When \(\rho=1\), it indicates gradient descent (non-random selection of training data) using the full training data (also known as full-batch gradient descent) on all data owned by all participants. We still select the batch by using all the data on the selected participants. This baseline algorithm is known as FederatedSGD, where gradients are computed and sent to the server, assuming that the datasets owned by different participants are independently and identically distributed (IID-compliant) and that the batch selection mechanism differs from random selection. In federated learning with \(k\) participants, the goal is to have collaborative optimization of the empirical loss function:  
\[L(w)=\frac{1}{|D|}\sum_{k=1}^{K}|D_{k}|\cdot L_{k}(w) \tag{1}\]  
Figure 1: Horizontal federated learning system overview.  
where \(|D_{k}|\) is a dataset for participant \(k\), \(D\) is the union of all datasets for \(K\) participants, and \(L_{k}(w)\) is the local loss function computed over \(|D_{k}|\) for participant \(k\).  
In the federated learning setup, the initial global model weights \(w_{0}\) are distributed to all clients at the beginning of training. These initial weights are randomly initialized or derived from a pre-trained model, ensuring all participants begin with the same parameters before local updates. Once the initial weights are distributed, the central coordinator (or server) manages the training process. Participants update their local models during each round using distributed gradient descent with a fixed learning rate \(\eta\). Each participant \(k\) computes \(g_{k}=\
abla L_{k}(w_{t})\), the average gradient of its local data at the current model parameter \(w_{t}\). The coordinator aggregates these gradients and updates the global model parameters as follows:  
\[w_{t+1}\gets w_{t}-\eta\sum_{k=1}^{K}\frac{|D_{k}|}{|D|}g_{k} \tag{2}\]  
In Equation (2), \(g_{k}=\
abla L_{k}(w_{t})\) represents the direction of the steepest increase in the loss function. By subtracting the gradient, the model parameters \(w_{t}\) move in the direction that reduces the loss, which is the core principle of gradient descent. The term \(\eta\) is the learning rate, which determines the size of the step taken toward the negative gradient. This update rule ensures that the weights are adjusted to minimize the loss function, improving the model's performance over time. The coordinator can send the updated model parameters \(w_{t+1}\) to the participants or send the average gradient to compute the updated model locally. This method, known as gradient averaging, works similarly to model averaging. We use an equivalent federated model training method [18]:  
\[\forall k,\,w_{t+1}^{(k)}\leftarrow\overline{w}_{t}-\eta g_{k} \tag{3}\]  
\[\overline{w}_{t+1}\leftarrow\sum_{k=1}^{K}\frac{n_{k}}{n}w_{t+1}^{(k)} \tag{4}\]  
where \(n_{k}\) is the number of data points in \(D_{k}\), and \(n\) is the number of data points in \(D\). Each client performs one or more steps of gradient descent locally and sends the updated parameters back to the server, which computes a weighted average and sends the aggregated model parameters to all participants.