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

  • ⏱️ runs within an arbitrary solve budget — wall-clock time or iteration count

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

  • ⚖️ natively supports flexible fairness constraints

    • uniquely supports constraints with overlapping groups & 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.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 max-div 0.16.2
File Size Uploaded
max_div-0.16.2.tar.gz 205.4 kB Details

Built distribution (wheel)

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

Total release size: 519.5 kB

Release files / max_div-0.16.2.tar.gz

Download URL max_div-0.16.2.tar.gz
Size 205.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2e99c320db3a4a190991c1b9dbe8b56bd30986e83c01398ba21844f3f31cec4a
BLAKE2b-256 checksum
How to use checksums
269565817de3bc26e04e31994be27605645fdead6a206273827fbd3bfc2e50aa
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.2-py3-none-any.whl

Download URL max_div-0.16.2-py3-none-any.whl
Size 314.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3df8201b1abf7b8a0a8107386313a6a47bc8a72dbbbc1239e5cf652e9241058c
BLAKE2b-256 checksum
How to use checksums
c9bcd2726d54a009fef4af85de83992a944c0373012d0884e5e0530cc40eb4fc
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

This release

0.16.2 This release

2 release files

0.16.1

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