maxmin#

nvmolkit.pickers.maxmin(
distance_matrix: AsyncGpuResult | Tensor | ndarray,
pick_size: int,
*,
first_picks: Sequence[int] = (),
seed: int = -1,
threshold: float | None = None,
stream: Stream | None = None,
output: OutputMode = OutputMode.DEVICE,
) → tuple[AsyncGpuResult | tuple[int, ...], float]#

Select a diverse subset from a distance matrix by greedy MaxMin.

Each step adds the candidate whose distance to its nearest pick is largest, breaking ties by lowest index, as in RDKit’s MaxMinPicker. A given seed selects the same random first pick as RDKit.

Distances are compared in float32, so distances within float32 rounding of each other tie, and a distance within float32 rounding of threshold can be classified differently than by RDKit’s MaxMinPicker, which compares in double precision.

Parameters:
  • distance_matrix – Square float32 or float64 matrix of shape (N, N). Element [i, j] is the distance from item i to item j. Values are converted to float32 for comparisons. Values that overflow float32 during conversion become infinity.

  • pick_size – Number of items to select, from 1 through N. All first_picks are retained even if they exceed this limit.

  • first_picks – Unique indices that start the selection, in order. If empty, the first pick is drawn at random.

  • seed – Seed for the random first pick. Negative values use system entropy.

  • threshold – Stop before adding a candidate whose nearest-pick distance is at most this value, rounded to float32. Must be between zero and the largest finite float32 value, or None for no threshold.

  • stream – CUDA stream to use. If None, uses the current stream.

  • output – Result representation.

Returns:

(indices, last_distance). indices is an AsyncGpuResult of int32 indices for OutputMode.DEVICE, or a tuple of indices for OutputMode.RDKIT. last_distance is the nearest-pick distance of the last item added, or -1 if none was added after first_picks.