pySPFM provides three main estimators that follow the scikit-learn API:
SparseDeconvolution: The core estimator for sparse hemodynamic deconvolution.
Supports both univariate (voxel-wise) and multivariate (joint spatial) solving modes.
LowRankPlusSparse: Decomposes fMRI data into low-rank (structured noise/drift)
and sparse (neural activity) components using robust PCA combined with sparse deconvolution.
StabilitySelection: Provides robust estimation through stability selection,
solving the problem across multiple subsampled datasets and computing area-under-curve (AUC)
stability scores.
Sparse hemodynamic deconvolution using LARS or FISTA.
This estimator implements Sparse Paradigm Free Mapping (SPFM) for
deconvolution of fMRI data. It estimates activity-inducing signals
(spike model) or innovation signals (block model) from BOLD timeseries.
The estimator supports two solving modes:
Univariate mode (group=0.0, default):
Each voxel is solved independently using pure L1 (LASSO) regularization.
This is efficient and suitable when spatial structure is not important.
Multivariate mode (group>0.0):
All voxels are solved jointly using L2,1 mixed-norm regularization,
which encourages spatial grouping of activity across voxels at the
same timepoint. This leverages spatial structure in 4D fMRI data.
Requires a FISTA-compatible criterion (‘mad’, ‘factor’, etc.).
Parameters:
tr (float) – Repetition time (TR) of the fMRI acquisition in seconds.
te (list of float, default=None) – Echo times in milliseconds for multi-echo data. If None or [0],
assumes single-echo data.
hrf_model (str, default=’spm’) – HRF model to use. Options are ‘spm’, ‘glover’, or a path to a custom
HRF file (.1D or .txt).
block_model (bool, default=False) – If True, estimate innovation signals (block model).
If False, estimate activity-inducing signals (spike model).
criterion (str, default=’bic’) – Criterion for lambda selection:
‘bic’, ‘aic’: Information criteria (LARS solver, univariate only).
debias (bool, default=True) – If True, perform debiasing step to recover true amplitude.
group (float, default=0.0) – Weight for spatial grouping using L2,1 mixed-norm regularization.
Range [0, 1] where:
group=0.0: Pure L1/LASSO (univariate, voxel-wise independent).
group=1.0: Pure L2,1 (multivariate, maximum spatial grouping).
0<group<1: Elastic net-like mix of L1 and L2,1.
When group>0, the solver operates on all voxels jointly
(multivariate mode) and requires a FISTA-compatible criterion.
pcg (float, default=0.8) – Percentage of maximum lambda to use (for criterion=’pcg’).
factor (float, default=1.0) – Factor to multiply noise estimate for lambda selection.
max_iter (int, default=400) – Maximum number of iterations for the FISTA solver.
tol (float, default=1e-6) – Convergence tolerance.
n_jobs (int, default=1) – Number of parallel jobs for the per-voxel LARS criteria (‘bic’, ‘aic’).
The FISTA criteria solve all voxels in a single batched call, so n_jobs
has no effect on them.
In multivariate mode, computation is inherently joint.
positive (bool, default=False) – If True, enforce non-negative coefficients.
weights (ndarray of shape (n_voxels,), default=None) – Per-voxel weight map modulating the multivariate (L2,1 + L1 mixed-norm)
penalty in multivariate mode (group>0), adaptive-LASSO style: the
effective threshold for voxel j is lambda/w_j, scaling both the
sparsity and grouping terms. Higher weights penalize less (retain more
activity); lower weights penalize more. Must be finite and strictly
positive (w_j=1 is neutral). Only valid in multivariate mode; passing
weights with group==0 (or a LARS criterion) raises ValueError.
Variables:
coef (ndarray of shape (n_timepoints, n_voxels)) – Estimated activity-inducing (spike) or innovation (block) signals.
lambda (ndarray of shape (n_voxels,) or float) – Selected regularization parameter. In multivariate mode, a single
lambda is used for all voxels.
hrf_matrix (ndarray of shape (n_timepoints * n_echoes, n_timepoints)) – The HRF convolution matrix used for deconvolution.
n_features_in (int) – Number of voxels seen during fit.
X (array-like of shape (n_timepoints, n_voxels) or (n_timepoints * n_echoes, n_voxels)) – The fMRI timeseries data. For multi-echo data, timepoints from
different echoes should be concatenated along the first axis.
y (None) – Not used, present for API consistency.
Returns:
self (object) – Fitted estimator.
Raises:
ValueError – If group>0 is used with a LARS criterion (‘bic’, ‘aic’),
since multivariate mode requires FISTA.
Return the explained variance ratio of the deconvolution.
The score is computed as \(R^2 = 1 - SS_{res} / SS_{tot}\),
where \(SS_{res}\) is the residual sum of squares and
\(SS_{tot}\) is the total sum of squares.
Parameters:
X (array-like of shape (n_timepoints, n_voxels)) – Test samples (fMRI timeseries).
y (None) – Not used, present for API consistency.
Returns:
score (float) – Explained variance ratio averaged across voxels.
The method works on simple estimators as well as on nested objects.
The latter have parameters of the form <component>__<parameter>
so that it’s possible to update each component of a nested object.
This estimator implements the Sparse and Low-Rank Paradigm Free Mapping
(SPLORA) algorithm, which separates fMRI data into low-rank (global/
structured) and sparse (transient neuronal) components.
Parameters:
tr (float) – Repetition time (TR) of the fMRI acquisition in seconds.
te (list of float, default=None) – Echo times in seconds for multi-echo data. If None or [0], assumes
single-echo data.
hrf_model (str, default=’spm’) – HRF model to use. Options are ‘spm’, ‘glover’, or a path to a custom
HRF file (.1D or .txt).
block_model (bool, default=False) – If True, estimate innovation signals (block model).
If False, estimate activity-inducing signals (spike model).
Return the explained variance ratio of the deconvolution.
The score is computed as \(R^2 = 1 - SS_{res} / SS_{tot}\),
where \(SS_{res}\) is the residual sum of squares and
\(SS_{tot}\) is the total sum of squares.
Parameters:
X (array-like of shape (n_timepoints, n_voxels)) – Test samples (fMRI timeseries).
y (None) – Not used, present for API consistency.
Returns:
score (float) – Explained variance ratio averaged across voxels.
The method works on simple estimators as well as on nested objects.
The latter have parameters of the form <component>__<parameter>
so that it’s possible to update each component of a nested object.
Stability selection for robust sparse deconvolution.
This estimator uses stability selection to identify robust features
in the sparse deconvolution problem. It runs multiple deconvolutions
on subsampled data and returns the selection frequency (AUC) for each
timepoint.
Parameters:
tr (float) – Repetition time (TR) of the fMRI acquisition in seconds.
te (list of float, default=None) – Echo times in seconds for multi-echo data.
hrf_model (str, default=’spm’) – HRF model to use.
Return the explained variance ratio of the deconvolution.
The score is computed as \(R^2 = 1 - SS_{res} / SS_{tot}\),
where \(SS_{res}\) is the residual sum of squares and
\(SS_{tot}\) is the total sum of squares.
Parameters:
X (array-like of shape (n_timepoints, n_voxels)) – Test samples (fMRI timeseries).
y (None) – Not used, present for API consistency.
Returns:
score (float) – Explained variance ratio averaged across voxels.
The method works on simple estimators as well as on nested objects.
The latter have parameters of the form <component>__<parameter>
so that it’s possible to update each component of a nested object.