nirs4all.controllers.models.components.index_normalizer module

Index Normalizer - Normalize and validate sample indices

This component handles conversion of sample indices to consistent format and validates them. Extracted from launch_training() lines 448-454.

class nirs4all.controllers.models.components.index_normalizer.IndexNormalizer[source]

Bases: object

Normalizes sample indices to consistent format.

Converts numpy int types to Python int and validates indices are within valid ranges.

Example

>>> normalizer = IndexNormalizer()
>>> indices = normalizer.normalize([np.int64(0), np.int64(1), np.int64(2)])
>>> indices
[0, 1, 2]
normalize(indices: List | ndarray | None, n_samples: int, default_range: bool = True, validate: bool = False) List[int][source]

Normalize indices to Python int list.

Parameters:
  • indices – Input indices (may be None, list, or numpy array)

  • n_samples – Total number of samples (for validation and defaults)

  • default_range – If True and indices is None, return range(n_samples)

  • validate – If True, validate indices are within bounds

Returns:

List of Python integers

Raises:

ValueError – If validate=True and indices are out of bounds

normalize_batch(indices_dict: dict, n_samples_dict: dict) dict[source]

Normalize a dictionary of indices for multiple partitions.

Parameters:
  • indices_dict – Dictionary with keys like ‘train’, ‘val’, ‘test’ and values as index lists/arrays

  • n_samples_dict – Dictionary with same keys and values as sample counts

Returns:

Dictionary with same keys but normalized indices