Pure Python SPACE: sparse partial correlation estimation
Project description
space-graph
Discover which variables in your dataset are directly related to each other, even after accounting for all other variables. Given a data matrix, SPACE estimates a sparse network of partial correlations -- connections that remain after removing indirect effects. Designed for settings where the number of variables can far exceed the number of samples (e.g. genomics).
Pure Python implementation of SPACE (Sparse Partial Correlation Estimation) from Peng et al. (2009), with no R or C dependencies.
Paper: Sparse Partial Correlation Estimation for High-Dimensional Data
Install
pip install space-graph
Optional Numba (faster inner jsrm loop):
pip install 'space-graph[numba]'
From GitHub:
pip install git+https://github.com/shahrozeabbas/space-graph.git
Usage
import numpy as np
from space_graph import SPACE
X = np.random.randn(20, 5)
model = SPACE(
alpha=0.7,
max_outer_iter=2,
max_inner_iter=500,
tol=1e-6,
weight='uniform',
)
model.fit(X)
print(model.partial_correlation_)
Penalty
alpha is overall regularization strength (like sklearn). gamma (γ) in [0, 1] sets the mix: lam1 = alpha * gamma, lam2 = alpha * (1 - gamma). Default gamma=1 matches R space::space.joint default lam2 = 0.
Options
gamma(default1): mix γ in[0, 1]forlam1/lam2;1matches R defaultlam2 = 0.tol(default1e-6): inner coordinate-descent stopping tolerance (and active-set threshold), same scale as the reference C code.weight: defaultuniform(unit weights). Useequalas an alias. Other modes:sig,degree, or a custom positive vector of lengthp.backend(defaultauto): inner JSRM shooting loop.numpyalways uses pure NumPy (no Numba import).autouses Numba when installed (lazy on firstfit), otherwise NumPy.numbarequires Numba and raisesImportErrorif it is missing. The firstfitwithautoornumbamay include JIT compilation time.
Tests
pytest
For a quick manual run after an editable install (or with PYTHONPATH=. from the repo root), see test_space_graph.py.
Optional: build libjsrm_test.so from ../space/src/JSRM.c to run the ctypes cross-check in tests/test_space.py.
License
GPL-3.0-or-later (same family as the original space R package).
Project details
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 space_graph-0.5.0.tar.gz.
File metadata
- Download URL: space_graph-0.5.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8af00db47676a343297294aa76ffbeea78264ad26260567fa952f09f03f1cbc6
|
|
| MD5 |
30a492cbb02b8430f7f4e5abff879fb1
|
|
| BLAKE2b-256 |
26962fb1ee9c091fc664f8ddd2f2503f44cbba184403eacbb8d3530f5870b14e
|
File details
Details for the file space_graph-0.5.0-py3-none-any.whl.
File metadata
- Download URL: space_graph-0.5.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f282936e215566f0735629689368defaaeed88a276a58e88f9a9b82feebb7e3
|
|
| MD5 |
0a7b649d52b7fa9775dbeea3b1e9d57f
|
|
| BLAKE2b-256 |
4ab9bf0105fbf89f4cf156702fa4c4cfbe898018607818b382d57edea37719f5
|