# Federated Learning-Based Resource Management with Blockchain Trust Assurance in Smart IoT
## 4 Proposed FL-Based Resource Management with Blockchain Trust Assurance Algorithm
Since a nonlinear dynamic process requires a series of complex algorithms to be implemented [31], the linear regression FL algorithm is used in this paper in order to clearly analyze the performance of the proposed algorithm [32]. Define \(g_{0}\) as the global model, \(g_{i}\) as the local model, and \(p_{i}\) as the local model parameters. Assume that the output of the FL algorithm is \(z_{i}\) in local device \(i\). The input and output of the FL algorithm follow Equation (9):  
\[z=-2X+1+n\times 0.4 \tag{9}\]  
For different FL training tasks, different loss functions can be defined. For the FL linear regression FL algorithm in this paper, the loss function in Equation (10) can be simply defined as  
\[f(w_{j},X^{i},p_{i},z_{i})=\frac{1}{2}\big{(}w_{j}\cdot\text{res}_{i,j}\cdot p_{ i}-z_{i}\big{)}^{2} \tag{11}\]  
In Equation (11), \(w_{j}\cdot\text{res}_{i,j}\cdot p_{i}\) is the predicted output. Thus, the loss function is defined as the square of the prediction error. This indicates that the value of the loss function will increase sharply as the prediction error increases. Therefore, using the loss function as the performance indicator of the FL algorithm can clearly reflect the accuracy of the FL algorithm. The flowchart of the proposed FL-based resource management with the blockchain trust assurance algorithm is given in Figure 4. The detailed steps are as follows. _Step 1. The application initiates the resource request._  
The IoT application deployed in the MEC server invokes the FL server to initiate a resource request to the connected local IoT devices through the edge network. These local devices will eventually take on the role of task execution. _Step 2. Resource reporting and participant selection for FL training._  
The local devices that have received resource requests and agree to participate in FL training report their communication bandwidth, computing power, available storage size, data volume, and their energy status to the FL server. The FL server normalizes the various resources for each device and then aggregates them in a weighted manner to obtain the total resource R(i) of the device. The decision boundary is calculated using the SVM mechanism, and the classification is obtained by Equation (7). The trustworthiness of the local node is calculated by Equation (8). If the FL server judges that the node is a malicious node or an untrustworthy node, the node will not be selected to participate in the FL training. This selection mechanism is simple and fast, and can reflect the degree of influence of different types of resources on the selection of FL participants by adjusting the size of the weights. Moreover, by detecting and eliminating untrustworthy nodes from participating in FL model training, the long FL model training time can be avoided and the accuracy of the global model can be guaranteed. _Step 3. FL local model training update and the updated parameters are uploaded to the blockchain._  
Figure 4: The flowchart of the proposed algorithm. The local devices that have received confirmation of the FL training participant selection start the FL local training update. The first-round local model update is based on the local dataset, and subsequent updates will also be based on the global model updated parameters sent by the FL server. The updated model parameters are uploaded to the blockchain after the local model training is completed, and then the FL server obtains the updated local model parameters from the blockchain. _Step 4. FL server performs a global model update, and the updated parameters are uploaded to the blockchain._  
After the FL server obtains the local model updated parameters of all participant devices, it performs a global model update using the received trained local model parameters as well as application-related data. This is a synchronous update method. The global model updated parameters are uploaded to the blockchain, and then the local nodes obtain the global model updated parameters from the blockchain. _Step 5.