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,_MultimodalEstimatorLearn source encoders and a classifier from aligned raw source blocks.
Accepts the same
transformers,model,fusionandsource_weightsandmissing_source_policyparameters asMultimodalRegressor. Optionalsource_masksare 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_probais available only when the configured classifier supports it; probability columnjcorresponds toclasses_[j]. Neither labels nor probabilities are scored by this wrapper. Withbackend="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-derivedsource_schemas.- 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_functionmethod.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(seesklearn.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 todecision_functionif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it todecision_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_masksparameter indecision_function.source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
source_schemasparameter indecision_function.
- Returns:
self – The updated object.
- Return type:
- 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
fitmethod.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(seesklearn.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 tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.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_weightparameter infit.source_masks (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
source_masksparameter infit.source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
source_schemasparameter infit.
- Returns:
self – The updated object.
- Return type:
- 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_probamethod.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(seesklearn.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 topredict_probaif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict_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_masksparameter inpredict_proba.source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
source_schemasparameter inpredict_proba.
- Returns:
self – The updated object.
- Return type:
- 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
predictmethod.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(seesklearn.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 topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.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_masksparameter inpredict.source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
source_schemasparameter inpredict.
- Returns:
self – The updated object.
- Return type:
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MultimodalClassifier
Configure whether metadata should be requested to be passed to the
scoremethod.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(seesklearn.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 toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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.
- 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,_MultimodalEstimatorLearn source encoders and a regressor from aligned raw source blocks.
transformersmaps source names to sklearn transformers,Noneor"passthrough". Its insertion order defines the input block order.fusion='early'concatenates encoded features;'intermediate'passes a list of encoded blocks tomodel. For a Torch factory or module, intermediate fusion trains one joint module withforward(**inputs); each input retains its configured name. The initial Torch profile requires two to four complete dense float matrices, passthrough transformers,source_weights=Noneand one complete target. An importable decorated Torch factory receivesinput_shapes={name: (width,)}; a supplied module preserves its initial state. All its encoders and head share one optimizer. Optionalsource_weightsmultiply 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-derivedsource_schemas; publicrunsupplies them. Use portableresult.exportand public archivepredictfor replay, andcloseto 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 booleantarget_masktofit; True means observed. Without a mask every cell is observed, so nonfinite targets are rejected. Per-target fits exposetarget_models_andtarget_counts_, without a shared fittedmodel_ortransformers_. No target is imputed.source_masksmaps 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.- 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
fitmethod.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(seesklearn.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 tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.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_weightparameter infit.source_masks (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
source_masksparameter infit.source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
source_schemasparameter infit.target_mask (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
target_maskparameter infit.
- Returns:
self – The updated object.
- Return type:
- 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
predictmethod.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(seesklearn.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 topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.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_masksparameter inpredict.source_schemas (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
source_schemasparameter inpredict.
- Returns:
self – The updated object.
- Return type:
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MultimodalRegressor
Configure whether metadata should be requested to be passed to the
scoremethod.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(seesklearn.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 toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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.
- class nirs4all.operators.models.multimodal.TensorPCA(n_components: int | float | None = None, *, whiten: bool = False, random_state: int | None = None)[source]
Bases:
TransformerMixin,BaseEstimatorLearn 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.
Noneretains all available components.whiten – Whether to scale components to unit variance.
random_state – Seed passed to sklearn PCA.