# Joint Resource Allocation and Learning Optimization for UAV-Assisted Federated Learning
## 3 Joint Optimization Algorithm
### Subproblem 3: User Computation and Communication Resources
#### 3.3.2 Subproblem 3-1: \(\mathbf{b}\) Optimization Problem
```
1:Input: \(\textbf{f}^{(0)}\textbf{t}^{(0)}\textbf{p}^{(0)}\textbf{b}^{(0)}\) iteration \(r_{4}=0\), maximum iterations \(r_{4}^{\text{max}}\)
2:Output: \(\textbf{f}^{*}\textbf{p}^{*}\textbf{b}^{*}\)
3:while\(r_{4}<r_{4}^{\text{max}}\)
4: Fixed **b**, according to Algorithm 3 to obtain **f**, **t**, **p**
5: Fixed **f**, **t**, **p**, according to Algorithm 4 to obtain **b**
6: Set \(r_{4}=r_{4}+1\)
7:endwhile
```  
**Algorithm 5** Iterative Algorithm for Communication and Computing Resources  
```
1:Input: \(\textbf{f}^{(0)}\textbf{t}^{(0)}\textbf{p}^{(0)}\textbf{b}^{(0)}\) iteration \(r_{4}=0\), maximum iterations \(r_{4}^{\text{max}}\)
2:Output: \(\textbf{f}^{*}\textbf{p}^{*}\textbf{b}^{*}\)
3:while\(r_{4}<r_{4}^{\text{max}}\)
4: Fixed **b**, according to Algorithm 3 to obtain **f**, **t**, **p**
5: Fixed **b**, according to Algorithm 3 to obtain **f**, **t**, **p**
6: Fixed **f**, **t**, **p**, according to Algorithm 4 to obtain **b**
7: Set \(r_{4}=r_{4}+1\)
8:endwhile
```  
**Algorithm 6** Iterative Algorithm for Communication and Computing Resources  
```
1:Input: \(\textbf{f}^{(0)}\textbf{t}^{(0)}\textbf{p}^{(0)}\textbf{b}^{(0)}\) iteration \(r_{4}=0\), maximum iterations \(r_{4}^{\text{max}}\)
2:Output: \(\textbf{f}^{*}\textbf{p}^{*}\textbf{b}^{*}\)
3:while\(r_{4}<r_{4}^{\text{max}}\)
4: Fixed **b**, according to Algorithm 3 to obtain **f**, **t**, **p**
5: Fixed **b**, according to Algorithm 3 to obtain **f**, **t**, **p**
6: Fixed **b**, according to Algorithm 3 to obtain **f**, **t**, **p**
7: Fixed **b**, according to Algorithm 3 to obtain **f**, **t**, **p**
8: Fixed **b**, according to Algorithm 3 to obtain **f**, **t**, **p**
9: Fixed **b**, according to Algorithm 3 to obtain **f**, **t**, **p**
10:endif
11:endwhile
```  
**Algorithm 7** Iterative Algorithm for Communication and Computing Resources  
```
1:Input: \(\textbf{f}^{(0)}\textbf{t}^{(0)}\textbf{p}^{(0)}\textbf{b}^{(0)}\) iteration \(r_{4}=0\), maximum iterations \(r_{4}^{\text{max}}\)
2:Output: \(\textbf{f}^{*}\textbf{p}^{*}\textbf{b}^{*}\)
4:while\(r_{4}<r_{4}^{\text{max}}\)
5: Fixed **b**, according to Algorithm 3 to obtain **f**, **t**, **p**
6: Fixed **b**, according to AlgorithmThrough Algorithms 1,2 and 5 iterations, the final converged solution is obtained, and then according to the \(\Delta h_{\min}\) change the altitude of the UAV, repeat three subproblem iterative process, until the UAV altitude \(h\) exceeds \(h^{\max}\). Eventually, return \(\mathbf{q}_{m}^{*}\), \(h^{*}\), \(\mathbf{f}^{*}\), \(\mathbf{t}^{*}\), \(\mathbf{p}^{*}\), \(\mathbf{b}^{*}\), \(\eta^{*}\) when the P1 objective function is optimal. The overall iterative algorithm flow is shown in Algorithm 6. ```
1:Initial feasible solution \(\mathbf{q}_{m}^{(0)}\), \(\mathbf{f}^{(0)}\), \(\mathbf{t}^{(0)}\), \(\mathbf{p}^{(0)}\), \(\mathbf{b}^{(0)}\), \(\eta^{(0)}\)
2:repeat
3:Set \(h=h^{\min}\)
4:repeat
5:Fixed \(\mathbf{f}^{(j)}\), \(\mathbf{t}^{(j)}\), \(\mathbf{p}^{(j)}\), \(\mathbf{b}^{(j)}\), \(\eta^{(j)}\), according to Algorithm 1 to obtain \(\mathbf{q}_{m}^{(j+1)}\)
6:Fixed \(\mathbf{f}^{(j)}\), \(\mathbf{t}^{(j)}\), \(\mathbf{p}^{(j)}\), \(\mathbf{b}^{(j)}\), \(\mathbf{q}_{m}^{(j+1)}\), according to Algorithm 2 to obtain \(\eta^{(j+1)}\)
7:Fixed \(\mathbf{q}_{m}^{(j+1)}\), \(\eta^{(j+1)}\), according to Algorithm 5 to obtain \(\mathbf{f}^{(j+1)}\), \(\mathbf{t}^{(j+1)}\), \(\mathbf{p}^{(j+1)}\mathbf{b}^{(j+1)}\)
8:Set \(j=j+1\)
9:until P1 objective converges
10:Set \(h=h+\Delta h_{\min}\)
11:until \(h>h^{\max}\)
12:return\(\mathbf{q}_{m}^{*}\), \(\mathbf{f}^{*}\), \(\mathbf{t}^{*}\), \(\mathbf{p}^{*}\), \(\mathbf{b}^{*}\), \(\eta^{*}\) when P1 objective function is optimal
```

**Algorithm 6** Overall Iterative Algorithm

## 4 Simulation Results and Performance Analysis

In this paper, we used python to simulate the proposed algorithm, and used pytorch to build the convolutional neural network to verify the performance of FL.