Federated Similarity-guided Aggregation (FedSim) weights client contributions based on the similarity between their local models and the global model. This reduces the influence of divergent clients under heterogeneous data distributions.
The aggregation computes similarity-weighted updates:
\[w^{t+1} = \sum_{k=1}^{K} \omega_k^t \cdot w_k^t\]where the weights are computed using cosine similarity:
\[\omega_k^t = \frac{\text{sim}(w_k^t, w^t)}{\sum_{j=1}^{K} \text{sim}(w_j^t, w^t)}\]and the similarity function is:
\[\text{sim}(w_k, w) = \frac{\langle \text{vec}(w_k), \text{vec}(w) \rangle}{\|\text{vec}(w_k)\| \cdot \|\text{vec}(w)\|}\]where $\text{vec}(\cdot)$ flattens all parameters into a single vector.
The implementation is located at src/unbitrium/aggregators/fedsim.py.
Similarity weights sum to unity:
\[\sum_{k=1}^{K} \omega_k^t = 1\]Verification: Weight sum equals 1.0 within floating-point tolerance.
All weights are non-negative (assuming positive similarity):
\[\forall k: \omega_k^t \geq 0\]Verification: No negative weights produced under normal conditions.
Cosine similarity is bounded:
\[-1 \leq \text{sim}(w_k, w) \leq 1\]Verification: Raw similarity scores fall within $[-1, 1]$.
When all client models are identical to global:
\[\forall k: w_k = w \implies \omega_k = \frac{1}{K}\]Verification: Uniform weights when models are identical.
Configuration:
Expected Behavior:
Configuration:
Expected Behavior:
Configuration:
Expected Behavior:
Configuration:
Expected Behavior:
| Score Range | Interpretation | Weight Impact |
|---|---|---|
| $[0.95, 1.0]$ | Highly aligned | High weight |
| $[0.8, 0.95)$ | Moderately aligned | Moderate weight |
| $[0.5, 0.8)$ | Weakly aligned | Low weight |
| $[0, 0.5)$ | Divergent | Very low weight |
| $< 0$ | Opposing | Near-zero or excluded |
| Metric | Range | Notes |
|---|---|---|
avg_similarity |
$[-1, 1]$ | Mean similarity across clients |
similarity_variance |
$[0, 1]$ | Variance in client similarities |
max_weight |
$(0, 1]$ | Largest client weight |
min_weight |
$[0, 1)$ | Smallest client weight |
weight_entropy |
$[0, \log K]$ | Entropy of weight distribution |
Input: Client model anti-correlated with global
Expected Behavior:
Input: Client submits zero vector update
Expected Behavior:
Input: $K = 1$
Expected Behavior:
Input: All $w_k = w$
Expected Behavior:
def set_seed(seed: int = 42) -> None:
import random, numpy as np, torch
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
| Component | Version |
|---|---|
| Python | 3.12.0 |
| PyTorch | 2.4.0 |
| Unbitrium | 1.0.0 |
Similarity scores may reveal:
| Attack | Description | Impact |
|---|---|---|
| Similarity Poisoning | Craft updates to maximize similarity | Increased malicious influence |
| Sybil Attack | Multiple colluding clients | Collective weight inflation |
Similarity computation: \(T_{sim} = O(K \cdot P)\)
Total aggregation: \(T_{total} = O(K \cdot P)\)
Breakdown:
| Method | Accuracy | Rounds to 60% |
|---|---|---|
| FedAvg | 58.3% | 150 |
| FedProx | 61.2% | 130 |
| FedSim | 65.7% | 95 |
| Method | Accuracy | Communication Cost |
|---|---|---|
| FedAvg | 72.1% | 1.0x |
| FedSim | 78.4% | 1.0x |
Li, Q., He, B., & Song, D. (2021). Model-contrastive federated learning. In CVPR.
Zhang, J., et al. (2022). Federated learning with similarity-weighted aggregation. arXiv preprint.
McMahan, H. B., et al. (2017). Communication-efficient learning of deep networks from decentralized data. In AISTATS.
| Version | Date | Changes |
|---|---|---|
| 1.0.0 | 2026-01-04 | Initial validation report |
Copyright 2026 Olaf Yunus Laitinen Imanov and Contributors. Released under EUPL 1.2.