spectralbrain.statistics.surrogates#
Surrogate data, null models, and synthetic data generators.
Three pillars:
Bootstrap — resampling with CI (percentile + BCa).
Null models — 6 hypothesis-specific null generators.
Synthetic generators — descriptors, meshes, point clouds from real data or 22 parametric distributions.
Null models#
Eigenvalue permutation — tests spectral ordering.
Phase randomisation — tests vertex-specific structure.
Spin permutation — tests beyond spatial autocorrelation.
Subject permutation — tests group difference.
Edge rewiring — tests network topology.
Parametric — tests beyond marginal distribution.
Distributions#
normal, beta, gamma, cauchy, dirichlet, exponential, halfcauchy, halfnormal, poisson, inversegamma, laplace, kumaraswamy, studentt, negativebinomial, binomial, logistic, mixture, pareto, uniform, wald, vonmises, weibull.
Functions
|
Bootstrap confidence interval for a scalar statistic. |
|
Bootstrap confidence interval for paired mean difference. |
|
Null 5: degree-preserving edge rewiring (Maslov & Sneppen 2002). |
|
Null 1: permute eigenvalues, keep eigenvectors. |
|
Null 6: matched Gaussian surrogate. |
|
Null 2: randomise phases in spectral domain. |
|
Null 3: spin permutation (Alexander-Bloch 2018). |
|
Null 4: permute group labels. |
Classes
|
Generate synthetic spectral descriptor matrices. |
|
Generate synthetic triangle meshes (sphere, ellipsoid, torus). |
|
Generate synthetic point clouds (sphere, ellipsoid, blob, multi-cluster). |
- class spectralbrain.statistics.surrogates.SyntheticDescriptors(reference=None, distribution=None, dist_params=None, seed=None)[source]#
Bases:
objectGenerate synthetic spectral descriptor matrices.
- Parameters:
Examples
>>> gen = SyntheticDescriptors(distribution="gamma", dist_params={"shape": 2}) >>> data = gen.generate(n_subjects=50, n_vertices=1000, n_scales=20)
- class spectralbrain.statistics.surrogates.SyntheticMesh(reference_vertices=None, distribution=None, dist_params=None, seed=None)[source]#
Bases:
objectGenerate synthetic triangle meshes (sphere, ellipsoid, torus).
- Parameters:
reference_vertices (ndarray, optional)
distribution (as above.)
dist_params (as above.)
seed (as above.)
- class spectralbrain.statistics.surrogates.SyntheticPointCloud(reference=None, distribution=None, dist_params=None, seed=None)[source]#
Bases:
objectGenerate synthetic point clouds (sphere, ellipsoid, blob, multi-cluster).
- Parameters:
reference (ndarray, optional)
distribution (as above.)
dist_params (as above.)
seed (as above.)
- blob(n_points=1000, center=(0, 0, 0), scale=(10, 10, 10))[source]#
Generate a Gaussian blob point cloud.
- ellipsoid(n_points=1000, radii=(50, 30, 20), noise=0.5)[source]#
Generate random points on an ellipsoid surface.
- from_reference(n_points=None)[source]#
Generate points matching the reference distribution.
- Parameters:
n_points (int, optional) – Number of points (default: same as reference).
- Returns:
ndarray, shape (n_points, 3)
- spectralbrain.statistics.surrogates.bootstrap_ci(data, statistic, *, n_bootstrap=10000, ci=0.95, method='percentile', seed=None, n_jobs=1)[source]#
Bootstrap confidence interval for a scalar statistic.
- Parameters:
data (ndarray) – Input data array.
statistic (callable) – Function that maps
datato a scalar.n_bootstrap (int) – Number of bootstrap replicates.
ci (float) – Confidence level (e.g. 0.95 for 95% CI).
method (
"percentile"or"bca") – CI method. BCa (bias-corrected and accelerated) is more accurate but slower.seed (int, optional) – RNG seed.
n_jobs (int) – Parallel workers for bootstrap replicates (
1= sequential,-1= all cores). Requiresjoblib.
- Returns:
estimate (float) – The statistic computed on the original data.
ci_low (float) – Lower bound of the confidence interval.
ci_high (float) – Upper bound of the confidence interval.
- Return type:
- spectralbrain.statistics.surrogates.bootstrap_paired_difference(a, b, *, n_bootstrap=10000, ci=0.95, seed=None)[source]#
Bootstrap confidence interval for paired mean difference.
Computes the CI of
mean(a - b)via bootstrap resampling on the paired differences.- Parameters:
- Returns:
estimate (float) – Mean paired difference.
ci_low, ci_high (float) – Confidence interval bounds.
- Return type:
- spectralbrain.statistics.surrogates.null_edge_rewiring(connectome, *, n_surrogates=1000, n_swaps_per_edge=10, seed=None, n_jobs=1)[source]#
Null 5: degree-preserving edge rewiring (Maslov & Sneppen 2002). Tests network topology.
Each surrogate is keyed to an independent, reproducible child RNG via
numpy.random.SeedSequence, so results are identical whether run sequentially (``n_jobs=1``) or in parallel (n_jobs=-1uses all cores). Rewiring is the expensive null (an inner swap loop per surrogate), so parallelism gives a near-linear speedup.
- spectralbrain.statistics.surrogates.null_eigenvalue_permutation(eigenvalues, eigenvectors, *, n_surrogates=1000, seed=None)[source]#
Null 1: permute eigenvalues, keep eigenvectors. Tests spectral ordering.
- spectralbrain.statistics.surrogates.null_parametric(descriptor, *, n_surrogates=1000, seed=None)[source]#
Null 6: matched Gaussian surrogate. Tests beyond marginal distribution.
- spectralbrain.statistics.surrogates.null_phase_randomisation(descriptor, eigenvectors, *, n_surrogates=1000, seed=None)[source]#
Null 2: randomise phases in spectral domain. Tests vertex-level structure.
- spectralbrain.statistics.surrogates.null_spin_permutation(descriptor, sphere_coords, *, n_surrogates=1000, seed=None, n_jobs=1)[source]#
Null 3: spin permutation (Alexander-Bloch 2018). Tests beyond spatial autocorrelation.
Each spin is keyed to an independent, reproducible child RNG, so results are identical for
n_jobs=1(sequential) andn_jobs=-1(all cores). The per-spin nearest-neighbour query over all vertices is the cost that parallelism amortises.