CARLsim
4.1.0
CARLsim: a GPU-accelerated SNN simulator
|
Go to the documentation of this file.
61 monitorId_ = monitorId;
65 spkMonLastUpdated_ = 0;
68 persistentData_ =
false;
69 userHasBeenWarned_ =
false;
70 needToWriteFileHeader_ =
true;
71 spikeFileSignature_ = 206661989;
72 spikeFileVersion_ = 0.2f;
78 void SpikeMonitorCore::init() {
85 spkVector_.resize(nNeurons_);
97 if (spikeFileId_!=NULL) {
108 userHasBeenWarned_ =
false;
115 for (
int i=0; i<nNeurons_; i++)
116 spkVector_[i].
clear();
118 needToCalculateFiringRates_ =
true;
119 needToSortFiringRates_ =
true;
120 firingRates_.clear();
121 firingRatesSorted_.clear();
122 firingRates_.assign(nNeurons_,0);
123 firingRatesSorted_.assign(nNeurons_,0);
145 for (
int i=0; i<nNeurons_; i++)
146 std += (rates[i]-meanRate)*(rates[i]-meanRate);
147 std = sqrt(std/(nNeurons_-1));
157 for (
int i=0; i<nNeurons_; i++)
167 calculateFiringRates();
185 return rates.front();
190 assert(neurId>=0 && neurId<nNeurons_);
197 assert(neurId>=0 && neurId<nNeurons_);
200 return spkVector_[neurId].size();
209 return firingRatesSorted_;
214 assert(min>=0.0f && max>=0.0f);
221 std::vector<float>::const_iterator it_begin = firingRatesSorted_.begin();
222 std::vector<float>::const_iterator it_end = firingRatesSorted_.end();
223 for(std::vector<float>::const_iterator it=it_begin; it!=it_end; it++){
224 if((*it) >= min && (*it) <= max)
261 int dispSpkTimPerRow = 7;
263 KERNEL_INFO(
"(t=%.3fs) SpikeMonitor for group %s(%d) has %d spikes in %ld ms (%.2f +/- %.2f Hz)",
272 if (printSpikeTimes && mode_==
AER) {
274 KERNEL_INFO(
"| Neur ID | Rate (Hz) | Spike Times (ms)");
275 KERNEL_INFO(
"|- - - - -|- - - - - -|- - - - - - - - - - - - - - - - -- - - - - - - - - - - - -")
277 for (
int i=0; i<nNeurons_; i++) {
279 #if defined(WIN32) || defined(WIN64)
284 int nSpk = spkVector_[i].size();
285 for (
int j=0; j<nSpk; j++) {
287 #if defined(WIN32) || defined(WIN64)
288 _snprintf(times, 10,
"%8d", spkVector_[i][j]);
290 snprintf(times, 10,
"%8d", spkVector_[i][j]);
292 strcat(buffer, times);
293 if (j%dispSpkTimPerRow == dispSpkTimPerRow-1 && j<nSpk-1) {
295 strcpy(buffer,
"| | | ");
307 spkVector_[neurId].push_back(time);
313 if (!persistentData_) {
322 needToCalculateFiringRates_ =
true;
323 needToSortFiringRates_ =
true;
327 if (persistentData_) {
330 startTime_ = (startTime_<0) ? currentTime : startTime_;
331 startTimeLast_ = currentTime;
332 accumTime_ = (totalTime_>0) ? totalTime_ : 0;
336 startTime_ = currentTime;
337 startTimeLast_ = currentTime;
344 assert(startTime_>-1 && startTimeLast_>-1 && accumTime_>-1);
351 userHasBeenWarned_ =
false;
355 totalTime_ = stopTime_-startTimeLast_ + accumTime_;
356 assert(totalTime_>=0);
363 if (spikeFileId_!=NULL) {
364 fclose(spikeFileId_);
369 spikeFileId_=spikeFileId;
371 if (spikeFileId_==NULL)
372 needToWriteFileHeader_ =
false;
375 needToWriteFileHeader_ =
true;
376 writeSpikeFileHeader();
381 void SpikeMonitorCore::calculateFiringRates() {
383 if (!needToCalculateFiringRates_)
389 firingRates_.assign(nNeurons_,0);
390 firingRatesSorted_.assign(nNeurons_,0);
394 KERNEL_WARN(
"SpikeMonitorCore: calculateFiringRates has 0 totalTime");
399 assert(totalTime_>0);
400 for(
int i=0;i<nNeurons_;i++) {
401 firingRates_[i]=spkVector_[i].size()*1000.0/totalTime_;
404 needToCalculateFiringRates_ =
false;
408 void SpikeMonitorCore::sortFiringRates() {
410 if (!needToSortFiringRates_)
414 calculateFiringRates();
416 firingRatesSorted_=firingRates_;
417 std::sort(firingRatesSorted_.begin(),firingRatesSorted_.end());
419 needToSortFiringRates_ =
false;
424 void SpikeMonitorCore::writeSpikeFileHeader() {
425 if (!needToWriteFileHeader_)
429 if (!fwrite(&spikeFileSignature_,
sizeof(
int),1,spikeFileId_))
430 KERNEL_ERROR(
"SpikeMonitorCore: writeSpikeFileHeader has fwrite error");
433 if (!fwrite(&spikeFileVersion_,
sizeof(
float),1,spikeFileId_))
434 KERNEL_ERROR(
"SpikeMonitorCore: writeSpikeFileHeader has fwrite error");
438 int tmpInt = grid.
numX;
439 if (!fwrite(&tmpInt,
sizeof(
int),1,spikeFileId_))
440 KERNEL_ERROR(
"SpikeMonitorCore: writeSpikeFileHeader has fwrite error");
443 if (!fwrite(&tmpInt,
sizeof(
int),1,spikeFileId_))
444 KERNEL_ERROR(
"SpikeMonitorCore: writeSpikeFileHeader has fwrite error");
447 if (!fwrite(&tmpInt,
sizeof(
int),1,spikeFileId_))
448 KERNEL_ERROR(
"SpikeMonitorCore: writeSpikeFileHeader has fwrite error");
451 needToWriteFileHeader_ =
false;
458 long int bufferSize=0;
459 for(
int i=0; i<spkVector_.size();i++){
460 bufferSize+=spkVector_[i].size()*
sizeof(int);
468 if(userHasBeenWarned_)
473 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