Skip to main content

CI coverage tests docs-build-status PyPI Python License code style: ruff OpenSSF Scorecard

max-div logo

max-div

A versatile, high-performance solver for Maximum Diversity Problems — select the k most diverse of n items, under optional fairness constraints.

Highlights

  • ⚡ obtains near-optimal results within seconds-to-one-minute for problems up to n=200k

  • 🚀 leverages numba JIT-compilation for maximum speed without relying on pre-compiled binaries

  • ⚖️ natively supports flexible fairness constraints

    • uniquely supports constraints with overlapping sets & ranged counts

    • returns the least infeasible solution (with configurable weighted linear or quadratic penalties) when constraints conflict

    • provides proofs of (in)feasibility

  • 📐 uniquely supports 5+ distance metrics (L1, L2, L∞, Minkowski, cosine — or precomputed distances) and 4 diversity metrics (minimum, mean & geomean separation + mean pairwise distance) in any combination

  • 💾 computes item distances eagerly when memory allows (maximum speed), lazily when problem size requires (minimal memory usage)

  • 🤝 leverages multi-core CPUs with parallel workers in independent, cooperative or dynamically grouped configurations, without duplicating core problem data

Feature comparison of max-div against exact solvers and one-shot pickers: distance metrics, diversity objectives, constraint handling, time budgets and practical scale

The benchmarks compare max-div in depth with 10 other freely available solvers.

Installation

pip install max-div

Python 3.11+; free-threaded builds (3.14t) are supported and CI-tested (see the installation notes for the numba version they require).

Quick start

import numpy as np
from max_div import MaxDivProblem, MaxDivSolverBuilder, seconds

rng = np.random.default_rng(42)
vectors = rng.random((200, 5))               # 200 points in 5 dimensions

# select the 20 most diverse, improving for up to 5 seconds
problem = MaxDivProblem.new(vectors, k=20)
solution = MaxDivSolverBuilder(problem).with_preset(seconds(5)).build().solve()

print(solution.i_selected)                   # indices of the selected items

With fairness constraints

Require a minimum and/or maximum number of selected items from given subsets — useful for fair representation across groups. Groups may overlap, and infeasible constraints degrade gracefully to the least-infeasible selection rather than failing.

from max_div import Constraint

# require between 8 and 12 of the selected items from each half of the data
constraints = [
    Constraint(int_set=set(range(0, 100)),   min_count=8, max_count=12),
    Constraint(int_set=set(range(100, 200)), min_count=8, max_count=12),
]
problem = MaxDivProblem.new(vectors, k=20, constraints=constraints)

Documentation

Full documentation lives at max-div.readthedocs.io, including:

License

Licensed under the Apache License 2.0.

Release files for max-div 0.16.1

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

Source distribution (sdist)

Source distribution for max-div 0.16.1
File Size Uploaded
max_div-0.16.1.tar.gz 201.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for max-div 0.16.1
File Interpreter ABI Platform
max_div-0.16.1-py3-none-any.whl Python 3 none any Details

Total release size: 510.7 kB

Release files / max_div-0.16.1.tar.gz

Download URL max_div-0.16.1.tar.gz
Size 201.1 kB
Tags Source
SHA-256 checksum
How to use checksums
70902ae31823d3ec98bda8d04ba535a04306e5f81bfc14a5b2d881e73a5eb864
BLAKE2b-256 checksum
How to use checksums
4daa12e5214fdfdb117b6607f47f55a5c9c1479ebcc6d30ee20feec541859c05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2026.

Transparency log

Release files / max_div-0.16.1-py3-none-any.whl

Download URL max_div-0.16.1-py3-none-any.whl
Size 309.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96cb3c5b791e01bec47f46b9b2d8b8e1f2c667791d1b4482e44a998c574bdda9
BLAKE2b-256 checksum
How to use checksums
d8f464017997404daa0d0d17ccad6481d4d335a400efcc6510660bcc19eb0154
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2026.

Transparency log

Release history Release notifications | RSS feed

0.18.2

2 release files

0.18.1

2 release files

0.18.0

2 release files

0.17.5

2 release files

0.16.2

2 release files

This release

0.16.1 This release

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.3

2 release files

0.14.2

2 release files

0.14.1

2 release files

0.14.0

2 release files

0.13.3

2 release files

0.13.2

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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