Partial Correlation Graphical LASSO (PCGLASSO) — fast Rust-backed Python implementation
Project description
pcglasso
pcglasso is a Python package for finding direct relationships between
variables in noisy, high-dimensional data.
Instead of asking which variables are merely correlated, PCGLASSO estimates which variables remain connected after accounting for all the others. The result can be read as a sparse network: variables are nodes, and selected edges are direct conditional relationships.
The package exposes a small Python API and runs the iterative solver in Rust for speed.
What you can use it for
- Build an interpretable network from tabular data.
- Separate direct relationships from indirect correlations.
- Estimate sparse Gaussian graphical models.
- Work with data where variable scales differ, because PCGLASSO is scale invariant.
- Fit many related column subsets in parallel.
- Fit repeated, similar problems efficiently with warm starts.
Common use cases include genomics, neuroscience, finance, survey analysis, and other settings where many variables may be related but only some relationships are direct.
Install
pip install pcglasso
To build from source, use maturin with Python 3.10 or newer:
pip install maturin
maturin develop --release
Quick start
Use PCGLasso like a small sklearn-style estimator:
import numpy as np
from pcglasso import PCGLasso
X = np.random.default_rng(0).standard_normal((200, 20))
model = PCGLasso(alpha=0.1).fit(X)
model.partial_correlation_ # strength of direct relationships
model.adjacency_ # selected network edges
model.precision_ # estimated inverse covariance matrix
The most readable output is often adjacency_, a boolean matrix showing which
variables are connected after the model has removed weaker indirect effects.
If you already have a covariance or correlation matrix, use the functional API:
from pcglasso import pcglasso
res = pcglasso(S, alpha=0.1, c=None, method='dual')
res.precision_, res.partial_correlation_, res.objective_
Mapping over column subsets
Use pcglasso_map when you want to run the same PCGLASSO fit across many
subsets of columns from one data matrix. This is useful for resampling,
screening local neighborhoods, or fitting many overlapping feature groups.
from pcglasso import pcglasso_map
index_sets = [
[0, 1, 2, 3],
[2, 3, 4, 5],
[10, 11, 12],
]
results = pcglasso_map(X, index_sets, alpha=0.1, n_jobs=-1)
results[0].adjacency_ # graph for columns [0, 1, 2, 3]
results[0].partial_correlation_ # direct relationships for that subset
pcglasso_map returns one PCGLassoResult per subset. It runs the independent
fits in parallel with Rayon; n_jobs=-1 uses all available cores, n_jobs=1
runs serially. For speed, covariance_ is None in mapped results.
Choosing alpha
alpha controls how sparse the network is:
- Larger
alphavalues remove more edges and produce simpler networks. - Smaller
alphavalues keep more edges and produce denser networks.
There is no universal best value. In practice, choose alpha by validation,
stability analysis, domain knowledge, or by fitting a sequence of values and
inspecting how the graph changes.
Warm starts
Set warm_start=True to reuse the previous solution as the next fit's starting
point. This is useful for a sequence of similar problems, such as bootstrap
resamples or a path of nearby alpha values.
model = PCGLasso(alpha=0.1, warm_start=True)
graphs = []
for X_b in resamples:
model.fit(X_b)
graphs.append(model.precision_.copy())
Main outputs
partial_correlation_: direct relationship strengths on a common scale.adjacency_: boolean conditional-dependence graph with a zero diagonal.precision_: estimated precision matrix.covariance_: model-implied covariance matrix.n_iter_andconverged_: basic solver diagnostics.
Advanced options
PCGLASSO estimates a sparse Gaussian precision matrix by penalising partial correlations rather than raw precision-matrix entries. This is what makes the estimator scale invariant and helps with hub-structured graphs.
The package includes two coordinate-descent solvers from Bogdan et al. (2026):
method='primal'(default): uses thepcglassoFastapproach and returns partial correlations directly. This is a good default, especially for hub-structured problems.method='dual': uses thepcglassoFast_Dualapproach, adapted from the GLASSO dual. This can be faster on some generic sparse problems.
Both solvers use a Rust core through PyO3 and maturin. The hot loop does not require BLAS or LAPACK, which helps keep wheels portable.
Other parameters:
c: diagonal parameter. WhenNone, the package chooses a data-dependent default.max_iter: maximum number of outer iterations.tol: convergence tolerance.assume_centered: whether input data has already been centered.
Status
This is an early Python implementation. The implementation follows the original R package and the source papers; CI currently builds the package and runs a smoke test across Linux, macOS, and Windows.
References
- Carter, Rossell & Smith (2024). Partial correlation graphical LASSO. Scandinavian Journal of Statistics.
- Carter & Molinari (2025). Existence and optimisation of the partial correlation graphical lasso.
- Bogdan, Chojecki, Hejný, Kołodziejek & Wallin (2026). Identifying network hubs with the partial correlation graphical LASSO.
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 Distributions
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 pcglasso-0.2.0.tar.gz.
File metadata
- Download URL: pcglasso-0.2.0.tar.gz
- Upload date:
- Size: 26.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7a6ee8ccb8587b713486c8c6ff2a9263197e5ebe072f736cfb7b3832ce728ef
|
|
| MD5 |
cb6f54a8f0166997bd5f19d33b3fc70f
|
|
| BLAKE2b-256 |
d952e4269fc439283c0989984b7d49d950bc4daf71e5d6b4ff7643ab53cc5ec9
|
Provenance
The following attestation bundles were made for pcglasso-0.2.0.tar.gz:
Publisher:
release.yml on shahrozeabbas/pcglasso
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pcglasso-0.2.0.tar.gz -
Subject digest:
f7a6ee8ccb8587b713486c8c6ff2a9263197e5ebe072f736cfb7b3832ce728ef - Sigstore transparency entry: 1905357231
- Sigstore integration time:
-
Permalink:
shahrozeabbas/pcglasso@bfd0a8474dc138d89b627635fd686f9cb750b813 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/shahrozeabbas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfd0a8474dc138d89b627635fd686f9cb750b813 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pcglasso-0.2.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: pcglasso-0.2.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 224.2 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe5cf58749e20c9351ec20e268191db94ea0ae5e978e95f55ef35144dbcb6214
|
|
| MD5 |
959823d8dfa12f9926cf98f0f2f189e8
|
|
| BLAKE2b-256 |
eb0ad83ed8dffe75c3e122a2238edd0ee18d8929c96cc0966e6b54715aa50cd2
|
Provenance
The following attestation bundles were made for pcglasso-0.2.0-cp310-abi3-win_amd64.whl:
Publisher:
release.yml on shahrozeabbas/pcglasso
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pcglasso-0.2.0-cp310-abi3-win_amd64.whl -
Subject digest:
fe5cf58749e20c9351ec20e268191db94ea0ae5e978e95f55ef35144dbcb6214 - Sigstore transparency entry: 1905357439
- Sigstore integration time:
-
Permalink:
shahrozeabbas/pcglasso@bfd0a8474dc138d89b627635fd686f9cb750b813 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/shahrozeabbas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfd0a8474dc138d89b627635fd686f9cb750b813 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pcglasso-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pcglasso-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 348.5 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b24f5b5e159889d3560359cbf215cd1cb3692347faedadedfbad2a16c8102eb7
|
|
| MD5 |
f9046ad64f465ce508d9d2aa2b9cce7f
|
|
| BLAKE2b-256 |
557acca8010ce077603b89b357c284d3716cbac34a31be229d94c06709bcabc9
|
Provenance
The following attestation bundles were made for pcglasso-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on shahrozeabbas/pcglasso
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pcglasso-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
b24f5b5e159889d3560359cbf215cd1cb3692347faedadedfbad2a16c8102eb7 - Sigstore transparency entry: 1905357536
- Sigstore integration time:
-
Permalink:
shahrozeabbas/pcglasso@bfd0a8474dc138d89b627635fd686f9cb750b813 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/shahrozeabbas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfd0a8474dc138d89b627635fd686f9cb750b813 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pcglasso-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pcglasso-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 331.3 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ffd34d614fc581534c534281e57c3f3b19ced23848218e0a12c12a0fe58d6c6
|
|
| MD5 |
a418d36e0c54fe48fa9b6e189e19c176
|
|
| BLAKE2b-256 |
d83a812ba223b1fe35ea86ccb114cca1add116f4294be493219e4783f7b1aa01
|
Provenance
The following attestation bundles were made for pcglasso-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on shahrozeabbas/pcglasso
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pcglasso-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
5ffd34d614fc581534c534281e57c3f3b19ced23848218e0a12c12a0fe58d6c6 - Sigstore transparency entry: 1905357321
- Sigstore integration time:
-
Permalink:
shahrozeabbas/pcglasso@bfd0a8474dc138d89b627635fd686f9cb750b813 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/shahrozeabbas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfd0a8474dc138d89b627635fd686f9cb750b813 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pcglasso-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: pcglasso-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 604.8 kB
- Tags: CPython 3.10+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
822dc6cfb79cae220d05f809b95d9cc27c834f27a68c5da209d4449287253eb7
|
|
| MD5 |
89640a89edd8660c79e1a693c220d628
|
|
| BLAKE2b-256 |
714c77310a488808b2befba8c8124f1f8e7a58370ee7762f3210c3587e1e9749
|
Provenance
The following attestation bundles were made for pcglasso-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:
Publisher:
release.yml on shahrozeabbas/pcglasso
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pcglasso-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl -
Subject digest:
822dc6cfb79cae220d05f809b95d9cc27c834f27a68c5da209d4449287253eb7 - Sigstore transparency entry: 1905357680
- Sigstore integration time:
-
Permalink:
shahrozeabbas/pcglasso@bfd0a8474dc138d89b627635fd686f9cb750b813 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/shahrozeabbas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfd0a8474dc138d89b627635fd686f9cb750b813 -
Trigger Event:
push
-
Statement type: