CARLsim
3.1.3
CARLsim: a GPU-accelerated SNN simulator
|
The PoissonRate class allows a user create spike trains whose inter-spike interval follows a Poisson process. The object can then be linked to a spike generator group (created via CARLsim::createSpikeGeneratorGroup) by calling CARLsim::setSpikeRate.
The easiest way to initialize a PoissonRate object is via the following:
This will generate a mean rate vector for 50 neurons. By default, these rates will be allocated on CPU. An optional second argument to the constructor allows allocation on GPU instead (onGPU=true
). This allows the minimization of memory transfers when CARLsim is run in GPU_MODE:
At first, all the rates will be initialized to zero. The user then has several options to assign non-zero rates:
The mean firing rates can then be queried via the following getter functions:
Finally, a PoissonRate object can be linked to a spike generator group (created via CARLsim::createSpikeGeneratorGroup) by calling CARLsim::setSpikeRate. For this to work, the number of neurons for the PoissonRate object must be the same as for the spike generator group.
A PeriodicSpikeGenerator can be used to generate spike trains of a given mean firing rate with a constant inter-spike-interval (ISI) that is equal to 1/rate.
A PeriodicSpikeGenerator is instantiated as follows:
Here, the firing rate of the Spike Generator is 10 Hz (rate
), which leads to an ISI of 100ms. Thus, the PeriodicSpikeGenerator will schedule spike for each neuron in the group it is applied to at t=100ms, t=200ms, t=300ms, etc. If the flag spikeAtZero
is set to true, an additional spike will be scheduled at t=0.
In order for a PeriodicSpikeGenerator to be associated with a SpikeGenerator group, CARLsim::setSpikeGenerator must be called on the group in CONFIG_STATE:
A SpikeGeneratorFromVector can be used to schedule exact spike times (ms) from a vector. Note that currently the only option is to specify a single vector of spike times, which will apply to all neurons in the group. In the future, it should be possible to specify a vector of spike times for each neuron in the group.
A SpikeGeneratorFromVector is instantiated as follows:
In order for a SpikeGeneratorFromVector to be associated with a SpikeGenerator group, CARLsim::setSpikeGenerator must be called on the group in CONFIG_STATE:
A SpikeGeneratorFromFile can be used to schedule exact spike times (ms) from a spike file binary that was previously created with a SpikeMonitor. This makes it possible to repeatedely apply pre-recorded spike times to the same network (or a different network with the same amount of neurons in the associated group).
A SpikeGeneratorFromFile is instantiated as follows:
where the string "results/spk_input.dat" points to a spike file previously created with a SpikeMonitor.
In order for a SpikeGeneratorFromFile to be associated with a SpikeGenerator group, CARLsim::setSpikeGenerator must be called on the group in CONFIG_STATE:
For more fine-grained control over spike generation, individual spike times can be specified per neuron in each group. This is accomplished by using a callback mechanism, which is called at each time step, to specify whether a neuron has fired or not.
In order to specify spike times, a new class is defined that derives from the SpikeGenerator class:
The user must then define a SpikeGenerator::nextSpikeTime method. The following is a simple example that generates a spike every 100ms for each neuron in the group.
In order for a custom SpikeGenerator to be associated with a SpikeGenerator group, CARLsim::setSpikeGenerator must be called on the group in CONFIG_STATE:
CARLsim::setExternalCurrent can be used to inject currents, specified on a per-neuron basis, into the soma of each neuron in a group, at each timestep of the simulation (every millisecond). For this, a float vector of current amounts (mA) is specified, one element per neuron in the group.
Note that once CARLsim::setExternalCurrent is called, the specified amount of current will be injected every timestep, until the user calls CARLsim::setExternalCurrent again with updated values (e.g., with value zero).
To input different currents into a neuron over time, the idea is to run short periods of CARLsim::runNetwork and subsequently calling CARLsim::setExternalCurrent with updated current values.
For example, the following code snippet injects 5mA for 50ms into the soma of every neuron in the group:
Note that in the case where the same current applies to every neuron, it is sufficient to pass a single float value:
After stimulation, the idea is to reset the external current to zero:
The VisualStimulus utility consists of a MATLAB Toolbox that allows for the generation of 2D visual stimuli such as sinusoidal gratings, plaids, and random dot fields as well as some C++ CARLsim plug-in code. The MATLAB class allows to mix-and-match stimuli of different types, on a frame-by-frame basis. Stimuli can also be confined to visual aperture and combined with noise. Frames can then be dumped to a binary file, so that they can be reloaded later on.
Usage example: The following MATLAB code snippet creates a 32x32 pixel grayscale stimulus that consists of a sinusoidal grating (first ten frames), followed by a blank frame (delay period), followed by a plaid stimulus (next ten frames), confined to a circular aperture. The resulting stimulus is first plotted in figure axes, then recorded to AVI, and finally stored as a binary with a default name depending on the stimulus type, such as "inpGratingPlaid_gray_32x32x21.dat".
CARLsim provides plug-in code to interface the generated binary files with SpikeGenerator groups. This allows the user to create sophisticated visual stimuli in MATLAB, and interface them to a spiking network on a frame-by-frame basis. The class VisualStimulus reads frames from binary, and returns either the raw character array or a PoissonRate object with the same size as number of pixels in a stimulus frame.
A VisualStimulus is instantiated as follows:
where the string "inpGratingPlaid_gray_32x32x21.dat" references the created file mentioned above. The number of frames can be retrieved with VisualStimulus::getStimulusLength.
It is then straightforward to interface the recorded stimulus with a CARLsim simulation by making use of VisualStimulus::readFrame, which, whenever called, reads the next unread frame and returns it either as a raw character array or as a PoissonRate object.
The following figures shows a number of different stimulus frames created with the MATLAB Visual Stimulus toolbox. The Toolbox provides methods to compose stimuli made of sinusoidal gratings, bars, dots, noise, and custom frames. Apertures can be rectangular or circular. Noise can be white, Gaussian, Poissonian, salt & pepper, or speckle. Random dots can exhibit translatory motion, rotations, expansions, contractions, and mixtures of those types.