nirs4all.controllers.models.stacking.crossbranch module
Cross-Branch Stacking Support (Phase 7).
This module provides support for stacking across multiple branches, allowing meta-models to use predictions from models in different preprocessing branches.
Key Features: 1. BranchScope.ALL_BRANCHES support - stack across all branches 2. Feature alignment validation - ensure samples match across branches 3. Branch compatibility detection - identify compatible vs incompatible branches 4. Cross-branch prediction aggregation - combine predictions from multiple branches
Compatibility Matrix:
| Branch Type | Cross-Branch Stacking | Notes |
|---------------------|———————-|----------------------------------|
| Preprocessing | ✅ Supported | Same samples, different features |
| Generator (_or_) | ✅ Supported | Same samples, model variants |
| Outlier Excluder | ✅ Supported | Same samples, different training |
| Sample Partitioner | ❌ Not Supported | Different samples per partition |
Example
>>> validator = CrossBranchValidator(prediction_store)
>>> result = validator.validate_cross_branch_stacking(
... source_candidates=candidates,
... context=context
... )
>>> if result.is_compatible:
... aligned_features = validator.align_branch_features(...)
- nirs4all.controllers.models.stacking.crossbranch.validate_all_branches_scope(prediction_store: Predictions, source_candidates: list[ModelCandidate], context: ExecutionContext) CrossBranchValidationResult[source]
Convenience function for validating BranchScope.ALL_BRANCHES.
- Parameters:
prediction_store – Predictions storage.
source_candidates – List of candidate source models.
context – Execution context.
- Returns:
CrossBranchValidationResult with compatibility info.