# A Trusted Federated Incentive Mechanism Based on Blockchain for 6G Network Data Security
## 3 Isfl-Sys Architecture
### Effl Federated Learning Mechanism
#### 3.3.2 Trust Scoring Method  
**(1) Cosine Similarity Evaluation Method:** Common similarity measurement methods involve using cosine similarity between two gradients to quantify their directional similarity [26]. In an \(n\)-dimensional vector space, given two attribute vectors \(A\) and \(B\), their cosine similarity is calculated based on their dot product and vector magnitudes, with the formula as follows:  
\[similarity(A,B)=cos(\theta)=\frac{A\cdot B}{\|A\|\|B\|}=\frac{\sum_{i=1}^{n}A _{i}\times B_{i}}{\sqrt{\sum_{i=1}^{n}(A_{i})^{2}}\times\sqrt{\sum_{i=1}^{n}( B_{i})^{2}}}, \tag{4}\]  
where the \(A_{i}\),\(B_{i}\) represent the respective components of vectors \(A\) and \(B\). The resulting similarity ranges from \(-1\) to \(1\), where \(-1\) signifies that the two vectors point in completely opposite directions, \(1\) indicates that they point in exactly the same direction, \(0\) typically represents that they are independent (as in perpendicular), Values within the range of \(-1\) to \(1\) represent the similarity or dissimilarity between the two entities. To facilitate the understanding of the calculation method for two vectors in an \(n\)-dimensional vector space, Figure 5 illustrates the cosine similarity calculation method in two-dimensional and three-dimensional vector spaces. As shown in the above figure, when the angle between two vectors is \(0\) degrees, indicating that their directions align perfectly, the cosine value is \(1\), signifying complete reliability. When the angle is \(90\) degrees, the cosine value is \(0\), implying no contribution to the global model aggregation and, hence, a lack of credibility. When the angle falls between \(0\) and \(90\) degrees, the cosine value is inversely proportional to the magnitude of the angle. Similarly, the obtained cosine value serves as a trust score. To mitigate the negative impact of cosine similarity (resulting from reverse updates of model gradients), it is common practice to employ the Rectified Linear Unit (\(ReLU\)) function to clip the data range of cosine similarity. The final cosine similarity value obtained  
Figure 5: Cosine similarity evaluation method for vectors in two-dimensional and three-dimensional spaces. in this manner is referred to as the trust score. When the angle between the two vectors falls within the range of 0 to 90 degrees, the cosine value ranges from 0 to 1. Defined by the following formula,  
\[TS_{i}=ReLU(c_{i})=similarity(A,B), \tag{5}\]  
\(c_{i}\) represents the cosine similarity between the gradients of the two models in the i-th round, while \(TS_{i}\) denotes the trust score for client updates of gradients in the i-th round. The cosine similarity values are constrained by the \(ReLU\) function, as illustrated in Figure 6.  
**(2) Euclidean Distance Evaluation Method:** A novel approach has been devised for assessing Euclidean distances, which measures the degree of similarity between two vectors. It is defined as follows: For two vectors with the same magnitude, the smaller the straight-line distance between their endpoints, the more similar the vectors are. In other words, upon standardizing the vectors' magnitudes, the Euclidean distance becomes directly proportional to the size of the angle. Similarly to the previous explanation, our new Euclidean distance evaluation method is depicted in Figure 7.  
Assuming that all normalized model gradient vectors involved in the evaluation have a magnitude of m, the maximum Euclidean distance between the server model and the client model is 2 m. To account for the potential malicious feedback caused by opposing model update trends, the same \(ReLU\) function is used to clip the data range of the Euclidean distance. After removing the malicious models with reverse updates, the range of Euclidean distance values between the server model and the client model becomes \(\left[0,\sqrt{2}m\right]\). The mapping relationship between Euclidean distance and model vector similarity is depicted in Figure 8.  
Figure 6: Clipping cosine similarity.