# Fed-Hetero: A Self-Evaluating Federated Learning Framework for Data Heterogeneity
## 5 Experiment Setup
### Data heterogeneity Estimation
#### 5.4.2 Estimate Label Distribution Skew  
To estimate label distribution skew, based on the weight divergence factor the server requests the probability distribution \(P_{D_{m_{0}}},P_{D_{m_{1}}}\) for each class from all the clients. The comparison of the label distributions using the Jensen-Shannon Divergence (JSD) is given below as follows:  
Let \(P_{D_{m_{0}}}\) and \(P_{D_{m1}}\) represent the probability distributions of class 0 and class 1 in client \(m\), respectively, where m = no. of the clients.  
The probabilities can be defined as follows:  
\[P_{D_{m_{0}}} =\frac{n_{0}^{(D_{1})}}{N^{(D_{1})}}\] \[P_{D_{m1}} =\frac{n_{1}^{(D_{1})}}{N^{(D_{1})}}\]  
where \(n_{i}^{(D)}\) is the count of instances for class \(i\) in client \(m\), and \(N^{(m)}\) is the total number of instances in client \(C\). Each client computes the \(P_{D_{m_{0}}}\) and \(P_{D_{m_{1}}}\), which is then sent to the server. Based on the probabilities received from the clients, the server calculates the JSD between the four distributions for each class as follows:  
\(P_{D_{m1}}^{(0)}\), \(P_{D_{m2}}^{(0)}\), \(P_{D_{m1}}^{(1)}\), \(P_{D_{m2}}^{(1)}\) are the probability distributions for class 0 and class 1 in datasets \(D_{m1}\), \(D_{m2}\) associated with clients 1 to \(m\) where \(m1\), \(m2\) represent a pair of clients. \(\text{JSD}_{\text{Class}\,0}(P_{D_{m1}}^{(0)}\parallel P_{D_{m2}}^{(0)})\) and \(\text{JSD}_{\text{Class}\,1}(P_{D_{m1}}^{(1)}\parallel P_{D_{m2}}^{(1)})\) are calculated for each class. Assume that the distributions \(P_{D_{m1}^{(0)}}\), \(P_{D_{m2}^{(0)}}\) for class 0, and \(P_{D_{m1}^{(1)}}\), \(P_{D_{m2}^{(1)}}\) for class 1 over the same domain \(\mathcal{X}\).  
For Class 0, compute the average distribution:  
\[M^{(0)}(x)=\frac{1}{2}\Big{(}P_{D_{m1}}^{(0)}(x)+P_{D_{m2}}^{(0)}(x)\Big{)} \quad\forall x\in\mathcal{X} \tag{27}\]  
Compute the KL divergences for Class 0:  
\[\text{KL}_{\text{D}}(P_{D_{m1}}^{(0)}\parallel M^{(0)})=\sum_{x\in\mathcal{X }}P_{D_{m1}}^{(0)}(x)\log\frac{P_{D_{m1}}^{(0)}(x)}{M^{(0)}(x)} \tag{28}\]  
\[\text{KL}_{\text{D}}(P_{D_{m2}}^{(0)}\parallel M^{(0)})=\sum_{x\in\mathcal{X }}P_{D_{m2}}^{(0)}(x)\log\frac{P_{D_{m2}}^{(0)}(x)}{M^{(0)}(x)} \tag{29}\]  
Compute the Jensen-Shannon Divergence for Class 0:  
\[D_{j}S,0=\frac{1}{2}\Big{(}\text{KL}(P_{D_{m1}}^{(0)}\parallel M^{(0)})+ \text{KL}(P_{D_{m2}}^{(0)}\parallel M^{(0)})\Big{)} \tag{30}\]Similarly, compute the average distribution for Class 1:  
\[M^{(1)}(x)=\frac{1}{2}\Big{(}P^{(1)}_{D_{m1}}(x)+P^{(1)}_{D_{m2}}(x)\Big{)}\quad \forall x\in\mathcal{X} \tag{31}\]  
Compute the KL divergences for Class 1:  
\[KL_{\text{D}}(P^{(1)}_{D_{m1}}\parallel M^{(1)})=\sum_{x\in\mathcal{X}}P^{(1)} _{D_{m1}}(x)\log\frac{P^{(1)}_{D_{m1}}(x)}{M^{(1)}(x)} \tag{32}\]  
\[KL_{\text{D}}(P^{(1)}_{D_{m2}}\parallel M^{(1)})=\sum_{x\in\mathcal{X}}P^{(1)} _{D_{m2}}(x)\log\frac{P^{(1)}_{D_{m2}}(x)}{M^{(1)}(x)} \tag{33}\]  
Compute the Jensen-Shannon Divergence for Class 1:  
\[D_{j}S,1=\frac{1}{2}\Big{(}\text{KL}(P^{(1)}_{D_{m1}}\parallel M^{(1)})+\text {KL}(P^{(1)}_{D_{m2}}\parallel M^{(1)})\Big{)} \tag{34}\]  
\[R_{I0}=\begin{cases}D_{j}S,0<0.1&\text{No label skew}\\ D_{j}S,0>0.4&\text{label skew}\end{cases} \tag{35}\]  
\[R_{I1}=\begin{cases}D_{j}S,1<0.1&0-\text{No label skew}\\ D_{j}S,1>0.4&1-\text{label skew}\end{cases} \tag{36}\]  
JSD [39] is a measure of similarity between two probability distributions. A JSD value near to zero indicates similar distributions and, as the value moves toward 1, this indicates dissimilar distributions. Based upon the \(D_{j}S,0\), \(D_{j}S,1\) value of each classes 0, 1 as shown in Equations (35) and (36), the server can provide recommendations \(R_{l}\) to clients such that they can improve the number of samples with respect to each class using data augmentation [28].