## 5 Personalized FL with Multi-Level Privacy-Preserving IoT Knowledge Sharing  
### Multi-Level ACE-Based FL Process  
In an HBCE-FL system with multi-level ACE-based IoT knowledge sharing, a low-security-level server cannot communicate with high-security-level clients, while high-security-level servers can communicate with clients of the same or lower level. In other words, high-security-level servers can aggregate more local models to deliver better and more secure services to high-level users.  
The objective of FL is to train a single global model that minimizes the aggregate loss across all participating clients. Suppose there are \(K\) clients in the system, then the aim of FL is to solve:  
\[\min_{\theta}G(F^{1}(\theta),\dots,F^{K}(\theta)), \tag{10}\]  
where \(\theta\) is the model parameter that is being optimized across all clients. Each client optimizes its local objective function with respect to the same global parameter \(\theta\). Each client has a local data distribution \(D^{k}=P^{k}(x,y)\). The \(k\)th client has the optimization target:  
\[\min_{\theta}F^{k}(\theta)\overset{\Delta}{=}E_{(x^{k},y^{k})\sim D^{k}}[l(f( x^{k};\theta),y^{k})], \tag{11}\]  
where \(f\) is the prediction function, and \(l\) is the loss function. We use FedAvg [41], a standard FL aggregation method, that is:  
\[\min_{\theta}\sum_{k\in K}\frac{n_{k}}{\sum_{k}n_{k}}F^{k}(\theta), \tag{12}\]  
where \(n_{k}\) is the number of samples on the \(k\)th client. In each round of FedAvg, every client updates the model on its local dataset \(D^{k}\) using the stochastic gradient descent rule. \(W(j)=\{i|P(i,j)=1\}\) represents the set of clients \(i\) capable of sending messages to server \(j\). The Algorithms 2 and 3 outline the local training and cloud aggregation processes of the proposed multi-level ACE-based privacy-preserving FL. The client computes the local average loss function with the initialized model parameters (lines 2-4 in Algorithm 2) and locally takes one step of gradient descent on the current model (line 5 in Algorithm 2). It then executes the ACE\({}^{n}.Enc\) the algorithm to encrypt the new model parameter (lines 8-9 in Algorithm 2) to send to the server. The server executes the ACE\({}^{n}.Dec\) algorithm to decrypt the messages received from the clients containing FL parameter information (lines 1-2 in Algorithm 3). It then selects the client model parameters that comply with the access control rules and engages in the current aggregation process (lines 3-7 in Algorithm 3). Averaging the model parameters produces new parameters for distribution (line 9 in Algorithm 3).  
```
0: Local data \(D^{k}\), batch size \(B\), number of local epochs \(E\), initialized model parameters \(\theta_{s,t}\), and client encryption key \(ek\).
0: Ciphertext C.
1:\(\theta_{s,t}^{k}\leftarrow\theta_{s,t}\)
2:for local epoch \(e=1,2,\dots,E\)do
3:for each batch\(\{(x_{i}^{t},y_{i}^{t})\}_{i=1}^{B}\) sampled from \(D^{k}\)do
4:\(\mathcal{L}(\theta_{s,t}^{k},D^{k})=\frac{1}{B}\sum_{i=1}^{B}l(\theta_{s,t}^{k },x_{i}^{k},y_{i}^{k})\)
5:\(\theta_{s,t}^{k}\leftarrow\theta_{s,t}^{k}-\eta\
abla\mathcal{L}(\theta_{s,t}^ {k},D^{k})\)
6:endfor
7:endfor
8:\(m\leftarrow\theta_{s,t}^{k}\)
9:\(\mathcal{C}\leftarrow\) ACE\({}^{n}.Enc(ek,m)\)
10:return C
```  
**Algorithm 2** Client procedure.  
```
0: Maximum number of communication rounds \(T\), client selection ratio \(Q\), sanitized ciphertext \(C^{\prime}\), and server decryption key \(dk\).
0: The final aggregated global model \(\theta_{s,T+1}\)
1:for global round \(t=0,1,2,\ldots,T\)do
2:\(m^{\prime}\leftarrow\text{ACE}^{n}.Dec(dk,C^{\prime})\)
3:for\(k\in W\)do
4:\(\theta_{s,t}^{k}\gets m^{\prime}\)
5:\(S_{t}\leftarrow\text{sample}\max(Q\cdot k,1)\) clients
6:for\(k\in S_{t}\)do
7:\(C\leftarrow\text{Client Procedure}(k,\theta_{s,t}^{\prime})\)
8:endfor
9:\(\theta_{s,t+1}\leftarrow\sum_{k\in S_{t}}\frac{1}{|S_{t}|}\theta_{s,t}^{k}\)
10:endfor
11:endfor
12:return\(\theta_{s,T+1}\)
```  
**Algorithm 3** Server procedure.