Repository navigation
HTFA 0.1.0
HTFA fits spatial factors and their sample weights to spatial data, including brain images. Topographic factor analysis (TFA) models one participant; hierarchical TFA shares a template across participants, with optional nested group templates. The package is a standalone Python implementation with NumPy and torch backends and no BrainIAK or MPI runtime requirement.
Install
pip install htfaPython 3.10 or newer. Optional extras include plot (matplotlib and Nilearn), brain3d (3D networks and animations), images, gpu, and tutorials. For example:
pip install "htfa[plot,brain3d]"Optional dependencies install on first use; HTFA_AUTO_INSTALL=0 disables that behavior. Torch is a core dependency on Apple Silicon Macs. See installation for platform requirements.
Highlights
- Spatial factors. Gaussian, Laplace, and signed Mexican-hat kernels, with one or more components per factor. Each mixture shares one time course across its spatial components.
- Fitting.
htfa.fitloads NIfTI files, folders, NumPy arrays, and 2D images; theTFAandHTFAestimators fit arrays directly. Fast and exact solver modes optimize the same objective with different step models. CPU, CUDA, and Apple Metal backends support different workloads; multiple CUDA GPUs can fit subjects concurrently. - Nested groups. Group templates connect subjects to a global template, with names and nesting inferred from subfolders by default. Permutation comparisons use a label-independent factor reference and report per-factor results with optional family-wise correction.
- Connectivity and visualization. Static, dynamic, and inter-subject factor connectivity; BrainNet Viewer-style plots and animations; Nilearn glass-brain views. Mixture components appear as separate lobes with the factor connection value repeated between component pairs. Sphere/centroid summaries are also available.
- Reconstruction statistics. R², nominal parameter counts, and conditional Gaussian AIC, AICc, and BIC. Reconstruction figures share color scales so the data and fitted values can be compared directly.
- Worked examples. Synthetic recovery, real fMRI kernel comparisons, word decoding, dynamic ISFC, group inference, and plotting tutorials, with checksum-verified cached assets.