Explore the polyhedral complexes of ReLU neural networks.
Project description
Relucent is a Python package for computing the polyhedra of ReLU networks! Its main features include:
- Distributed calculation of the activation regions of ReLU networks via local search
- Visualization of ReLU complexes in two or three dimensions with Plotly
- Automatic compatibility with existing PyTorch networks
- Computation of the complex's dual as a NetworkX Graph
- Various calculations for individual activation regions, decision boundaries, and affine splines
Environment Setup
- Core package only (without PyTorch):
pip install relucent - With PyTorch support:
pip install "relucent[torch]"- Note: Supports PyTorch
>=2.5.0(PyTorch install guide)
- Note: Supports PyTorch
Development Check Modes
- With torch (full checks):
pip install ".[dev,torch]" && pytest - Without torch (optional-dependency compatibility):
pip install ".[dev]" && pytest tests/test_no_torch.py
Getting Started
To see if the installation has been successful, try plotting the complex of a randomly initialized network in 2 dimensions like this:
import numpy as np
import torch.nn as nn
import relucent
if __name__ == '__main__':
# Create Model
network = nn.Sequential(
nn.Linear(2, 10),
nn.ReLU(),
nn.Linear(10, 5),
nn.ReLU(),
nn.Linear(5, 1),
) ## or conveniently, relucent.mlp(widths=[2, 10, 5, 1])
## Initialize a Complex to track calculations
cplx = relucent.Complex(network)
## Calculate the activation regions via local search
cplx.bfs()
## Plotting functions return Plotly figures
fig = cplx.plot()
fig.show()
Given some input point, you could get a minimal H-representation of the polyhedral region containing it like this:
input_point = np.random.random((1, 2))
p = cplx.point2poly(input_point)
print(p.halfspaces[p.shis])
Attributes like p.halfspaces (halfspaces of the form Ax + b <= 0, in format [A; b], induced by each neuron), p.shis (the indices of the non-redundant halfspaces), and p.center (the Chebyshev Center) are computed lazily.
You could also check the average number of faces of all polyhedrons with:
sum(len(p.shis) for p in cplx) / len(cplx)
Or, get the adjacency graph of top-dimensional cells in the complex with:
print(cplx.get_dual_graph())
You can view the full documentation for this library at https://bl-ake.github.io/relucent/
Obtaining a Gurobi License
This package will work for most applications without a license. However, without one, Gurobi will only work with a limited feature set. This includes a limit on the number of decision variables in the models it can solve, which limits the size of the networks this code is able to analyze. There are multiple ways to install the software, but we recommend the following steps to those eligible for an academic license: 0. Create a fresh Python environment using a distribution of Anaconda.
- Install the Gurobi Python library using
conda install -c gurobi gurobi. - Obtain a Gurobi license (Note: a WLS license will limit the number of concurrent sessions across multiple devices, which can result in slowdowns when using this library on different machines simultaneously.)
- In your Conda environment, run
grbgetkeyfollowed by your license key - Complete the remaining steps in Getting Started
Citing this Package
If you run into any problems or have any feature requests, please create an issue on the project's Github. If you want to credit its use in your research, please cite our paper.
@inproceedings{
gaines2026characterizing,
title={Characterizing the Discrete Geometry of Re{LU} Networks},
author={Blake B. Gaines and Jinbo Bi},
booktitle={The Fourteenth International Conference on Learning Representations},
year={2026},
url={https://openreview.net/forum?id=TgLW2DiRDG}
}
Related Software:
Please check out the amazing software created by others working in this area. Depending on your goal, some of these could be even better!
- GoL Toolbox by Turgay Caglar (Paper)
- CanonicalPoly 2.0 by Marissa Maden (Paper)
- ReLU Edge Subdivision by Arturs Berzins (Paper)
- SplineCam by Ahmed Imtiaz Humayun (Paper)
- Neural Network Elements by Andrew Tawfeek (Paper)
Bibliography
This package was made possible by the following work:
- Fukuda, K. (2004, August 26). Frequently Asked Questions in Polyhedral Computation. https://people.inf.ethz.ch/~fukudak/polyfaq/
- Grigsby, J. E., & Lindsey, K. (2022). On Transversality of Bent Hyperplane Arrangements and the Topological Expressiveness of ReLU Neural Networks. SIAM Journal on Applied Algebra and Geometry, 6(2), 216–242. https://doi.org/10.1137/20M1368902
- Liu, Y., Caglar, T., Peterson, C., & Kirby, M. (2023). Integrating geometries of ReLU feedforward neural networks. Frontiers in Big Data, 6, 1274831. https://doi.org/10.3389/fdata.2023.1274831
- Masden, M. (2025). Algorithmic Determination of the Combinatorial Structure of the Linear Regions of ReLU Neural Networks. SIAM Journal on Applied Algebra and Geometry, 9(2), 374–404. https://doi.org/10.1137/24M1646996
- Xu, S., Vaughan, J., Chen, J., Zhang, A., & Sudjianto, A. (2022). Traversing the Local Polytopes of ReLU Neural Networks. The AAAI-22 Workshop on Adversarial Machine Learning and Beyond. https://openreview.net/forum?id=EQjwT2-Vaba
- Yajing Liu, Christina M Cole, Chris Peterson, & Michael Kirby. (2023). ReLU Neural Networks, Polyhedral Decompositions, and Persistent Homolog. TAG-ML.
- Zhang, X., & Wu, D. (2019, September 25). Empirical Studies on the Properties of Linear Regions in Deep Neural Networks. International Conference on Learning Representations. https://openreview.net/forum?id=SkeFl1HKwr
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 relucent-0.9.0.tar.gz.
File metadata
- Download URL: relucent-0.9.0.tar.gz
- Upload date:
- Size: 66.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7345e343f8976930c6b0f29cb10dc36a8b57aca4813229cec5eeaf9bbfc32c14
|
|
| MD5 |
656e2d3bf9dd95daee0eaf72da1190a4
|
|
| BLAKE2b-256 |
ec3e0d05cbc1e15a6469333fcded9e228871b1fd2eb4fe40de0b297a564da72b
|
Provenance
The following attestation bundles were made for relucent-0.9.0.tar.gz:
Publisher:
publish.yml on bl-ake/relucent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
relucent-0.9.0.tar.gz -
Subject digest:
7345e343f8976930c6b0f29cb10dc36a8b57aca4813229cec5eeaf9bbfc32c14 - Sigstore transparency entry: 1395063481
- Sigstore integration time:
-
Permalink:
bl-ake/relucent@6309e140dcc91099e2d685c2b1caf593da7781a3 -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/bl-ake
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6309e140dcc91099e2d685c2b1caf593da7781a3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file relucent-0.9.0-py3-none-any.whl.
File metadata
- Download URL: relucent-0.9.0-py3-none-any.whl
- Upload date:
- Size: 72.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bee5d9c37c71d84fb45a3f2b943c9fb1b9f9a36f3714994c3094f9a6f5935840
|
|
| MD5 |
a49e280af4bc9800899779c091b1af2d
|
|
| BLAKE2b-256 |
098581377fc00ad9dff428b92b4939d985f2385d30542b2a3055254dd5723a0d
|
Provenance
The following attestation bundles were made for relucent-0.9.0-py3-none-any.whl:
Publisher:
publish.yml on bl-ake/relucent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
relucent-0.9.0-py3-none-any.whl -
Subject digest:
bee5d9c37c71d84fb45a3f2b943c9fb1b9f9a36f3714994c3094f9a6f5935840 - Sigstore transparency entry: 1395063490
- Sigstore integration time:
-
Permalink:
bl-ake/relucent@6309e140dcc91099e2d685c2b1caf593da7781a3 -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/bl-ake
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6309e140dcc91099e2d685c2b1caf593da7781a3 -
Trigger Event:
release
-
Statement type: