Skip to main content

FairSwarm

Provably fair particle swarm optimization for federated learning coalition selection

License Python 3.9+

Overview

FairSwarm is a novel particle swarm optimization algorithm designed for fair client selection in federated learning. It provides provable guarantees on both convergence and demographic fairness.

Key Innovation

FairSwarm introduces a fairness-aware velocity update that steers optimization toward demographically balanced coalitions:

v = ω·v + c₁·r₁·(pBest - x) + c₂·r₂·(gBest - x) + c₃·∇_fair
                                                    ^^^^^^^^
                                                    Novel fairness gradient

Theoretical Guarantees

Result Guarantee
Theorem 1 Convergence to a stationary point under the fairness-gradient perturbation
Theorem 2 ε-fairness: DemDiv(S*) ≤ ε with high probability
Proposition (approximation) SelectTop rounding loses only O(Δ_f/m) (unconditional); under a monotone-submodularity hypothesis this gives α·(1−1/e) − O(1/m)
Proposition (privacy) Privacy–fairness tradeoff via the standard Gaussian-mechanism / Rényi-DP bound

Data Access and Compliance

This library contains no patient data. Examples and tests use only synthetic data generated by create_synthetic_clients().

Experiments on restricted clinical datasets (MIMIC-III, eICU-CRD) require that you independently obtain credentialed access:

  1. Complete CITI "Data or Specimens Only Research" training.
  2. Sign the PhysioNet Data Use Agreement at https://physionet.org/about/database/.
  3. Download MIMIC-III / eICU under your own credentials.
  4. Place derived cohort files outside the repository tree, or in a path covered by .gitignore (data/processed/, data/raw/).
  5. Set the MIMIC_DATA_PATH (or EICU_DATA_PATH) environment variable to point the experiment scripts at your local data.

Do NOT commit, redistribute, or share patient-level data in any form. You are solely responsible for compliance with the PhysioNet DUA, HIPAA, and your institution's IRB requirements.

The full threat model — what the server sees, what is out of scope (malicious servers, sybil clients, model inversion, side-channel attacks), and how the package's privacy claims align with HIPAA Safe Harbor / GDPR / PhysioNet DUA / All of Us terms — is in THREAT_MODEL.md.

Installation

pip install fairswarm

For development:

pip install fairswarm[dev]

Quick Start

from fairswarm import FairSwarm, FairSwarmConfig, Client
from fairswarm.demographics import DemographicDistribution, CensusTarget
import numpy as np

# Create clients (hospitals) with demographic information
clients = [
    Client(
        id=f"hospital_{i}",
        demographics=np.random.dirichlet([2, 2, 2, 2]),
        dataset_size=1000 + i * 100,
    )
    for i in range(20)
]

# Configure the optimizer
config = FairSwarmConfig(
    swarm_size=30,
    max_iterations=100,
    coalition_size=10,
    fairness_weight=0.3,  # λ in fitness function
    seed=42,
)

# Create target demographics (e.g., US Census 2020)
target = DemographicDistribution.from_dict({
    "white": 0.576,
    "black": 0.124,
    "hispanic": 0.187,
    "asian": 0.061,
    "other": 0.052,
})

# Run optimization
optimizer = FairSwarm(
    clients=clients,
    coalition_size=10,
    target_demographics=target,
    config=config,
)
# Use built-in demographic fitness (or supply your own callable)
from fairswarm.fitness import DemographicFitness
fitness_fn = DemographicFitness(target=target)

result = optimizer.optimize(fitness_fn)

# Check results
print(f"Selected coalition: {result.coalition}")
print(f"Fitness: {result.fitness:.4f}")
print(f"ε-fair: {result.is_epsilon_fair(0.05)}")

Documentation

Full API documentation is available in the source code docstrings. For the formal algorithm specification, theoretical proofs, and experimental methodology, please refer to:

T. Norwood, D. Das, P. Chatterjee, E. Bentley, and U. Ghosh, "FairSwarm: Trustworthy Coalition Selection for Fair and Secure Federated Intelligence," IEEE Trans. Consum. Electron., 2026. note : Submitted

Citation

If you use this library or its results, please cite the article (preferred — the one that carries the formal theorems) and, if relevant, the specific software release.

@article{norwood2026fairswarm,
  title   = {FairSwarm: Trustworthy Coalition Selection for Fair
             and Secure Federated Intelligence},
  author  = {Norwood, Tenicka and Das, D. and Chatterjee, P. and
             Bentley, E. and Ghosh, U.},
  journal = {IEEE Transactions on Consumer Electronics},
  year    = {2026},
  note    = {Submitted}
}

CITATION.cff backs GitHub's "Cite this repository" button and points at the same record.

License

This project is licensed under the PolyForm Noncommercial License 1.0.0. You are free to use, modify, and distribute it for any noncommercial purpose, including academic research, education, and personal projects.

Commercial licensing is available. For commercial use inquiries, please contact Tenicka Norwood.

See LICENSE for full terms.

Metadata

Release files for fairswarm 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fairswarm 0.6.2
File Size Uploaded
fairswarm-0.6.2.tar.gz 244.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fairswarm 0.6.2
File Interpreter ABI Platform
fairswarm-0.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 416.0 kB

Release files / fairswarm-0.6.2.tar.gz

Download URL fairswarm-0.6.2.tar.gz
Size 244.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ac0aae4900e5e6888dc7339fa1f1d06b6b3edef273b7fbaf7ef7faabb4fc2caf
BLAKE2b-256 checksum
How to use checksums
0daafe3bee6e34b42717e5cff0a0e3099ca6805194dfa874787c2e551f1e77ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / fairswarm-0.6.2-py3-none-any.whl

Download URL fairswarm-0.6.2-py3-none-any.whl
Size 171.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14f4bb447f31c27ec9397f21f27732fbb4020c039638191b83d6a0ca227b5675
BLAKE2b-256 checksum
How to use checksums
b728bbb6d75ad8dcbce8d9595e8d33b383a0dca5bf3e793212b3b36a0e16b70a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files

0.6.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page