# `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
| Backend | Parity | 50×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-03 | 2.71 ms🏆 | 1.52 ms🏆 | 14.8 ms | 86.2 ms🏆 | 2.07 ms | 2.70 ms | 7.95 ms | 77.7 ms🏆 | 424.9 ms | 40.1 ms | 399.5 ms | 2.0 s | 136.5 ms | 1.4 s |
pls4all.cpp.blas+omp | ≈ +9e-03 | 3.00 ms | 2.39 ms | 14.7 ms🏆 | 87.2 ms | 1.95 ms🏆 | 2.68 ms🏆 | 6.34 ms🏆 | 87.5 ms | 424.6 ms🏆 | 37.1 ms🏆 | 396.2 ms🏆 | 1.8 s🏆 | 135.1 ms🏆 | 1.3 s🏆 |
pls4all.cpp.omp | ≈ +9e-03 | 3.18 ms | 2.47 ms | 14.8 ms | 95.6 ms | 2.06 ms | 3.00 ms | 7.09 ms | 84.1 ms | 452.8 ms | 40.5 ms | 413.4 ms | 1.9 s | 145.6 ms | 1.5 s |
pls4all.cpp.ref | ≈ +9e-03 | 3.08 ms | 2.69 ms | 14.9 ms | 91.2 ms | 2.14 ms | 2.84 ms | 7.83 ms | 83.8 ms | 444.0 ms | 39.9 ms | 400.0 ms | 2.0 s | 137.3 ms | 1.4 s |
| Python · pls4all |
pls4all.python | ✓ bind | 3.10 ms | — | — | — | 2.16 ms | 2.69 ms | — | — | — | — | — | — | — | — |
pls4all.sklearn | ✓ 4e-15 | 2.90 ms | — | — | — | 2.42 ms | 3.13 ms | — | — | — | — | — | — | — | — |
| R · pls4all |
pls4all.R | ✗ +6e-03 | 11.4 ms | — | — | — | 7.62 ms | 8.62 ms | — | — | — | — | — | — | — | — |
pls4all.R.formula | ✗ +6e-03 | 20.5 ms | — | — | — | 10.1 ms | 10.0 ms | — | — | — | — | — | — | — | — |
pls4all.R.mdatools | ✗ +6e-03 | 18.0 ms | — | — | — | 8.62 ms | 9.50 ms | — | — | — | — | — | — | — | — |
pls4all.R.pls | ✗ +6e-03 | 21.5 ms | — | — | — | 9.17 ms | 10.2 ms | — | — | — | — | — | — | — | — |
| MATLAB · pls4all |
pls4all.matlab | ✗ +9e+00 | 4.49 ms | — | — | — | 3.36 ms | 5.00 ms | — | — | — | — | — | — | — | — |
pls4all.matlab.classdef | ✗ +9e+00 | 5.26 ms | — | — | — | 4.03 ms | 5.81 ms | — | — | — | — | — | — | — | — |
| Python · external |
📐ref.python_chun_keles_spls | source | 6.07 ms | — | — | — | 4.04 ms | 5.12 ms | — | — | — | — | — | — | — | — |
| R · external |
📐ref.r_spls | ~ shape 1e-14 | 29.0 ms | — | — | — | 21.8 ms | 17.0 ms | — | — | — | — | — | — | — | — |
:::
:::{tab-item} 3 threads
:sync: threads-3
| Backend | Parity | 50×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-03 | — | — | — | — | 1.97 ms🏆 | — | — | — | — | — | — | — | — | — |
pls4all.cpp.blas+omp | ~ shape 9e-03 | — | — | — | — | 2.82 ms | — | — | — | — | — | — | — | — | — |
pls4all.cpp.omp | ~ shape 9e-03 | — | — | — | — | 2.10 ms | — | — | — | — | — | — | — | — | — |
pls4all.cpp.ref | ~ shape 9e-03 | — | — | — | — | 2.10 ms | — | — | — | — | — | — | — | — | — |
| Python · pls4all |
pls4all.python | ✓ 7e-15 | — | — | — | — | 2.59 ms | — | — | — | — | — | — | — | — | — |
pls4all.sklearn | ✓ 6e-15 | — | — | — | — | 2.53 ms | — | — | — | — | — | — | — | — | — |
| R · pls4all |
pls4all.R | ✗ +4e-03 | — | — | — | — | 6.45 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.formula | ✗ +4e-03 | — | — | — | — | 8.94 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.mdatools | ✗ +4e-03 | — | — | — | — | 8.57 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.pls | ✗ +4e-03 | — | — | — | — | 7.73 ms | — | — | — | — | — | — | — | — | — |
| MATLAB · pls4all |
pls4all.matlab | ✗ +9e+00 | — | — | — | — | 3.36 ms | — | — | — | — | — | — | — | — | — |
pls4all.matlab.classdef | ✗ +9e+00 | — | — | — | — | 5.67 ms | — | — | — | — | — | — | — | — | — |
| Python · external |
📐ref.python_chun_keles_spls | source | — | — | — | — | 3.90 ms | — | — | — | — | — | — | — | — | — |
| R · external |
📐ref.r_spls | ~ shape 6e-15 | — | — | — | — | 18.4 ms | — | — | — | — | — | — | — | — | — |
:::
:::{tab-item} 10 threads
:sync: threads-10
| Backend | Parity | 50×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-03 | — | — | — | — | 1.85 ms | — | — | — | — | — | — | — | — | — |
pls4all.cpp.blas+omp | ~ shape 9e-03 | — | — | — | — | 1.85 ms🏆 | — | — | — | — | — | — | — | — | — |
pls4all.cpp.omp | ~ shape 9e-03 | — | — | — | — | 1.91 ms | — | — | — | — | — | — | — | — | — |
pls4all.cpp.ref | ~ shape 9e-03 | — | — | — | — | 1.89 ms | — | — | — | — | — | — | — | — | — |
| Python · pls4all |
pls4all.python | ✓ 7e-15 | — | — | — | — | 2.02 ms | — | — | — | — | — | — | — | — | — |
pls4all.sklearn | ✓ 6e-15 | — | — | — | — | 2.06 ms | — | — | — | — | — | — | — | — | — |
| R · pls4all |
pls4all.R | ✗ +4e-03 | — | — | — | — | 5.39 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.formula | ✗ +4e-03 | — | — | — | — | 6.17 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.mdatools | ✗ +4e-03 | — | — | — | — | 6.14 ms | — | — | — | — | — | — | — | — | — |
pls4all.R.pls | ✗ +4e-03 | — | — | — | — | 6.22 ms | — | — | — | — | — | — | — | — | — |
| MATLAB · pls4all |
pls4all.matlab | ✗ +9e+00 | — | — | — | — | 3.02 ms | — | — | — | — | — | — | — | — | — |
pls4all.matlab.classdef | ✗ +9e+00 | — | — | — | — | 3.34 ms | — | — | — | — | — | — | — | — | — |
| Python · external |
📐ref.python_chun_keles_spls | source | — | — | — | — | 3.52 ms | — | — | — | — | — | — | — | — | — |
| R · external |
📐ref.r_spls | ~ shape 6e-15 | — | — | — | — | 13.2 ms | — | — | — | — | — | — | — | — | — |
:::
::::
---
_See also_: [benchmark overview](../benchmarks/overview.md) · [methods index](index.md) · [interactive dashboard](../landing/dashboard.md)