MEDfl 2.0.10.dev14__tar.gz → 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/params_optimiser.py +4 -4
  2. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/shap/aggregation.py +1 -1
  3. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/strategy.py +3 -0
  4. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/xgboost/strategy.py +3 -0
  5. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/client.py +4 -4
  6. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/strategy.py +40 -30
  7. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/xgboost/strategy.py +3 -0
  8. {medfl-2.0.10.dev14 → medfl-2.1.0}/PKG-INFO +2 -2
  9. {medfl-2.0.10.dev14 → medfl-2.1.0}/README.md +1 -1
  10. {medfl-2.0.10.dev14 → medfl-2.1.0}/medfl.egg-info/PKG-INFO +2 -2
  11. {medfl-2.0.10.dev14 → medfl-2.1.0}/setup.py +1 -1
  12. {medfl-2.0.10.dev14 → medfl-2.1.0}/LICENSE +0 -0
  13. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/__init__.py +0 -0
  14. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/client.py +0 -0
  15. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/dp.py +0 -0
  16. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/dynamicModal.py +0 -0
  17. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/federated_dataset.py +0 -0
  18. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/flpipeline.py +0 -0
  19. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/model.py +0 -0
  20. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/params.yaml +0 -0
  21. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/plot.py +0 -0
  22. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/server.py +0 -0
  23. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/shap/__init__.py +0 -0
  24. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/shap/config.py +0 -0
  25. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/shap/explainer.py +0 -0
  26. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/shap/xgboost_explainer.py +0 -0
  27. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/utils.py +0 -0
  28. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/xgboost/__init__.py +0 -0
  29. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/xgboost/client.py +0 -0
  30. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/xgboost/config.py +0 -0
  31. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/xgboost/data.py +0 -0
  32. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/xgboost/metrics.py +0 -0
  33. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/xgboost/serialization.py +0 -0
  34. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/LearningManager/xgboost/server.py +0 -0
  35. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/NetManager/__init__.py +0 -0
  36. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/NetManager/database_connector.py +0 -0
  37. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/NetManager/dataset.py +0 -0
  38. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/NetManager/flsetup.py +0 -0
  39. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/NetManager/net_helper.py +0 -0
  40. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/NetManager/net_manager_queries.py +0 -0
  41. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/NetManager/network.py +0 -0
  42. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/NetManager/node.py +0 -0
  43. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/__init__.py +0 -0
  44. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/__init__.py +0 -0
  45. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/holdout.py +0 -0
  46. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/identity.py +0 -0
  47. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/model.py +0 -0
  48. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/server.py +0 -0
  49. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/xgboost/__init__.py +0 -0
  50. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/xgboost/client.py +0 -0
  51. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/xgboost/config.py +0 -0
  52. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/xgboost/data.py +0 -0
  53. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/xgboost/metrics.py +0 -0
  54. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/rw/xgboost/serialization.py +0 -0
  55. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/scripts/__init__.py +0 -0
  56. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/scripts/base.py +0 -0
  57. {medfl-2.0.10.dev14 → medfl-2.1.0}/MEDfl/scripts/create_db.py +0 -0
  58. {medfl-2.0.10.dev14 → medfl-2.1.0}/alembic/__init__.py +0 -0
  59. {medfl-2.0.10.dev14 → medfl-2.1.0}/alembic/env.py +0 -0
  60. {medfl-2.0.10.dev14 → medfl-2.1.0}/medfl.egg-info/SOURCES.txt +0 -0
  61. {medfl-2.0.10.dev14 → medfl-2.1.0}/medfl.egg-info/dependency_links.txt +0 -0
  62. {medfl-2.0.10.dev14 → medfl-2.1.0}/medfl.egg-info/requires.txt +0 -0
  63. {medfl-2.0.10.dev14 → medfl-2.1.0}/medfl.egg-info/top_level.txt +0 -0
  64. {medfl-2.0.10.dev14 → medfl-2.1.0}/setup.cfg +0 -0
  65. {medfl-2.0.10.dev14 → medfl-2.1.0}/tests/test_dataset.py +0 -0
  66. {medfl-2.0.10.dev14 → medfl-2.1.0}/tests/test_federated_dataset.py +0 -0
  67. {medfl-2.0.10.dev14 → medfl-2.1.0}/tests/test_flpipeline.py +0 -0
  68. {medfl-2.0.10.dev14 → medfl-2.1.0}/tests/test_flsetup.py +0 -0
  69. {medfl-2.0.10.dev14 → medfl-2.1.0}/tests/test_network.py +0 -0
  70. {medfl-2.0.10.dev14 → medfl-2.1.0}/tests/test_node.py +0 -0
  71. {medfl-2.0.10.dev14 → medfl-2.1.0}/tests/test_rw_holdout.py +0 -0
@@ -75,7 +75,7 @@ class CustomPyTorchClassifier(BaseEstimator):
75
75
  for inputs, labels in train_loader:
76
76
  optimizer.zero_grad()
77
77
  outputs = self.model(inputs)
78
- loss = criterion(outputs.squeeze(), labels)
78
+ loss = criterion(outputs.view(-1), labels)
79
79
  loss.backward()
80
80
  optimizer.step()
81
81
  return self
@@ -87,7 +87,7 @@ class CustomPyTorchClassifier(BaseEstimator):
87
87
  self.model.eval()
88
88
  with torch.no_grad():
89
89
  outputs = self.model(torch.from_numpy(X).float())
90
- predictions = (outputs.squeeze() > self.th).float().numpy()
90
+ predictions = (outputs.view(-1) > self.th).float().numpy()
91
91
  return predictions
92
92
 
93
93
  def score(self, X, y):
@@ -219,7 +219,7 @@ class ParamsOptimiser:
219
219
  for batch_X, batch_y in train_loader:
220
220
  optimizer.zero_grad()
221
221
  outputs = model(batch_X)
222
- loss = criterion(outputs.squeeze(), batch_y)
222
+ loss = criterion(outputs.view(-1), batch_y)
223
223
  loss.backward()
224
224
  optimizer.step()
225
225
 
@@ -281,7 +281,7 @@ class ParamsOptimiser:
281
281
  for batch_X, batch_y in train_loader:
282
282
  final_optimizer.zero_grad()
283
283
  outputs = final_model(batch_X)
284
- loss = final_criterion(outputs.squeeze(), batch_y)
284
+ loss = final_criterion(outputs.view(-1), batch_y)
285
285
  loss.backward()
286
286
  final_optimizer.step()
287
287
 
@@ -65,7 +65,7 @@ def aggregate_federated_shap(
65
65
  """
66
66
  Aggregate additive local SHAP statistics.
67
67
 
68
- The global mean absolute SHAP is equivalent to calculating:
68
+ The global mean absolute SHAP is equivalent to calculating::
69
69
 
70
70
  sum of all |SHAP values| / number of all explained samples
71
71
  """
@@ -8,9 +8,12 @@ This file provides a Strategy factory that wraps any Flower server strategy
8
8
  - Per-client fit/eval history with round + num_examples (+ loss for eval)
9
9
  - Per-round server summary history (results/failures, cids, example stats)
10
10
  - Global-weights fingerprints after aggregation:
11
+
11
12
  * w_norm, delta_norm, cos_sim_prev, nan_or_inf
13
+
12
14
  - Uses Flower logging (NOT print) so logs show up reliably in simulation
13
15
  - Optional metrics aggregation functions to remove:
16
+
14
17
  "No fit_metrics_aggregation_fn provided" warning
15
18
 
16
19
  Usage (server side):
@@ -22,16 +22,19 @@ class XGBoostSimulationStrategy:
22
22
 
23
23
  This class follows the same high-level contract as the existing MEDfl
24
24
  Strategy wrapper:
25
+
25
26
  - it exposes create_strategy();
26
27
  - it stores the Flower strategy in self.strategy_object;
27
28
  - it can be passed directly into FederatedServer.
28
29
 
29
30
  First supported mode:
31
+
30
32
  - bagging-style federated XGBoost using Flower strategy hooks.
31
33
 
32
34
  Notes
33
35
  -----
34
36
  This implementation is conservative and non-invasive:
37
+
35
38
  - It does not modify the existing PyTorch FedAvg/FedAdam/FedYogi path.
36
39
  - It uses Flower Parameters containing serialized XGBoost boosters.
37
40
  - It saves XGBoost models as .ubj files instead of .npz files.
@@ -493,7 +493,7 @@ class FlowerClient(fl.client.NumPyClient):
493
493
  for X_batch, y_batch in self.train_loader:
494
494
  self.optimizer.zero_grad()
495
495
  outputs = self.model(X_batch)
496
- loss = self.criterion(outputs.squeeze(), y_batch)
496
+ loss = self.criterion(outputs.view(-1), y_batch)
497
497
  loss.backward()
498
498
  self.optimizer.step()
499
499
  total_loss += loss.item() * X_batch.size(0)
@@ -501,7 +501,7 @@ class FlowerClient(fl.client.NumPyClient):
501
501
  avg_loss = total_loss / (len(self.train_loader.dataset) * local_epochs)
502
502
 
503
503
  with torch.no_grad():
504
- logits = self.model(self.X_tensor).squeeze()
504
+ logits = self.model(self.X_tensor).view(-1)
505
505
  probs = torch.sigmoid(logits).cpu().numpy()
506
506
  y_true = self.y_tensor.cpu().numpy()
507
507
  binary_preds = (probs >= 0.5).astype(int)
@@ -539,9 +539,9 @@ class FlowerClient(fl.client.NumPyClient):
539
539
  with torch.no_grad():
540
540
  for X_batch, y_batch in self.test_loader:
541
541
  outputs = self.model(X_batch)
542
- loss = self.criterion(outputs.squeeze(), y_batch)
542
+ loss = self.criterion(outputs.view(-1), y_batch)
543
543
  total_loss += loss.item() * X_batch.size(0)
544
- probs = torch.sigmoid(outputs.squeeze()).cpu().numpy()
544
+ probs = torch.sigmoid(outputs.view(-1)).cpu().numpy()
545
545
  all_probs.extend(probs.tolist())
546
546
  all_true.extend(y_batch.cpu().numpy().tolist())
547
547
 
@@ -38,36 +38,46 @@ def aggregate_eval_metrics(results):
38
38
  # ===================================================
39
39
  class Strategy:
40
40
  """
41
- Flower Strategy wrapper:
42
- - Dynamic hyperparameters via on_fit_config_fn
43
- - Custom metric aggregation
44
- - Per-client & aggregated metric logging
45
- - Synchronous get_properties() inspection in configure_fit()
46
- - Saving global parameters every saveOnRounds to savingPath
47
-
48
- Extended:
49
- - split_mode:
50
- * "global": use global val_fraction/test_fraction for all clients
51
- * "per_client": use client_fractions[hostname] if present
52
- - client_fractions:
53
- {
54
- "HOSTNAME_1": {
55
- "val_fraction": float (optional),
56
- "test_fraction": float (optional),
57
- "test_ids": [..] or "id1,id2" (optional)
58
- },
59
- ...
60
- }
61
- - In per_client mode:
62
- * if test_ids is present for a client:
63
- -> send test_ids
64
- -> do NOT use that client's test_fraction
65
- * otherwise:
66
- -> use that client's val_fraction/test_fraction if provided,
67
- else fall back to global val_fraction/test_fraction
68
- - client id in this mapping = hostname from client.get_properties()
69
- - id_col:
70
- * column name used on clients to match test_ids (default "id")
41
+ Flower strategy wrapper for MEDfl real-world pipelines.
42
+
43
+ It wraps any strategy of ``flwr.server.strategy`` (selected by ``name``) and adds:
44
+
45
+ - the experiment configuration (schema, splits, hyperparameters) pushed to the
46
+ clients at every round;
47
+ - custom metric aggregation, and per-client and aggregated metric logging;
48
+ - inspection of the client properties before each training round;
49
+ - checkpoints of the global parameters every ``saveOnRounds`` rounds;
50
+ - final-round federated SHAP and federated holdout test.
51
+
52
+ Parameters
53
+ ----------
54
+ name : str
55
+ Name of a Flower strategy class, e.g. ``"FedAvg"``, ``"FedAdam"``, ``"FedProx"``.
56
+ features : str
57
+ Comma-separated feature columns enforced on every client. Empty: all columns
58
+ except the target.
59
+ target : str
60
+ Target column. Empty: the last column of each client CSV.
61
+ val_fraction, test_fraction : float
62
+ Default validation and test fractions on each client.
63
+ split_mode : str
64
+ ``"global"``: every client uses ``val_fraction`` / ``test_fraction``.
65
+ ``"per_client"``: a client listed in ``client_fractions`` uses its own settings.
66
+ client_fractions : dict, optional
67
+ Per-client split settings keyed by client name (hostname, or ``MEDFL_AGENT_ID``),
68
+ e.g. ``{"hospital-a": {"val_fraction": 0.1, "test_ids": [1, 2, 3]}}``. Allowed keys:
69
+ ``val_fraction``, ``test_fraction``, ``test_ids`` (list or ``"1,2,3"``). When
70
+ ``test_ids`` is given, that client's ``test_fraction`` is ignored.
71
+ id_col : str
72
+ Client column matched against ``test_ids``.
73
+ savingPath : str
74
+ Checkpoint directory. Empty: no checkpoint.
75
+ saveOnRounds : int
76
+ Save the global model every N rounds (and at the last round).
77
+ shap_config : SHAPConfig, optional
78
+ Final-round federated SHAP configuration.
79
+ holdout_config : HoldoutConfig, optional
80
+ Final-round federated holdout test configuration.
71
81
  """
72
82
 
73
83
  def __init__(
@@ -33,16 +33,19 @@ class XGBoostStrategy:
33
33
 
34
34
  This class follows the same high-level contract as the existing MEDfl
35
35
  Strategy wrapper:
36
+
36
37
  - it exposes create_strategy();
37
38
  - it stores the Flower strategy in self.strategy_object;
38
39
  - it can be passed directly into FederatedServer.
39
40
 
40
41
  First supported mode:
42
+
41
43
  - bagging-style federated XGBoost using Flower strategy hooks.
42
44
 
43
45
  Notes
44
46
  -----
45
47
  This implementation is conservative and non-invasive:
48
+
46
49
  - It does not modify the existing PyTorch FedAvg/FedAdam/FedYogi path.
47
50
  - It uses Flower Parameters containing serialized XGBoost boosters.
48
51
  - It saves XGBoost models as .ubj files instead of .npz files.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: medfl
3
- Version: 2.0.10.dev14
3
+ Version: 2.1.0
4
4
  Summary: Python Open-source package for simulating federated learning and differential privacy
5
5
  Home-page: https://github.com/MEDomics-UdeS/MEDfl
6
6
  Author: MEDomics consortium
@@ -303,7 +303,7 @@ FlowerClient(server_address="SERVER_IP:8080",
303
303
  holdout_path="data/site_holdout.csv").start()
304
304
  ```
305
305
 
306
- **Optimized threshold.** With `threshold_source="optimized"`, clients also send score histograms of their whole learning set (train + validation + test). The server selects the threshold on these pooled histograms (Youden's J or the lowest threshold reaching a target sensitivity), then reports holdout metrics at that threshold. The holdout data is **never** used to choose the threshold, so holdout results remain an unbiased estimate.
306
+ **Optimized threshold.** With `threshold_source="optimized"`, clients also send score histograms of their whole learning set (train + validation + test). The server selects the threshold on these pooled histograms (Youden's J, or the highest threshold that still reaches a target sensitivity), then reports holdout metrics at that threshold. The holdout data is **never** used to choose the threshold, so holdout results remain an unbiased estimate.
307
307
 
308
308
  Holdout testing works for both the PyTorch and the XGBoost real-world backends (binary classification).
309
309
 
@@ -283,7 +283,7 @@ FlowerClient(server_address="SERVER_IP:8080",
283
283
  holdout_path="data/site_holdout.csv").start()
284
284
  ```
285
285
 
286
- **Optimized threshold.** With `threshold_source="optimized"`, clients also send score histograms of their whole learning set (train + validation + test). The server selects the threshold on these pooled histograms (Youden's J or the lowest threshold reaching a target sensitivity), then reports holdout metrics at that threshold. The holdout data is **never** used to choose the threshold, so holdout results remain an unbiased estimate.
286
+ **Optimized threshold.** With `threshold_source="optimized"`, clients also send score histograms of their whole learning set (train + validation + test). The server selects the threshold on these pooled histograms (Youden's J, or the highest threshold that still reaches a target sensitivity), then reports holdout metrics at that threshold. The holdout data is **never** used to choose the threshold, so holdout results remain an unbiased estimate.
287
287
 
288
288
  Holdout testing works for both the PyTorch and the XGBoost real-world backends (binary classification).
289
289
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: medfl
3
- Version: 2.0.10.dev14
3
+ Version: 2.1.0
4
4
  Summary: Python Open-source package for simulating federated learning and differential privacy
5
5
  Home-page: https://github.com/MEDomics-UdeS/MEDfl
6
6
  Author: MEDomics consortium
@@ -303,7 +303,7 @@ FlowerClient(server_address="SERVER_IP:8080",
303
303
  holdout_path="data/site_holdout.csv").start()
304
304
  ```
305
305
 
306
- **Optimized threshold.** With `threshold_source="optimized"`, clients also send score histograms of their whole learning set (train + validation + test). The server selects the threshold on these pooled histograms (Youden's J or the lowest threshold reaching a target sensitivity), then reports holdout metrics at that threshold. The holdout data is **never** used to choose the threshold, so holdout results remain an unbiased estimate.
306
+ **Optimized threshold.** With `threshold_source="optimized"`, clients also send score histograms of their whole learning set (train + validation + test). The server selects the threshold on these pooled histograms (Youden's J, or the highest threshold that still reaches a target sensitivity), then reports holdout metrics at that threshold. The holdout data is **never** used to choose the threshold, so holdout results remain an unbiased estimate.
307
307
 
308
308
  Holdout testing works for both the PyTorch and the XGBoost real-world backends (binary classification).
309
309
 
@@ -14,7 +14,7 @@ with open('requirements.txt') as f:
14
14
 
15
15
  setup(
16
16
  name="medfl",
17
- version="2.0.10.dev14",
17
+ version="2.1.0",
18
18
  author="MEDomics consortium",
19
19
  author_email="medomics.info@gmail.com",
20
20
  description="Python Open-source package for simulating federated learning and differential privacy",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes