nirs4all.controllers.models.stacking.branch_validator module

Branch Validator for Meta-Model Stacking (Phase 4).

This module provides validation logic for stacking in branched pipelines, including support for: - Preprocessing branches (same samples, different features) - Sample partitioner branches (different sample subsets) - Outlier excluder branches (same samples, different exclusions) - Generator syntax branches (same samples, model variants)

The validator ensures that stacking is only performed in compatible scenarios and provides clear error messages for unsupported cases.

class nirs4all.controllers.models.stacking.branch_validator.BranchInfo(branch_type: BranchType, branch_id: int | None = None, branch_name: str | None = None, branch_path: list[int] = <factory>, partition_info: dict[str, ~typing.Any] | None=None, exclusion_info: dict[str, ~typing.Any] | None=None, sample_indices: list[int] | None = None, n_samples: int | None = None, is_nested: bool = False, nesting_depth: int = 0)[source]

Bases: object

Information about branch context for stacking validation.

branch_id: int | None = None
branch_name: str | None = None
branch_path: list[int]
branch_type: BranchType
exclusion_info: dict[str, Any] | None = None
is_nested: bool = False
n_samples: int | None = None
nesting_depth: int = 0
partition_info: dict[str, Any] | None = None
sample_indices: list[int] | None = None
nirs4all.controllers.models.stacking.branch_validator.get_disjoint_branch_info(context: ExecutionContext) → dict[str, Any] | None[source]

Get information about the disjoint branch if applicable.

Parameters:

context – Execution context with branch info.

Returns:

Dict with partition info, or None if not a disjoint branch. Keys may include:

  • partition_type: “metadata”, “sample”, “tag”, or “filter”

  • column: Metadata column name (for metadata partitioner)

  • partition_value: Value(s) for this partition

  • sample_indices: List of sample indices in this partition

  • n_samples: Number of samples in this partition

  • separation_type: New v2 separation type (“by_tag”, “by_metadata”, “by_filter”)

nirs4all.controllers.models.stacking.branch_validator.is_disjoint_branch(context: ExecutionContext) → bool[source]

Check if the current branch context represents disjoint sample branching.

Disjoint branches partition samples into non-overlapping sets, where each sample exists in exactly ONE branch. This is in contrast to copy branches where all branches see all samples.

Disjoint branch types:
  • METADATA_PARTITIONER: Branches by metadata column value (by_metadata)

  • SAMPLE_PARTITIONER: Branches by tag or outlier status (by_tag)

  • OUTLIER_EXCLUDER: Branches by filter result (by_filter)

Copy branch types:
  • PREPROCESSING: All branches see all samples (duplication or by_source)

  • GENERATOR: All branches see all samples (model variants)

Parameters:

context – Execution context with branch info.

Returns:

True if current context represents a disjoint sample branch.