# `sparse_simpls` — Sparse SIMPLS (Chun & Keleş 2010)
_Group_: **Sparse** · _Registry tolerance_: `1e-08`
## 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_estimators_sparse_simpls_fit`. Reference: CRAN `spls 2.3.2` (Chun & Keleş authors). No widely installable Python port exists with this exact normalisation convention.
R roxygen note (`sklearn_methods.R::sparse_pls`):
> Sparse SIMPLS — formula entry point.
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_estimators_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} R · pls4all (raw fn)
:sync: r-raw
:class-label: lang-r
```r
library(pls4all)
res <- sparse_simpls_fit(X, Y, n_components, sparsity_lambda = 0.05)
yhat <- pls4all_predict(res, X_test)
```
:::
:::{tab-item} R · pls4all (formula+S3)
:sync: r-formula
:class-label: lang-r
```r
library(pls4all)
fit <- sparse_pls(y ~ ., data = train, ncomp = 4L)
yhat <- predict(fit, newdata = test)
summary(fit)
```
:::
:::{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 · strict (rmse_rel ≤ 1e-08) — 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 · strict (rmse_rel ≤ 1e-08) — 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 · ⇄ 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`](../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 | 200×50 (ms) |
| C++ native · libn4m |
pls4all.cpp.blas+omp | ✓ ref 7e-16 | 1.89 ms |
| Python · pls4all |
pls4all.python | ✓ bind | 1.93 ms |
pls4all.sklearn | ✓ bind | 1.88 ms🏆 |
| R · pls4all |
pls4all.R | ✓ 5e-15 | 4.60 ms |
pls4all.R.formula | ✓ 5e-15 | 5.64 ms |
pls4all.R.mdatools | ✓ 5e-15 | 6.30 ms |
pls4all.R.pls | ✓ 5e-15 | 5.36 ms |
| Python · external |
📐ref.python_chun_keles_spls | source | 3.55 ms |
| R · external |
📐ref.r_spls | ⇄ +6e-15 | 13.4 ms |
:::
:::{tab-item} 3 threads
:sync: threads-3
| Backend | Parity | 200×50 (ms) |
| C++ native · libn4m |
pls4all.cpp.blas+omp | ✓ ref 7e-16 | 1.93 ms |
| Python · pls4all |
pls4all.python | ✓ bind | 1.87 ms🏆 |
pls4all.sklearn | ✓ bind | 1.92 ms |
| R · pls4all |
pls4all.R | ✓ 5e-15 | 4.97 ms |
pls4all.R.formula | ✓ 5e-15 | 6.05 ms |
pls4all.R.mdatools | ✓ 5e-15 | 6.32 ms |
pls4all.R.pls | ✓ 5e-15 | 5.77 ms |
| Python · external |
📐ref.python_chun_keles_spls | source | 3.54 ms |
| R · external |
📐ref.r_spls | ⇄ +6e-15 | 12.8 ms |
:::
:::{tab-item} 10 threads
:sync: threads-10
| Backend | Parity | 200×50 (ms) |
| C++ native · libn4m |
pls4all.cpp.blas+omp | ✓ ref 7e-16 | 1.91 ms🏆 |
| Python · pls4all |
pls4all.python | ✓ bind | 1.98 ms |
pls4all.sklearn | ✓ bind | 1.95 ms |
| R · pls4all |
pls4all.R | ✓ 5e-15 | 4.83 ms |
pls4all.R.formula | ✓ 5e-15 | 5.49 ms |
pls4all.R.mdatools | ✓ 5e-15 | 6.00 ms |
pls4all.R.pls | ✓ 5e-15 | 5.74 ms |
| Python · external |
📐ref.python_chun_keles_spls | source | 3.58 ms |
| R · external |
📐ref.r_spls | ⇄ +6e-15 | 12.0 ms |
:::
::::
---
_See also_: [benchmark overview](../benchmarks/overview.md) · [methods index](index.md) · [interactive dashboard](../landing/dashboard.md)