# MDIFL: Robust Federated Learning Based on Malicious Detection and Incentives
## 3 Materials and Methods
### Incentive Mechanism
#### 3.2.1 Problem Formulation  
The resources consumed by participants can be divided into computing resources and communication resources [25]. The time it takes for participant \(P_{n}\) to iterate once in local model training is  
\[T_{n}^{cmp}=\frac{c_{n}s_{n}}{f_{n}} \tag{3}\]  
\(c_{n}\) is the number of CPU cycles for single data training, \(s_{n}\) is the size of the local data sample of participant \(P_{n}\), and \(f_{n}\) is the computing resource contributed by each participant \(P_{n}\) for local model training, that is, the CPU cycle frequency. The transfer rate of participant \(P_{n}\) can be expressed as  
\[r_{n}=Bln(1+\frac{\rho_{n}h_{n}}{N_{0}}) \tag{4}\]  
\(B\) is the transmission bandwidth, \(\rho_{n}\) is the transmission power of participant \(P_{n}\), \(N_{0}\) is the background noise, \(h_{n}\) is the channel gain of the peer-to-peer link between participant \(P_{n}\) and the aggregator. Considering the data size \(\sigma\) of the local model update as a constant, the transmission time of the local model update can be obtained as  
\[T_{n}^{com}=\frac{\sigma}{Bln(1+\frac{\rho_{n}h_{n}}{N_{0}})} \tag{5}\]  
In this way, the total time for a complete global iteration of participant \(P_{n}\) can be expressed as  
\[T_{n}^{t}=\tau T_{n}^{cmp}+T_{n}^{com} \tag{6}\]  
\(\tau\) is the number of local model update iterations. In addition, the CPU energy consumption of participant \(P_{n}\) is  
\[E_{n}^{cmp}(f_{n})=\zeta c_{n}s_{n}f_{n}^{2} \tag{7}\]  
\(\zeta\) denotes the effective capacitance parameter of the computing chipset of participant \(P_{n}\). The energy consumed by participant \(P_{n}\) to transmit local model updates in global iterations is  
\[E_{n}^{com}=T_{n}^{com}\cdot\rho_{n}=\frac{\sigma\rho_{n}}{Bln(1+\frac{\rho_ {n}h_{n}}{N_{0}})} \tag{8}\]  
The total energy consumption of a complete global iteration of participant \(P_{n}\) can be obtained as  
\[E_{n}^{t}=\tau E_{n}^{cmp}+E_{n}^{com} \tag{9}\]  
The types of participants can be divided into M categories, \(\theta_{1}<\theta_{2}<\theta_{3}<\cdots<\theta_{m}<\cdots<\theta_{M},n\in\{1 \dots M\}\). Among them, \(\theta_{m}\) represents the quality of the data that the participants have. The larger \(\theta_{m}\) means the higher the quality of the data the participants have, the higher the willingness to participate in the training. Similarly, participants can be divided into M categories from high to low according to the amount of data they have, \(s_{1}<s_{2}<s_{3}<\cdots<s_{m}<\cdots<s_{M},n\in\{1\dots M\}\). The larger \(s_{m}\) means the more data it has. That is to say, the participants of type M are the best participants, whereasthe participants of type 1 are relatively the worst. If participants provide more large and high-quality data, this will make the model performance higher. Model performance can be expressed as  
\[M(\theta_{n}s_{n})=1-e^{-\varphi(\theta_{n}s_{n})} \tag{10}\]  
\(\varphi\) is the weighting factor. Assuming that the number of participants in the model training task \(S\) is \(|S|\), the total profit function of the entire training task can be expressed as  
\[ \begin{split} p(s)&=\sum_{n=1}^{|S|}[(1-e^{-\varphi (\theta_{n}s_{n})})-G_{n}]\\ s.t.G_{n}&=\gamma E_{n}^{t}=\gamma(\tau\zeta c_{n} s_{n}f_{n}^{2}+\frac{\sigma\rho_{n}}{Bln(1+\frac{\rho_{n}h_{n}}{N_{0}})}) \end{split}  \tag{11}\]  
\(G_{n}\) is the cost consumed by the participants, and \(\gamma\) is the predefined weight parameter for energy consumption. Due to information asymmetry, for different types of participants with different data quality, the aggregator should design corresponding different types of contracts to maximize benefits. Therefore, we can obtain the maximized utility function of participant \(P_{n}\), as follows  
\[ \begin{split} maxU_{n}&=R_{n}-G_{n}+log(\omega \frac{p(s\backslash\{n\})}{p(s)}+1)\\ s.t.A_{n}&=log(\omega\frac{p(s\backslash\{n\})}{p (s)}+1)\end{split}  \tag{12}\]  
\(R_{n}\) and \(A_{n}\) are the corresponding contract rewards and extra income of type n participants, respectively.