Skip to main content

Python/C++ interface to the Bruce-Zilany-Carney auditory nerve model

Project description

Bruce-Zilany-Carney Auditory Nerve Model (Python Interface)

This repository provides a modern Python interface to the auditory periphery model developed by the Bruce, Zilany, and Carney labs. The model simulates spike train responses in auditory nerve fibers with detailed physiological realism.

It is implemented in C++ with pybind11. All dependencies on Matlab have been removed, making it fully standalone and suitable for Python-based environments. In general, the library should have feature-parity with the original source, but the code should be considerably faster to execute.


🧠 Model Background

This code is based on:

  • Bruce, I. C., Erfani, Y., & Zilany, M. S. A. (2018)
    A phenomenological model of the synapse between the inner hair cell and auditory nerve: Implications of limited neurotransmitter release sites.
    Hearing Research, 360:40–54.

  • Bruce, I., Buller, A., & Zilany, M. (2023)
    Modeling of auditory nerve fiber input/output functions near threshold.
    Acoustics 2023, Sydney, Australia.

📢 Please cite both of the above if you publish research using this model or a modified version.


🚀 Getting Started

1. Install prerequisites

You need a working C++14 compiler and Python 3.9+. Use a virtual environment if needed.

2. Clone and install

git clone https://github.com/jacobdenobel/brucezilany.git
cd brucezilany
pip install .

For development mode:

pip install -e .

Install from PyPi

Alternatively, you can also install the package from pip, if you want to include it as dependency.

pip install brucezilany

🧪 Example Usage

import numpy as np
from brucezilany import inner_hair_cell, synapse, stimulus, map_to_synapse

# Generate a stimulus
stim = stimulus.ramped_sine_wave(
    duration=0.05,
    simulation_duration=0.1,
    sampling_rate=100000,
    rt=0.005,
    delay=0.01,
    f0=1000,
    db=65
)

# IHC response
ihc_output = inner_hair_cell(stim, cf=1000, n_rep=10)

# Intermediate mapper. In the orginal Matlab, this was part of the synapse function. 
# Here, it is separate, and needs to be called before synapse.
mapped_ihc = map_to_synapse(
    ihc_output=ihc_output,
    spontaneous_firing_rate=100,
    characteristic_frequency=1000,
    time_resolution=stim.time_resolution,
)

# Synapse response
out = synapse(
    amplitude_ihc=mapped_ihc,
    cf=1000,
    n_rep=10,
    n_timesteps=stim.n_simulation_timesteps,
    spontaneous_firing_rate=100
)

print("Mean firing rate:", np.mean(out.mean_firing_rate))

See examples/ for more. These contain Python translations of the Matlab test files contained in the original source.


⚙️ Model Components

inner_hair_cell

Simulates the receptor potential of an inner hair cell (IHC) in response to acoustic stimuli. Includes cochlear filtering and nonlinear transduction.

Args:

  • stimulus: Stimulus object
  • cf: characteristic frequency (Hz)
  • n_rep: number of stimulus repetitions
  • cohc: normal ohc function (float)
  • cihc: normal ihc function (float)
  • species: Species enum

Returns:

  • IHC output as a vector (float)

map_to_synapse

In the original Matlab source, this was included in the synapse function. However, since you sometimes want to call synapse for a number of trails, see for example test_adaptive_redocking.py, you don't always need to recompute this function. Therefore, in this code, it is separate, and you call this outside of calling synapse. The function applies a mapping function to the output of inner_hair_cell, by default a SOFTPLUS function.

Args:

  • ihc_output: array of floats
  • spontaneous_firing_rate: spontaneous firing rate of the fiber
  • characteristic_frequency: characteristic frequency
  • time_resolution: 1 / sampling rate
  • mapping_function: SynapseMapping enum

Returns:

  • mapped IHC output as a vector (float)

synapse

Simulates stochastic spike generation at the IHC-ANF synapse, using a 4-site vesicle model with adaptive redocking and realistic refractory behavior. Note that you can provide an optional seeded RNG. This is important, because otherwise this model will produce a deterministic output. Alternatively, calling brucezilany.set_seed(<int>) before calling synapse, also make this function behave randomly. Again, see test_adaptive_redocking.py for an example.

Args:

  • amplitude_ihc: IHC potential vector
  • cf: characteristic frequency (Hz)
  • n_rep: number of stimulus repetitions
  • n_timesteps: number of stimulus time steps
  • time_resolution: 1 / sampling rate
  • spontaneous_firing_rate: in spikes/s
  • noise: random noise mode (NoiseType)
  • pla_impl: power-law adaptation method (PowerLaw)
  • spontaneous_firing_rate: spontaneous firing rate of the fiber
  • abs_refractory_period: absolute refractory period
  • rel_refractory_period: relative refractory period
  • rng: optional seeded RNG

Returns:

  • SynapseOutput object with PSTH, spike times, and statistics

🎧 Stimulus Handling

The brucezilany.stimulus module provides tools for generating and loading stimuli with precise control over sampling rate, duration, delay, and amplitude. This ensures accurate modeling of auditory nerve responses to various acoustic signals.

📦 Stimulus Class

Stimuli are represented as Stimulus objects that encapsulate both the waveform and simulation parameters.

from brucezilany import stimulus

# Create a sine wave burst with a ramped onset/offset
stim = stimulus.ramped_sine_wave(
    duration=0.05,              # duration of tone burst (s)
    simulation_duration=0.1,    # total simulation time (s)
    sampling_rate=100_000,      # sampling rate (Hz)
    rt=2.5e-3,                  # rise/fall time (s)
    delay=25e-3,                # delay before tone onset (s)
    f0=5000,                    # frequency (Hz)
    db=60.0                     # SPL (dB)
)

You can inspect:

print("Stimulus duration:", stim.stimulus_duration)
print("Sampling rate:", stim.sampling_rate)
print("Samples:", stim.data.shape)

📂 Load from File

You can also load .wav files (e.g., speech or natural sounds):

stim = stimulus.from_file("data/defineit.wav", verbose=False)

By default, this:

  • Resamples to 100 kHz
  • Normalizes to 65 dB SPL
  • Pads with silence to match a simulation time of 1s

📐 Normalization

If you want to adjust the dB level of a stimulus manually:

stimulus.normalize_db(stim, stim_db=70)

🧰 Additional Tools

Neurogram class

Multi-threaded simulation manager for full neurograms across CFs and fiber types.

from brucezilany import Neurogram

ng = Neurogram(n_cf=50, n_low=5, n_med=5, n_high=10)
ng.create(sound_wave=stim, species=Species.HUMAN_SHERA, n_trials=3)

output = ng.get_output()  # 3D array: [fiber, trial, time]

🛠 Refactoring & Enhancements

Compared to the original code, the following major changes were made:

  • All Matlab dependencies removed

    • C++ replacements for resample, randn, etc.
    • Fully standalone backend
  • Modern C++14 style

    • No new/delete, safer memory via STL containers
    • Cleaner APIs and encapsulation
  • Modular structure

    • Split between IHC, map_to_synapse, synapse
  • Python bindings via pybind11

    • Fully exposed enums, structured output objects
  • Multi-threading support

    • Neurogram uses parallel processing for simulating many CF/fiber combinations

The original Matlab code can be found here. A reference to the code use to build this repository is included as a .zip file in the data/ folder.


🧠 References

Additional foundational papers:

  • Zilany, M. S. A., Bruce, I. C., & Carney, L. H. (2014). Updated parameters and expanded simulation options for a model of the auditory periphery. JASA, 135(1):283–286.

  • Zilany, M. S. A., Bruce, I. C., Nelson, P. C., & Carney, L. H. (2009). A phenomenological model of the synapse between the inner hair cell and auditory nerve: Long-term adaptation with power-law dynamics. JASA, 126(5):2390–2412.


📬 Contact

Questions or contributions? Open a GitHub issue or pull request.

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

brucezilany-0.0.1.tar.gz (53.7 kB view details)

Uploaded Source

Built Distributions

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

brucezilany-0.0.1-cp312-cp312-win_amd64.whl (189.9 kB view details)

Uploaded CPython 3.12Windows x86-64

brucezilany-0.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (437.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

brucezilany-0.0.1-cp311-cp311-win_amd64.whl (188.8 kB view details)

Uploaded CPython 3.11Windows x86-64

brucezilany-0.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (439.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

brucezilany-0.0.1-cp310-cp310-win_amd64.whl (187.8 kB view details)

Uploaded CPython 3.10Windows x86-64

brucezilany-0.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (438.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

brucezilany-0.0.1-cp39-cp39-win_amd64.whl (183.2 kB view details)

Uploaded CPython 3.9Windows x86-64

brucezilany-0.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (438.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file brucezilany-0.0.1.tar.gz.

File metadata

  • Download URL: brucezilany-0.0.1.tar.gz
  • Upload date:
  • Size: 53.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for brucezilany-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4c6ed9a67d9069623c6a336227875f803f713319a79ce5c2e3584a042f76572e
MD5 b512f945c20f1b5bdd2fa2d6c4496631
BLAKE2b-256 fa1300f917edf41d72bf2d3a9fd9b8bc3f9108276b9d30e97792f3819bf45dff

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.1.tar.gz:

Publisher: python-publish.yml on jacobdenobel/brucezilany

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

File details

Details for the file brucezilany-0.0.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b8f1dc6fec0fc0b961705c6b92b29847ddf2297b49f91e0237063d94a58a761d
MD5 9d67aee67ae2bbafec89e50832c71ecb
BLAKE2b-256 4cdd40222178d1c37df87b3e717c25677898bac4fc3654dadfdb9ab1dc872909

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.1-cp312-cp312-win_amd64.whl:

Publisher: python-publish.yml on jacobdenobel/brucezilany

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

File details

Details for the file brucezilany-0.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aad9671484fe55de7e2ec3ad1a3b20ad309ff6ab7b1966cf7cd0ca901bfaa087
MD5 a6b355518d3d3e4cfd9a5111e7d36c6a
BLAKE2b-256 9041f0ac6b8fd68b4242a442ed8552cc3cd9df5f528bd6feed766857a431b327

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish.yml on jacobdenobel/brucezilany

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

File details

Details for the file brucezilany-0.0.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 584bcb872d7149789a179216884e2745e0c2c2e4b5fe22a0d4bd49ea41267d2d
MD5 5b6c6967e875e5604c388ec003d750d2
BLAKE2b-256 713a85563df5f0579825a36f18607d328b10351b4ec86ea382c45d9d6d5df42a

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.1-cp311-cp311-win_amd64.whl:

Publisher: python-publish.yml on jacobdenobel/brucezilany

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

File details

Details for the file brucezilany-0.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d44c5e1412a91b05131948a270cdfeade0b2df94a833283ae40d62802c80cbbc
MD5 671df9a2cd58262d255e8221075772b3
BLAKE2b-256 9231e96393f28d9c86e75c4c88fa2a0b469fabf5378d2d5d55c1987aca10faa5

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish.yml on jacobdenobel/brucezilany

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

File details

Details for the file brucezilany-0.0.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 272713f63d6329e0cc3f2ba9e42314c46633768262de8a4d80b09f3b22544e54
MD5 1e281b18bb859fdd21a7d0431fc3d173
BLAKE2b-256 645fac383d7a2319babe04af25a53a5a9b65b4b4527ab3720c84da966649cdfb

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.1-cp310-cp310-win_amd64.whl:

Publisher: python-publish.yml on jacobdenobel/brucezilany

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

File details

Details for the file brucezilany-0.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a98d448da53601962c76a409f5ff9ff47e3de8c9000f1dcd6a3f130443fcade8
MD5 ced0d5286e5effaaee2762d5567c5d78
BLAKE2b-256 3e6ecbdc9f3a5287dfadd9e0666f0dbf9cfffe266d033ab4e886269443f26157

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish.yml on jacobdenobel/brucezilany

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

File details

Details for the file brucezilany-0.0.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: brucezilany-0.0.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 183.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for brucezilany-0.0.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5db13e617b6e9cbbd141ea52835795a39f9ab674c7674e2b39ee8a2e3cac6774
MD5 ebe974c50c1ba34f3e188b6dd4d6539c
BLAKE2b-256 8f94bc35b8338ae79c3c3bb33d46b8faea4a2051de5215454dcc10391273b845

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.1-cp39-cp39-win_amd64.whl:

Publisher: python-publish.yml on jacobdenobel/brucezilany

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

File details

Details for the file brucezilany-0.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c53122e9b9b480cff1764386d788fbd492a08509ca7d18078b41e6069d829ef8
MD5 17b0d043af96989460e68148ad34333e
BLAKE2b-256 7691c2634de5200a2c61f8e7067a87bc1bb34d0cc1bed178b034045634947292

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish.yml on jacobdenobel/brucezilany

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