nirs4all.controllers.models.residual_model module

Controller for the residual model-combination operator (ResidualModel / {"residual": {...}}).

Fits a base model (leakage-safe OOF), trains a learner on the OOF residuals, and stores the combined prediction base + lambda*gate*learner. Both sub-models are routed through their own framework controllers, so the learner may be any nirs4all model (sklearn, PyTorch nicon, TabPFN, …).

The two sub-models are fit by delegating to the standard model controllers via the router; the residual target is delivered to the learner through a numeric-rooted processed-target series (add_processed_targets + context.with_y), so no learner-side change is needed.

class nirs4all.controllers.models.residual_model.ResidualModelController[source]

Bases: OperatorController

Fit base + residual-learner combination. Priority 5 (above framework model controllers).

execute(step_info, dataset, context, runtime_context, source: int = -1, mode: str = 'train', loaded_binaries=None, prediction_store=None)[source]

Run the operator with the given parameters and context.

Parameters:
  • step_info – Parsed step containing operator, keyword, and metadata

  • dataset – Dataset to operate on

  • context – Pipeline execution context

  • runtime_context – Runtime infrastructure context

  • source – Data source index

  • mode – Execution mode (“train” or “predict”)

  • loaded_binaries – Pre-loaded binary objects for prediction mode

  • prediction_store – External prediction store for model predictions

Returns:

Tuple of (updated_context, StepOutput)

classmethod matches(step: Any, operator: Any, keyword: str) → bool[source]

Check if the operator matches the step and keyword.

priority: int = 5
classmethod supports_prediction_mode() → bool[source]

Check if the controller should execute during prediction mode.

Returns:

True if the controller should execute in prediction mode, False if it should be skipped (e.g., chart controllers)

classmethod use_multi_source() → bool[source]

Check if the operator supports multi-source datasets.