# `sparse_simpls` — Sparse SIMPLS (Chun & Keleş 2010) _Group_: **Sparse** · _Registry tolerance_: `1.0` ## Description Sparse SIMPLS with soft-threshold lambda From the `pls4all.sklearn.SparseSimplsRegression` docstring: > Sparse SIMPLS with soft-thresholded weights (Chun & Keles 2010). > **Registry note** — R `spls` 2.3.2 (Chun & Keles 2010) is the canonical external reference. The in-tree NumPy port `SparseSimplsPythonReference` provides a hermetic alternative when R is unavailable. ### Parameters | Name | Type | Default | Notes | |------|------|---------|-------| | `n_components` | `int` | `2` | Number of latent components extracted (k). | | `sparsity_lambda` | `float` | `0.05` | L1 soft-threshold magnitude applied to the PLS weight vectors. | ## Explanations ### Bibliographic source Chun, H. & Keleş, S. (2010). *Sparse partial least squares regression for simultaneous dimension reduction and variable selection*. JRSS B 72(1), 3–25. ### Mathematical principle Sparse PLS adds a soft-thresholding step to each SIMPLS loading weight so that the latent direction is supported on only a small subset of features. Mathematically, after the un-thresholded weight $\mathbf{w}$ is computed, we solve $\mathbf{w}^{\star} = \arg\min_{\|\mathbf{c}\|=1} \|\mathbf{c} - \mathbf{w}\|_2^2 + \lambda \|\mathbf{c}\|_1$, which has the closed-form soft-threshold solution $c_j = \operatorname{sign}(w_j)\,(|w_j| - \lambda/2)_+$ followed by re-normalisation. The penalty $\lambda$ controls sparsity: small $\lambda$ approaches standard PLS, large $\lambda$ zeroes most weights. In high-dimensional ($p \gg n$) spectroscopy or omics data, sparse PLS simultaneously builds the latent predictive direction *and* selects the variables that support it — a much cleaner story than running PLS then thresholding coefficients post-hoc. The Chun & Keleş formulation differs subtly from the earlier Lê Cao 2008 sPLS (used in mixOmics): Chun & Keleş threshold the un-deflated weight while Lê Cao threshold the deflated weight at each iteration. pls4all implements the Chun & Keleş formulation. ### Implementation `n4m_sparse_simpls_fit`. Reference: CRAN `spls 2.3.2` (Chun & Keleş authors). No widely installable Python port exists with this exact normalisation convention. MATLAB header (`bindings/matlab/+pls4all/SparsePlsRegression.m`): ```text pls4all.SparsePlsRegression — Sparse SIMPLS (Chun & Keles 2010) as a tier-2 classdef. Construct via the factory: mdl = pls4all.fitrsparsepls(X, y, "NumComponents", 5, "Lambda", 0.05) or directly: ``` ### 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_sparse_simpls_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 sparse_simpls_fit with pls4all.Context() as ctx, pls4all.Config() as cfg: res = sparse_simpls_fit(ctx, cfg, X, y, n_components=4) # 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 SparseSimplsRegression mdl = SparseSimplsRegression(n_components=2, sparsity_lambda=0.05) 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("sparse_simpls", X, y, n_components = 4L, params = list(sparsity_lambda = 0.05)) # 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.sparse_simpls(X, y, 4); % see header of bindings/matlab/+pls4all/sparse_simpls.m for full % parameter surface: % res = sparse_simpls(X, Y, n_components, sparsity_lambda) yhat = predict(res, Xtest); ``` ::: :::{tab-item} MATLAB · pls4all (classdef) :sync: matlab-classdef :class-label: lang-matlab ```matlab mdl = pls4all.fit("sparse_simpls", X, y, "NumComponents", 4); yhat = predict(mdl, Xtest); ``` ::: :::: **Registry parity references** 📐 :::{card} :class-card: external-refs - 📐 **`ref.python_chun_keles_spls`** (python · python) — `chun_keles_spls` 1.0 · qualitative (rmse_rel ≤ 1e+00) — In-tree NumPy port of Chun & Keles 2010 sparse PLS (the default `pls2` / `simpls` configuration of R `spls::spls`). Verified against the R 2.3.2 package on the parity cells. - 📐 **`ref.r_spls`** (R · r) — `spls` 2.3.2 · qualitative (rmse_rel ≤ 1e+00) — R `spls` 2.3.2 (Chun & Keles). Predicts via the regression coefficient matrix from sparse-thresholded SIMPLS. ::: ### 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**: qualitative — shape/smoke comparison only. The external library and pls4all do not produce numerically equivalent output for this method (see the MethodSpec notes); the `rmse_rel_tol ≤ 1e+00` budget is set wide on purpose. Treat ~ shape as *“we ran both, both finished”*, not as numerical agreement. 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×50 (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≈ +9e-032.71 ms🏆1.52 ms🏆14.8 ms86.2 ms🏆2.07 ms2.70 ms7.95 ms77.7 ms🏆424.9 ms40.1 ms399.5 ms2.0 s136.5 ms1.4 s
pls4all.cpp.blas+omp≈ +9e-033.00 ms2.39 ms14.7 ms🏆87.2 ms1.95 ms🏆2.68 ms🏆6.34 ms🏆87.5 ms424.6 ms🏆37.1 ms🏆396.2 ms🏆1.8 s🏆135.1 ms🏆1.3 s🏆
pls4all.cpp.omp≈ +9e-033.18 ms2.47 ms14.8 ms95.6 ms2.06 ms3.00 ms7.09 ms84.1 ms452.8 ms40.5 ms413.4 ms1.9 s145.6 ms1.5 s
pls4all.cpp.ref≈ +9e-033.08 ms2.69 ms14.9 ms91.2 ms2.14 ms2.84 ms7.83 ms83.8 ms444.0 ms39.9 ms400.0 ms2.0 s137.3 ms1.4 s
Python · pls4all
pls4all.python✓ bind3.10 ms2.16 ms2.69 ms
pls4all.sklearn✓ 4e-152.90 ms2.42 ms3.13 ms
R · pls4all
pls4all.R✗ +6e-0311.4 ms7.62 ms8.62 ms
pls4all.R.formula✗ +6e-0320.5 ms10.1 ms10.0 ms
pls4all.R.mdatools✗ +6e-0318.0 ms8.62 ms9.50 ms
pls4all.R.pls✗ +6e-0321.5 ms9.17 ms10.2 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+004.49 ms3.36 ms5.00 ms
pls4all.matlab.classdef✗ +9e+005.26 ms4.03 ms5.81 ms
Python · external
📐ref.python_chun_keles_splssource6.07 ms4.04 ms5.12 ms
R · external
📐ref.r_spls~ shape 1e-1429.0 ms21.8 ms17.0 ms
::: :::{tab-item} 3 threads :sync: threads-3
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×50 (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~ shape 9e-031.97 ms🏆
pls4all.cpp.blas+omp~ shape 9e-032.82 ms
pls4all.cpp.omp~ shape 9e-032.10 ms
pls4all.cpp.ref~ shape 9e-032.10 ms
Python · pls4all
pls4all.python✓ 7e-152.59 ms
pls4all.sklearn✓ 6e-152.53 ms
R · pls4all
pls4all.R✗ +4e-036.45 ms
pls4all.R.formula✗ +4e-038.94 ms
pls4all.R.mdatools✗ +4e-038.57 ms
pls4all.R.pls✗ +4e-037.73 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+003.36 ms
pls4all.matlab.classdef✗ +9e+005.67 ms
Python · external
📐ref.python_chun_keles_splssource3.90 ms
R · external
📐ref.r_spls~ shape 6e-1518.4 ms
::: :::{tab-item} 10 threads :sync: threads-10
BackendParity50×250 (ms)100×50 (ms)100×500 (ms)100×2500 (ms)200×50 (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~ shape 9e-031.85 ms
pls4all.cpp.blas+omp~ shape 9e-031.85 ms🏆
pls4all.cpp.omp~ shape 9e-031.91 ms
pls4all.cpp.ref~ shape 9e-031.89 ms
Python · pls4all
pls4all.python✓ 7e-152.02 ms
pls4all.sklearn✓ 6e-152.06 ms
R · pls4all
pls4all.R✗ +4e-035.39 ms
pls4all.R.formula✗ +4e-036.17 ms
pls4all.R.mdatools✗ +4e-036.14 ms
pls4all.R.pls✗ +4e-036.22 ms
MATLAB · pls4all
pls4all.matlab✗ +9e+003.02 ms
pls4all.matlab.classdef✗ +9e+003.34 ms
Python · external
📐ref.python_chun_keles_splssource3.52 ms
R · external
📐ref.r_spls~ shape 6e-1513.2 ms
::: :::: --- _See also_: [benchmark overview](../benchmarks/overview.md) · [methods index](index.md) · [interactive dashboard](../landing/dashboard.md)