CARLsim
5.0.0
CARLsim: a GPU-accelerated SNN simulator
|
Go to the documentation of this file.
62 monitorId_ = monitorId;
66 spkMonLastUpdated_ = 0;
69 persistentData_ =
false;
70 userHasBeenWarned_ =
false;
71 needToWriteFileHeader_ =
true;
72 spikeFileSignature_ = 206661989;
73 spikeFileVersion_ = 0.2f;
79 void SpikeMonitorCore::init() {
86 spkVector_.resize(nNeurons_);
98 if (spikeFileId_!=NULL) {
109 userHasBeenWarned_ =
false;
116 for (
int i=0; i<nNeurons_; i++)
117 spkVector_[i].
clear();
119 needToCalculateFiringRates_ =
true;
120 needToSortFiringRates_ =
true;
121 firingRates_.clear();
122 firingRatesSorted_.clear();
123 firingRates_.assign(nNeurons_,0);
124 firingRatesSorted_.assign(nNeurons_,0);
146 for (
int i=0; i<nNeurons_; i++)
147 std += (rates[i]-meanRate)*(rates[i]-meanRate);
148 std = sqrt(std/(nNeurons_-1));
158 for (
int i=0; i<nNeurons_; i++)
168 calculateFiringRates();
186 return rates.front();
191 assert(neurId>=0 && neurId<nNeurons_);
198 assert(neurId>=0 && neurId<nNeurons_);
201 return spkVector_[neurId].size();
210 return firingRatesSorted_;
215 assert(min>=0.0f && max>=0.0f);
222 std::vector<float>::const_iterator it_begin = firingRatesSorted_.begin();
223 std::vector<float>::const_iterator it_end = firingRatesSorted_.end();
224 for(std::vector<float>::const_iterator it=it_begin; it!=it_end; it++){
225 if((*it) >= min && (*it) <= max)
262 int dispSpkTimPerRow = 7;
264 KERNEL_INFO(
"(t=%.3fs) SpikeMonitor for group %s(%d) has %d spikes in %ld ms (%.2f +/- %.2f Hz)",
273 if (printSpikeTimes && mode_==
AER) {
275 KERNEL_INFO(
"| Neur ID | Rate (Hz) | Spike Times (ms)");
276 KERNEL_INFO(
"|- - - - -|- - - - - -|- - - - - - - - - - - - - - - - -- - - - - - - - - - - - -")
278 for (
int i=0; i<nNeurons_; i++) {
280 #if defined(WIN32) || defined(WIN64)
285 int nSpk = spkVector_[i].size();
286 for (
int j=0; j<nSpk; j++) {
288 #if defined(WIN32) || defined(WIN64)
289 _snprintf(times, 10,
"%8d", spkVector_[i][j]);
291 snprintf(times, 10,
"%8d", spkVector_[i][j]);
293 strcat(buffer, times);
294 if (j%dispSpkTimPerRow == dispSpkTimPerRow-1 && j<nSpk-1) {
296 strcpy(buffer,
"| | | ");
308 spkVector_[neurId].push_back(time);
314 if (!persistentData_) {
323 needToCalculateFiringRates_ =
true;
324 needToSortFiringRates_ =
true;
328 if (persistentData_) {
331 startTime_ = (startTime_<0) ? currentTime : startTime_;
332 startTimeLast_ = currentTime;
333 accumTime_ = (totalTime_>0) ? totalTime_ : 0;
337 startTime_ = currentTime;
338 startTimeLast_ = currentTime;
345 assert(startTime_>-1 && startTimeLast_>-1 && accumTime_>-1);
352 userHasBeenWarned_ =
false;
356 totalTime_ = stopTime_-startTimeLast_ + accumTime_;
357 assert(totalTime_>=0);
364 if (spikeFileId_!=NULL) {
365 fclose(spikeFileId_);
370 spikeFileId_=spikeFileId;
372 if (spikeFileId_==NULL)
373 needToWriteFileHeader_ =
false;
376 needToWriteFileHeader_ =
true;
377 writeSpikeFileHeader();
382 void SpikeMonitorCore::calculateFiringRates() {
384 if (!needToCalculateFiringRates_)
390 firingRates_.assign(nNeurons_,0);
391 firingRatesSorted_.assign(nNeurons_,0);
395 KERNEL_WARN(
"SpikeMonitorCore: calculateFiringRates has 0 totalTime");
400 assert(totalTime_>0);
401 for(
int i=0;i<nNeurons_;i++) {
402 firingRates_[i]=spkVector_[i].size()*1000.0/totalTime_;
405 needToCalculateFiringRates_ =
false;
409 void SpikeMonitorCore::sortFiringRates() {
411 if (!needToSortFiringRates_)
415 calculateFiringRates();
417 firingRatesSorted_=firingRates_;
418 std::sort(firingRatesSorted_.begin(),firingRatesSorted_.end());
420 needToSortFiringRates_ =
false;
425 void SpikeMonitorCore::writeSpikeFileHeader() {
426 if (!needToWriteFileHeader_)
430 if (!fwrite(&spikeFileSignature_,
sizeof(
int),1,spikeFileId_))
431 KERNEL_ERROR(
"SpikeMonitorCore: writeSpikeFileHeader has fwrite error");
434 if (!fwrite(&spikeFileVersion_,
sizeof(
float),1,spikeFileId_))
435 KERNEL_ERROR(
"SpikeMonitorCore: writeSpikeFileHeader has fwrite error");
439 int tmpInt = grid.
numX;
440 if (!fwrite(&tmpInt,
sizeof(
int),1,spikeFileId_))
441 KERNEL_ERROR(
"SpikeMonitorCore: writeSpikeFileHeader has fwrite error");
444 if (!fwrite(&tmpInt,
sizeof(
int),1,spikeFileId_))
445 KERNEL_ERROR(
"SpikeMonitorCore: writeSpikeFileHeader has fwrite error");
448 if (!fwrite(&tmpInt,
sizeof(
int),1,spikeFileId_))
449 KERNEL_ERROR(
"SpikeMonitorCore: writeSpikeFileHeader has fwrite error");
452 needToWriteFileHeader_ =
false;
459 long int bufferSize=0;
460 for(
int i=0; i<spkVector_.size();i++){
461 bufferSize+=spkVector_[i].size()*
sizeof(int);
469 if(userHasBeenWarned_)
474 userHasBeenWarned_=
true;
int getGroupNumNeurons(int gGrpId)
long int getAccumTime()
returns the total accumulated time
@ AER
mode in which spike information is collected in AER format
float getMinFiringRate()
returns the smallest recorded firing rate
~SpikeMonitorCore()
destructor, cleans up all the memory upon object deletion
void pushAER(int time, int neurId)
inserts a (time,neurId) tupel into the 2D spike vector
void print(bool printSpikeTimes)
prints the AER vector in human-readable format
bool isRecording()
returns recording status
int getPopNumSpikes()
returns the total number of recorded spikes in the group
#define KERNEL_WARN(formatc,...)
float getPopStdFiringRate()
computes the standard deviation of firing rates in the group
long int getBufferSize()
returns the approximate size of the spike vector in bytes
std::vector< float > getAllFiringRates()
returns a list of firing rates for all neurons in the group (sorted by neuron ID ascending)
float getPopMeanFiringRate()
returns the recorded mean firing rate of the group
void stopRecording()
stops recording AER data
long int getRecordingTotalTime()
returns the total recorded time in ms
SpikeMonitorCore(SNN *snn, int monitorId, int grpId)
constructor (called by CARLsim::setSpikeMonitor)
#define KERNEL_ERROR(formatc,...)
float getPercentSilentNeurons()
returns percentage of neurons that didn't spike during recording
#define KERNEL_INFO(formatc,...)
int getNumNeuronsWithFiringRate(float min, float max)
returns number of neurons whose firing rate was in [min,max] during recording
std::vector< float > getAllFiringRatesSorted()
returns a list of firing rates for all neurons in the group (sorted by firing rate ascending)
const FILE * getLogFpErr()
returns file pointer to error log
int getNumSilentNeurons()
returns number of neurons that didn't spike while recording
bool isBufferBig()
returns true if spike buffer is close to maxAllowedBufferSize
const FILE * getLogFpInf()
function writes population weights from gIDpre to gIDpost to file fname in binary.
A struct to arrange neurons on a 3D grid (a primitive cubic Bravais lattice with cubic side length 1)
void clear()
deletes data from the 2D spike vector
SpikeMonMode getMode()
returns recording mode
const FILE * getLogFpDeb()
returns file pointer to debug log
std::string getGroupName(int grpId)
int getNeuronNumSpikes(int neurId)
returns the number of recorded spikes of a specific neuron
void setSpikeFileId(FILE *spikeFileId)
sets pointer to spike file
Contains all of CARLsim's core functionality.
float getNeuronMeanFiringRate(int neurId)
returns the recorded mean firing rate for a specific neuron
#define MAX_SPIKE_MON_BUFFER_SIZE
std::vector< std::vector< int > > getSpikeVector2D()
returns the 2D AER vector
float getMaxFiringRate()
returns the largest recorded firing rate
Grid3D getGroupGrid3D(int grpId)
float getPercentNeuronsWithFiringRate(float min, float max)
returns percentage of neurons whose firing rate was in [min,max] during recording
void updateSpikeMonitor(int grpId=ALL)
copy required spikes from firing buffer to spike buffer
void startRecording()
starts recording AER data
const FILE * getLogFpLog()
returns file pointer to log file