nirs4all.operators.models.multimodal module

Sklearn host operators for sample-aligned multimodal prediction.

The coordinator owns sample alignment, folds, selection and scoring. These operators only learn source representations and a predictor for the rows given to fit. Raw tensors reach their source transformer without flattening.

class nirs4all.operators.models.multimodal.MultimodalClassifier(transformers: Mapping[str, Any], model: Any, *, fusion: str = 'early', source_weights: Mapping[str, float] | None = None, missing_source_policy: str = 'error', backend: str = 'sklearn')[source]

Bases: ClassifierMixin, _MultimodalEstimator

Learn source encoders and a classifier from aligned raw source blocks.

Accepts the same transformers, model, fusion and source_weights and missing_source_policy parameters as MultimodalRegressor. Optional source_masks are forwarded by fit, predict and predict_proba. Each encoder receives the original raw block and training labels; all learned components are cloned before fitting. Binary and multiclass labels may be strings or noncontiguous numbers. Classification requires a single target column.

classes_ preserves the fitted classifier’s exact class order. predict_proba is available only when the configured classifier supports it; probability column j corresponds to classes_[j]. Neither labels nor probabilities are scored by this wrapper. With backend="methods", the genuine native PLS-logistic head owns numerical execution, while a signed sorted typed table maps original labels to native integer IDs. Direct native fit requires explicit IO-derived source_schemas.

close() → None[source]

Release native classifier ownership; harmless before fitting.

decision_function(X: list[Any], *, source_masks: Mapping[str, Any] | None = None, source_schemas: Any = None) → ndarray[source]

Return the declared model’s native decision scores.

fit(X: list[Any], y: Any, *, source_masks: Mapping[str, Any] | None = None, source_schemas: Any = None, sample_weight: Any = None) → Self[source]

Fit native PLS-logistic or the declared sklearn classifier.

predict(X: list[Any], *, source_masks: Mapping[str, Any] | None = None, source_schemas: Any = None) → ndarray[source]

Return labels in their original signed scalar representation.

predict_proba(X: list[Any], *, source_masks: Mapping[str, Any] | None = None, source_schemas: Any = None) → ndarray[source]

Return genuine probabilities, column j corresponding to classes_[j].

set_decision_function_request(*, source_masks: bool | None | str = '$UNCHANGED$', source_schemas: bool | None | str = '$UNCHANGED$') → MultimodalClassifier

Configure whether metadata should be requested to be passed to the decision_function method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to decision_function if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to decision_function.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • source_masks (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_masks parameter in decision_function.

  • source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_schemas parameter in decision_function.

Returns:

self – The updated object.

Return type:

object

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$', source_masks: bool | None | str = '$UNCHANGED$', source_schemas: bool | None | str = '$UNCHANGED$') → MultimodalClassifier

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in fit.

  • source_masks (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_masks parameter in fit.

  • source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_schemas parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_predict_proba_request(*, source_masks: bool | None | str = '$UNCHANGED$', source_schemas: bool | None | str = '$UNCHANGED$') → MultimodalClassifier

Configure whether metadata should be requested to be passed to the predict_proba method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • source_masks (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_masks parameter in predict_proba.

  • source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_schemas parameter in predict_proba.

Returns:

self – The updated object.

Return type:

object

set_predict_request(*, source_masks: bool | None | str = '$UNCHANGED$', source_schemas: bool | None | str = '$UNCHANGED$') → MultimodalClassifier

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • source_masks (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_masks parameter in predict.

  • source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_schemas parameter in predict.

Returns:

self – The updated object.

Return type:

object

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') → MultimodalClassifier

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns:

self – The updated object.

Return type:

object

class nirs4all.operators.models.multimodal.MultimodalRegressor(transformers: Mapping[str, Any], model: Any, *, fusion: str = 'early', source_weights: Mapping[str, float] | None = None, target_policy: str = 'complete', missing_source_policy: str = 'error', backend: str = 'sklearn')[source]

Bases: RegressorMixin, _MultimodalEstimator

Learn source encoders and a regressor from aligned raw source blocks.

transformers maps source names to sklearn transformers, None or "passthrough". Its insertion order defines the input block order. fusion='early' concatenates encoded features; 'intermediate' passes a list of encoded blocks to model. For a Torch factory or module, intermediate fusion trains one joint module with forward(**inputs); each input retains its configured name. The initial Torch profile requires two to four complete dense float matrices, passthrough transformers, source_weights=None and one complete target. An importable decorated Torch factory receives input_shapes={name: (width,)}; a supplied module preserves its initial state. All its encoders and head share one optimizer. Optional source_weights multiply each encoded block. All learned components are cloned and fitted on the supplied rows only. Nested sklearn parameters remain configurable.

backend='sklearn' is the default. backend='methods' supports the closed four-source NIR/image/series/mixed-metadata early-fusion Ridge recipe and delegates all learned encoders and predictor state to Methods. Direct fit requires explicit IO-derived source_schemas; public run supplies them. Use portable result.export and public archive predict for replay, and close to release a directly fitted native predictor.

Targets may be one-dimensional or contain multiple output columns when supported by the underlying regressor. Target dimensions and prediction shapes are preserved; the wrapper never flattens multi-output targets.

target_policy='complete' fits one joint model and requires every target cell to be observed. 'per_target' fits a complete, independent encoder and model chain for each target using only its observed rows. Pass an explicit boolean target_mask to fit; True means observed. Without a mask every cell is observed, so nonfinite targets are rejected. Per-target fits expose target_models_ and target_counts_, without a shared fitted model_ or transformers_. No target is imputed.

source_masks maps every source name to a boolean sample vector (True means present). It may be passed to fit and predict. Masks default to all present. missing_source_policy='zero_with_indicator' learns encoders only from present rows, fills absent encoded features with zero and appends one weighted presence column per source, even when every row is present. Each source requires at least one present training row for every target; prediction may contain entirely absent sources without calling encoders.

close() → None[source]

Release a directly fitted Methods predictor; harmless before fitting.

fit(X: list[Any], y: Any, *, target_mask: Any = None, source_masks: Mapping[str, Any] | None = None, source_schemas: Any = None, sample_weight: Any = None) → Self[source]

Fit joint or target-specific chains using only observed target cells.

predict(X: list[Any], *, source_masks: Mapping[str, Any] | None = None, source_schemas: Any = None) → ndarray[source]

Predict every fitted target, retaining the original target rank.

set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$', source_masks: bool | None | str = '$UNCHANGED$', source_schemas: bool | None | str = '$UNCHANGED$', target_mask: bool | None | str = '$UNCHANGED$') → MultimodalRegressor

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in fit.

  • source_masks (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_masks parameter in fit.

  • source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_schemas parameter in fit.

  • target_mask (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for target_mask parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_predict_request(*, source_masks: bool | None | str = '$UNCHANGED$', source_schemas: bool | None | str = '$UNCHANGED$') → MultimodalRegressor

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • source_masks (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_masks parameter in predict.

  • source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for source_schemas parameter in predict.

Returns:

self – The updated object.

Return type:

object

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') → MultimodalRegressor

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns:

self – The updated object.

Return type:

object

class nirs4all.operators.models.multimodal.TensorPCA(n_components: int | float | None = None, *, whiten: bool = False, random_state: int | None = None)[source]

Bases: TransformerMixin, BaseEstimator

Learn a PCA representation of fixed-shape images or temporal tensors.

All non-sample dimensions are flattened inside this encoder, after checking their exact shape. PCA is fitted only on the supplied training rows. No raw samples are retained by this encoder.

Parameters:
  • n_components – Number of components, or a variance fraction accepted by sklearn PCA. None retains all available components.

  • whiten – Whether to scale components to unit variance.

  • random_state – Seed passed to sklearn PCA.

fit(X: Any, y: Any = None) → TensorPCA[source]

Fit the encoder on an array with samples on its first axis.

transform(X: Any) → ndarray[source]

Encode new samples with the fitted shape and PCA state.