Compute identification rates for SPD-matrix metrics across resolutions and tasks
Project description
SPD Metrics ID
Compute identification rates (ID-rates) for symmetric positive-definite (SPD) connectivity matrices using a variety of distance and divergence metrics.
Features
- Alpha-Z Bures–Wasserstein divergence
- Alpha-Procrustes (“ProE”) distance
- Bures–Wasserstein distance
- Affine-invariant Riemannian distance
- Log-Euclidean distance
- Pearson correlation–based distance
- Euclidean distance on flattened matrices
- CLI interface with customizable tasks, scan directions, parcellation resolutions, and SPD regularization (
τ) - Python API for programmatic integration
- Unit tests with pytest
Installation
Clone the repo and install:
git clone https://github.com/yourusername/spd-metrics-id.git
cd spd-metrics-id
# (Recommended) Create a virtual environment
python -m venv .venv
# macOS/Linux
source .venv/bin/activate
# Windows
.venv\Scripts\activate
# Install in editable mode
pip install --upgrade pip
pip install -e .
Command-Line Usage
After installation, the spd-id console script is available:
spd-id \
--base-path PATH/TO/DATA \
--tasks REST1 LANGUAGE EMOTION \
--scan-types LR RL \
--resolutions 100 200 \
--metric alpha_z \
--alpha 0.99 \
--z 1.0 \
--tau 1e-6 \
--num-subjects 30
Key Arguments
-
--base-path
Path to root folder containing one subfolder per subject. -
--tasks
List of tasks. UseREST1for resting-state (rfMRI_REST1) or any of
EMOTION,GAMBLING,LANGUAGE,MOTOR,RELATIONAL,SOCIAL,WM
for task fMRI (tfMRI_<TASK>). -
--scan-types
Two scan directions to compare, e.g.LR RL. -
--resolutions
One or more parcellation sizes, e.g.100 200 300. -
--metric
Choice of SPD metric:
alpha_z,alpha_pro,bw,geo,log,pearson,euclid. -
--alpha,--z
Parameters foralpha_zandalpha_prometrics. -
--tau
SPD regularization forgeoandlogmetrics (default1e-6). -
--num-subjects
Maximum number of subjects to include (default: all).
Example Output
INFO: Task=REST, Scans=LR→RL, Metric=Alpha-Z BW, Res=[100], Subjects=30, ID1=0.9000, ID2=0.8333, AvgID=0.8667
Python API
import numpy as np
from spd_metrics_id.io import find_subject_paths, load_matrix
from spd_metrics_id.distance import compute_alpha_z_bw
from spd_metrics_id.id_rate import compute_id_rate
base = "connectomes_100/"
# find the 30 REST‐LR and REST‐RL files at resolution 100
lr_paths = find_subject_paths(base, "REST", "LR", [100], n=30)
rl_paths = find_subject_paths(base, "REST", "RL", [100], n=30)
# load them
mats_lr = [load_matrix(p) for p in lr_paths]
mats_rl = [load_matrix(p) for p in rl_paths]
# build distance matrices
D12 = np.array([[compute_compute_alpha_z_bw(A, B,0.99,1)
for B in mats_rl] for A in mats_lr])
D21 = np.array([[compute_compute_alpha_z_bw(A, B,0.99,1)
for B in mats_lr] for A in mats_rl])
# compute ID rates
id1 = compute_id_rate(D12)
id2 = compute_id_rate(D21)
print("Average ID rate:", (id1 + id2) / 2)
Testing
Run the full test suite with pytest:
python -m pytest
All divergence functions and the ID-rate calculation are covered by unit tests.
Contributing
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature
- Write code & tests.
- Run
pytestto verify. - Submit a pull request.
Please adhere to PEP 8 and include new tests for any added functionality.
License
SPDX license identifier: MIT
See the LICENSE file for full terms.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spd_metrics_id-0.1.0.tar.gz.
File metadata
- Download URL: spd_metrics_id-0.1.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91ff675b8503fe6d40c10b757197d1e4c9e04a6508c5a0a9a498c31f61a368dc
|
|
| MD5 |
54798b917789e16d1ee4e35eeebb5f22
|
|
| BLAKE2b-256 |
fee9236b4b840356e1c7e1a943783dcbe5538ac60e438f8a012bde779008d813
|
File details
Details for the file spd_metrics_id-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spd_metrics_id-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
213a32a3cafd5937b3bc36ef68e535527c88c96af341dde427e0ce7b399ebc2c
|
|
| MD5 |
0f2b6918379d551cbc526d25ab2c9fa2
|
|
| BLAKE2b-256 |
7f396485d400659df5a8af5c9cfd9a6c160a399139cb375d7e3aea20360bb369
|