## 6 Algorithm Design for Improved QoS
### Decentralized Algorithm Design  
Based on the above analysis, we propose (1) a data scheduling algorithm that can help maximize model utility within a latency constraint--curriculum learning is used in the algorithm with an adaptive moving window--and (2) an aggregation algorithm that can better reflect the diminishing marginal contribution effect with the data quantity to replace the one proposed by FedAvg. Both the valuation and marginal utility of data samples are considered in order to improve the test accuracy of the aggregated model.  
We first describe our curriculum data scheduling algorithm as the pseudo-code in Algorithm 1.  
Note that calculating \(S_{i,n,r}\) is basically model inference on \(\mathbf{d}_{n}\). The time complexity varies depending on the model structure. The time complexity of sorting operations for smartphone \(n\) is \(\mathcal{O}(\tilde{d}_{n}log(\tilde{d}_{n}))\).  
After local training on curriculum data, model weights \(\mathcal{W}_{r}\) are aggregated into a global model. Let \(\mathbf{w}_{r}^{U}\) and \(\mathbf{w}_{r}^{U}\) denote weights aggregated by considering marginal utility and information loss, respectively. We provide the pseudo-code for weight aggregation using blockchain-based data valuation in Algorithm 2.  
```
0: Global model weights \(\mathbf{w}_{r}\), private local dataset \(\mathbf{d}_{n}\) and latency requirement \(T_{n}\).
0: Local training dataset for the current round \(\mathbf{d}_{n,r}\).
1:for instance \((\mathbf{x}_{n,i},y_{n,i})\in\mathbf{d}_{n}\)do// obtain difficulty score.
2: Calculate \(S_{i,n,r}\) by (20);
3:endfor
4: Sorting \(\mathcal{S}_{n,r}\) in ascending order.
5: Obtain \(\mathbf{\hat{d}}_{n,r}\) by sorting \(\mathbf{d}_{n}\) accordingly.
6: Obtain \(\mathbf{d}_{n,r}\) according to (26).
```  
**Algorithm 1** Proposed curriculum data scheduling for any smartphone \(n\) in round \(r\).  
```
0: Model weights \(\mathbf{w}_{r-1}\), \(\mathcal{W}_{r}\) and data quantity \(\mathcal{D}_{r}\).
0: Global weights \(\mathbf{w}_{r}\).
1:for smartphone \(n\in\mathcal{N}\)do// decentralized data valuation.
2:for\(i\in\mathcal{N}\), \(i\
eq n\)do
3: Calculate \(\Phi_{i,n,r}\) by (14);
4:endfor
5:endfor
6:for server \(m\in\mathcal{M}_{D}\)do// delegated servers conduct model aggregation.
7:if\(m=r+L\pmod{M_{D}}\)then// a round-robin leader conducts aggregation.
8:for\(n\in\mathcal{N}\)do
9: Calculate \(V_{n,r}\) by (15);
10: Calculate \(C_{n,r}\) by (19);
11:endfor
12:\(V_{r}\leftarrow\sum_{n\in\mathcal{N}}V_{n,r}\);
13:\(C_{r}\leftarrow\sum_{n\in\mathcal{N}}C_{n,r}\);
14:\(\mathbf{w}_{r}^{V}\leftarrow\mathbf{w}_{r-1}-\eta_{r}\sum_{n\in\mathcal{N}}\frac{V_{n,r}}{\mathcal{W}_{r}^{V}}\mathcal{S}_{n,r}\);// aggregation by valuation of data samples.
15:\(\mathbf{w}_{r}^{U}\leftarrow\mathbf{w}_{r-1}-\eta_{r}\sum_{n\in\mathcal{N}}\frac{C_{n,r}}{\mathcal{C}_{r}}\mathcal{S}_{n,r}\);// aggregation by data marginal utility.
16:if\(\mathbf{w}_{r}^{V}\) results in greater validation accuracy then
17:\(\mathbf{w}_{r}\leftarrow\mathbf{w}_{r}^{V}\);
18:else
19:\(\mathbf{w}_{r}\leftarrow\mathbf{w}_{r}^{C}\).
20:endif
21:endif
22:endfor
```  
**Algorithm 2** Proposed aggregation algorithm for round \(r\).  
We choose to apply two aggregation protocols separately in every round. Global weights \(\mathbf{w}_{r}\) are obtained by comparing the utilities of aggregated weights \(\mathbf{w}_{r}^{U}\) and \(\mathbf{w}_{r}^{V}\), i.e., \(\sum_{n\in\mathcal{N}}\mathcal{A}(\mathbf{w}_{r}^{U},\mathbf{d}_{n}^{\text{val}})\) and \(\sum_{n\in\mathcal{N}}\mathcal{A}(\mathbf{w}_{r}^{V},\mathbf{d}_{n}^{\text{val}})\). Our scheme is shown to be effective in Section 7.