# Federated Few-Shot Learning-Based Machinery Fault Diagnosis in the Industrial Internet of Things
## 4 Proposed Method
### Federated Learning Process  
In the subsequent section, we present the federated training process for the CDAE-MN algorithm, denoted as FedCDAE-MN. As shown Algorithm 1, FedCDAE-MN operates through the following steps:  
1. Initialization of Global Parameters. The centralized cloud server initializes the global model parameters \(\theta_{E}(0)\), \(\theta_{D}(0)\), \(\theta_{C}(0)\), and \(\theta_{M}(0)\).
2. Parameters Broadcasting. The cloud server broadcasts the global model parameters \(\theta_{E}(0)\), \(\theta_{D}(0)\), \(\theta_{C}(0)\), and \(\theta_{M}(0)\) to the source domains.
3. Local Supervised Learning. For each source domain, a batch of data \(D^{s,i}\) is randomly selected, and batch training is employed to update parameters. This update is carried out using Equation (2) to obtain new local model parameters \(\theta_{E}^{s,i}(k+1)\), \(\theta_{D}^{s,i}(k+1)\), and \(\theta_{C}^{s,i}(k+1)\).
4. Upload Local Parameters. The new local model parameters \(\theta_{E}^{s,i}(k+1)\), \(\theta_{D}^{s,i}(k+1)\), and \(\theta_{C}^{s,i}(k+1)\) are uploaded to the cloud sever for each source domain.
5. Global Model Update. The cloud aggregates the parameters according to Equation (3). These steps (2 to 5) are repeated until the specified number of iterations is reached.
6. Fixing \(\theta_{E}\) Parameters. The parameters of \(\theta_{E}\) are fixed at this stage.
7. Local Feature-Space Metric Learning. From the local data \(D^{s,i}\), source domains extract \(t\) few-shot tasks and update the parameters using Equation (8). This process yields new local metric module parameters \(\theta_{M}^{s,i}(k+1)\).
8. Upload Local Parameters. The new local model parameters \(\theta_{M}^{s,i}(k+1)\) are uploaded to the cloud server for each source domain.
9. Global Model Update. The cloud aggregates parameters according to Equation (9).  
These steps are repeated iteratively until the desired convergence is achieved.  
```
1:Local dataset of each domain: \(D^{s,i}\); Learning rate of supervised learning: \(\alpha_{B}\); Learning rate of feature-space learning: \(\alpha_{M}\); Iteration of supervised learning: \(N_{E}\); Iteration of feature-space learning: \(N_{M}\); Number of tasks in each iteration: \(t\);
2:\(\theta_{E}\)*\(,\theta_{M}\)*
3:Initialize \(\theta_{E},\theta_{D},\theta_{C},\theta_{M}\) randomly;
4:/* Federated Supervised Learning */
5:for\(k=1,2,\dots,N_{E}\)do
6: /* Source Domain */
7:for\(i=1,2,\dots,M\)do
8: Update \(\theta_{E}^{s,i}(k),\theta_{C}^{s,i}(k),\theta_{D}^{s,i}(k)\) according to Equation (2);
9: Upload \(\theta_{E}^{s,i}(k),\theta_{C}^{s,i}(k),\theta_{D}^{s,i}(k)\) to the server;
10:endfor
11: /* Centralized Cloud Server */
12: Obtain aggregated parameters \(\theta_{E}(k),\theta_{C}(k),\theta_{D}(k)\) according to Equation (3);
13: Send \(\theta_{E}(k),\theta_{C}(k),\theta_{D}(k)\) to each source domain;
14:endfor
15: Fix \(\theta_{E}\) as the subsequent feature extractor;
16:/* Federated Feature-Space Learning */
17:for\(k=1,2,\dots,N_{M}\)do
18:for\(i=1,2,\dots,M\)do
19: /* Source Domain */
20: Select few-shot tasks \(T^{s,i}=\{T_{a}^{s,i}\}_{a=1}^{t}\) from \(D^{s,i}\);
21: Update \(\theta_{M}^{s,i}(k)\) according to Equation (8);
22:endfor
23: /* Centralized Cloud Server */
24: Obtain aggregated parameters \(\theta_{M}(k)\) according to Equation (9);
25: Send \(\theta_{M}(k)\) to each source domain;
26:endfor
27:return\(\theta_{E}\)*\(,\theta_{M}\)*;
```  
**Algorithm 1** Federated training process of CDAE-MN