NearestNeighborConverter#

class sdm.prior.NearestNeighborConverter(p: HP[float] | Correlated[float] | float, output_mode: str | HP[str] = 'identity', *, random_fn: RandomFunction | None = None)#

Bases: CategoricalConverter

Assign each row to its nearest sampled center using Minkowski distance.

Parameters:
  • p (HP[float] | Correlated[float] | float) – Minkowski distance exponent.

  • output_mode (str | HP[str]) – Representation passed to child nodes. "identity" keeps input slices, "index" repeats category indices across channels, "center" returns the nearest center, and "function" applies random_fn to that center.

  • random_fn (RandomFunction | None) – Random function applied to selected centers. Required for "function" output mode.

forward(slices: Tensor, generator: Generator | None = None) → tuple[Tensor, Tensor]#

Return category indices and slices passed to child nodes.

Parameters:
  • slices (Tensor) – Node-channel slices per column with shape [C, K, R] for columns, categories, and rows. The category count K may be ragged across columns.

  • generator (Generator | None) – Pseudorandom generator.

Returns:

Category indices with shape [C, R] and updated node-channel slices with the input shape for use by child nodes.

Return type:

tuple[Tensor, Tensor]