Skip to content

Commit

Permalink
Releasing 0.3.2 (Brian2 extensions).
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodo Rueckauer committed Nov 4, 2019
1 parent 624ce46 commit 0b0b8a2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
10 changes: 10 additions & 0 deletions RELEASE_NOTES.rst → changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
SNN Toolbox: Release Notes
==========================

Version 0.3.2
-------------

Simulation with Brian2 backend now supports:
- Constant input currents (less noisy than Poisson input)
- Reset-by-subtraction (more accurate than reset-to-zero).
- Bias currents

Thanks to wilkieolin for this contribution.

Version 0.3.1
-------------

Expand Down
22 changes: 10 additions & 12 deletions examples/mnist_keras_brian2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

import keras
from keras import Input, Model
from keras.layers import Conv2D, AveragePooling2D, Flatten, Dense, Dropout
from keras.layers import Conv2D, AveragePooling2D, Flatten, Dense, Dropout, \
BatchNormalization, Activation
from keras.datasets import mnist
from keras.utils import np_utils

Expand Down Expand Up @@ -67,24 +68,21 @@

layer = Conv2D(filters=16,
kernel_size=(5, 5),
strides=(2, 2),
activation='relu',
use_bias=False)(input_layer)
strides=(2, 2))(input_layer)
layer = BatchNormalization(axis=axis)(layer)
layer = Activation('relu')(layer)
layer = Conv2D(filters=32,
kernel_size=(3, 3),
activation='relu',
use_bias=False)(layer)
activation='relu')(layer)
layer = AveragePooling2D()(layer)
layer = Conv2D(filters=8,
kernel_size=(3, 3),
padding='same',
activation='relu',
use_bias=False)(layer)
activation='relu')(layer)
layer = Flatten()(layer)
layer = Dropout(0.01)(layer)
layer = Dense(units=10,
activation='softmax',
use_bias=False)(layer)
activation='softmax')(layer)

model = Model(input_layer, layer)

Expand Down Expand Up @@ -123,11 +121,11 @@
'duration': 50, # Number of time steps to run each sample.
'num_to_test': 5, # How many test samples to run.
'batch_size': 1, # Batch size for simulation.
'dt': 0.1 # Time interval for the differential equations to be solved over.
'dt': 0.1 # Time resolution for ODE solving.
}

config['input'] = {
'poisson_input': True # Images are encodes as spike trains.
'poisson_input': False # Images are encodes as spike trains.
}

config['output'] = {
Expand Down
16 changes: 4 additions & 12 deletions examples/mnist_keras_nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,19 @@
layer = Conv2D(filters=16,
kernel_size=(5, 5),
strides=(2, 2),
activation='relu',
use_bias=False)(input_layer)
activation='relu')(input_layer)
layer = Conv2D(filters=32,
kernel_size=(3, 3),
activation='relu',
use_bias=False)(layer)
activation='relu')(layer)
layer = AveragePooling2D()(layer)
layer = Conv2D(filters=8,
kernel_size=(3, 3),
padding='same',
activation='relu',
use_bias=False)(layer)
activation='relu')(layer)
layer = Flatten()(layer)
layer = Dropout(0.01)(layer)
layer = Dense(units=10,
activation='softmax',
use_bias=False)(layer)
activation='softmax')(layer)

model = Model(input_layer, layer)

Expand Down Expand Up @@ -125,10 +121,6 @@
'batch_size': 1, # Batch size for simulation.
}

config['input'] = {
'poisson_input': True # Images are encodes as spike trains.
}

config['output'] = {
'plot_vars': { # Various plots (slows down simulation).
'spiketrains', # Leave section empty to turn off plots.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name='snntoolbox',
version='0.3.1', # see https://www.python.org/dev/peps/pep-0440/
version='0.3.2', # see https://www.python.org/dev/peps/pep-0440/
description='Spiking neural network conversion toolbox',
long_description=long_description,
author='Bodo Rueckauer',
Expand Down
18 changes: 9 additions & 9 deletions snntoolbox/simulation/target_simulators/brian2_target_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def __init__(self, config, queue=None):
self.v_reset = 'v = v - v_thresh'
else:
self.v_reset = 'v = v_reset'
self.eqs = ''' dv/dt = bias : 1
bias : hertz'''
self.eqs = '''dv/dt = bias : 1
bias : hertz'''
self.spikemonitors = []
self.statemonitors = []
self.snn = None
Expand Down Expand Up @@ -219,14 +219,14 @@ def compile(self):

def simulate(self, **kwargs):

inputs = kwargs[str('x_b_l')].flatten() / self.sim.ms
if self._poisson_input:
self._input_layer.rates = kwargs[str('x_b_l')].flatten() * 1000 / \
self.rescale_fac * self.sim.Hz
self._input_layer.rates = inputs / self.rescale_fac
elif self._dataset_format == 'aedat':
# TODO: Implement by using brian2.SpikeGeneratorGroup.
raise NotImplementedError
else:
self._input_layer.bias = kwargs[str('x_b_l')].flatten() / self.sim.ms
self._input_layer.bias = inputs

self.snn.run(self._duration * self.sim.ms, namespace=self._cell_params,
report='stdout', report_period=10 * self.sim.ms)
Expand Down Expand Up @@ -385,8 +385,8 @@ def set_spiketrain_stats_input(self):
AbstractSNN.set_spiketrain_stats_input(self)

def set_biases(self, biases):
"""Set biases.
"""
"""Set biases."""
if any(biases):
assert self.layers[-1].bias.shape == biases.shape, "Shape of biases and network do not match."
self.layers[-1].bias = biases * 1000 * self.sim.Hz
assert self.layers[-1].bias.shape == biases.shape, \
"Shape of biases and network do not match."
self.layers[-1].bias = biases / self.sim.ms

0 comments on commit 0b0b8a2

Please sign in to comment.