61 monitorId_ = monitorId;
65 neuronMonLastUpdated_ = 0;
67 persistentData_ =
false;
68 userHasBeenWarned_ =
false;
69 needToWriteFileHeader_ =
true;
70 neuronFileSignature_ = 206661979;
71 neuronFileVersion_ = 0.1f;
77 void NeuronMonitorCore::init() {
82 vectorV_.resize(nNeurons_+1);
83 vectorU_.resize(nNeurons_+1);
84 vectorI_.resize(nNeurons_+1);
96 if (neuronFileId_!=NULL) {
97 fclose(neuronFileId_);
105 userHasBeenWarned_ =
false;
112 for (
int i=0; i<=nNeurons_; i++){
125 vectorV_[neurId].push_back(V);
126 vectorU_[neurId].push_back(U);
127 vectorI_[neurId].push_back(I);
130 const int n = vectorV_[neurId].size();
131 if (vectorV_[nNeurons_].size() < n) {
133 vectorV_[nNeurons_].push_back(V / nNeurons_);
134 vectorU_[nNeurons_].push_back(U / nNeurons_);
135 vectorI_[nNeurons_].push_back(I / nNeurons_);
139 vectorV_[nNeurons_][n-1] += V / nNeurons_;
140 vectorU_[nNeurons_][n-1] += U / nNeurons_;
141 vectorI_[nNeurons_][n-1] += I / nNeurons_;
148 if (!persistentData_) {
160 if (persistentData_) {
163 startTime_ = (startTime_<0) ? currentTime : startTime_;
164 startTimeLast_ = currentTime;
165 accumTime_ = (totalTime_>0) ? totalTime_ : 0;
169 startTime_ = currentTime;
170 startTimeLast_ = currentTime;
177 assert(startTime_>-1 && startTimeLast_>-1 && accumTime_>-1);
184 userHasBeenWarned_ =
false;
188 totalTime_ = stopTime_-startTimeLast_ + accumTime_;
189 assert(totalTime_>=0);
201 if (neuronFileId_!=NULL) {
202 fclose(neuronFileId_);
203 neuronFileId_ = NULL;
207 neuronFileId_=neuronFileId;
209 if (neuronFileId_==NULL)
210 needToWriteFileHeader_ =
false;
213 needToWriteFileHeader_ =
true;
220 if (!needToWriteFileHeader_)
224 if (!fwrite(&neuronFileSignature_,
sizeof(
int),1,neuronFileId_))
225 KERNEL_ERROR(
"NeuronMonitorCore: writeNeuronFileHeader has fwrite error");
228 if (!fwrite(&neuronFileVersion_,
sizeof(
float),1,neuronFileId_))
229 KERNEL_ERROR(
"NeuronMonitorCore: writeNeuronFileHeader has fwrite error");
233 int tmpInt = grid.
numX;
234 if (!fwrite(&tmpInt,
sizeof(
int),1,neuronFileId_))
235 KERNEL_ERROR(
"NeuronMonitorCore: writeNeuronFileHeader has fwrite error");
238 if (!fwrite(&tmpInt,
sizeof(
int),1,neuronFileId_))
239 KERNEL_ERROR(
"NeuronMonitorCore: writeNeuronFileHeader has fwrite error");
242 if (!fwrite(&tmpInt,
sizeof(
int),1,neuronFileId_))
243 KERNEL_ERROR(
"NeuronMonitorCore: writeNeuronFileHeader has fwrite error");
247 if (!fwrite(&max_neuron_mon_group_size,
sizeof(
int),1,neuronFileId_))
248 KERNEL_ERROR(
"NeuronMonitorCore: writeNeuronFileHeader has fwrite error");
250 needToWriteFileHeader_ =
false;
254 long int bufferSize=0;
255 for(
int i=0; i<vectorV_.size();i++){
256 bufferSize+=vectorV_[i].size()*
sizeof(int);
258 return 3 * bufferSize;
264 if(userHasBeenWarned_)
269 userHasBeenWarned_=
true;
297 int dispVoltsPerRow = 7;
301 KERNEL_INFO(
"|- - - - -|- - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - -")
303 for (
int i=meanOnly?nNeurons_:0; i<=nNeurons_; i++) {
306 #if defined(WIN32) || defined(WIN64) 307 _snprintf(buffer, 100,
"| %7d | ", i);
309 snprintf(buffer, 100,
"| %7d | ", i);
313 #if defined(WIN32) || defined(WIN64) 314 _snprintf(buffer, 100,
"| %7s | ",
"mean");
316 snprintf(buffer, 100,
"| %7s | ",
"mean");
319 int nV = vectorV_[i].size();
320 for (
int j=0; j<nV; j++) {
322 #if defined(WIN32) || defined(WIN64) 323 _snprintf(volts, 10,
"%4.4f ", vectorV_[i][j]);
325 snprintf(volts, 10,
"%4.4f ", vectorV_[i][j]);
327 strcat(buffer, volts);
328 if (j%dispVoltsPerRow == dispVoltsPerRow-1 && j<nV-1) {
330 strcpy(buffer,
"| |");
void pushNeuronState(int neurId, float V, float U, float I)
inserts a (time,neurId) tupel into the D Neuron State vector
#define MAX_NEURON_MON_BUFFER_SIZE
~NeuronMonitorCore()
destructor, cleans up all the memory upon object deletion
bool isRecording()
returns recording status
NeuronMonitorCore(SNN *snn, int monitorId, int grpId)
constructor (called by CARLsim::setNeuronMonitor)
void print(bool meanOnly)
prints neuron states in human-readable format
#define MAX_NEURON_MON_GRP_SZIE
#define KERNEL_ERROR(formatc,...)
long int getBufferSize()
returns the approximate size of the state vectors in bytes
void writeNeuronFileHeader()
void updateNeuronMonitor(int grpId=ALL)
copy required neuron state values from ??? buffer to ??? buffer
std::vector< std::vector< float > > getVectorV()
returns the Neuron state vector
Grid3D getGroupGrid3D(int grpId)
#define KERNEL_INFO(formatc,...)
A struct to arrange neurons on a 3D grid (a primitive cubic Bravais lattice with cubic side length 1)...
void stopRecording()
stops recording Neuron state
const FILE * getLogFpLog()
returns file pointer to log file
std::vector< std::vector< float > > getVectorU()
std::vector< std::vector< float > > getVectorI()
void setNeuronFileId(FILE *neuronFileId)
sets pointer to Neuron file
void clear()
deletes data from the neuron state vector
const FILE * getLogFpErr()
returns file pointer to error log
Contains all of CARLsim's core functionality.
void startRecording()
starts recording Neuron state
bool isBufferBig()
returns true if state buffers are close to maxAllowedBufferSize
const FILE * getLogFpDeb()
returns file pointer to debug log
int getGroupNumNeurons(int gGrpId)
long int getAccumTime()
returns the total accumulated time
const FILE * getLogFpInf()
function writes population weights from gIDpre to gIDpost to file fname in binary.