Skip to main content

Partial Correlation Graphical LASSO (PCGLASSO) — fast Rust-backed Python implementation

Project description

pcglasso

CI PyPI Python License: GPL-3.0-or-later

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 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_

Choosing alpha

alpha controls how sparse the network is:

  • Larger alpha values remove more edges and produce simpler networks.
  • Smaller alpha values 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_ and converged_: 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 the pcglassoFast approach and returns partial correlations directly. This is a good default, especially for hub-structured problems.
  • method='dual': uses the pcglassoFast_Dual approach, 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. When None, 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pcglasso-0.1.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pcglasso-0.1.0-cp310-abi3-win_amd64.whl (149.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

pcglasso-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (263.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

pcglasso-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (261.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

pcglasso-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (475.1 kB view details)

Uploaded CPython 3.10+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file pcglasso-0.1.0.tar.gz.

File metadata

  • Download URL: pcglasso-0.1.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pcglasso-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b72548333a1cb3cd537b0d58d8bbeffe5c9436b0e26a21ba0dce30d8da4d74e
MD5 7a7c41aa9740af498c844390083e4949
BLAKE2b-256 0f5ee60cd9caba463757ab173f97282f522da2fb0c8886e05fb2fb49080c2006

See more details on using hashes here.

Provenance

The following attestation bundles were made for pcglasso-0.1.0.tar.gz:

Publisher: release.yml on shahrozeabbas/pcglasso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pcglasso-0.1.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: pcglasso-0.1.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 149.8 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

Hashes for pcglasso-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e3b62d28714e0bfe114b292a784084b9214762a33941bb11049170d055ab8789
MD5 983395d1f2ee61979a05ec481dbb9511
BLAKE2b-256 ec91bfa0100bb8f8e843735d4a34e61c410470a0d61b7583c1165d107c0d282e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pcglasso-0.1.0-cp310-abi3-win_amd64.whl:

Publisher: release.yml on shahrozeabbas/pcglasso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pcglasso-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pcglasso-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d2f499a7b6d656af741e39d7f5ef582573959ea718182efa7fc51d417cf6fabc
MD5 510cf1cfbfab94f27026c58be33eb2b5
BLAKE2b-256 f74176abf101d950a24e35710942fc066662e89a5945ded246cddd8d7e1d7de3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pcglasso-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on shahrozeabbas/pcglasso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pcglasso-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pcglasso-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2051f2bc8e90ed7b550b69175a2faa26f46af3c1754d7a548dd7df638d5e92dc
MD5 87aae6cf6e791dda0cce4d8a2030b42f
BLAKE2b-256 d1b6aca44c797b9a3a474c0b990c5e63b94ca61d17dd71945c4185f8da8a7c44

See more details on using hashes here.

Provenance

The following attestation bundles were made for pcglasso-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on shahrozeabbas/pcglasso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pcglasso-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for pcglasso-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 c1040d9259922c3ac5a64a153c9dec07df41ad76e76e85e318399f669f25c7a2
MD5 bc188fe5c000d73640f4e1818b99ddb0
BLAKE2b-256 b3565485c2bb1f7bef430c23701231fe388993147d4ec5380ff9cc82c9ac5246

See more details on using hashes here.

Provenance

The following attestation bundles were made for pcglasso-0.1.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on shahrozeabbas/pcglasso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page