genn-team / ml_genn

A library for deep learning with Spiking Neural Networks (SNN).
https://ml-genn.readthedocs.io
GNU Lesser General Public License v2.1
24 stars 7 forks source link

Spike count record #73

Closed neworderofjamie closed 1 year ago

neworderofjamie commented 1 year ago

Implemented spike count recording as an option for the SpikeRecorder callback meaning that all existing filtering etc works here. The implementation could use https://github.com/numpy/numpy/pull/21429 to further improve efficiency.

# Evaluate model and record spikes and spike counts of input population
callbacks = ["batch_progress_bar", SpikeRecorder(input, key="input_spikes"),
             SpikeRecorder(input, key="input_spike_counts", record_counts=True)]
metrics, cb_data  = compiled_net.evaluate({input: spikes},
                                          {output: labels},
                                          callbacks=callbacks)

# Extract spikes and spike counts
input_spikes = cb_data["input_spikes"]
input_spike_counts = cb_data["input_spike_counts"]

# Assert that manually-calculated spike counts from arbitrary example match those calculated using new system
assert np.array_equal(np.bincount(input_spikes[1][100], minlength=NUM_INPUT),
                                  input_spike_counts[100])

Fixes #60

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 15.38% and project coverage change: -0.12% :warning:

Comparison is base (413f304) 62.60% compared to head (f3cb032) 62.49%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #73 +/- ## ========================================== - Coverage 62.60% 62.49% -0.12% ========================================== Files 97 97 Lines 3768 3775 +7 ========================================== Hits 2359 2359 - Misses 1409 1416 +7 ``` | [Files Changed](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team) | Coverage Δ | | |---|---|---| | [ml\_genn/ml\_genn/callbacks/spike\_recorder.py](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team#diff-bWxfZ2Vubi9tbF9nZW5uL2NhbGxiYWNrcy9zcGlrZV9yZWNvcmRlci5weQ==) | `20.31% <0.00%> (-2.50%)` | :arrow_down: | | [ml\_genn/ml\_genn/callbacks/var\_recorder.py](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team#diff-bWxfZ2Vubi9tbF9nZW5uL2NhbGxiYWNrcy92YXJfcmVjb3JkZXIucHk=) | `28.57% <0.00%> (ø)` | | | [ml\_genn/ml\_genn/compilers/compiler.py](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team#diff-bWxfZ2Vubi9tbF9nZW5uL2NvbXBpbGVycy9jb21waWxlci5weQ==) | `80.79% <ø> (ø)` | | | [ml\_genn/ml\_genn/compilers/event\_prop\_compiler.py](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team#diff-bWxfZ2Vubi9tbF9nZW5uL2NvbXBpbGVycy9ldmVudF9wcm9wX2NvbXBpbGVyLnB5) | `22.02% <ø> (ø)` | | | [ml\_genn/ml\_genn/connectivity/avg\_pool\_2d.py](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team#diff-bWxfZ2Vubi9tbF9nZW5uL2Nvbm5lY3Rpdml0eS9hdmdfcG9vbF8yZC5weQ==) | `91.42% <ø> (ø)` | | | [ml\_genn/ml\_genn/losses/mean\_square\_error.py](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team#diff-bWxfZ2Vubi9tbF9nZW5uL2xvc3Nlcy9tZWFuX3NxdWFyZV9lcnJvci5weQ==) | `37.50% <0.00%> (ø)` | | | [.../ml\_genn/losses/sparse\_categorical\_crossentropy.py](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team#diff-bWxfZ2Vubi9tbF9nZW5uL2xvc3Nlcy9zcGFyc2VfY2F0ZWdvcmljYWxfY3Jvc3NlbnRyb3B5LnB5) | `50.00% <0.00%> (ø)` | | | [ml\_genn/ml\_genn/neurons/input.py](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team#diff-bWxfZ2Vubi9tbF9nZW5uL25ldXJvbnMvaW5wdXQucHk=) | `47.94% <ø> (ø)` | | | [ml\_genn/ml\_genn/neurons/spike\_input.py](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team#diff-bWxfZ2Vubi9tbF9nZW5uL25ldXJvbnMvc3Bpa2VfaW5wdXQucHk=) | `50.00% <ø> (ø)` | | | [ml\_genn/ml\_genn/utils/data.py](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team#diff-bWxfZ2Vubi9tbF9nZW5uL3V0aWxzL2RhdGEucHk=) | `34.95% <0.00%> (ø)` | | | ... and [4 more](https://app.codecov.io/gh/genn-team/ml_genn/pull/73?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=genn-team) | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.