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 8+ distance metrics (L1, L2, L∞, L−∞, Minkowski, cosine, geometric mean, single-dimension — or precomputed distances) and 5 diversity metrics (minimum, mean, geomean & harmonic separation + mean pairwise distance) in any combination — including hybrid objectives that combine several diversity terms, each over its own distance

  • 💾 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 the other freely available solvers.

Installation

pip install max-div

Python 3.12+; 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.18.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.18.2
File Size Uploaded
max_div-0.18.2.tar.gz 242.4 kB Details

Built distribution (wheel)

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

Total release size: 601.9 kB

Release files / max_div-0.18.2.tar.gz

Download URL max_div-0.18.2.tar.gz
Size 242.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9d1ba9d2420ee01b9fada88dffd9c601840329855e9d1b12223e625a3a77150d
BLAKE2b-256 checksum
How to use checksums
b0dbe1c43bfa885b0271f5ec8c71e124c07477dba9965061022df916a71eeb92
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 Sep 25, 2026.

Transparency log

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

Download URL max_div-0.18.2-py3-none-any.whl
Size 359.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f072df29eb03874766f676d3214eb8401e1ca0ee6602022b8a8a028cf799abe
BLAKE2b-256 checksum
How to use checksums
18ceb3d00cd6f3463d07089d9c10b47db72496291fb9a2829793e43d7a360c3b
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 Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.18.2 This release

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

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