Skip to main content

spire-rd

Information-theoretic rate-distortion bounds and optimal spike codes for spiking neural networks.

Computes the R(D)/capacity ceiling of a noisy spike channel, then builds constructive codes that approach it. The "LDPC moment" for spike codes.

Installation

pip install -e .

# with PyTorch wrappers:
pip install -e ".[torch]"

Requires Python 3.10+, NumPy, SciPy.

Quick start

import numpy as np
from spire_rd import SpikeChannel, RDBound, SpikeEncoder, SoftDecoder

# Define the noisy spike channel
ch = SpikeChannel(T=32, sigma=1.0, p_d=0.05, p_i=0.01)

# Compute the R(D) ceiling
bound = RDBound(ch, K=64, nsamp=4000)
result = bound.compute(sigma=1.0)
print(f"capacity = {result.capacity:.3f} bits/spike")
print(f"frontier points: {len(result.hull)}")

# Build multi-spike codes
enc = SpikeEncoder(ch, K=64, m_set=[1, 2, 4], h_half=3)
enc_result = enc.compute(sigma=1.0)
print(f"TTFS: D={enc_result.ttfs_D:.4f}, R={enc_result.ttfs_R:.3f}")

# Decode with pseudo-likelihood
K = 64
dec = SoftDecoder(ch, K=K)
bin_centers = (np.arange(K) + 0.5) / K
w_map = [np.array([int(np.round((1 - bc) * (ch.T - 1)))]) for bc in bin_centers]
bufs = ch.simulate(np.array([10, 20]), n=64, seed=0)
log_L = dec.intensity_matrix(w_map)
values = dec.decode(bufs, log_L, method="pl")

Modules

Module What it does
SpikeChannel Canonical noisy spike channel: jitter, deletion, insertion
RDBound R(D) frontiers via direct I(X; x_hat) minimization
SpikeEncoder Multi-spike code family with tunable redundancy knob
SoftDecoder Channel-aware pseudo-likelihood decoder

Channel model

The spike channel applies three operations in fixed order:

  1. Jitter: each spike position is displaced by a discretized Gaussian kernel
  2. Deletion: each surviving spike is independently removed with probability p_d
  3. Insertion: each clock step independently generates a spurious spike with probability p_i

Boundary handling after jitter: clip (default), drop, or wrap.

R(D) computation

The RDBound class computes the information-theoretic rate-distortion ceiling using exponentiated-gradient mirror descent that minimizes the true end-to-end rate I(X; x_hat) — no surrogate, no looseness.

result = bound.compute(
    sigma=1.0,       # jitter
    metric="mse",    # or "task" for classification
    betas=np.logspace(-2, 4, 60),
)
# result.hull gives the Pareto-optimal (D, R) frontier
# result.capacity gives the channel capacity

Optional PyTorch integration

from spire_rd.torch import SpikeChannelLayer, SoftDecoderLayer

# Inject channel noise during training
noise_layer = SpikeChannelLayer(T=32, sigma=2.0, p_d=0.1, p_i=0.02)
x_noisy = noise_layer(x_clean)

# PL decoding layer
dec_layer = SoftDecoderLayer(ch, K=64)
values = dec_layer(bufs, log_L)

Tests

pytest tests/

License

MIT

Metadata

Release files for spire-rd 1.0.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 spire-rd 1.0.0
File Size Uploaded Provenance
spire_rd-1.0.0.tar.gz 25.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for spire-rd 1.0.0
File Interpreter ABI Platform
spire_rd-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.6 kB

Release files / spire_rd-1.0.0.tar.gz

Download URL spire_rd-1.0.0.tar.gz
Size 25.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e2b89e35f9313f1d3379cf45f6d2d7c31ee4c4f456dc3301da988906f807e7fa
BLAKE2b-256 checksum
How to use checksums
2f87a956ce73768780eb523764f063391023ac4faf00327a62e9fa91d761ec39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / spire_rd-1.0.0-py3-none-any.whl

Download URL spire_rd-1.0.0-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05964d8db1617a1941ee75a4b6240c8d159c3dfb57dc26227d10da0882fb6386
BLAKE2b-256 checksum
How to use checksums
40ef016ce9278791268279ef25e2317d473cf68c0c56abfef43ff05f25b81843
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Security for spire-rd 1.0.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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