# FedCrow: Federated-Learning-Based Data Privacy Preservation in Crowd Sensing
## 3 FedCrow Design
### The Contribution-Level-Based Legitimate User Selection Approach  
Regardless of the method employed, data security threats stem from malicious users who attempt to disrupt the system's model accuracy by engaging in abnormal training or uploading incorrect data. Furthermore, they may exploit vulnerabilities to steal other users' data through gradient analysis, posing serious security risks. Typically, the number of malicious users is small, and their contribution to the overall model on the server is minimal or negative. Leveraging this principle, the similarity between the gradients of the models contributed by participating users and the total model on the server is computed. A low similarity indicates unreliability, thereby effectively filtering out legitimate users and reducing the attack threats posed by malicious users. The approach proposed in this paper measures the contribution level of different clients to the aggregated model based on gradients. It uses cosine similarity to calculate the similarity between the client model and the aggregated model, and uses this similarity to quantify the client's contribution level. In gradient-based learning, high-quality client gradients typically exhibit a high similarity to the total model gradient, indicating minimal model loss. Conversely, low-quality client gradients demonstrate lower similarity to the total model gradient, suggesting greater model loss. In order to locate the minimum point of the loss function, first-order optimization can be achieved using the gradient descent method. This method involves searching in the opposite direction until reaching a local minimum, enabling the identification of the lowest point and the values of model parameters. Through iterative processes of gradient ascent and gradient descent, local optimal solutions can be effectively discovered to assess the similarity of models or data. The gradient describes the direction of the derivative of the function at a specific location, which reflects the speed and rate of change of the function. In [37], the gradient value was leveraged as structural information in images, leading to the proposal of two structural similarity algorithms: gradient structural similarity (GSSIM) and gradient structural dissimilarity (GSSD), both of which have demonstrated significant achievements in evaluating images with certain types of distortions. The neural network structure is illustrated in Figure 1. To solve for the minimum loss function, the gradient descent method is employed to compute and update the weight matrix W. The weight matrix is a parameter matrix obtained through continuous updates. By calculating the similarity of the weight matrix, inferences can be made about the similarity of gradients. Directly utilizing the weight parameters can reduce the computational energy required for recalculating gradients, thereby lowering the system burden. This study investigated the contribution of different clients to the overall model after model aggregation from the perspective of gradients. The cosine similarity was utilized to compute the similarity between client models and the overall model, and the similarity was used to calculate the reputation scores of clients. The calculation of the loss function for a simple linear regression model is represented by Formula (1). \(L(w,b)\) is the loss function, which measures the discrepancy between the model's predicted values and the actual values. \(\frac{1}{N}\sum_{i=1}^{N}\) represents the average across all samples, where \(N\) is the number of  
Figure 1: Neural network architecture. samples. \(y_{i}\) represents the true label of the \(i\)th sample. \(f(w_{xi}+b)\) is the model's prediction for the \(i\)th sample, where \(w\) is the weight of the feature and \(b\) is the bias. \((y_{i}-f(w_{xi}+b))^{2}\) represents the square of the difference between the actual value \(y_{i}\) and the model's predicted value \(f(w_{xi}+b)\). This is commonly known as the mean squared error (MSE) loss function.