CARLsim  6.1.0
CARLsim: a GPU-accelerated SNN simulator
SpikeGeneratorFromFile Class Reference

a SpikeGeneratorFromFile schedules spikes from a spike file binary More...

#include <spikegen_from_file.h>

Inheritance diagram for SpikeGeneratorFromFile:
[legend]
Collaboration diagram for SpikeGeneratorFromFile:
[legend]

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 ()
 

Detailed Description

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:

// configure a CARLsim network
CARLsim sim("LoadFromFile", CPU_MODE, USER);
int gIn = sim.createSpikeGeneratorGroup("input", 10, EXCITATORY_NEURON);
// Initialize a SpikeGeneratorFromFile object from a previously recorded
// spike file (make sure that group had 10 neurons, too!)
SpikeGeneratorFromFile SGF("results/spk_input.dat");
// assign spike generator to group
sim.setSpikeGenerator(gIn, &SGF);
// continue configuring ...
// schedule the exact same spikes as in the file
// let's assume the first spike time occurs at t=42ms and the last at t=967ms
sim.runNetwork(1,0);
// SGF can rewind to the beginning of the spike file, but now add offset of 1000ms: this can be done
// either by hardcoding the number or by calling CARLsim::getSimTime:
SGF.rewind((int)sim.getSimTime());
// now spikes will be scheduled again, but the first spike is at t=42+1000ms, and the last at t=967+1000ms
sim.runNetwork(1,0);
Note
Make sure the new neuron group has the exact same number of neurons as the group that was used to record the spike file.
Attention
Upon initializiation, all spikes from the spike file will be buffered as vectors of ints, which might take up a lot of memory if you have a large and highly active neuron group.
Since
v3.0

Definition at line 124 of file spikegen_from_file.h.

Constructor & Destructor Documentation

◆ SpikeGeneratorFromFile()

SpikeGeneratorFromFile ( std::string  fileName,
int  offsetTimeMs = 0 
)
Parameters
[in]fileNamefile name of spike file (must be created from SpikeMonitor)
[in]offsetTimeMsoptional 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.

◆ ~SpikeGeneratorFromFile()

Definition at line 74 of file spikegen_from_file.cpp.

Member Function Documentation

◆ loadFile()

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.

Parameters
[in]fileNamefile name of spike file (must be created from SpikeMonitor)
[in]offsetTimeMsoptional offset (ms) that will be applied to all scheduled spike times. Can assume both positive and negative values. Default: 0.
Since
v3.1

Definition at line 81 of file spikegen_from_file.cpp.

◆ nextSpikeTime()

int nextSpikeTime ( CARLsim sim,
int  grpId,
int  nid,
int  currentTime,
int  lastScheduledSpikeTime,
int  endOfTimeSlice 
)
virtual

This function schedules the next spike time, given the currentTime and the lastScheduledSpikeTime. It implements the virtual function of the base class.

Parameters
[in]simpointer to a CARLsim object
[in]grpIdcurrent group ID for which to schedule spikes
[in]nidcurrent neuron ID for which to schedule spikes
[in]currentTimecurrent time (ms) at which spike scheduler is called
[in]lastScheduledSpikeTimethe last time (ms) at which a spike was scheduled for this nid, grpId
[in]endOfTimeSlicethe end of the current scheduling time slice (ms). A spike delivered at a time >= endOfTimeSlice will not be scheduled by CARLsim
Returns
the next spike time (ms)

Implements SpikeGenerator.

Definition at line 174 of file spikegen_from_file.cpp.

◆ rewind()

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:

  1. Assume spike file contains only two spikes <neurId,spikeTime>: <2,123> and <6,987>
  2. If we run CARLsim for a second, SpikeGeneratorFromFile will schedule exactly these two spikes at times t1=123ms and t2=987ms
  3. If we run CARLsim for longer, no additional spikes will be scheduled.
  4. However, calling SpikeGeneratorFromFile::rewind with offset 1000ms (which is what CARLsim::getSimTime will return at that point) will re-schedule all spikes, but now t1=1000+123ms and t2=100+123ms
Parameters
[in]offsetTimeMsoffset (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.

Here is the call graph for this function:

The documentation for this class was generated from the following files: