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,
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 givenseedselects 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
thresholdcan be classified differently than by RDKit’sMaxMinPicker, which compares in double precision.- Parameters:
distance_matrix – Square float32 or float64 matrix of shape
(N, N). Element[i, j]is the distance from itemito itemj. 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. Allfirst_picksare 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).indicesis anAsyncGpuResultof int32 indices forOutputMode.DEVICE, or a tuple of indices forOutputMode.RDKIT.last_distanceis the nearest-pick distance of the last item added, or-1if none was added afterfirst_picks.