Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

isc

isc

Intersubject Correlation (ISC) with GPU-Accelerated Permutation Testing.

This module provides both leave-one-out (LOO) and pairwise ISC computation with efficient CPU-parallel and GPU-batched implementations. Follows the statistical methods from Chen et al. (2016) for correct bootstrap resampling of correlation matrices.

Key Features
  • Two ISC modes: leave-one-out and pairwise (statistically different)

  • GPU acceleration for voxel-wise computation (10-30× speedup)

  • CPU-parallel bootstrap with joblib

  • Correct subject-wise bootstrap (Chen et al. 2016)

  • Memory-efficient condensed matrix storage

References

Chen, G., Shin, Y. W., Taylor, P. A., Glen, D. R., Reynolds, R. C., Israel, R. B., & Cox, R. W. (2016). Untangling the relatedness among correlations, part I: nonparametric approaches to inter-subject correlation analysis at the group level. NeuroImage, 142, 248-259.

Notes

Leave-one-out and pairwise ISC are monotonically correlated but statistically different. LOO is computationally more efficient and provides unbiased estimates. Pairwise captures full correlation structure but is O(n²) in subjects.

Methods:

NameDescription
isc_group_permutation_testCompute ISC difference between groups with permutation testing.
isc_permutation_testCompute intersubject correlation with permutation testing.

Methods

isc_group_permutation_test

isc_group_permutation_test(group1: np.ndarray, group2: np.ndarray, *, n_permute: int = 5000, summary: Literal['median', 'mean'] = 'median', method: Literal['permute', 'bootstrap'] = 'permute', summary_statistic: Literal['leave-one-out', 'pairwise'] = 'pairwise', ci_percentile: float = 95, tail: int | str = 2, device: Literal['cpu', 'gpu'] | None = 'cpu', n_jobs: int = -1, random_state: int | None = None, return_null: bool = False, progress_bar: bool = False, exclude_self_corr: bool = True, metric: str = 'correlation') -> dict[str, Any]

Compute ISC difference between groups with permutation testing.

Supports both subject-wise permutation and bootstrap methods with efficient CPU-parallel and optional GPU acceleration. Follows the statistical methods from Chen et al. (2016) for correct group comparison inference.

Parameters:

NameTypeDescriptionDefault
group1ndarrayFirst group data with one of the following shapes: - (n_observations, n_subjects1): Single feature - (n_observations, n_subjects1, n_voxels): Voxel-wiserequired
group2ndarraySecond group data with one of the following shapes: - (n_observations, n_subjects2): Single feature - (n_observations, n_subjects2, n_voxels): Voxel-wiserequired
n_permuteintNumber of permutations/bootstrap iterations. Defaults to 5000.5000
summaryLiteral [‘median’, ‘mean’]Summary statistic for aggregating ISC values: - ‘median’: Direct median (robust to outliers) - ‘mean’: Fisher z-transformed mean (unbiased averaging) Defaults to ‘median’.‘median’
methodLiteral [‘permute’, ‘bootstrap’]Resampling method for p-value computation: - ‘permute’: Subject-wise permutation (combines groups, permutes labels) - ‘bootstrap’: Subject-wise bootstrap (resamples within each group) Defaults to ‘permute’.‘permute’
summary_statisticLiteral [‘leave-one-out’, ‘pairwise’]ISC computation method: - ‘pairwise’: Average all pairwise correlations - ‘leave-one-out’: Correlate each subject with mean of others Defaults to ‘pairwise’.‘pairwise’
ci_percentilefloatConfidence interval percentile (e.g., 95 for 95% CI). Defaults to 95.95
tailint | strTwo-tailed (2 or ‘two’, default) or one-tailed (1 or ‘one’, positive direction) p-value.2
deviceLiteral [‘cpu’, ‘gpu’] | NoneParallelization method: - ‘cpu’: CPU parallelization via joblib (default, 4-8× speedup) - ‘gpu’: GPU acceleration via PyTorch (10-30× speedup for voxel-wise LOO) - None: Single-threaded NumPy (for debugging/small problems) Defaults to ‘cpu’.‘cpu’
n_jobsintNumber of CPU cores for parallelization (-1 = all cores). Only used when device=‘cpu’. Defaults to -1.-1
random_stateint | NoneRandom seed for reproducibility.None
return_nullboolIf True, return null distribution in result dict. Defaults to False.False
progress_barboolShow progress bar during bootstrap/permutation. Defaults to False.False
exclude_self_corrboolMask self-correlations in bootstrap (pairwise only). Defaults to True.True
metricstrSimilarity metric for pairwise ISC computation. See sklearn.metrics.pairwise_distances for valid options. Only applies when summary_statistic=‘pairwise’. Defaults to ‘correlation’.‘correlation’

Returns:

TypeDescription
dict [ str , Any ]Dictionary with the following keys:
dict [ str , Any ]- ‘isc_group_difference’: Observed ISC difference (float or array per voxel)
dict [ str , Any ]- ‘p’: P-value (Phipson-Smyth corrected)
dict [ str , Any ]- ‘ci’: Confidence interval tuple (lower, upper)
dict [ str , Any ]- ‘device’: Parallelization method used
dict [ str , Any ]- ‘null_dist’: (optional) Bootstrap/permutation distribution

Examples:

>>> # Single-feature ISC group comparison
>>> group1 = np.random.randn(100, 10)  # 10 subjects
>>> group2 = np.random.randn(100, 10)
>>> result = isc_group_permutation_test(group1, group2, n_permute=1000)
>>> print(f"ISC difference: {result['isc_group_difference']:.3f}, p: {result['p']:.3f}")
>>> # Voxel-wise ISC group comparison with GPU acceleration
>>> group1_voxels = np.random.randn(100, 10, 5000)  # 5K voxels
>>> group2_voxels = np.random.randn(100, 10, 5000)
>>> result = isc_group_permutation_test(
...     group1_voxels,
...     group2_voxels,
...     summary_statistic='leave-one-out',
...     device='gpu',  # GPU for LOO computation
...     n_permute=5000
... )
>>> print(f"Significant voxels: {(result['p'] < 0.05).sum()}")
References

Chen, G., Shin, Y. W., Taylor, P. A., Glen, D. R., Reynolds, R. C., Israel, R. B., & Cox, R. W. (2016). Untangling the relatedness among correlations, part I: nonparametric approaches to inter-subject correlation analysis at the group level. NeuroImage, 142, 248-259.

Notes
  • Permutation method combines groups and permutes labels (Chen et al. 2016)

  • Bootstrap method resamples subjects within each group independently

  • Bootstrap distribution is centered by subtracting observed difference

  • GPU acceleration available for voxel-wise LOO computation

isc_permutation_test

isc_permutation_test(data: np.ndarray, *, n_permute: int = 5000, summary: Literal['median', 'mean'] = 'median', summary_statistic: Literal['leave-one-out', 'pairwise'] = 'pairwise', method: Literal['bootstrap', 'circle_shift', 'phase_randomize'] = 'bootstrap', ci_percentile: float = 95, tail: int | str = 2, return_null: bool = False, progress_bar: bool = False, exclude_self_corr: bool = True, metric: str = 'correlation', device: Literal['cpu', 'gpu'] | None = 'cpu', n_jobs: int = -1, max_gpu_memory_gb: float | None = None, random_state: int | None = None) -> dict[str, Any]

Compute intersubject correlation with permutation testing.

Supports both leave-one-out and pairwise ISC computation modes with GPU acceleration for large voxel-wise problems and CPU-parallel bootstrap resampling.

Parameters:

NameTypeDescriptionDefault
datandarrayData array with one of the following shapes: - (n_observations, n_subjects): Single feature ISC - (n_observations, n_subjects, n_voxels): Voxel-wise ISCrequired
n_permuteintNumber of bootstrap iterations or permutations. Defaults to 5000.5000
summaryLiteral [‘median’, ‘mean’]Summary statistic to aggregate ISC values. - ‘median’: Direct median (robust to outliers) - ‘mean’: Fisher z-transformed mean (unbiased averaging) Defaults to ‘median’.‘median’
summary_statisticLiteral [‘leave-one-out’, ‘pairwise’]ISC computation method. Options: - ‘leave-one-out’: Correlate each subject with mean of others. O(n_subjects), unbiased, recommended by Chen et al. 2016. - ‘pairwise’: Average all pairwise correlations. O(n_subjects²), captures full correlation structure. Note: These methods are statistically different and monotonically but non-linearly related (see Chen et al. 2016, Figure 3). Defaults to ‘pairwise’.‘pairwise’
methodLiteral [‘bootstrap’, ‘circle_shift’, ‘phase_randomize’]Resampling method for p-value computation: - ‘bootstrap’: Subject-wise bootstrap (default, Chen et al. 2016) - ‘circle_shift’: Circular time-series shift (preserves autocorrelation) - ‘phase_randomize’: FFT phase randomization (preserves power spectrum) Defaults to ‘bootstrap’.‘bootstrap’
ci_percentilefloatConfidence interval percentile (e.g., 95 for 95% CI). Defaults to 95.95
tailint | strTwo-tailed (2 or ‘two’, default) or one-tailed (1 or ‘one’, positive direction) p-value.2
return_nullboolIf True, return bootstrap/permutation distribution in result dict. Defaults to False.False
progress_barboolShow progress bar during bootstrap/permutation. Defaults to False.False
exclude_self_corrboolIf True, mask self-correlations (perfect correlations from duplicate subjects in bootstrap samples) as NaN. If False, include them in the summary statistic. Only applies when method=‘bootstrap’ and summary_statistic=‘pairwise’. Defaults to True.True
metricstrSimilarity metric for pairwise ISC computation. See sklearn.metrics.pairwise_distances for valid options. Only applies when summary_statistic=‘pairwise’. For ‘correlation’, uses optimized np.corrcoef. Other metrics use pairwise_distances. Defaults to ‘correlation’.‘correlation’
deviceLiteral [‘cpu’, ‘gpu’] | NoneParallelization method: - ‘cpu’: CPU parallelization via joblib (default, 4-8× speedup) - ‘gpu’: GPU acceleration via PyTorch (10-30× speedup for voxel-wise LOO) - None: Single-threaded NumPy (for debugging/small problems) Defaults to ‘cpu’.‘cpu’
n_jobsintNumber of CPU cores for parallelization (-1 = all cores). Only used when device=‘cpu’. Defaults to -1.-1
max_gpu_memory_gbfloat | NoneGPU working-set budget in GB. For the pairwise GPU bootstrap (device='gpu', summary_statistic='pairwise', method='bootstrap') this bounds the (perm_batch, voxel_chunk, n_subjects, n_subjects) resample tensor, chunking voxels and permutations to fit — so whole-brain runs stay within budget. Not used by the LOO or surrogate (circle_shift/phase_randomize) paths. Defaults to 4.None
random_stateint | NoneRandom seed for reproducibility.None

Returns:

TypeDescription
dict [ str , Any ]Dictionary with the following keys:
dict [ str , Any ]- ‘isc’: Observed ISC value (float or array per voxel)
dict [ str , Any ]- ‘p’: P-value (Phipson-Smyth corrected)
dict [ str , Any ]- ‘ci’: Confidence interval tuple (lower, upper)
dict [ str , Any ]- ‘device’: Parallelization method used
dict [ str , Any ]- ‘null_dist’: (optional) Bootstrap/permutation distribution

Examples:

>>> # Single-feature ISC
>>> data = np.random.randn(100, 10)  # 100 timepoints, 10 subjects
>>> result = isc_permutation_test(data, n_permute=1000)
>>> print(f"ISC: {result['isc']:.3f}, p: {result['p']:.3f}")
>>> # Voxel-wise ISC with GPU acceleration
>>> data_voxels = np.random.randn(100, 50, 5000)  # 5K voxels
>>> result = isc_permutation_test(
...     data_voxels,
...     summary_statistic='leave-one-out',
...     device='gpu',  # GPU for LOO computation
...     n_permute=5000
... )
>>> print(f"Significant voxels: {(result['p'] < 0.05).sum()}")
>>> # Compare LOO vs pairwise
>>> result_loo = isc_permutation_test(data, summary_statistic='leave-one-out')
>>> result_pair = isc_permutation_test(data, summary_statistic='pairwise')
>>> print(f"LOO: {result_loo['isc']:.3f}, Pairwise: {result_pair['isc']:.3f}")
References

Chen, G., Shin, Y. W., Taylor, P. A., Glen, D. R., Reynolds, R. C., Israel, R. B., & Cox, R. W. (2016). Untangling the relatedness among correlations, part I: nonparametric approaches to inter-subject correlation analysis at the group level. NeuroImage, 142, 248-259.

Notes
  • Leave-one-out is 20-30× faster than pairwise for large n_subjects

  • GPU acceleration helps most for voxel-wise LOO (10-30× speedup)

  • Pairwise bootstrap uses correct subject-wise resampling (Chen 2016)

  • Bootstrap distribution is centered by subtracting observed ISC