CARLsim  5.0.0
CARLsim: a GPU-accelerated SNN simulator
SpikeMonitor Class Reference

Class SpikeMonitor. More...

#include <spike_monitor.h>

Public Member Functions

 SpikeMonitor (SpikeMonitorCore *spikeMonitorCorePtr)
 SpikeMonitor constructor. More...
 
 ~SpikeMonitor ()
 SpikeMonitor destructor. More...
 
void clear ()
 Truncates the 2D spike vector. More...
 
std::vector< float > getAllFiringRates ()
 Returns the average firing rate of all the neurons in the group as a vector of floats. More...
 
std::vector< float > getAllFiringRatesSorted ()
 Returns all the neuronal mean firing rates in ascending order. More...
 
float getMaxFiringRate ()
 returns the largest neuronal mean firing rate in the group More...
 
float getMinFiringRate ()
 returns the smallest neuronal mean firing rate in the group More...
 
SpikeMonMode getMode ()
 Returns the current SpikeMonitor mode. More...
 
float getNeuronMeanFiringRate (int neurId)
 returns the mean firing rate of a specific neuron in the group More...
 
int getNeuronNumSpikes (int neurId)
 returns the total number of spikes of a specific neuron in the group More...
 
int getNumNeuronsWithFiringRate (float min, float max)
 Returns the number of neurons that fall within this particular min/max range (inclusive). More...
 
int getNumSilentNeurons ()
 returns the number of neurons that are silent. More...
 
float getPercentNeuronsWithFiringRate (float min, float max)
 returns the percentage of total neurons in that are in the range specified by the user, min/max (inclusive). More...
 
float getPercentSilentNeurons ()
 returns the percentage of total neurons in group that are silent. More...
 
bool getPersistentData ()
 Returns a flag that indicates whether PersistentMode is on (true) or off (false) More...
 
float getPopMeanFiringRate ()
 Returns the mean firing rate of the entire neuronal population. More...
 
int getPopNumSpikes ()
 Returns the total number of spikes in the group. More...
 
float getPopStdFiringRate ()
 Returns the standard deviation of firing rates in the entire neuronal population. More...
 
long int getRecordingLastStartTime ()
 Returns the simulation time (ms) of the last call to startRecording() More...
 
long int getRecordingStartTime ()
 Returns the simulation time (ms) of the first call to startRecording() More...
 
long int getRecordingStopTime ()
 Returns the simulation time (ms) of the last call to stopRecording() More...
 
long int getRecordingTotalTime ()
 Returns the total recording time (ms) More...
 
std::vector< std::vector< int > > getSpikeVector2D ()
 returns the 2D spike vector More...
 
bool isRecording ()
 Recording status (true=recording, false=not recording) More...
 
void print (bool printSpikeTimes=true)
 prints the 2D spike vector. More...
 
void setLogFile (const std::string &logFileName)
 Sets the name of the spike file binary. More...
 
void setMode (SpikeMonMode mode=AER)
 Sets the current SpikeMonitor mode. More...
 
void setPersistentData (bool persistentData)
 Sets PersistentMode either on (true) or off (false) More...
 
void startRecording ()
 Starts a new recording period. More...
 
void stopRecording ()
 Ends a recording period. More...
 

Detailed Description

The SpikeMonitor class allows a user record spike data from a particular neuron group. First the method CARLsim::setSpikeMonitor must be called with the group ID of the desired group as an argument. The setSpikeMonitor call returns a pointer to a SpikeMonitor object which can be queried for spike data.

There are two different modes that define what information is collected exactly.

  • AER: AER mode will collect the exact spike times of all neurons in the group and store them in a 2D spike spike vector. The first dimension of the vector is neuron id, the second dimension is spike times. Each element spkVector[i] is thus a vector of all spike times for the i-th neuron in the group. This mode is activated by default. Because of the sheer amount of information, it is unwise to run this mode for extended periods of time. Note that recording in this mode may significantly slow down your simulation.
  • COUNT: SpikeCount mode will only collect spike count information, such as the number of spikes per neuron. This mode cannot retrieve exact spike times. Thus it is not possible to calculate some of the more elaborate metrics, such as spike-time correlations.

Spike data will not be recorded until the SpikeMonitor member function startRecording() is called. Before any metrics can be computed, the user must call stopRecording(). In general, a new recording period (the time period between startRecording and stopRecording calls) can be started at any point in time, and can last any number of milliseconds. The SpikeMonitor has a PersistentMode, which is off by default. When PersistentMode is off, only the last recording period will be considered. When PersistentMode is on, all the recording periods will be considered. By default, PersistentMode can be switched on/off by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

The above configurations do not affect the generation of the .dat spike file. That file will always contain all the spikes of all the neurons in the group, for the entire simulation.

SpikeMonitor objects should only be used after setupNetwork has been called. SpikeMonitor objects will be deallocated automatically.

Example usage:

// configure a network etc. ...
// create a SpikeMonitor pointer to grab the pointer from setSpikeMonitor.
SpikeMonitor* spikeMonExc;
// call setSpikeMonitor with carlsim object, sim, with the group ID, excGrpId, as an argument.
spikeMonExc=sim.setSpikeMonitor(excGrpId);
// begin recording spike data for group excGrpId
spikeMonExc->startRecording();
// run simulation that generates spikes for 20 seconds.
sim.runNetwork(20);
// stop recording data for group excGrpId so we can get spike statistics.
spikeMonExc->stopRecording();
// print a summary of the spike information
spikeMonExc->print();
// get the average firing rate of each of the neurons in group excGrpId
vector<float> excFRs = spikeMonExc->getAllFiringRates();

For additional information on how to use the SpikeMonitor object, please see Examples/spikeInfo.

TODO:
finish documentation

Definition at line 120 of file spike_monitor.h.

Constructor & Destructor Documentation

◆ SpikeMonitor()

SpikeMonitor ( SpikeMonitorCore spikeMonitorCorePtr)

Creates a new instance of the SpikeMonitor class.

Definition at line 59 of file spike_monitor.cpp.

◆ ~SpikeMonitor()

Cleans up all the memory upon object deletion.

Definition at line 64 of file spike_monitor.cpp.

Member Function Documentation

◆ clear()

void clear ( )

This function truncates all the data found in the 2D spike vector. If PersistentMode is off, this function will be called automatically in startRecording(), such that all spikes from previous recording periods will be discarded. By default, PersistentMode is off. If PersistentMode is on, the user can call this function after any number of recordings. However, isRecording() must always be off.

Definition at line 70 of file spike_monitor.cpp.

◆ getAllFiringRates()

std::vector< float > getAllFiringRates ( )

This function returns the average firing rate for each neuron in the group. If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime(). Use getGroupFiringRate() to get the mean firing rate of the entire group.

Returns
float vector for the average firing rate of each neuron.

Definition at line 116 of file spike_monitor.cpp.

◆ getAllFiringRatesSorted()

std::vector< float > getAllFiringRatesSorted ( )

This function returns a vector of neuronal mean firing rates, sorted in ascending order. The size of the vector is the same as the number of neurons in the group. Firing rates are converted to spikes/sec (Hz). If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Returns
a vector of neuronal mean firing rates in ascending order

Definition at line 183 of file spike_monitor.cpp.

◆ getMaxFiringRate()

float getMaxFiringRate ( )

If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Returns
float value of the largest neuronal firing rate of the group.

Definition at line 102 of file spike_monitor.cpp.

◆ getMinFiringRate()

float getMinFiringRate ( )

If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Returns
float value of the smallest neuronal firing rate of the group.

Definition at line 109 of file spike_monitor.cpp.

◆ getMode()

SpikeMonMode getMode ( )

This function returns the current SpikeMonitor mode. COUNT: Will collect only spike count information (such as number of spikes per neuron), not the explicit spike times. COUNT mode cannot retrieve exact spike times per neuron, and is thus not capable of computing spike train correlation etc. AER: Will collect spike information in AER format (will collect both neuron IDs and spike times).

Definition at line 251 of file spike_monitor.cpp.

◆ getNeuronMeanFiringRate()

float getNeuronMeanFiringRate ( int  neurId)

This function returns the average firing rate of a specific neuron in the group in spikes/sec (Hz), averaged over the recording time window. If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime(). Use getPopMeanFiringRate to find the population mean firing rate.

Parameters
[in]neurIdthe neuron ID (0-indexed, must be smaller than getNumNeurons)

Definition at line 123 of file spike_monitor.cpp.

◆ getNeuronNumSpikes()

int getNeuronNumSpikes ( int  neurId)

This function returns the total number of spikes emitted by a specific neuron in the recording period, which is equal to the number of elements in the 2D spike vector. If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime(). Use getGroupNumSpikes to find the number of spikes of all the neurons in the group.

Parameters
[in]neurIdthe neuron ID (0-indexed, must be smaller than getNumNeurons)

Definition at line 131 of file spike_monitor.cpp.

◆ getNumNeuronsWithFiringRate()

int getNumNeuronsWithFiringRate ( float  min,
float  max 
)

If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Returns
int value of the number of neurons that have a firing rate within the min/max range.

Definition at line 143 of file spike_monitor.cpp.

◆ getNumSilentNeurons()

int getNumSilentNeurons ( )

If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Returns
int of the number of neurons that are silent

Definition at line 161 of file spike_monitor.cpp.

◆ getPercentNeuronsWithFiringRate()

float getPercentNeuronsWithFiringRate ( float  min,
float  max 
)

If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Parameters
minminimum value of range (inclusive) to be searched.
maxmaximum value of range (inclusive) to be searched.
Returns
float of the percentage of total neurons that are in this range.

Definition at line 151 of file spike_monitor.cpp.

◆ getPercentSilentNeurons()

float getPercentSilentNeurons ( )

If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Returns
float of the percentage of total neurons that are silent.

Definition at line 168 of file spike_monitor.cpp.

◆ getPersistentData()

bool getPersistentData ( )

This function returns a flag that indicates whether PersistentMode is currently on (true) or off (false). If PersistentMode is off, only the last recording period will be considered for calculating metrics. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, but can be switched on at any point in time by calling setPersistentData(bool).

Definition at line 243 of file spike_monitor.cpp.

◆ getPopMeanFiringRate()

float getPopMeanFiringRate ( )

This function returns the average firing rate of all the neurons in the group in spikes/sec (Hz), averaged over the recording time window. If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Returns
the average firing rate of all the neurons in the group

Definition at line 77 of file spike_monitor.cpp.

◆ getPopNumSpikes()

int getPopNumSpikes ( )

This function returns the total number of spikes in the group, which is equal to the number of elements in the 2D spike vector. If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime(). Use getNeuronNumSpikes to find the number of spikes of a specific neuron in the group.

Definition at line 91 of file spike_monitor.cpp.

◆ getPopStdFiringRate()

float getPopStdFiringRate ( )

This function returns the standard deviation of firing rates of all the neurons in the group in spikes/sec (Hz), averaged over the recording time window. If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Returns
the standard deviation of firing rates of all the neurons in the group

Definition at line 84 of file spike_monitor.cpp.

◆ getRecordingLastStartTime()

long int getRecordingLastStartTime ( )

This function returns the simulation time (timestamp) of the last call to startRecording(). If PersistentMode is off, this number is equivalent to getRecordingStartTime().

Returns
the simulation time (ms) of the last call to startRecording()

Definition at line 222 of file spike_monitor.cpp.

◆ getRecordingStartTime()

long int getRecordingStartTime ( )

This function returns the simulation time (timestamp) of the first call to startRecording(). If PersistentMode is off, this number is equivalent to getRecordingLastStartTime().

Returns
the simulation time (ms) of the first call to startRecording()

Definition at line 229 of file spike_monitor.cpp.

◆ getRecordingStopTime()

long int getRecordingStopTime ( )

This function returns the simulation time (timestamp) of the last call to stopRecording().

Returns
the simulation time (ms) of the last call to stopRecording()

Definition at line 236 of file spike_monitor.cpp.

◆ getRecordingTotalTime()

long int getRecordingTotalTime ( )

This function returns the total amount of recording time upon which the calculated metrics are based. If PersistentMode is off, this number is equivalent to getRecordingStopTime()-getRecordingStartTime(). If PersistentMode is on, this number is equivalent to the total time accumulated over all past recording periods. Note that this is not necessarily equivalent to getRecordingStopTime()-getRecordingStartTime(), as there might have been periods in between where recording was off.

Returns
the total recording time (ms)

Definition at line 215 of file spike_monitor.cpp.

◆ getSpikeVector2D()

std::vector< std::vector< int > > getSpikeVector2D ( )

This function returns a 2D spike vector containing all the spikes of all the neurons in the group. The first dimension of the vector is neurons, the second dimension is spike times. Each element spkVector[i] is thus a vector of all spike times for the i-th neuron in the group. If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Returns
2D vector where first dimension is neurons, second dimension is spike times

Definition at line 175 of file spike_monitor.cpp.

◆ isRecording()

bool isRecording ( )

Gets record status as a bool. True means it is recording, false means it is not recording.

Returns
bool that is true if object is recording, false otherwise.

Definition at line 190 of file spike_monitor.cpp.

◆ print()

void print ( bool  printSpikeTimes = true)

This function prints all the spiking information in the group in legible format.

Parameters
[in]printSpikeTimeswhether to print the list of spike times for each neuron

Definition at line 194 of file spike_monitor.cpp.

◆ setLogFile()

void setLogFile ( const std::string &  logFileName)

This function sets the name of the spike file binary. It can be called at any time during the simulation, but must be called outside of startRecording / stopRecording periods. The function will close the previous file stream (the one that was set in CARLsim::setSpikeMonitor), and from that moment on direct new incoming spikes into a new file. This allows a user to record spikes to different files during a simulation, for example to "training.dat" and "testing.dat". In order to stop recording to file, pass string "NULL".

Parameters
[in]logFileNamepath to binary file or "NULL" (for not recording to file at all)
Attention
Make sure the directory exists!
Since
v3.0

Definition at line 263 of file spike_monitor.cpp.

◆ setMode()

void setMode ( SpikeMonMode  mode = AER)

This function returns the current SpikeMonitor mode. COUNT: Will collect only spike count information (such as number of spikes per neuron), not the explicit spike times. COUNT mode cannot retrieve exact spike times per neuron, and is thus not capable of computing spike train correlation etc. AER: Will collect spike information in AER format (will collect both neuron IDs and spike times).

Definition at line 255 of file spike_monitor.cpp.

◆ setPersistentData()

void setPersistentData ( bool  persistentData)

This function sets PersistentMode either on (true) or off (false). If PersistentMode is off, only the last recording period will be considered for calculating metrics. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, but can be switched on at any point in time. The current state of PersistentMode can be retrieved by calling getPersistentData().

Definition at line 247 of file spike_monitor.cpp.

◆ startRecording()

void startRecording ( )

This function starts a new recording period. From that moment onward, the 2D spike vector will be populated with all the spikes of all the neurons in the group. Before any metrics can be computed, the user must call stopRecording(). Recording periods must be ended with stopRecording(). In general, a new recording period can be started at any point in time, and can last any number of milliseconds. If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Definition at line 201 of file spike_monitor.cpp.

◆ stopRecording()

void stopRecording ( )

This function ends a recording period, at which point the 2D spike vector will no longer be populated with spikes. In general, a recording period can be ended at any point in time, and last any number of milliseconds. From this moment onward, a variety of metrics can be computed, which are based on the spikes found in the 2D spike vector. It is also possible to retrieve the raw spike vector itself by calling getSpikeVector2D(). If PersistentMode is off, only the last recording period will be considered. If PersistentMode is on, all the recording periods will be considered. By default, PersistentMode is off, and can be switched on by calling setPersistentData(bool). The total time over which the metric is calculated can be retrieved by calling getRecordingTotalTime().

Definition at line 208 of file spike_monitor.cpp.


The documentation for this class was generated from the following files:
SpikeMonitor
Class SpikeMonitor.
Definition: spike_monitor.h:120
CARLsim::runNetwork
int runNetwork(int nSec, int nMsec=0, bool printRunSummary=true)
run the simulation for time=(nSec*seconds + nMsec*milliseconds)
Definition: carlsim.cpp:1910
SpikeMonitor::getAllFiringRates
std::vector< float > getAllFiringRates()
Returns the average firing rate of all the neurons in the group as a vector of floats.
Definition: spike_monitor.cpp:116
SpikeMonitor::print
void print(bool printSpikeTimes=true)
prints the 2D spike vector.
Definition: spike_monitor.cpp:194
SpikeMonitor::stopRecording
void stopRecording()
Ends a recording period.
Definition: spike_monitor.cpp:208
CARLsim::setupNetwork
void setupNetwork()
build the network
Definition: carlsim.cpp:1915
SpikeMonitor::startRecording
void startRecording()
Starts a new recording period.
Definition: spike_monitor.cpp:201
CARLsim::setSpikeMonitor
SpikeMonitor * setSpikeMonitor(int grpId, const std::string &fileName)
Sets a Spike Monitor for a groups, prints spikes to binary file.
Definition: carlsim.cpp:1973