Skip to main content

Rectified Spectral Units (ReSU) implementation based on Qin et al. (2025)

Project description

pyresu: Rectified Spectral Units

Python NumPy Pytest PyPI License Version Maintained zread

pyresu is a Python package implementing Rectified Spectral Units (ReSU), a biologically inspired neural building block based on the research by Qin et al. (2025). Unlike traditional deep learning that relies on backpropagation, ReSUs learn temporal features through spectral decomposition (CCA) and rectification.

Features

  • Backprop-Free Training: Implements a layer-wise, feed-forward training regime using analytical solutions.
  • Spectral Learning: Uses Canonical Correlation Analysis (CCA) to align past and future temporal windows.
  • Biologically Inspired: Mimics self-supervised learning in biological circuits.
  • Temporal Lag Management: Built-in utilities for Hankel matrix construction and lag vector handling.
  • Interpretability: Learnable filters (Canonical Directions) are directly interpretable as temporal features.

Mathematical Mapping

Concept Symbol Implementation
Past/Future Lags $p_t, f_t$ construct_lag_vectors
Covariances $C_{pp}, C_{ff}, C_{fp}$ compute_covariance_matrices
Spectral Solution $\Psi, \sigma_i$ perform_truncated_cca
ReSU Output $z_{t,i}^+, z_{t,i}^-$ ReSUCell.forward (ON/OFF)
Mutual Info $I_r$ calculate_mutual_information

Installation

Install the package in editable mode for development:

git clone https://github.com/username/pyresu.git
cd pyresu
pip install -e .

For development dependencies (tests, linting):

pip install -e ".[dev]"

Quick Start

import numpy as np
from pyresu.preprocessing import construct_lag_vectors, center_lag_vectors
from pyresu.models import ReSUCell

# 1. Prepare some time-series data
data = np.random.randn(1000, 1)

# 2. Create past and future lag vectors
# memory=10 (past), horizon=5 (future)
past, future = construct_lag_vectors(data, memory=10, horizon=5)
past_c, future_c = center_lag_vectors(past, future)

# 3. Initialize and fit the ReSU Cell
# rank=3 (number of neurons)
cell = ReSUCell(rank=3)
cell.fit(past_c, future_c)

# 4. Forward pass
on_output, off_output = cell.forward(past_c)

print(f"ON shape: {on_output.shape}")  # (N, 3)
print(f"OFF shape: {off_output.shape}") # (N, 3)

Project Structure

  • src/pyresu/: Main implementation code.
    • core.py: CCA and spectral solvers.
    • models.py: ReSUCell implementation.
    • preprocessing.py: Lag vector and whitening utilities.
    • simulation.py: Synthetic data generators (OU processes, GP).
  • tests/: Comprehensive test suite using pytest and hypothesis.

Testing

Run the tests using pytest:

pytest

References

This project incorporates research from the following paper:

  • A Network of Biologically Inspired Rectified Spectral Units (ReSUs) Learns Hierarchical Features Without Error Backpropagation Shanshan Qin, Joshua L. Pughe-Sanford, Alexander Genkin, Pembe Gizem Ozdil, Philip Greengard, Anirvan M. Sengupta, Dmitri B. Chklovskii arXiv:2512.23146

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

pyresu-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

pyresu-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyresu-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a220aa5ceb8a722b8bba1a9ee6571dcf000af1f198042a3238743b119880b78c
MD5 cc329f80e3fa0d69d938a148e1a0f09b
BLAKE2b-256 46297c05a3af78ae3a807894e6b2eb8e99d01fed0b75cda691dc8ad08429747c

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on kuslavicek/pyresu

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

File details

Details for the file pyresu-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyresu-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyresu-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 750d292659b4f68204f264b50dd4773b98ffbf11b16c04ca1f1fbcbd1c082b76
MD5 9a3e45bfbada33b93be83ea324195bfe
BLAKE2b-256 b35fe120aab93dd48efeab0a1e4dd563539743487ae6db84e91cdeb3b1c1a220

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyresu-0.1.0-py3-none-any.whl:

Publisher: publish.yml on kuslavicek/pyresu

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