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

Download files

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

Source Distribution

spire_rd-1.0.0.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

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

spire_rd-1.0.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file spire_rd-1.0.0.tar.gz.

File metadata

  • Download URL: spire_rd-1.0.0.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.11

File hashes

Hashes for spire_rd-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e2b89e35f9313f1d3379cf45f6d2d7c31ee4c4f456dc3301da988906f807e7fa
MD5 66131eaee6c596661a2590ba85cff2e3
BLAKE2b-256 2f87a956ce73768780eb523764f063391023ac4faf00327a62e9fa91d761ec39

See more details on using hashes here.

File details

Details for the file spire_rd-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: spire_rd-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.11

File hashes

Hashes for spire_rd-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05964d8db1617a1941ee75a4b6240c8d159c3dfb57dc26227d10da0882fb6386
MD5 e0f7b42254d44c76f0d63c20bbcc154c
BLAKE2b-256 40ef016ce9278791268279ef25e2317d473cf68c0c56abfef43ff05f25b81843

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 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