CARLsim  5.0.0
CARLsim: a GPU-accelerated SNN simulator
spike_monitor_core.h
Go to the documentation of this file.
1 /* * Copyright (c) 2016 Regents of the University of California. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions
5 * are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * 3. The names of its contributors may not be used to endorse or promote
15 * products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * *********************************************************************************************** *
31 * CARLsim
32 * created by: (MDR) Micah Richert, (JN) Jayram M. Nageswaran
33 * maintained by:
34 * (MA) Mike Avery <averym@uci.edu>
35 * (MB) Michael Beyeler <mbeyeler@uci.edu>,
36 * (KDC) Kristofor Carlson <kdcarlso@uci.edu>
37 * (TSC) Ting-Shuo Chou <tingshuc@uci.edu>
38 * (HK) Hirak J Kashyap <kashyaph@uci.edu>
39 *
40 * CARLsim v1.0: JM, MDR
41 * CARLsim v2.0/v2.1/v2.2: JM, MDR, MA, MB, KDC
42 * CARLsim3: MB, KDC, TSC
43 * CARLsim4: TSC, HK
44 * CARLsim5: HK, JX, KC
45 *
46 * CARLsim available from http://socsci.uci.edu/~jkrichma/CARLsim/
47 * Ver 12/31/2016
48 */
49 
50 #ifndef _SPIKE_MON_CORE_H_
51 #define _SPIKE_MON_CORE_H_
52 
53 #include <carlsim_datastructures.h> // SpikeMonMode
54 #include <stdio.h> // FILE
55 #include <vector> // std::vector
56 
57 class SNN; // forward declaration of SNN class
58 
59 
60 /*
61  * \brief SpikeMonitor private core implementation
62  *
63  * Naming convention for methods:
64  * - getPop*: a population metric (single value) that applies to the entire group; e.g., getPopMeanFiringRate.
65  * - getNeuron*: a neuron metric (single value), about a specific neuron (requires neurId); e.g., getNeuronNumSpikes.
66  * - getAll*: a metric (vector) that is based on all neurons in the group; e.g. getAllFiringRates.
67  * - getNum*: a number metric, returns an int
68  * - getPercent*: a percentage metric, returns a float
69  * - get*: all the others
70  */
72 public:
74  SpikeMonitorCore(SNN* snn, int monitorId, int grpId);
75 
78 
79 
80  // +++++ PUBLIC METHODS: +++++++++++++++++++++++++++++++++++++++++++++++//
81 
83  std::vector<float> getAllFiringRates();
84 
86  std::vector<float> getAllFiringRatesSorted();
87 
89  int getGrpId() { return grpId_; }
90 
92  int getGrpNumNeurons() { return nNeurons_; }
93 
95  float getMaxFiringRate();
96 
98  float getMinFiringRate();
99 
101  SpikeMonMode getMode() { return mode_; }
102 
104  int getMonitorId() { return monitorId_; }
105 
107  float getNeuronMeanFiringRate(int neurId);
108 
110  int getNeuronNumSpikes(int neurId);
111 
113  int getNumNeuronsWithFiringRate(float min, float max);
114 
116  int getNumSilentNeurons();
117 
119  float getPercentNeuronsWithFiringRate(float min, float max);
120 
122  float getPercentSilentNeurons();
123 
125  bool getPersistentData() { return persistentData_; }
126 
128  float getPopMeanFiringRate();
129 
131  int getPopNumSpikes();
132 
134  float getPopStdFiringRate();
135 
137  long int getRecordingTotalTime() { return totalTime_; }
138 
140  long int getRecordingStartTime() { return startTime_; }
141 
143  long int getRecordingLastStartTime() { return startTimeLast_; }
144 
146  long int getRecordingStopTime() { return stopTime_; }
147 
149  std::vector<std::vector<int> > getSpikeVector2D();
150 
152  bool isRecording() { return recordSet_; }
153 
155  void print(bool printSpikeTimes);
156 
158  void pushAER(int time, int neurId);
159 
161  void setMode(SpikeMonMode mode) { mode_ = mode; }
162 
164  void setPersistentData(bool persistentData) { persistentData_ = persistentData; }
165 
167  void startRecording();
168 
170  void stopRecording();
171 
172 
173  // +++++ PUBLIC METHODS THAT SHOULD NOT BE EXPOSED TO INTERFACE +++++++++//
174 
176  void clear();
177 
179  FILE* getSpikeFileId() { return spikeFileId_; }
180 
182  void setSpikeFileId(FILE* spikeFileId);
183 
185  long int getLastUpdated() { return spkMonLastUpdated_; }
186 
188  void setLastUpdated(long int lastUpdate) { spkMonLastUpdated_ = lastUpdate; }
189 
191  bool isBufferBig();
192 
194  long int getBufferSize();
195 
197  long int getAccumTime();
198 
199 private:
201  void init();
202 
204  void calculateFiringRates();
205 
207  void sortFiringRates();
208 
210  void writeSpikeFileHeader();
211 
213  bool needToCalculateFiringRates_;
214 
216  bool needToSortFiringRates_;
217 
219  bool needToWriteFileHeader_;
220 
221  SNN* snn_;
222  int monitorId_;
223  int grpId_;
224  int nNeurons_;
225 
226  FILE* spikeFileId_;
227  int spikeFileSignature_;
228  float spikeFileVersion_;
229 
231  std::vector<std::vector<int> > spkVector_;
232 
233  std::vector<float> firingRates_;
234  std::vector<float> firingRatesSorted_;
235 
236  bool recordSet_;
237  long int startTime_;
238  long int startTimeLast_;
239  long int stopTime_;
240  long int totalTime_;
241  long int accumTime_;
242 
243  long int spkMonLastUpdated_;
244 
246  bool persistentData_;
247 
249  bool userHasBeenWarned_;
250  SpikeMonMode mode_;
251 
252  // file pointers for error logging
253  const FILE* fpInf_;
254  const FILE* fpErr_;
255  const FILE* fpDeb_;
256  const FILE* fpLog_;
257 };
258 
259 
260 #endif
SpikeMonitorCore::getAccumTime
long int getAccumTime()
returns the total accumulated time
Definition: spike_monitor_core.cpp:484
SpikeMonitorCore
Definition: spike_monitor_core.h:71
SpikeMonitorCore::getRecordingLastStartTime
long int getRecordingLastStartTime()
returns the timestamp of the last startRecording in ms
Definition: spike_monitor_core.h:143
SpikeMonitorCore::getRecordingStartTime
long int getRecordingStartTime()
retunrs the timestamp of the first startRecording in ms
Definition: spike_monitor_core.h:140
carlsim_datastructures.h
SpikeMonitorCore::getMinFiringRate
float getMinFiringRate()
returns the smallest recorded firing rate
Definition: spike_monitor_core.cpp:181
SpikeMonitorCore::~SpikeMonitorCore
~SpikeMonitorCore()
destructor, cleans up all the memory upon object deletion
Definition: spike_monitor_core.cpp:97
SpikeMonitorCore::pushAER
void pushAER(int time, int neurId)
inserts a (time,neurId) tupel into the 2D spike vector
Definition: spike_monitor_core.cpp:304
SpikeMonitorCore::print
void print(bool printSpikeTimes)
prints the AER vector in human-readable format
Definition: spike_monitor_core.cpp:258
SpikeMonitorCore::isRecording
bool isRecording()
returns recording status
Definition: spike_monitor_core.h:152
SpikeMonitorCore::getPopNumSpikes
int getPopNumSpikes()
returns the total number of recorded spikes in the group
Definition: spike_monitor_core.cpp:154
SpikeMonitorCore::getPersistentData
bool getPersistentData()
returns status of PersistentData mode
Definition: spike_monitor_core.h:125
SpikeMonitorCore::getPopStdFiringRate
float getPopStdFiringRate()
computes the standard deviation of firing rates in the group
Definition: spike_monitor_core.cpp:136
SpikeMonitorCore::setMode
void setMode(SpikeMonMode mode)
sets recording mode
Definition: spike_monitor_core.h:161
SpikeMonitorCore::getBufferSize
long int getBufferSize()
returns the approximate size of the spike vector in bytes
Definition: spike_monitor_core.cpp:458
SpikeMonitorCore::getGrpNumNeurons
int getGrpNumNeurons()
returns number of neurons in the group
Definition: spike_monitor_core.h:92
SpikeMonitorCore::getAllFiringRates
std::vector< float > getAllFiringRates()
returns a list of firing rates for all neurons in the group (sorted by neuron ID ascending)
Definition: spike_monitor_core.cpp:164
SpikeMonitorCore::getPopMeanFiringRate
float getPopMeanFiringRate()
returns the recorded mean firing rate of the group
Definition: spike_monitor_core.cpp:127
SpikeMonitorCore::getRecordingStopTime
long int getRecordingStopTime()
returns the timestamp of stopRecording
Definition: spike_monitor_core.h:146
SpikeMonitorCore::stopRecording
void stopRecording()
stops recording AER data
Definition: spike_monitor_core.cpp:343
SpikeMonitorCore::getRecordingTotalTime
long int getRecordingTotalTime()
returns the total recorded time in ms
Definition: spike_monitor_core.h:137
SpikeMonitorCore::SpikeMonitorCore
SpikeMonitorCore(SNN *snn, int monitorId, int grpId)
constructor (called by CARLsim::setSpikeMonitor)
Definition: spike_monitor_core.cpp:59
SpikeMonitorCore::getPercentSilentNeurons
float getPercentSilentNeurons()
returns percentage of neurons that didn't spike during recording
Definition: spike_monitor_core.cpp:245
SpikeMonitorCore::getNumNeuronsWithFiringRate
int getNumNeuronsWithFiringRate(float min, float max)
returns number of neurons whose firing rate was in [min,max] during recording
Definition: spike_monitor_core.cpp:213
SpikeMonitorCore::getAllFiringRatesSorted
std::vector< float > getAllFiringRatesSorted()
returns a list of firing rates for all neurons in the group (sorted by firing rate ascending)
Definition: spike_monitor_core.cpp:204
SpikeMonitorCore::getNumSilentNeurons
int getNumSilentNeurons()
returns number of neurons that didn't spike while recording
Definition: spike_monitor_core.cpp:232
SpikeMonMode
SpikeMonMode
SpikeMonitor mode.
Definition: carlsim_datastructures.h:201
SpikeMonitorCore::setLastUpdated
void setLastUpdated(long int lastUpdate)
sets timestamp of last SpikeMonitor update
Definition: spike_monitor_core.h:188
SpikeMonitorCore::getSpikeFileId
FILE * getSpikeFileId()
returns a pointer to the spike file
Definition: spike_monitor_core.h:179
SpikeMonitorCore::isBufferBig
bool isBufferBig()
returns true if spike buffer is close to maxAllowedBufferSize
Definition: spike_monitor_core.cpp:468
SpikeMonitorCore::clear
void clear()
deletes data from the 2D spike vector
Definition: spike_monitor_core.cpp:106
SpikeMonitorCore::getMode
SpikeMonMode getMode()
returns recording mode
Definition: spike_monitor_core.h:101
SpikeMonitorCore::getGrpId
int getGrpId()
returns the group ID
Definition: spike_monitor_core.h:89
SpikeMonitorCore::getNeuronNumSpikes
int getNeuronNumSpikes(int neurId)
returns the number of recorded spikes of a specific neuron
Definition: spike_monitor_core.cpp:196
SpikeMonitorCore::setSpikeFileId
void setSpikeFileId(FILE *spikeFileId)
sets pointer to spike file
Definition: spike_monitor_core.cpp:360
SNN
Contains all of CARLsim's core functionality.
Definition: snn.h:115
SpikeMonitorCore::getNeuronMeanFiringRate
float getNeuronMeanFiringRate(int neurId)
returns the recorded mean firing rate for a specific neuron
Definition: spike_monitor_core.cpp:189
SpikeMonitorCore::getSpikeVector2D
std::vector< std::vector< int > > getSpikeVector2D()
returns the 2D AER vector
Definition: spike_monitor_core.cpp:251
SpikeMonitorCore::getLastUpdated
long int getLastUpdated()
returns timestamp of last SpikeMonitor update
Definition: spike_monitor_core.h:185
SpikeMonitorCore::getMonitorId
int getMonitorId()
returns the SpikeMonitor ID
Definition: spike_monitor_core.h:104
SpikeMonitorCore::getMaxFiringRate
float getMaxFiringRate()
returns the largest recorded firing rate
Definition: spike_monitor_core.cpp:173
SpikeMonitorCore::setPersistentData
void setPersistentData(bool persistentData)
sets status of PersistentData mode
Definition: spike_monitor_core.h:164
SpikeMonitorCore::getPercentNeuronsWithFiringRate
float getPercentNeuronsWithFiringRate(float min, float max)
returns percentage of neurons whose firing rate was in [min,max] during recording
Definition: spike_monitor_core.cpp:239
SpikeMonitorCore::startRecording
void startRecording()
starts recording AER data
Definition: spike_monitor_core.cpp:311