# Node Screening Method Based on Federated Learning with IoT in Opportunistic Social Networks
## 3 Methods
### Description of the Transmission Process  
The focus of the transmission process in the community lies in the selection of nodes. In terms of node selection, we mainly design and select schemes and algorithms based on federated learning. As mentioned above, the composition of a computing network includes terminal equipment, micro base stations, macro base stations, and computing servers. In the terminal equipment, we must first perform local training. For a task \(\lambda\in\Lambda\), define the total data set related to the task as  
\[U_{\lambda}=\sum_{m\in M_{\lambda}}\sum_{n\in N_{\lambda}}U_{m,n} \tag{3}\]When the terminal device \(n\) is performing the local training task \(\lambda\), the loss function can be expressed as  
\[U_{\lambda}=\sum_{m\in M_{\lambda}}\sum_{n\in N_{\lambda}}U_{m,n} \tag{4}\]  
When the terminal device \(n\) is performing the local training task \(\lambda\), the loss function can be expressed as \(d^{\lambda}_{m,n}(x_{m,n},y_{m,n};\mu_{m,n})\), This can represent the difference between its predicted value on the sample data set \(U_{m,n}\) and the true value, so the loss function of task \(t\) in all data sets can be defined as:  
\[D^{\lambda}(\mu)=\frac{1}{|U_{\lambda}|}\sum_{m\in M_{\lambda}}d^{\lambda}_{m,n}(x_{m,n},y_{m,n};\mu_{m,n}) \tag{5}\]  
where \(\mu\) is the weight of the current training model \(|U_{\lambda}|\) represents the size of the training data set. The main purpose of federated learning in this transmission model is to minimize the loss function \(D^{\lambda}(\mu)\) of the task to optimize the global model parameters, which can be expressed as:  
\[\mu=argminD^{\lambda}(\mu) \tag{6}\]  
The parameters of federated learning in this article need to be updated, and the method of updating is gradient descent. This can also be expressed as randomly selecting a piece of data \(\{x_{m,n},y_{m,n}\}\) to update each time. This method can greatly reduce the amount of calculation, but because it is randomly selected, we also need to carry out enough local training to take care of the quality of the model. The update of model parameters can be expressed as  
\[\mu^{p}_{m,n}=\mu^{p}_{m,n}-\sigma\
abla d\left(\mu^{p-1}_{m,n}\right) \tag{7}\]  
Among them, \(\sigma\) represents the learning rate when the parameters are updated, and \(p\) is the number of iterations. When the local model calculation reaches a certain amount or the number of iterations reaches a certain amount, the server of the macro base station can perform global model aggregation on the local model. The specific weight aggregation can be expressed as:  
\[\mu^{*}_{a}=\mu_{a}+\sum_{m\in M_{\lambda}}\sum_{n\in N_{\lambda}}\frac{|U_{m, n}|(\mu^{*}_{m,n}-\mu_{m,n})}{|U_{\lambda}|} \tag{8}\]  
Among them, \(U_{m,n}\) represents the size of the data set of the terminal device \(n\) participating in the federated learning task. It can be seen that a terminal device with a larger data set has a larger weight. The selection of device nodes is affected by many factors. First, the differentiated computing and communication capabilities of terminal devices will directly affect the local training and data transmission delays. Second, the size of the data set of each terminal device in the opportunistic social network is also different, so this paper constructs a model of the optimal accuracy problem for node selection. The first thing to pay attention to is the accuracy rate. For a federated learning task \(\lambda\in\Lambda\), its training quality is defined as the test accuracy rate of the aggregated global model on the test data set. This article uses the sum of the loss functions of the test data set to express the test accuracy rate, it can be expressed as:  
\[S_{\lambda}=D^{\lambda}(x_{test},y_{test};\mu_{a}) \tag{9}\]  
Then consider the issue of time delay. The total delay of each model aggregation will include the training delay of the data on the terminal equipment and the transmission delay on the link.