Skip to main content

Provably fair particle swarm optimization for federated learning coalition selection

Project description

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

Theorem Guarantee
Theorem 1 Convergence to stationary point with probability 1
Theorem 2 ε-fairness: DemDiv(S*) ≤ ε with high probability
Theorem 3 (1-1/e-η) approximation for submodular objectives
Theorem 4 Privacy-fairness tradeoff lower bound

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, "FairSwarm: Provably Fair Particle Swarm Optimization for Federated Learning Coalition Selection," IEEE Trans. Neural Netw. Learn. Syst., 2026.

Citation

@phdthesis{norwood2025fairswarm,
  title={FairSwarm: A Provably Fair Particle Swarm Optimization Algorithm
         for Federated Learning Coalition Selection with Applications in Healthcare},
  author={Norwood, Tenicka},
  year={2026},
  school={Meharry Medical College}
}

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fairswarm-0.1.2.tar.gz (178.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fairswarm-0.1.2-py3-none-any.whl (138.9 kB view details)

Uploaded Python 3

File details

Details for the file fairswarm-0.1.2.tar.gz.

File metadata

  • Download URL: fairswarm-0.1.2.tar.gz
  • Upload date:
  • Size: 178.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for fairswarm-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3e2e3e6ba0bb2de6190964913585fef217ad6ea0e975dc2610592a6d5eda0dc0
MD5 c4d0f0e2f46ff908d5f33e3cd780f14a
BLAKE2b-256 f9b808d5db8b751cd54a6fee3b03e19e3c3bffc76ee918905aa137caf7228a93

See more details on using hashes here.

File details

Details for the file fairswarm-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fairswarm-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 138.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for fairswarm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e2fda751bf2cb0416c08b128b29c0efc2acdd3e320e18f44a9188a5c26b7e3b4
MD5 5ad265710ee2a66f50d4de0afb5bda5b
BLAKE2b-256 5c66f51791050a382780e2fcbb77831d595826e79f3e585c9f0f0af3e9133a8f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page