opls — Orthogonal PLS (OPLS)¶
Group: Core PLS · Registry tolerance: 0.001
Description¶
Orthogonal PLS (Trygg & Wold 2002)
From the pls4all.sklearn.OPLSRegression docstring:
Orthogonal PLS regression (Trygg & Wold 2002).
Registry note — Bioconductor
ropls::oplsis the external OPLS reference; convergence and orthogonal-component conventions may differ.
Parameters¶
Name |
Type |
Default |
Notes |
|---|---|---|---|
|
|
|
Number of latent components extracted (k). |
|
|
|
Inner algorithm: ‘nipals’, ‘simpls’, ‘svd’, ‘kernel’, ‘orthogonal-scores’, ‘power’, ‘randomized-svd’, ‘wide-kernel’. |
|
|
|
Subtract the column mean of X before fitting. |
|
|
|
Standardize X columns to unit variance before fitting. |
|
|
|
Subtract the column mean of y before fitting. |
|
|
|
Standardize y columns to unit variance before fitting. |
|
|
|
Convergence tolerance for iterative solvers (NIPALS / power-iteration). |
|
|
|
Maximum iterations for iterative solvers. |
|
|
|
If True, keep the latent score matrix ( |
Explanations¶
Bibliographic source¶
Trygg, J. & Wold, S. (2002). Orthogonal projections to latent structures (O-PLS). Journal of Chemometrics 16(3), 119–128.
Mathematical principle¶
OPLS rotates the standard PLS latent space so that a single direction captures all \(\mathbf{Y}\)-correlated variation while the remaining components capture \(\mathbf{Y}\)-orthogonal structural variation in \(\mathbf{X}\). The resulting decomposition \(\mathbf{X} = \mathbf{t}_p\mathbf{p}_p^{\top} + \mathbf{T}_o\mathbf{P}_o^{\top} + \mathbf{E}\) separates the predictive component \(\mathbf{t}_p\) from the orthogonal block \(\mathbf{T}_o\), which absorbs spectroscopic baselines, scatter and other nuisance factors that confound interpretation of the predictive loading.
Numerically OPLS proceeds by NIPALS-deflating \(\mathbf{X}\) against directions orthogonal to \(\mathbf{X}^{\top}\mathbf{y}\) before each new predictive component is extracted. Predictions are identical to those of a one-component PLS on the orthogonal-corrected \(\mathbf{X}\); the value is in the interpretation of the loadings, not in better predictions per se.
OPLS shines in metabolomics and process spectroscopy where the spectra carry strong systematic but non-predictive variation; in those settings the single-vector predictive loading is far easier to relate to biology / chemistry than a multi-component PLS loading matrix.
Implementation¶
Algorithm.OPLS + Solver.NIPALS + Deflation.ORTHOGONAL. Reference: Bioconductor ropls::opls. Note: orthogonal-component ordering and the criterion that stops orthogonal extraction differ between implementations — exact bit parity is not expected, but RMSE-rel parity within ~1e-3 is.
MATLAB header (bindings/matlab/+pls4all/OplsRegression.m):
pls4all.OplsRegression — Orthogonal Partial Least Squares Regression model.
Example:
mdl = pls4all.OplsRegression(X, y, 5);
yhat = predict(mdl, Xnew);
Usage¶
Every pls4all binding tab dispatches into the same C kernel; the external libraries listed at the bottom of the page are the parity references registered in benchmarks.parity_timing.registry. Switch tabs to read the same fit in your language. The R package now ships drop-in-compatible facades for the CRAN pls package (plsr, pcr, mvr) and for the mdatools::pls(x, y, ...) matrix idiom — those tabs appear only on the methods that have a meaningful equivalence.
pls4all bindings
/* C ABI — libn4m (Model.fit path) */
n4m_context_t* ctx = n4m_context_create();
n4m_config_t* cfg = n4m_config_create();
n4m_config_set_algorithm(cfg, N4M_ALGORITHM_PLS_REGRESSION);
n4m_config_set_solver (cfg, N4M_SOLVER_SIMPLS);
n4m_config_set_n_components(cfg, 4);
n4m_model_t* mdl = NULL;
n4m_model_fit(ctx, cfg, &x_view, &y_view, &mdl);
n4m_model_predict(ctx, mdl, &x_test_view, &y_hat_view);
n4m_model_destroy(mdl);
n4m_config_destroy(cfg);
n4m_context_destroy(ctx);
import pls4all
from pls4all import Algorithm, Solver
with pls4all.Context() as ctx, pls4all.Config() as cfg:
cfg.algorithm = Algorithm.PLS_REGRESSION
cfg.solver = Solver.SIMPLS
cfg.n_components = 4
with pls4all.Model.fit(ctx, cfg, X, y) as mdl:
y_hat = mdl.predict(X_test)
from pls4all.sklearn import OPLSRegression
mdl = OPLSRegression(n_components=2, solver='nipals', center_x=True, scale_x=True, center_y=True, scale_y=False, tol=1e-06, max_iter=500, store_scores=False)
mdl.fit(X, y)
y_hat = mdl.predict(X_test)
library(pls4all)
# Unified low-level dispatcher (May 2026 R cleanup):
res <- pls4all_method("opls", X, y,
n_components = 4L)
# res is a named list with MethodResult arrays/scalars.
# selected_indices / top_k_intervals are 1-based.
res = pls4all.opls(X, y, 4);
% see header of bindings/matlab/+pls4all/opls.m for full
% parameter surface:
% [coefs, x_mean, y_mean, predictions] = opls(X, Y, n_components)
yhat = predict(res, Xtest);
mdl = pls4all.fit("opls", X, y, "NumComponents", 4);
yhat = predict(mdl, Xtest);
Registry parity references 📐
📐
ref.r_ropls(R · r) —roplsBioc · relaxed (rmse_rel ≤ 1e-03) — Bioconductorropls::opls— OPLS reference. Permutations and plotting are disabled in benchmark timing; ropls still requires crossvalI >= 1 for a finite Q2 path.
Benchmarks¶
Adaptive wall-clock per cell measured against full_matrix.csv. Only backends that implement this method are listed; libraries without the method are omitted.
Verdict · ✓ ref / ≈ ref / ~ shape mark a reference-gate pass at strict / relaxed / qualitative tolerance · ✓ bind = pls4all binding agrees with the C++ baseline · ⇄ cross-check = documented by-design selector/RNG/model, noncanonical API/facade convention, or secondary oracle · ✗ divergent · ⚠ error · — not run. The fastest backend per column is marked 🏆.
Reference gate: strict — numeric equivalence (rmse_rel_tol ≤ 1e-08).
Rows tagged with 📐 are the canonical parity references for this method (declared in parity_timing.registry). C++ and external rows show reference parity; pls4all language bindings show binding parity against the C++ backend. Hover the icon for role and tolerance band.
| Backend | Parity | 200×50 (ms) |
|---|---|---|
| C++ native · libn4m | ||
pls4all.cpp.blas+omp | ✓ ref 5e-15 | 1.87 ms🏆 |
| Python · pls4all | ||
pls4all.python | ✓ bind | 1.88 ms |
pls4all.sklearn | ✓ bind | 2.12 ms |
| R · pls4all | ||
pls4all.R | ✓ 2e-14 | 4.35 ms |
pls4all.R.formula | ✓ 2e-14 | 5.13 ms |
pls4all.R.mdatools | ✓ 2e-14 | 5.23 ms |
pls4all.R.pls | ✓ 2e-14 | 5.40 ms |
| R · external | ||
📐ref.r_ropls | source | 15.4 ms |
| Backend | Parity | 200×50 (ms) |
|---|---|---|
| C++ native · libn4m | ||
pls4all.cpp.blas+omp | ✓ ref 5e-15 | 1.96 ms |
| Python · pls4all | ||
pls4all.python | ✓ bind | 1.79 ms🏆 |
pls4all.sklearn | ✓ bind | 2.14 ms |
| R · pls4all | ||
pls4all.R | ✓ 2e-14 | 6.22 ms |
pls4all.R.formula | ✓ 2e-14 | 5.57 ms |
pls4all.R.mdatools | ✓ 2e-14 | 7.12 ms |
pls4all.R.pls | ✓ 2e-14 | 7.88 ms |
| R · external | ||
📐ref.r_ropls | source | 16.0 ms |
| Backend | Parity | 200×50 (ms) |
|---|---|---|
| C++ native · libn4m | ||
pls4all.cpp.blas+omp | ✓ ref 5e-15 | 1.73 ms🏆 |
| Python · pls4all | ||
pls4all.python | ✓ bind | 1.81 ms |
pls4all.sklearn | ✓ bind | 1.94 ms |
| R · pls4all | ||
pls4all.R | ✓ 2e-14 | 4.17 ms |
pls4all.R.formula | ✓ 2e-14 | 5.09 ms |
pls4all.R.mdatools | ✓ 2e-14 | 5.39 ms |
pls4all.R.pls | ✓ 2e-14 | 5.17 ms |
| R · external | ||
📐ref.r_ropls | source | 16.0 ms |
See also: benchmark overview · methods index · interactive dashboard