pySPFM.StabilitySelection#

class StabilitySelection(*, tr, te=None, hrf_model='spm', block_model=False, n_surrogates=50, n_lambdas=None, threshold=0.6, n_jobs=1)[source]#

Bases: _BaseDeconvolution

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.

  • block_model (bool, default=False) – If True, estimate innovation signals (block model).

  • n_surrogates (int, default=50) – Number of bootstrap surrogates.

  • n_lambdas (int, default=None) – Number of lambda values in the regularization path. If None, uses n_scans.

  • threshold (float, default=0.6) – Selection threshold for considering a feature as selected.

  • n_jobs (int, default=1) – Number of parallel jobs.

Variables:
  • selection_frequency (ndarray of shape (n_timepoints, n_voxels)) – Selection frequency (AUC) for each timepoint and voxel.

  • coef (ndarray of shape (n_timepoints, n_voxels)) – Binary selection indicators based on threshold.

  • hrf_matrix (ndarray) – The HRF convolution matrix.

  • n_features_in (int) – Number of voxels.

Examples

>>> from pySPFM import StabilitySelection
>>> import numpy as np
>>> X = np.random.randn(100, 50)
>>> model = StabilitySelection(tr=2.0, n_surrogates=20)
>>> model.fit(X)
StabilitySelection(n_surrogates=20, tr=2.0)
>>> selection_freq = model.selection_frequency_

See also

SparseDeconvolution

Standard sparse deconvolution.

References

__repr__(N_CHAR_MAX=700)[source]#

Return a string representation of the estimator.

fit(X, y=None)[source]#

Fit the stability selection model.

Parameters:
  • X (array-like of shape (n_timepoints, n_voxels)) – The fMRI timeseries data.

  • y (None) – Not used, present for API consistency.

Returns:

self (object) – Fitted estimator.

fit_transform(X, y=None, **fit_params)[source]#

Fit to data, then transform it.

Fits the estimator to X and y with optional parameters fit_params, and returns a transformed version of X.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Input samples.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).

  • **fit_params (dict) – Additional fit parameters.

Returns:

X_new (ndarray of shape (n_samples, n_features_new)) – Transformed array.

get_fitted_signal()[source]#

Get the fitted signal (HRF convolved with estimates).

Returns:

fitted (ndarray of shape (n_timepoints, n_voxels)) – The fitted signal (reconstruction).

get_params(deep=True)[source]#

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params (dict) – Parameter names mapped to their values.

get_residuals(X)[source]#

Get the residuals after deconvolution.

Parameters:

X (array-like of shape (n_timepoints, n_voxels)) – The original fMRI data.

Returns:

residuals (ndarray of shape (n_timepoints, n_voxels)) – The residuals (X - fitted_signal).

score(X, y=None)[source]#

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.

set_params(**params)[source]#

Set the parameters of this estimator.

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.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self (estimator instance) – Estimator instance.

transform(X)[source]#

Return selection frequencies.

Parameters:

X (array-like of shape (n_timepoints, n_voxels)) – The fMRI timeseries data (not used, returns stored frequencies).

Returns:

selection_frequency (ndarray of shape (n_timepoints, n_voxels)) – Selection frequency (AUC) for each timepoint.