Skip to main content

Phenomological Adaptive STochastic auditory nerve fiber model

Project description

Phenomological Adaptive STochastic auditory nerve fiber model

test-python

This repository contains an archive implementation of a phenomenological auditory nerve fiber model. The model is implemented in C++, with a runtime interface for Python. It can be easily installed via pip:

pip install phastc

The model has been tested and built for python versions 3.9-12, and is compiled using g++ for MacOS and Linux and msvc on Windows.

Running PHAST

The PHAST model simulates the response of a single auditory nerve fiber to electrical stimulation. As such, the model revolves arround two main inputs, the stimulus, and a list of fibers. These are both managed by objects in Python and explained in detail in the following sections.

Pulse Train

The pulse train encodes the stimulus to be used in the simulation. We differentiate between a ConstantPulseTrain object and a PulseTrain object. The former can be used when the stimulation has a constant interval and amplitude, and can be a lot more efficient. The latter should be used whenever each pulse in the pulse train can be different, for example when using stimuli produced by a speech coding strategy. The PulseTrain has the following signature:

stimulus = PulseTrain(
    pulse_train: np.ndarray = ...,
    time_step: float = 1e-6,
    ...
)

Only the first parameter is required, and should be a numpy array (matrix) of shape n electrodes x time steps. Then each element of the matrix encodes the amplitude of a pulse at given timestep for a given electrode. Ensure that the time steps of the matrix match the ```time_step`` parameter.

The ConstantPulseTrain has the following signature:

stimulus = ConstantPulseTrain(
    duration: float = ...,
    rate: float = ...,
    amplitude: float = ...,
    time_step: float = 1e-6,
)

Here, the duration denotes the total length in seconds of the pulse train, and rate the pulse rate, i.e. number of pulses per second. Each pulse in this pulse train has the same amplitude, specified by amplitude. Again, time_step encodes the time step of the pulse train. Note that this object can only be used for single electrode stimulation.

Fiber

The Fiber object encodes a single fiber to be analyzed by the PHAST model. Many can be analyzed at the same time, so often a list of several fibers can be considered at any given time. The object has the following signature:

fiber = Fiber(
    i_det: np.ndarray = ...,
    spatial_constant: np.ndarray = ...,
    sigma: np.ndarray = ...,
    fiber_id: int = ...,
    sigma_rs: float = ...,
    refractory_period: RefractoryPeriod = ...,
    decay: Decay = ...,
    store_stats: bool = False
)

Here i_det, spatial_constant, sigma, are all vectors of length number of electrodes, which should match the number of electrodes in the PulseTrain used in stimulation. For i_det, this defines the deteriministic threshold after which the fiber spikes, for a pulse from a given electrode. The spatial_constant defines an electrode specific spatial constant, which is used to scale stimulation. The sigma parameter is another electrode specific parameter, which is the relative spread per i_det, i.e. relative_spread * i_det. fiber_id encodes a unique identifier, specified by the used to attach to the fiber. sigma_rs is used for stochasticy between trials. store_stats defines whether all statistics should be stored, such as the refractoriness at each time step. This defaults to False, and should be used with caution, as this significantly increases memory usage. RefractoryPeriod is a parameter wrapper for handling both absolute and relative refractoriness. It can be defined as follows, and if not given explicitly to the Fiber, the following default values are used:

ref = RefractoryPeriod(
    absolute_refractory_period: float = 4e-4,
    relative_refractory_period: float = 8e-4,
    sigma_absolute_refractory_period: float = 0.0,
    sigma_relative_refractory_period: float = 0.0
)

Decay

Several different versions of the model can be used, which use a different model for controlling spike rate decay.

  • Exponential: The first version of the model, as used in: van Gendt, Margriet J., et al. "A fast, stochastic, and adaptive model of auditory nerve responses to cochlear implant stimulation." Hearing research 341 (2016): 130-143. This model uses an exponential decay function.
  • Power Law: In a subsequent paper, the exponential decay was replaced by a power law function, to better approximate long duratioin fiber behaviour, presented in: van Gendt, Margriet J., et al. "Short and long-term adaptation in the auditory nerve stimulated with high-rate electrical pulse trains are better described by a power law." Hearing Research 398 (2020): 108090.
  • Leaky Integrator: In the latest paper, the power law decay was replaced by a leaky integrator, which was shown to approximate long duration fiber behavoir with comparable accuracy as the power law decay function, but using significantly less computational resources. This version should be prefered when performing large scale experiments with PHAST. The model was presented in: de Nobel, Jacob, et al. "Biophysics-inspired spike rate adaptation for computationally efficient phenomenological nerve modeling." Hearing Research 447 (2024): 109011.

To use any of the previously mentioned versions of the PHAST model, the decay parameter needs to be specific when constructing a Fiber object with the correct Decay object. For the exponential decay model, we need to pass:

decay = Exponential(
    adaptation_amplitude: float = 0.01,
    accommodation_amplitude: float = 0.0003,
    sigma_adaptation_amplitude: float = 0.0,
    sigma_accommodation_amplitude: float = 0.0,
    exponents: list[tuple] = [(0.6875, 0.088), (0.1981, 0.7), (0.0571, 5.564)],
)

For the power law model, the following is required:

decay = Powerlaw(
    adaptation_amplitude: float = 2e-4,
    accommodation_amplitude: float = 8e-6,
    sigma_adaptation_amplitude: float = 0.0,
    sigma_accommodation_amplitude: float = 0.0,
    offset: float = 0.06,
    exp: float = -1.5
)

Finally, for the model which uses the leaky integrator, the following decay object needs to be passed:

decay = LeakyIntegratorDecay(
    adaptation_amplitude: float = 7.142,
    accommodation_amplitude: float = 0.072,
    adaptation_rate: float = 0.014,
    accommodation_rate: float = 19.996
)

phast

Then finally, we can combine the above to run the phast model (for a single fiber):

fiber_stats = phast(
    [fiber],                        # A list of Fiber objects
    pt,                             # A PulseTrain object, either PulseTrain or ConstantPulseTrain
    n_jobs = -1,                    # The number of parallel cores to use (-1 is all available)
    n_trials = 1                    # The number of trials to generate for each fiber
    use_random = True               # Whether the experiment should use randomness
)

This yields a list of FiberStats objects which contains information about the experiment, such as the occurence of spikes (e.g.fiber_stats[0].spikes), or other statistics, when store_stats has been enabled. In order to get consitent results when enabling randomness i.e. when use_random = True, a proper seed should be set, using phast.set_seed(seed_value), similar to how one would use np.random.seed.

Creating Neurograms

We include a helper to easily aggregate FiberStats data into neurograms in matrix form. To do this, the following can be used:

neurogram = Neurogram(
    fiber_stats, 
    bin_size: float,    # The required binsize of the neurogram, every spike falling in the bin is summed
)

This then creates a neurogram matrix, which can be accessed via the data member, i.e. neurogram.data.

We provide the following plotting utility to easiliy visualize these neurograms:

fig, ax = plt.subplots()
plot_neurogram(
    neurogram,
    ax=ax,      # Optional
    fig=fig     # Optional
)

Speech Coding Strategies

Note that we include several options for sound encoding and integrated with PHAST, see the folder phast/scs for more information.

Citation

@article{de2024biophysics,
title = {Biophysics-inspired spike rate adaptation for computationally efficient phenomenological nerve modeling},
journal = {Hearing Research},
volume = {447},
pages = {109011},
year = {2024},
issn = {0378-5955},
doi = {https://doi.org/10.1016/j.heares.2024.109011},
url = {https://www.sciencedirect.com/science/article/pii/S0378595524000649},
author = {Jacob {de Nobel} and Savine S.M. Martens and Jeroen J. Briaire and Thomas H.W. Bäck and Anna V. Kononova and Johan H.M. Frijns},
}

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

phastc-1.1.0.tar.gz (41.7 MB view details)

Uploaded Source

Built Distributions

phastc-1.1.0-cp312-cp312-win_amd64.whl (41.9 MB view details)

Uploaded CPython 3.12 Windows x86-64

phastc-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (42.0 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

phastc-1.1.0-cp312-cp312-macosx_11_0_arm64.whl (41.9 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

phastc-1.1.0-cp311-cp311-win_amd64.whl (41.9 MB view details)

Uploaded CPython 3.11 Windows x86-64

phastc-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (42.0 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

phastc-1.1.0-cp311-cp311-macosx_11_0_arm64.whl (41.9 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

phastc-1.1.0-cp310-cp310-win_amd64.whl (41.9 MB view details)

Uploaded CPython 3.10 Windows x86-64

phastc-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (42.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

phastc-1.1.0-cp310-cp310-macosx_11_0_arm64.whl (41.9 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

phastc-1.1.0-cp39-cp39-win_amd64.whl (41.9 MB view details)

Uploaded CPython 3.9 Windows x86-64

phastc-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (42.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

phastc-1.1.0-cp39-cp39-macosx_11_0_arm64.whl (41.9 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

File details

Details for the file phastc-1.1.0.tar.gz.

File metadata

  • Download URL: phastc-1.1.0.tar.gz
  • Upload date:
  • Size: 41.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for phastc-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d749c4b9cd1a3512565f310ebbf6cfee338332e279dc73951b7f8a975bc5989f
MD5 832acac7bea2a0cf502311dac639be2b
BLAKE2b-256 e3e8a1f2481a260e1549b7e03625cc87f566d111732102f7545e984222777391

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: phastc-1.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 41.9 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for phastc-1.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 cdc47336be3cb612923a000bdb258f4587c6526167d1e691adc7903717459312
MD5 fef598ff2234aee5e6018a8660ae6bad
BLAKE2b-256 a059c1517073227696795008a6a1a2a8eb25bd0860540ed1b16d1b97d0ecc344

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for phastc-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2f28e9d8193001ce6dfa18381bd8fb0c39bcf48732b0308d936a9117c9e4b80d
MD5 c438e22ac74ae75af7d8c296d4551b55
BLAKE2b-256 713747c7773a64f332f011b9baf6da97a30efe44cd0f7d926837d54bbc5fe79e

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for phastc-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f4fb5c298d6f3acd2bae407b17bce5e2dda156e58afbac2dfb232d1c75454b5
MD5 346e603e5471057713fc9d6f6e1b2975
BLAKE2b-256 5c396eeccc58fa15f41ebcce93e6f9312fb76b1ebc39de5b79de07ba569fb1fa

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: phastc-1.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 41.9 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for phastc-1.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0ba20d97c8e2e5abeec16e0c927beba10e6d87132919001b8fc88955e7e5d688
MD5 0f1a094f00eec3b263fc4fe095129d76
BLAKE2b-256 29b324dd6fd14d0f46e183b66574b78366d217c24547c0aa0541cb254ad3ffaf

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for phastc-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c088c9bf76727de8d719e5616d4ced473e5aabd21c43c5e7b024049148858a58
MD5 513ed5c1e08caaa180f40956df88903f
BLAKE2b-256 afe32d237132fec5f111cf91e1280ae19584af07072619d471891bfaab89a7ba

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for phastc-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 38e921780e0123074bde91e2df266ccad3208064a552e5ba77c3bb72358ddea4
MD5 d0bf2eb2ddbc4999e2f95e9d09db5646
BLAKE2b-256 1eb5afb75fae4ffeae32e374a15b41b17162542e0b0748e1530df421287f692e

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: phastc-1.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 41.9 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for phastc-1.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b2d5cb5bb7cdd47edd29f8d52240086999c6777bf4d666163e0d00c07f3ce020
MD5 d7a63f124ae2efdb9a3a03a7a5b15c03
BLAKE2b-256 98965d8094f20d3bad5e32752e67d860bf2d1059f11ed3c61fd70625063e1482

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for phastc-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 596704b2092801fb7a1e5bc669e36ce77682f29351f77f7914c2786d97a48237
MD5 871f65a30b7646e995b8047019f57ea5
BLAKE2b-256 9c94a4abcf9637752d5dc7ac7f9b86dd28ae1df71740d7694267250b59a6a6ba

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for phastc-1.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72b98b408530cee83b913048faece8bf9d257b177eb2929a9a7d5ce58c50f765
MD5 869c5cdd03851d0b5fe0bdade31e09df
BLAKE2b-256 5296467fea57950afc48988b924c99064fd31aada5e65fe60a0fbef60b1b0d87

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: phastc-1.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 41.9 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for phastc-1.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9c5329c77215e591a3cbb7f811e5a89c46eca91fdc97c69ce99915d86b555c18
MD5 dfbdde864af40d20d0b52c277c2611ac
BLAKE2b-256 6fcfafc307c123d6733d218490398b2d905e721bc6a4e3f19d92c028988e66b6

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for phastc-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b302c6a95b8ae2d98d500bb78ed66743bcd3be1571807d155c09050d67d1b2b
MD5 59100dfef4705d2252d61834287fba5f
BLAKE2b-256 3a982ba3cc7e9c98854f0c5332d5f55ef633c91b8dce6d208692157bf6209cc9

See more details on using hashes here.

File details

Details for the file phastc-1.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for phastc-1.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3213b7c215a7f25010038e69ed473d09aa16f2ec5eab62c2f502700de7b7d6e
MD5 a898d4cd8c4c17e2fdae885c330a4206
BLAKE2b-256 1cf922f60c5e358d621af31ed1defd2420fa2d49520b839f61e0e5160c1108f8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page