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.3.tar.gz (53.6 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.3-cp312-cp312-win_amd64.whl (196.8 kB view details)

Uploaded CPython 3.12Windows x86-64

brucezilany-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (458.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

brucezilany-0.0.3-cp311-cp311-win_amd64.whl (194.9 kB view details)

Uploaded CPython 3.11Windows x86-64

brucezilany-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (458.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

brucezilany-0.0.3-cp310-cp310-win_amd64.whl (194.0 kB view details)

Uploaded CPython 3.10Windows x86-64

brucezilany-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (458.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

brucezilany-0.0.3-cp39-cp39-win_amd64.whl (200.7 kB view details)

Uploaded CPython 3.9Windows x86-64

brucezilany-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (458.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for brucezilany-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c4840e1a0a665c007fefa415770695b997bdd097ed1331203bca1c88ec5a66f7
MD5 3e66bc19d798a57994299382e8619442
BLAKE2b-256 1d86cde00e4ace20af4e08062e0217db9cc788ba066160dc01c0e8ea4e136765

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.3.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.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: brucezilany-0.0.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 196.8 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for brucezilany-0.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2a431175978a7022b14a7130cf63e8299463d546bcc59643f40e1cbdaa714df8
MD5 03aba967b4eb54bd5f609aca55cf8b44
BLAKE2b-256 e21617d219409e1adb0c7518b9f38b4e40b5a5e90275dbd3f4a78bef50315d4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.3-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.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 298edc80fdafc46b0a0b315feee8ceb40f1b9d8ab1226d857a164049ddc6c9c9
MD5 6e4f30f678426a5bd0663daac91c73a0
BLAKE2b-256 04d062e978b40a9f0686c0796db53e40b48bc3820f8f37ff1548d5929a894768

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.3-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.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: brucezilany-0.0.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 194.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for brucezilany-0.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3cd018c1278b60384790f660ae33160d807a7321a44ed779d36bde1e0b98e198
MD5 cc30221fa8a32f2d12ddba66cea01db7
BLAKE2b-256 5677b25f03b44c17f43aec39ef21ff8c2ac64565f75cb9610dd19b39d9a5cf24

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.3-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.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ffb8fd32bf61310378cffcb86e8752690a0bf236e8ade2d1a80cb3e65558181c
MD5 7c0c1748e1fbb6ee467eaf214eb16867
BLAKE2b-256 d24d2f2ab1ca87a147ec7ea536da476bd8aef11fb89a2cfcae121cf5e893343d

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.3-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.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: brucezilany-0.0.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 194.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for brucezilany-0.0.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 be31712618a50b1f6e48413ad6fcec81395addb9807983f76aecbc3ce08282a4
MD5 458b4458b50be6123ef8a45fd0bae07f
BLAKE2b-256 789889e2191970c7507aaa663b995d2063d147b7a8fcb00f457c4cbd64cae5e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.3-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.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71b018447710394b94c27c56aa564744fd95a46d14ca29afbb48d366d94e4144
MD5 5a5f5c668322b2cff55531f60b012098
BLAKE2b-256 d81a8523b34aa3fc47a715e39df17f1992c7d081e91f7cfe0718454993d77516

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.3-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.3-cp39-cp39-win_amd64.whl.

File metadata

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

File hashes

Hashes for brucezilany-0.0.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 05f82e6f8889fe149c7d44fef245e24d577ce7f96d2ee3161588fe45f9abf248
MD5 335c52d96ec7b2266fc7473e290c6602
BLAKE2b-256 1a4dff825676f5487765de0d9b4926372b96ffcd26db5f3d453d917bc16a42ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.3-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.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for brucezilany-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 453615160a88569145a2ea0a0b8ee4748c6d76590d75f1568271a1a351957c85
MD5 efd91c5bac317ac955c00e50ef7080d7
BLAKE2b-256 6388754ea4b5c7d45cdec9dc04f68c90eb405148117b3968b794fe45e9bb5ec8

See more details on using hashes here.

Provenance

The following attestation bundles were made for brucezilany-0.0.3-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