nirs4all.operators.methods.n4m_ops module
Thin nirs4all operators dispatching to the nirs4all-methods engine.
The numerics live entirely in the portable C++ core (libn4m) and are
reached through the n4m ctypes binding. These wrappers own no numerical
logic: they only translate sklearn fit / transform / predict calls
into the binding’s own sklearn-contract objects and surface JSON-serializable
parameters via get_params so both nirs4all engines can round-trip them.
- class nirs4all.operators.methods.n4m_ops.MethodsPLS(n_components: int = 2, cv: int = 5, scale_x: bool = True)[source]
Bases:
RegressorMixin,BaseEstimatorPLS regression backed by the
nirs4all-methodsengine.Single-target moment-based PLS computed by the portable
libn4mcore. Numerically matches scikit-learn’ssklearn.cross_decomposition.PLSRegressionto floating-point precision for a fixed component count.- Parameters:
- fit(X: ndarray, y: ndarray) MethodsPLS[source]
Fit the native PLS model on
(X, y).The native engine is single-target (PLS1);
ymust be 1D or a single-column 2D array.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MethodsPLS
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.methods.n4m_ops.MethodsSNV(with_mean: bool = True, with_std: bool = True, ddof: int = 0)[source]
Bases:
TransformerMixin,BaseEstimatorStandard Normal Variate backed by the
nirs4all-methodsengine.Row-wise scatter correction computed by the portable
libn4mcore. Drop-in replacement for the pure-Pythonnirs4all.operators.transforms.StandardNormalVariate, numerically matching it (and scikit-learn) to floating-point precision.- Parameters:
- fit(X: ndarray, y: Any = None) MethodsSNV[source]
No-op fit; SNV is stateless (row-wise).
- nirs4all.operators.methods.n4m_ops.methods_binding_status() dict[str, Any][source]
Return the installed
n4mbinding status consumed by these operators.The result is intentionally JSON-serializable so tests, CLIs, and runtime diagnostics can report a useful blocker without importing or reimplementing any
nirs4all-methodsnumerical logic.