nirs4all.controllers.models.stacking.multilevel module

Multi-Level Stacking Validator (Phase 7).

This module provides validation and level detection for multi-level stacking, where meta-models can use predictions from other meta-models as sources.

The validator ensures: 1. No circular dependencies exist in the stacking hierarchy 2. Stacking levels don’t exceed configured maximum 3. Level detection works correctly for AUTO mode 4. Source models from appropriate levels are selected

Stacking Hierarchy:

Level 0: Base models (PLS, RF, XGBoost, Neural Networks, etc.) Level 1: First meta-models (stack on Level 0 only) Level 2: Second meta-models (stack on Level 0 + Level 1) Level 3: Third meta-models (stack on Level 0 + Level 1 + Level 2)

Example

>>> validator = MultiLevelValidator(prediction_store)
>>> result = validator.validate_sources(
...     meta_model_name="FinalMeta",
...     source_candidates=candidates,
...     context=context
... )
>>> if not result.is_valid:
...     raise CircularDependencyError(...)
nirs4all.controllers.models.stacking.multilevel.detect_stacking_level(prediction_store: Predictions, source_candidates: list[ModelCandidate], context: ExecutionContext) → int[source]

Convenience function for detecting stacking level.

Parameters:
  • prediction_store – Predictions storage.

  • source_candidates – List of candidate source models.

  • context – Execution context.

Returns:

Detected stacking level.

nirs4all.controllers.models.stacking.multilevel.validate_multi_level_stacking(prediction_store: Predictions, meta_model_name: str, source_candidates: list[ModelCandidate], context: ExecutionContext, max_level: int = 3, allow_meta_sources: bool = True) → LevelValidationResult[source]

Convenience function for validating multi-level stacking.

Parameters:
  • prediction_store – Predictions storage.

  • meta_model_name – Name of the meta-model.

  • source_candidates – List of candidate source models.

  • context – Execution context.

  • max_level – Maximum allowed stacking level.

  • allow_meta_sources – Whether to allow meta-model sources.

Returns:

LevelValidationResult with validation status.