CARLsim
6.1.0
CARLsim: a GPU-accelerated SNN simulator
|
a SpikeGeneratorFromFile schedules spikes from a spike file binary More...
#include <spikegen_from_file.h>
Public Member Functions | |
SpikeGeneratorFromFile (std::string fileName, int offsetTimeMs=0) | |
SpikeGeneratorFromFile constructor. More... | |
~SpikeGeneratorFromFile () | |
SpikeGeneratorFromFile destructor. More... | |
void | loadFile (std::string fileName, int offsetTimeMs=0) |
Loads a new spike file. More... | |
int | nextSpikeTime (CARLsim *sim, int grpId, int nid, int currentTime, int lastScheduledSpikeTime, int endOfTimeSlice) |
schedules the next spike time More... | |
void | rewind (int offsetTimeMs) |
Rewinds the spike file to beginning of file. More... | |
Public Member Functions inherited from SpikeGenerator | |
virtual | ~SpikeGenerator () |
This class implements a SpikeGenerator that schedules spikes exactly as specified by a spike file binary. The spike file must have been created with a SpikeMonitor.
The easiest used-case is wanting to re-run a simulation with the exact same spike trains. For example, if a spike file contains two AER events (in the format <neurId,spikeTime>): <2,123> and <10,12399>, then SpikeGeneratorFromFile will deliver a spike to neuron ID 2 exactly at simulation time 123ms and a spike to neuron ID 10 at simulation time 12399. Running the simulation for longer than that will have no effect, since there are no spikes left to schedule after that.
If in this simulation a SpikeMonitor is set on the same group, then the newly generated spike file should be identical to the one used as an input to SpikeGeneratorFromFile.
It is possible to off-set the spike times by adding a constant offsetTimeMs to every scheduled spike time. Thus the AER events <2,123> and <10,12399> will be converted to <2,123+offsetTimeMs> and <10,12399+offsetTimeMs>. This offset can be passed to both the constructor and SpikeGeneratorFromFile::rewind, and it can assume both positive or negative. Default value is zero.
It is also possible to repeatedly parse the spike file, adding different offsetTimeMs offsets per loop. This can be achieved by passing an optional argument to SpikeGeneratorFromFile::rewind.
Upon initialization, the class parses and buffers all spikes from the spike file in a format that allows for more efficient scheduling. Note that this might take up a lot of memory if you have a large and highly active neuron group.
Usage example:
Definition at line 124 of file spikegen_from_file.h.
SpikeGeneratorFromFile | ( | std::string | fileName, |
int | offsetTimeMs = 0 |
||
) |
[in] | fileName | file name of spike file (must be created from SpikeMonitor) |
[in] | offsetTimeMs | optional offset (ms) that will be applied to all scheduled spike times. Can assume both positive and negative values. Default: 0. |
Definition at line 61 of file spikegen_from_file.cpp.
Definition at line 74 of file spikegen_from_file.cpp.
void loadFile | ( | std::string | fileName, |
int | offsetTimeMs = 0 |
||
) |
This function loads a new spike file (must be created from SpikeMonitor). This allows changing files mid-simulation, which would otherwise not be possible without re-compiling the network, because CARLsim::setSpikeGenerator can only be called in CONFIG_STATE.
[in] | fileName | file name of spike file (must be created from SpikeMonitor) |
[in] | offsetTimeMs | optional offset (ms) that will be applied to all scheduled spike times. Can assume both positive and negative values. Default: 0. |
Definition at line 81 of file spikegen_from_file.cpp.
|
virtual |
This function schedules the next spike time, given the currentTime and the lastScheduledSpikeTime. It implements the virtual function of the base class.
[in] | sim | pointer to a CARLsim object |
[in] | grpId | current group ID for which to schedule spikes |
[in] | nid | current neuron ID for which to schedule spikes |
[in] | currentTime | current time (ms) at which spike scheduler is called |
[in] | lastScheduledSpikeTime | the last time (ms) at which a spike was scheduled for this nid, grpId |
[in] | endOfTimeSlice | the end of the current scheduling time slice (ms). A spike delivered at a time >= endOfTimeSlice will not be scheduled by CARLsim |
Implements SpikeGenerator.
Definition at line 174 of file spikegen_from_file.cpp.
void rewind | ( | int | offsetTimeMs | ) |
This function rewinds the spike file to the begining and applies an offset to the spike times. This means that the SpikeGenerator will continue to schedule spikes (starting over at the beginning of the spike file), but this time it will add offsetTimeMs to all spike times.
Most often, this offset is the current simulation time (in ms), which can be retrieved via CARLsim::getSimTime.
Specifying an offset is necessary, because SpikeGeneratorFromFile has no direct access to CARLsim, and thus cannot know how much time has already been simulated.
Consider the following illustrative example:
[in] | offsetTimeMs | offset (ms) that will be applied to all scheduled spike times. Can assume both positive and negative values. |
Definition at line 96 of file spikegen_from_file.cpp.