Skip to main content

pcglasso

CI PyPI 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 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 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.

Release files for pcglasso 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pcglasso 0.2.0
File Size Uploaded
pcglasso-0.2.0.tar.gz 26.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pcglasso 0.2.0
File
pcglasso-0.2.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
pcglasso-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
pcglasso-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
pcglasso-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64 Details

Total release size: 1.5 MB

Release files / pcglasso-0.2.0.tar.gz

Download URL pcglasso-0.2.0.tar.gz
Size 26.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f7a6ee8ccb8587b713486c8c6ff2a9263197e5ebe072f736cfb7b3832ce728ef
BLAKE2b-256 checksum
How to use checksums
d952e4269fc439283c0989984b7d49d950bc4daf71e5d6b4ff7643ab53cc5ec9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.

Transparency log

Release files / pcglasso-0.2.0-cp310-abi3-win_amd64.whl

Download URL pcglasso-0.2.0-cp310-abi3-win_amd64.whl
Size 224.2 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fe5cf58749e20c9351ec20e268191db94ea0ae5e978e95f55ef35144dbcb6214
BLAKE2b-256 checksum
How to use checksums
eb0ad83ed8dffe75c3e122a2238edd0ee18d8929c96cc0966e6b54715aa50cd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.

Transparency log

Release files / pcglasso-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pcglasso-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 348.5 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
b24f5b5e159889d3560359cbf215cd1cb3692347faedadedfbad2a16c8102eb7
BLAKE2b-256 checksum
How to use checksums
557acca8010ce077603b89b357c284d3716cbac34a31be229d94c06709bcabc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.

Transparency log

Release files / pcglasso-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pcglasso-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 331.3 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
5ffd34d614fc581534c534281e57c3f3b19ced23848218e0a12c12a0fe58d6c6
BLAKE2b-256 checksum
How to use checksums
d83a812ba223b1fe35ea86ccb114cca1add116f4294be493219e4783f7b1aa01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.

Transparency log

Release files / pcglasso-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL pcglasso-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 604.8 kB
Tags CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
822dc6cfb79cae220d05f809b95d9cc27c834f27a68c5da209d4449287253eb7
BLAKE2b-256 checksum
How to use checksums
714c77310a488808b2befba8c8124f1f8e7a58370ee7762f3210c3587e1e9749
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

5 release files

0.1.0

5 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page