MCPcopy Create free account

hub / github.com/chalakpaneer/feddefender / functions

Functions83 in github.com/chalakpaneer/feddefender

↓ 6 callersFunction_style
()
utils/plotter.py:31
↓ 6 callersMethodtrain
Run all `num_rounds` FL rounds. Parameters ---------- callback : optional function called after each round
models/fl_server.py:274
↓ 4 callersMethod__init__
(self, in_dim: int, out_dim: int, dropout: float = 0.2)
models/transformer_gnn.py:57
↓ 4 callersFunctionfedavg
w_global = (1/N) Σ w_i (Eq. 7) If client_sizes provided, uses weighted average (proportional to local dataset siz
aggregation/aggregator.py:41
↓ 4 callersFunctionflatten_weights
Stack all parameter tensors into a single 1-D numpy array.
aggregation/aggregator.py:22
↓ 3 callersMethod_evaluate_global
Evaluate global model accuracy on (X, y). If adversarial=True, first perturb with PGD.
models/fl_server.py:122
↓ 3 callersMethodget_all_reputations
(self)
blockchain/reputation.py:192
↓ 3 callersMethodget_trusted_clients
Returns list of client IDs whose reputation ≥ τ. Only these clients' updates are aggregated.
blockchain/reputation.py:176
↓ 2 callersMethod_build_node_features
Approximate per-node features by repeating the batch mean. In production, each node would have its own traffic summary.
models/fl_client.py:106
↓ 2 callersMethod_compute_hash
(self)
blockchain/reputation.py:42
↓ 2 callersFunction_generate_demo_history
Generate realistic synthetic history for demo mode.
dashboard/app.py:87
↓ 2 callersMethodget_excluded_clients
(self)
blockchain/reputation.py:186
↓ 2 callersMethodget_weights
Return local model weights. If malicious: inject poisoned updates instead.
models/fl_client.py:92
↓ 2 callersMethodis_valid
Verify chain integrity by recomputing all hashes.
blockchain/reputation.py:95
↓ 2 callersMethodset_weights
Load global model weights into the local model.
models/fl_client.py:88
↓ 2 callersMethodto_dict
(self)
blockchain/reputation.py:54
↓ 2 callersMethodupdate
Apply Eq. 9: R_i ← λ·R_i + (1-λ)·S_i Record on ledger.
blockchain/reputation.py:150
↓ 1 callersMethod_adversarial_robustness
Robustness = Acc(adversarial) / Acc(clean) (Eq. 12) Uses val set with PGD perturbation.
models/fl_server.py:161
↓ 1 callersMethod_compute_benign_mean
Compute mean weights over currently trusted clients.
models/fl_server.py:314
↓ 1 callersMethod_compute_score
S_i = weighted combination of: • accuracy – how well the client's update improved validation acc • consistency – cosin
blockchain/reputation.py:141
↓ 1 callersMethod_cosine_filter
Returns indices of clients that pass the cosine filter. If no global model yet → accept all.
aggregation/aggregator.py:190
↓ 1 callersMethod_genesis_block
(self)
blockchain/reputation.py:76
↓ 1 callersFunction_serialise
(obj)
main.py:75
↓ 1 callersMethodadd_record
(self, round_num: int, client_id: int, score: float, reputation: float)
blockchain/reputation.py:82
↓ 1 callersMethodaggregate
Full anomaly-aware aggregation pipeline. Returns ------- aggregated global weights
aggregation/aggregator.py:215
↓ 1 callersFunctionapply_backdoor_trigger
Injects a fixed-pattern trigger into the last `trigger_features` dimensions of every sample. In a backdoor attack the adversary trains w
attacks/adversarial.py:104
↓ 1 callersFunctionbuild_graph_edges
Builds a random Erdős–Rényi edge index for the IoT device graph G = (V, E) as described in Section III-A. Returns ------- edge_i
data/dataset.py:96
↓ 1 callersFunctioncompute_final_metrics
Aggregate summary metrics from the full training history. Returns ------- dict with final accuracy, robustness, malicious detection
utils/metrics.py:45
↓ 1 callersFunctioncompute_update_consistency
Measures how similar a client's update is to the benign cluster mean using normalised cosine similarity. High similarity → trustworthy u
blockchain/reputation.py:211
↓ 1 callersFunctionfgsm_attack
Fast Gradient Sign Method (Eq. 5): δ = ε · sign( ∇_x J(θ, x, y) ) x_adv = x + δ Parameters ---------- model : Th
attacks/adversarial.py:24
↓ 1 callersFunctiongenerate_adversarial_samples
Wrapper that generates adversarial samples for adversarial training (Section III-B). Randomly mixes clean and adversarial samples based
attacks/adversarial.py:141
↓ 1 callersFunctiongenerate_synthetic_data
Creates a labelled synthetic traffic dataset. Each class has its own mean vector so that the five traffic categories are distinguishable
data/dataset.py:31
↓ 1 callersMethodget_log
(self)
aggregation/aggregator.py:260
↓ 1 callersMethodget_recent_records
(self, n: int = 50)
blockchain/reputation.py:111
↓ 1 callersFunctionkrum
Byzantine-resilient Krum aggregation (Eq. 8). Algorithm: 1. Flatten each client's weights → vectors v_1 … v_N 2. For each v_i co
aggregation/aggregator.py:64
↓ 1 callersFunctionload_or_run
Load pre-computed results from results/metrics.json or generate synthetic demonstration data.
dashboard/app.py:74
↓ 1 callersMethodlocal_train
Run `local_epochs` of training on the local partition. For benign clients → adversarial training (FGSM/PGD) For malicious c
models/fl_client.py:117
↓ 1 callersFunctionmain
()
main.py:41
↓ 1 callersFunctionmulti_krum
Multi-Krum: selects the top-m clients by Krum score and averages their updates. More robust than single-Krum for larger federations.
aggregation/aggregator.py:115
↓ 1 callersFunctionpartition_data_noniid
Non-IID partition via Dirichlet distribution (Dir(α)). Lower α → more heterogeneous label distributions. Returns ------- List of
data/dataset.py:141
↓ 1 callersFunctionpgd_attack
Projected Gradient Descent (Eq. 6): x_t+1 = Proj_ε( x_t + α · sign( ∇_x J(θ, x_t, y) ) ) Stronger iterative version of FGSM.
attacks/adversarial.py:64
↓ 1 callersFunctionplot_accuracy_curve
(history: dict, save_path: str = "accuracy_curve.png")
utils/plotter.py:41
↓ 1 callersFunctionplot_client_reputations
(rep_mgr, malicious_ids: Set[int], save_path: str =
utils/plotter.py:189
↓ 1 callersFunctionplot_malicious_detection
(history: dict, malicious_ids: Set[int], save_path
utils/plotter.py:74
↓ 1 callersFunctionplot_reputation_heatmap
(history: dict, save_path: str = "reputation_heatmap.png")
utils/plotter.py:112
↓ 1 callersFunctionplot_robustness_comparison
(history: dict, save_path: str = "robustness.png")
utils/plotter.py:143
↓ 1 callersFunctionpoison_model_weights
Simulates a Byzantine client that submits deliberately corrupted weight updates. Strategy: scale weights by a large random factor + Gaus
attacks/adversarial.py:121
↓ 1 callersFunctionprepare_data
End-to-end data preparation: 1. Generate (or load) raw data 2. Standardise features 3. Train / val / test split 4. Partit
data/dataset.py:177
↓ 1 callersFunctionprint_summary
Pretty-print the final metrics summary.
utils/metrics.py:95
↓ 1 callersMethodrun_round
Execute one complete federated learning round.
models/fl_server.py:177
↓ 1 callersFunctiontrimmed_mean
Coordinate-wise trimmed mean. Removes the top and bottom `trim_ratio` fraction of values at each coordinate before averaging.
aggregation/aggregator.py:149
Method__getitem__
(self, idx)
data/dataset.py:89
Method__init__
(self, X: np.ndarray, y: np.ndarray, seq_len: int = 10)
data/dataset.py:80
Method__init__
(self, index: int, round_num: int, client_id: int, score: float, reputation:
blockchain/reputation.py:30
Method__init__
(self)
blockchain/reputation.py:73
Method__init__
(self, num_clients: int, cfg: dict)
blockchain/reputation.py:128
Method__init__
(self, client_id: int, X: np.ndarray, y: np.ndarray,
models/fl_client.py:47
Method__init__
(self, d_model: int, max_len: int = 512, dropout: float = 0.1)
models/transformer_gnn.py:25
Method__init__
(self, in_dim: int, hidden_dim: int, num_layers: int, dropout: float = 0.2)
models/transformer_gnn.py:91
Method__init__
(self, input_dim: int, d_model: int, nhead: int, num_layers: int, dropout: f
models/transformer_gnn.py:110
Method__init__
(self, cfg: dict)
models/transformer_gnn.py:154
Method__init__
(self, fl_cfg: dict, model_cfg: dict, adv_cfg: dict,
models/fl_server.py:44
Method__init__
(self, method: str = "krum", f: int = 4, cosine_threshold: float = 0.0)
aggregation/aggregator.py:183
Method__len__
(self)
data/dataset.py:86
Functioncompare_with_baselines
Baseline numbers from Table II and Table III of the paper. Used for the comparison chart.
utils/metrics.py:112
Functioncompute_detection_accuracy
Eq. 10: Accuracy = (TP + TN) / (TP + TN + FP + FN)
utils/metrics.py:15
Functioncompute_f1
(precision: float, recall: float)
utils/metrics.py:39
Functioncompute_fpr
Eq. 11: FPR = FP / (FP + TN)
utils/metrics.py:24
Functioncompute_robustness
Eq. 12: Robustness = Accuracy(adversarial) / Accuracy(clean)
utils/metrics.py:32
Methodevaluate
Evaluate local model on validation / test data. Returns accuracy (float in [0, 1]).
models/fl_client.py:198
Methodforward
(self, x: torch.Tensor)
models/transformer_gnn.py:41
Methodforward
h : (num_nodes, in_dim) edge_index : (2, num_edges) — [source_nodes, target_nodes]
models/transformer_gnn.py:64
Methodforward
(self, h: torch.Tensor, edge_index: torch.Tensor)
models/transformer_gnn.py:100
Methodforward
x : (batch, seq_len, input_dim) Returns H : (batch, d_model) — Eq. 2
models/transformer_gnn.py:129
Methodforward
x_seq : (batch, seq_len, input_dim) — sequential traffic node_feats : (num_nodes, input_dim) — per-device features
models/transformer_gnn.py:192
Methodget_history
(self, client_id: int)
blockchain/reputation.py:105
Methodget_weights
Return model parameters as a flat list for FL aggregation.
models/transformer_gnn.py:219
Functionpartition_data_iid
IID partition: each client receives an equal, random slice. Returns ------- List of (X_i, y_i) tuples, one per client.
data/dataset.py:125
Functionplot_convergence_comparison
Static chart replicating Table IV.
utils/plotter.py:229
Methodreset_client
Restore a client to initial reputation (manual override).
blockchain/reputation.py:195
Methodset_weights
Load aggregated global weights back into the model.
models/transformer_gnn.py:223
Methodsnapshot
Dict snapshot for logging / dashboard.
blockchain/reputation.py:199
Functionunflatten_weights
Reconstruct the weight list from a flat numpy array.
aggregation/aggregator.py:27