API reference¶
This page documents the public API of ArchePy. Internal modules
(those starting with an underscore, e.g. archepy._utils) are not part of
the public API and may change without deprecation notice.
Spatial MS-AA¶
- class archepy.Subject(X, sX, T=None, SST=None, sigmaSq=None, S=None, muS=None, sXC=None, XCtX=None, CtXtXC=None, SSt=None, XSt=None, SST_sigmaSq=0.0, NLL=0.0)[source]¶
Bases:
objectPer-subject data and per-iteration sufficient statistics.
- Parameters:
X (ndarray, shape (T, V)) – Observed data: time points × voxels.
sX (ndarray, shape (T, sV)) – “Tilde” data used to construct archetypes (often equal to X).
multi_subject_aa; (The remaining fields are populated and updated by)
yourself. (you do not need to set them)
T (Any)
SST (Any)
sigmaSq (Any)
S (Any)
muS (Any)
sXC (Any)
XCtX (Any)
CtXtXC (Any)
SSt (Any)
XSt (Any)
SST_sigmaSq (float)
NLL (float)
- archepy.multi_subject_aa(subj, noc, opts=None)[source]¶
Fit Multi-Subject Archetypal Analysis (spatial variant).
- Parameters:
subj (list of Subject) – One
Subjectper subject. Each providesX(T × V) andsX(T × sV); they may be the same array.noc (int) – Number of archetypes (K).
opts (dict, optional) –
Configuration. Keys (with defaults):
conv_crit(1e-6) — relative-NLL convergence thresholdmaxiter(100) — maximum outer iterationsfix_var_iter(5) — keepsigmaSqfixed for this many itersuse_gpu(False) — run on GPU via CuPyheteroscedastic(True) — per-voxel noise variancenumCstep(10) — inner C-update steps per outer iternumSstep(20) — inner S-update steps per outer itersort_crit(“corr”) — how to order archetypes at the endinit(“FurthestSum”) — initialization schemeinitSstep(250) — extra S-update steps during initrngSEED(None) — RNG seednoise_threshold(None) — lower bound forsigmaSq
- Returns:
results (list of dict) – Per-subject outputs:
S,sXC,sigmaSq,NLL,SSE,SST,SST_sigmaSq.C (ndarray, shape (sV, K)) – Shared archetype generator (columns sum to 1).
cost_fun (ndarray, shape (n_iter,)) – Negative log-likelihood at each outer iteration.
varexpl (float) – Variance explained,
(SST - sum(SSE)) / SST.elapsed (float) – Wall-clock time in seconds.
- Return type:
Temporal MS-AA¶
- class archepy.SubjectT(X, sX)[source]¶
Bases:
objectTemporal MS-AA subject container.
- Parameters:
X (ndarray, shape (V, T)) – Voxels × time points.
sX (ndarray, shape (V, sT)) – Voxels × “tilde” time points.
- archepy.multi_subject_aa_T(subj, noc, opts=None)[source]¶
Fit Multi-Subject Archetypal Analysis (temporal variant).
See
archepy.multi_subject_aa()for the spatial variant and a description of theoptsdictionary; the same options apply here.
Initialization¶
- archepy.furthest_sum(K, noc, i, exclude=None, *, treat_as_kernel=None, one_based=False)[source]¶
Greedy FurthestSum selection of
noccandidate archetype indices.- Parameters:
K (ndarray) – Either a data matrix of shape
(D, N)(observations as columns) or a symmetric kernel matrix of shape(N, N).noc (int) – Number of indices to select.
exclude (iterable of int, optional) – Indices that must not be selected.
treat_as_kernel (bool, optional) – If
None(default), auto-detect: a square symmetricKis treated as a kernel; otherwise as a data matrix. PassFalseexplicitly for large square data matrices to skip the symmetry check.one_based (bool, default False) – If
True, treat input/output indices as 1-based (MATLAB style).
- Returns:
list[int] – Selected indices.
- Return type:
fMRI helpers¶
- archepy.fmri.estimate_background_noise(file, file_filt)[source]¶
Estimate a noise variance threshold from background voxels of a NIfTI.
- Parameters:
- Returns:
float – Mean of per-voxel temporal variances over background voxels.
- Return type:
Notes
Requires
nibabel. Install withpip install archepy[fmri].
- archepy.fmri.generate_synthetic_noise(sx, sy, noise_var=None, stepsize=8, show_plot=False)[source]¶
Generate radial variance maps for simulating spatially-varying noise.
- Parameters:
sx (int) – Map size in x (rows) and y (cols).
sy (int) – Map size in x (rows) and y (cols).
noise_var (sequence of float, optional) – Maximum variances for each noise map. Defaults to
[1, 4, 16].stepsize (int, default 8) – Radial step size for the nested circular contours (in pixels).
show_plot (bool, default False) – If
True, render diagnostic plots (requiresmatplotlib).
- Returns:
ndarray, shape (sx, sy, K) – Stack of variance maps, one per entry in
noise_var.- Return type: