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
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:
- Getting started — installation, distance and diversity metrics, solver presets
- Comparison with other tools — how max-div relates to exact solvers, greedy pickers, and samplers
- Benchmarks — the measured comparison against third-party tools
License
Licensed under the Apache License 2.0.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file max_div-0.15.0.tar.gz.
File metadata
- Download URL: max_div-0.15.0.tar.gz
- Upload date:
- Size: 198.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f8fedec2dbe7e3359334fb65f1ff0130541f9274e4927c88a7ef34308df22cb
|
|
| MD5 |
f07b6decd0411c6015fe2c0836993020
|
|
| BLAKE2b-256 |
9eaf7b8f01afc7aa0e284ee4cb187a0488af40f8f06d124b2bfc9bd8d26a1769
|
Provenance
The following attestation bundles were made for max_div-0.15.0.tar.gz:
Publisher:
release_tag.yml on bertpl/max-div
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
max_div-0.15.0.tar.gz -
Subject digest:
0f8fedec2dbe7e3359334fb65f1ff0130541f9274e4927c88a7ef34308df22cb - Sigstore transparency entry: 2649112781
- Sigstore integration time:
-
Permalink:
bertpl/max-div@88185a0f2e04a43bfac98e4b6687b66313695cf7 -
Branch / Tag:
refs/tags/v0.15.0 - Owner: https://github.com/bertpl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_tag.yml@88185a0f2e04a43bfac98e4b6687b66313695cf7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file max_div-0.15.0-py3-none-any.whl.
File metadata
- Download URL: max_div-0.15.0-py3-none-any.whl
- Upload date:
- Size: 303.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01d0d8c991ffdf773b0c55ae28ad76fa2d2600e34290a44ed64037019b424943
|
|
| MD5 |
1907419c74f6eb2aeee6cf6f0a27a81c
|
|
| BLAKE2b-256 |
2fd0f8baf8cfd478c7ecd9cfc866e8461719cca81157920de8726379bbd88033
|
Provenance
The following attestation bundles were made for max_div-0.15.0-py3-none-any.whl:
Publisher:
release_tag.yml on bertpl/max-div
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
max_div-0.15.0-py3-none-any.whl -
Subject digest:
01d0d8c991ffdf773b0c55ae28ad76fa2d2600e34290a44ed64037019b424943 - Sigstore transparency entry: 2649112827
- Sigstore integration time:
-
Permalink:
bertpl/max-div@88185a0f2e04a43bfac98e4b6687b66313695cf7 -
Branch / Tag:
refs/tags/v0.15.0 - Owner: https://github.com/bertpl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_tag.yml@88185a0f2e04a43bfac98e4b6687b66313695cf7 -
Trigger Event:
push
-
Statement type: