teili.stimuli package¶
Submodules¶
teili.stimuli.testbench module¶
This class holds different pre-defined testbench stimuli.
The idea is to test certain aspects of you network with common stimuli.
Example
>>> import numpy as np
>>> from brian2 import us, ms
>>> from pyqtgraph.Qt import QtCore, QtGui
>>> import pyqtgraph as pg
>>> from teili.stimuli.testbench import OCTA_Testbench
>>> from teili.tools.plotter2d import Plotter2d
>>> app = QtGui.QApplication.instance()
>>> if app is None:
app = QtGui.QApplication(sys.argv)
>>> else:
print('QApplication instance already exists: %s' % str(app))
>>> testbench = OCTA_Testbench()
>>> testbench.rotating_bar(length=10, nrows=10, direction='ccw', ts_offset=3,
angle_step=10, noise_probability=0.2, repetitions=90, debug=False)
In order to visualize it:
>>> event_monitor = Plotter2d.loaddvs(testbench.events)
>>> imv1 = event_monitor.plot3d_on_off(plot_dt=10*ms, filtersize=15*ms)
>>> win = pg.GraphicsWindow(title="DVS Spikes")
>>> gridlayout = QtGui.QGridLayout(win)
>>> gridlayout.addWidget(imv1, 1, 1)
>>> win.resize(1500, 1000)
>>> win.setLayout(gridlayout)
>>> win.show()
>>> win.setWindowTitle('DVS plot')
>>> imv1.play(10)
>>> app.exec_()
Todo
As soon as visualizer class is updated, change imports!
-
class
teili.stimuli.testbench.
OCTA_Testbench
(DVS_SHAPE=(240, 180))[source]¶ Bases:
object
This class holds all relevant stimuli to test modules provided with the Online Clustering of Temporal Activity (OCTA) framework.
-
angles
¶ List of angles of orientation.
- Type
numpy.ndarray
-
DVS_SHAPE
¶ Input shape of the simulated DVS/DAVIS vision sensor.
- Type
TYPE
-
end
¶ End pixel location of the line.
- Type
TYPE
-
events
¶ Attribute storing events of testbench stimulus.
- Type
TYPE
-
indices
¶ Attribute storing neuron index of testbench stimulus.
- Type
TYPE
-
line
¶ Stimulus of the testbench which is used to either generate an interactive plot to record stimulus with a DVS/DAVIS camera or coordinates are used to generate a SpikeGenerator.
- Type
TYPE
-
start
¶ Start pixel location of the line.
- Type
TYPE
-
times
¶ Attribute storing spike times of testbench stimulus.
- Type
list
-
aedat2events
(rec, camera='DVS128')[source]¶ Wrapper function of the original aedat2numpy function in teili.tools.converter.
This function will save events for later usage and will directly return them if no SpikeGeneratorGroup is needed.
- Parameters
rec (str) – Path to stored .aedat file.
camera (str, optional) – Can either be string (‘DAVIS240’) or int 240, which specifies the larger of the 2 pixel dimension to unravel the coordinates into indices.
- Returns
4D numpy array with #events entries. Array is organized as x, y, ts, pol. See aedat2numpy for more details.
- Return type
events (np.ndarray)
-
ball
(rec_path)[source]¶ This function loads a simple recording of a ball moving in a small arena. The idea is to test the Online Clustering and Prediction module of OCTAPUS. The aim is to learn spatio-temporal features based on the ball’s trajectory and learn to predict its movement.
- Parameters
rec_path (str, required) – Path to recording.
- Returns
A SpikeGenerator which has index (i) and spiketimes (t) as attributes
- Return type
SpikeGeneratorGroup (brian2.obj)
- Raises
UserWarning – If no filename is given but aedat reacording should be loaded
-
dda_round
(x)[source]¶ Simple round funcion.
- Parameters
x (float) – Value to be rounded.
- Returns
Ceiled value of x.
- Return type
(int)
-
infinity
(cAngle)[source]¶ Given an angle cAngle this function returns the current position on an infinity trajectory.
- Parameters
cAngle (float) – current angle in rad which determines position on infinity trajectory.
- Returns
Postion in x, y coordinates.
- Return type
position (tuple)
-
rotating_bar
(length=10, nrows=10, ncols=None, direction='ccw', ts_offset=10, angle_step=10, artifical_stimulus=True, rec_path=None, save_path=None, noise_probability=None, repetitions=1, debug=False)[source]¶ This function returns a single SpikeGeneratorGroup (Brian object).
The purpose of this function is to provide a simple test stimulus. A bar is rotating in the center. The goal is to learn necessary spatio-temporal features of the moving bar and be able to make predictions about where the bar will move.
- Parameters
length (int) – Length of the bar in pixel.
nrows (int, optional) – X-Axis size of the pixel array.
ncols (int, optional) – Y-Axis size of the pixel array.
orientation (str) – Orientation of the bar. Can either be ‘vertical’ or ‘horizontal’.
ts_offset (int) – time between two pixel location.
angle_step (int, optional) – Angular velocity. Sets step width in np.arrange.
artifical_stimulus (bool, optional) – Flag if stimulus should be created or loaded from aedat file.
rec_path (str, optional) – Path/to/stored/location/of/recorded/stimulus.aedat.
save_path (str, optional) – Path to store generated events.
noise_probability (float, optional) – Probability of noise events between 0 and 1.
repetitions (int, optional) – Number of revolutions of the rotating bar.
debug (bool, optional) – Flag to print more detailed output of testbench.
- Returns
- Brian2 objects which holds the spike times as well
as the respective neuron indices
- Return type
SpikeGenerator obj
- Raises
UserWarning – If no filename is given but aedat recording should be loaded
-
rotating_bar_infinity
(length=10, nrows=64, ncols=None, orthogonal=False, shift=32, ts_offset=10, artifical_stimulus=True, rec_path=None, return_events=False)[source]¶ This function will either load recorded DAVIS/DVS recordings or generate artificial events of a bar moving on an infinity trajectory with fixed orientation, i.e. no super-imposed rotation. In both cases, the events are provided to a SpikeGeneratorGroup which is returned.
- Parameters
length (int, optional) – Length of the bar in pixel.
nrows (int, optional) – X-Axis size of the pixel array.
ncols (int, optional) – Y-Axis size of the pixel array.
orthogonal (bool, optional) – Flag which determines if bar is kept always orthogonal to trajectory, if it kept aligned with the trajectory or if it returns in a “chaotic” way.
shift (int, optional) – Offset in x where the stimulus will start.
ts_offset (int, optional) – Time in ms between consecutive pixels (stimulus velocity).
artifical_stimulus (bool, optional) – Flag if stimulus should be created or loaded from aedat file.
rec_path (str, optional) – Path/to/stored/location/of/recorded/stimulus.aedat.
return_events (bool, optional) – Flag to return events instead of SpikeGenerator.
- Returns
A SpikeGenerator which has index (i) and spiketimes (t) as attributes. events (numpy.ndarray, optional): If return_events is set, events will be returned.
- Return type
SpikeGeneratorGroup (brian2.obj)
- Raises
UserWarning – If no filename is given but aedat recording should be loaded.
-
translating_bar_infinity
(length=10, nrows=64, ncols=None, orientation='vertical', shift=32, ts_offset=10, artifical_stimulus=True, rec_path=None, return_events=False)[source]¶ This function will either load recorded DAVIS/DVS recordings or generate artificial events of a bar moving on an infinity trajectory with fixed orientation, i.e. no super-imposed rotation. In both cases, the events are provided to a SpikeGeneratorGroup which is returned.
- Parameters
length (int, optional) – length of the bar in pixel.
nrows (int, optional) – X-Axis size of the pixel array.
ncols (int, optional) – Y-Axis size of the pixel array.
orientation (str, optional) – lag which determines if bar is orientated vertically or horizontally.
shift (int, optional) – offset in x where the stimulus will start.
ts_offset (int, optional) – Time in ms between consecutive pixels (stimulus velocity).
artifical_stimulus (bool, optional) – Flag if stimulus should be created or loaded from aedat file.
rec_path (str, optional) – Path/to/stored/location/of/recorded/stimulus.aedat.
return_events (bool, optional) – Flag to return events instead of SpikeGenerator.
- Returns
A SpikeGenerator which has index (i) and spiketimes (t) as attributes. events (numpy.ndarray, optional): If return_events is set, events will be returned.
- Return type
SpikeGeneratorGroup (brian2.obj)
- Raises
UserWarning – If no filename is given but aedat recording should be loaded.
-
-
class
teili.stimuli.testbench.
STDGM_Testbench
(N=1, stimulus_length=1200)[source]¶ Bases:
object
This class provides a stimulus to test your spike-timing dependent gain modulation algorithm.
-
stimuli
(isi)[source]¶ Stimulus gneration for STDGM protocols.
This function returns two brian2 objects. Both are Spikegeneratorgroups which hold a single index each and varying spike times. The protocol follows homoeostasis, weak LTP, weak LTD, strong LTP, strong LTD, homoeostasis.
- Parameters
isi (int, optional) – Interspike Interval. How many spikes per stimulus phase.
- Returns
- Brian2 objects which hold the spiketimes and
the respective neuron indices.
- Return type
SpikeGeneratorGroup (brian2.obj
-
-
class
teili.stimuli.testbench.
STDP_Testbench
(N=1, stimulus_length=1200)[source]¶ Bases:
object
This class provides a stimulus to test your spike-timing dependent plasticity algorithm.
-
N
¶ Size of the pre and post neuronal population.
- Type
int
-
stimulus_length
¶ Length of stimuli in ms.
- Type
int
-
stimuli
(isi=10)[source]¶ Stimulus gneration for STDP protocols.
This function returns two brian2 objects. Both are Spikegeneratorgroups which hold a single index each and varying spike times. The protocol follows homoeostasis, weak LTP, weak LTD, strong LTP, strong LTD, homoeostasis.
- Parameters
isi (int, optional) – Interspike Interval. How many spikes per stimulus phase.
- Returns
- Brian2 objects which hold the spiketimes and
the respective neuron indices.
- Return type
SpikeGeneratorGroup (brian2.obj
-
-
class
teili.stimuli.testbench.
SequenceTestbench
(n_channels, n_items, cycle_length, noise_probability=None, rate=None)[source]¶ Bases:
object
This class provides a simple poisson encoded sequence testbench. This class returns neuron indices and spike times, which can used to instantiate a SpikeGeneratorGroup in brian2.
-
class
teili.stimuli.testbench.
WTA_Testbench
[source]¶ Bases:
object
Collection of functions to test the computational properties of the WTA building_block.
-
indices
¶ Array with neuron indices.
- Type
numpy.ndarray
-
noise_input
¶ PoissonGroup which provides noise events.
- Type
brian2.PoissonGroup
-
times
¶ Array with neuron spike times.
- Type
numpy.ndarray
-
background_noise
(num_neurons=10, rate=10)[source]¶ Provides background noise as Poisson spike trains
- Parameters
num_neurons (int, optional) – 1D size of WTA population.
rate (int, optional) – Spike frequency f Poisson noise process.
-
stimuli
(num_neurons=16, dimensions=2, start_time=10, end_time=500, isi=2)[source]¶ This function provides simple test stimuli to test the selection mechanism of a WTA population.
- Parameters
num_neurons (int, optional) – 1D size of WTA population.
dimensions (int, optional) – Dimension of WTA. Can either be 1 or 2
start_time (int, optional) – Start time when stimulus should start.
end_time (int, optional) – End time when stimulus should stop.
isi (int, optional) – Inter-spike between spike times.
- Raises
NotImplementedError – If dimension is not 1 or 2 this error is raised
-