max-div
Configurable solver for Maximum Diversity Problems with optional fairness constraints:
given n items — vectors or precomputed distances — select the k most diverse, optionally
subject to per-group minimum/maximum quotas.
max-div is an anytime heuristic: it returns a good selection quickly and keeps improving it for as long as you allow (wall-clock time or iteration count). Two things set it apart among freely available tools: it is the only dedicated diversity solver with native support for overlapping fairness constraints, and the only one offering a geometric-mean separation objective — one of four diversity metrics it provides (minimum, mean, and geometric-mean separation, plus mean pairwise distance).
It fills the gap between exact MIP/CP solvers, which prove optimal answers but do not scale, and single-shot pickers, which are fast but at best have very limited support for constraints. The benchmarks show where it leads and where it does not.
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.12.0.tar.gz.
File metadata
- Download URL: max_div-0.12.0.tar.gz
- Upload date:
- Size: 168.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5858787f8c68218db893e6023d18cb46d73a0c0b985c8e1f7e4792c821ae74a7
|
|
| MD5 |
79967a14fcb254b8bb6d0fedbcea9f14
|
|
| BLAKE2b-256 |
12baa54eb286bff867ce51dfbd374287258cdeaa7b43d3c1cd0d28d4cee36047
|
Provenance
The following attestation bundles were made for max_div-0.12.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.12.0.tar.gz -
Subject digest:
5858787f8c68218db893e6023d18cb46d73a0c0b985c8e1f7e4792c821ae74a7 - Sigstore transparency entry: 2474467201
- Sigstore integration time:
-
Permalink:
bertpl/max-div@5d20005e98b0abb1057fdf4e59fc049245819be8 -
Branch / Tag:
refs/tags/v0.12.0 - Owner: https://github.com/bertpl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_tag.yml@5d20005e98b0abb1057fdf4e59fc049245819be8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file max_div-0.12.0-py3-none-any.whl.
File metadata
- Download URL: max_div-0.12.0-py3-none-any.whl
- Upload date:
- Size: 267.8 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 |
7488a512cd57a7fd2c73549cc2b9e87b6e36dddfa1c5af856a5795384782b703
|
|
| MD5 |
919cb4ca09c5361f05ec5d56082055c4
|
|
| BLAKE2b-256 |
2301521b9081214f792d39436f4881160e905fd6b00cd1bbc1a32e3ba4a73fa6
|
Provenance
The following attestation bundles were made for max_div-0.12.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.12.0-py3-none-any.whl -
Subject digest:
7488a512cd57a7fd2c73549cc2b9e87b6e36dddfa1c5af856a5795384782b703 - Sigstore transparency entry: 2474467583
- Sigstore integration time:
-
Permalink:
bertpl/max-div@5d20005e98b0abb1057fdf4e59fc049245819be8 -
Branch / Tag:
refs/tags/v0.12.0 - Owner: https://github.com/bertpl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_tag.yml@5d20005e98b0abb1057fdf4e59fc049245819be8 -
Trigger Event:
push
-
Statement type: