# `o2pls` — O2-PLS (two-way orthogonal) _Group_: **Multi-block / cross-modal** · _Registry tolerance_: `1e-10` ## Description O2PLS — bi-directional OPLS (Trygg & Wold 2003) From the `pls4all.sklearn.O2PLSRegression` docstring: > O2-PLS (bi-directional OPLS, Trygg & Wold 2003). > **Registry note** — R `OmicsPLS::o2m` 2.1.0 (Bouhaddani 2018) joint-SVD O2PLS. pls4all defaults to the OmicsPLS::o2m algorithm and matches R bit-for-bit (~1e-13 max_abs). The pre-0.97 peel-then-PLS path (Trygg & Wold 2003 §3.2 power-iteration recipe) is reachable via the `legacy=True` adapter kwarg / `cfg.solver = NIPALS`. ### Parameters | Name | Type | Default | Notes | |------|------|---------|-------| | `n_predictive` | `int` | `2` | Number of joint (predictive) components shared by X and Y in O2-PLS. | | `n_x_orthogonal` | `int` | `1` | Number of X-orthogonal components (Y-irrelevant structure in X). | | `n_y_orthogonal` | `int` | `1` | Number of Y-orthogonal components (X-irrelevant structure in Y). | | `n_targets` | `int` | `4` | registry benchmark cell value | ## Explanations ### Bibliographic source Trygg, J. & Wold, S. (2003). *O2-PLS, a two-block (X–Y) latent variable regression method with an integral OSC filter*. Journal of Chemometrics 17(1), 53–64. ### Mathematical principle O2-PLS extends OPLS symmetrically to both $\mathbf{X}$ and $\mathbf{Y}$: it decomposes each block into a joint predictive component plus block-orthogonal components. Unlike OPLS, which is asymmetric ($\mathbf{Y}$ drives the decomposition of $\mathbf{X}$), O2-PLS treats both matrices as observation blocks of equal status. Required hyperparameters: $n_{\mathrm{pred}}$ (joint components), $n_{\mathrm{X,ortho}}$ (X-unique orthogonal), $n_{\mathrm{Y,ortho}}$ (Y-unique orthogonal). Choosing all three by cross-validation is a 3-D grid which can be expensive; a common compromise fixes the orthogonal counts at 1 and tunes only $n_{\mathrm{pred}}$. O2-PLS is dominant in metabolomics ↔ transcriptomics integration where the analyst wants to disentangle platform-specific orthogonal variation from biology that is consistent across platforms. ### Implementation `n4m_o2pls_fit`. Reference: CRAN `OmicsPLS 2.1.0`. MATLAB header (`bindings/matlab/+pls4all/O2plsRegression.m`): ```text pls4all.O2plsRegression O2-PLS (bi-directional OPLS). ``` ### 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** ::::{tab-set} :class: pls4all-bindings :::{tab-item} C ABI · libn4m :sync: c :class-label: lang-c ```c /* C ABI — libn4m */ n4m_context_t* ctx = n4m_context_create(); n4m_config_t* cfg = n4m_config_create(); n4m_method_result_t* res = NULL; n4m_o2pls_fit(ctx, cfg, &x_view, &y_view, /* hyperparams */, &res); /* … read coefficients / mask / scores via */ /* n4m_method_result_get_double_matrix / vector / scalar … */ n4m_method_result_destroy(res); n4m_config_destroy(cfg); n4m_context_destroy(ctx); ``` ::: :::{tab-item} Python · pls4all (raw) :sync: python-raw :class-label: lang-python ```python import pls4all from pls4all._methods import o2pls_fit with pls4all.Context() as ctx, pls4all.Config() as cfg: res = o2pls_fit(ctx, cfg, X, y) # then: res.matrix("predictions"), res.matrix("coefficients"), # res.vector("mask"), res.scalar("intercept"), … ``` ::: :::{tab-item} Python · pls4all.sklearn :sync: python-sklearn :class-label: lang-python ```python from pls4all.sklearn import O2PLSRegression mdl = O2PLSRegression(n_predictive=2, n_x_orthogonal=1, n_y_orthogonal=1) mdl.fit(X, y) y_hat = mdl.predict(X_test) ``` ::: :::{tab-item} R · pls4all_method() :sync: r-dispatcher :class-label: lang-r ```r library(pls4all) # Unified low-level dispatcher (May 2026 R cleanup): res <- pls4all_method("o2pls", X, y, n_components = 2L, params = list(n_targets = 4L, n_predictive = 2L, n_x_orthogonal = 1L, n_y_orthogonal = 1L)) # res is a named list with MethodResult arrays/scalars. # selected_indices / top_k_intervals are 1-based. ``` ::: :::{tab-item} MATLAB · pls4all (MEX) :sync: matlab-mex :class-label: lang-matlab ```matlab res = pls4all.o2pls(X, y, 2); % see header of bindings/matlab/+pls4all/o2pls.m for full % parameter surface: % res = o2pls(X, Y, n_predictive, n_x_orthogonal, n_y_orthogonal) yhat = predict(res, Xtest); ``` ::: :::{tab-item} MATLAB · pls4all (classdef) :sync: matlab-classdef :class-label: lang-matlab ```matlab mdl = pls4all.fit("o2pls", X, y, "NumComponents", 2); yhat = predict(mdl, Xtest); ``` ::: :::: **Registry parity references** 📐 :::{card} :class-card: external-refs - 📐 **`ref.r_omicspls`** (R · r) — `OmicsPLS` 2.1.0 · strict (rmse_rel ≤ 1e-10) — R `OmicsPLS::o2m` (Bouhaddani 2018), joint-SVD O2PLS. pls4all's default O2PLS path now matches this algorithm bit-for-bit (max_abs ~1e-13 on the parity sizes); the legacy peel-then-PLS implementation is opt-in. ::: ### Benchmarks Adaptive wall-clock per cell measured against [`full_matrix.csv`](../benchmarks/overview.md). 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  ·  ✗ divergent  ·  ⚠ error  ·  — not run. The fastest backend per column is marked 🏆. **Reference gate**: strict — numeric equivalence (`rmse_rel_tol ≤ 1e-10`). Rows tagged with **📐** are the canonical parity references for this method (declared in [`parity_timing.registry`](../benchmarks/methodology.md)). 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. ::::{tab-set} :class: parity-tabs :::{tab-item} 1 thread :sync: threads-1
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×30 (ms)250×50 (ms)500×50 (ms)500×500 (ms)500×2500 (ms)2500×50 (ms)2500×500 (ms)2500×2500 (ms)10000×50 (ms)10000×500 (ms)
C++ native · libn4m
pls4all.cpp.blas≈ +4e-103.13 ms1.39 ms12.8 ms70.1 ms1.32 ms2.73 ms6.52 ms🏆72.7 ms344.6 ms35.1 ms350.3 ms1.7 s138.6 ms1.3 s
pls4all.cpp.blas+omp≈ +4e-103.12 ms1.64 ms13.8 ms70.9 ms1.32 ms3.10 ms6.65 ms70.7 ms341.8 ms35.1 ms349.9 ms1.6 s🏆138.0 ms1.2 s
pls4all.cpp.omp≈ +4e-102.96 ms1.78 ms12.8 ms71.6 ms1.36 ms2.78 ms7.18 ms72.3 ms349.2 ms34.8 ms🏆359.4 ms1.6 s131.6 ms🏆1.2 s🏆
pls4all.cpp.ref≈ +4e-102.80 ms1.22 ms🏆11.8 ms🏆69.6 ms🏆1.29 ms🏆3.00 ms7.63 ms69.2 ms🏆341.1 ms🏆38.6 ms349.4 ms🏆1.7 s144.4 ms1.3 s
Python · pls4all
pls4all.python✓ bind2.76 ms🏆1.44 ms2.59 ms🏆
pls4all.sklearn✓ 2e-152.82 ms1.77 ms3.15 ms
R · pls4all
pls4all.R✗ +1e+0011.8 ms4.55 ms10.7 ms
pls4all.R.formula✗ +1e+0019.0 ms5.90 ms8.46 ms
pls4all.R.mdatools✗ +1e+0017.6 ms5.34 ms10.6 ms
pls4all.R.pls✗ +1e+0020.8 ms5.33 ms9.57 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+004.82 ms2.23 ms4.38 ms
pls4all.matlab.classdef✗ +9e+004.95 ms2.85 ms7.91 ms
R · external
📐ref.r_omicsplssource24.4 ms11.1 ms13.4 ms
::: :::{tab-item} 3 threads :sync: threads-3
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×30 (ms)250×50 (ms)500×50 (ms)500×500 (ms)500×2500 (ms)2500×50 (ms)2500×500 (ms)2500×2500 (ms)10000×50 (ms)10000×500 (ms)
C++ native · libn4m
pls4all.cpp.blas✓ ref 4e-101.47 ms
pls4all.cpp.blas+omp✓ ref 4e-101.30 ms
pls4all.cpp.omp✓ ref 4e-101.29 ms🏆
pls4all.cpp.ref✓ ref 4e-101.40 ms
Python · pls4all
pls4all.python✓ bind1.33 ms
pls4all.sklearn✓ 9e-161.82 ms
R · pls4all
pls4all.R✗ +1e+004.15 ms
pls4all.R.formula✗ +1e+005.40 ms
pls4all.R.mdatools✗ +1e+005.42 ms
pls4all.R.pls✗ +1e+005.30 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+002.31 ms
pls4all.matlab.classdef✗ +9e+003.04 ms
R · external
📐ref.r_omicsplssource12.0 ms
::: :::{tab-item} 10 threads :sync: threads-10
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×30 (ms)250×50 (ms)500×50 (ms)500×500 (ms)500×2500 (ms)2500×50 (ms)2500×500 (ms)2500×2500 (ms)10000×50 (ms)10000×500 (ms)
C++ native · libn4m
pls4all.cpp.blas✓ ref 4e-101.22 ms
pls4all.cpp.blas+omp✓ ref 4e-101.23 ms
pls4all.cpp.omp✓ ref 4e-101.21 ms🏆
pls4all.cpp.ref✓ ref 4e-101.23 ms
Python · pls4all
pls4all.python✓ bind1.46 ms
pls4all.sklearn✓ 9e-161.41 ms
R · pls4all
pls4all.R✗ +1e+003.04 ms
pls4all.R.formula✗ +1e+003.74 ms
pls4all.R.mdatools✗ +1e+003.67 ms
pls4all.R.pls✗ +1e+003.67 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+002.01 ms
pls4all.matlab.classdef✗ +9e+002.53 ms
R · external
📐ref.r_omicsplssource7.33 ms
::: :::: --- _See also_: [benchmark overview](../benchmarks/overview.md) · [methods index](index.md) · [interactive dashboard](../landing/dashboard.md)