CARLsim  4.1.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 *
45 * CARLsim available from http://socsci.uci.edu/~jkrichma/CARLsim/
46 * Ver 12/31/2016
47 */
48 
49 #ifndef _SPIKE_MON_CORE_H_
50 #define _SPIKE_MON_CORE_H_
51 
52 #include <carlsim_datastructures.h> // SpikeMonMode
53 #include <stdio.h> // FILE
54 #include <vector> // std::vector
55 
56 class SNN; // forward declaration of SNN class
57 
58 
59 /*
60  * \brief SpikeMonitor private core implementation
61  *
62  * Naming convention for methods:
63  * - getPop*: a population metric (single value) that applies to the entire group; e.g., getPopMeanFiringRate.
64  * - getNeuron*: a neuron metric (single value), about a specific neuron (requires neurId); e.g., getNeuronNumSpikes.
65  * - getAll*: a metric (vector) that is based on all neurons in the group; e.g. getAllFiringRates.
66  * - getNum*: a number metric, returns an int
67  * - getPercent*: a percentage metric, returns a float
68  * - get*: all the others
69  */
71 public:
73  SpikeMonitorCore(SNN* snn, int monitorId, int grpId);
74 
77 
78 
79  // +++++ PUBLIC METHODS: +++++++++++++++++++++++++++++++++++++++++++++++//
80 
82  std::vector<float> getAllFiringRates();
83 
85  std::vector<float> getAllFiringRatesSorted();
86 
88  int getGrpId() { return grpId_; }
89 
91  int getGrpNumNeurons() { return nNeurons_; }
92 
94  float getMaxFiringRate();
95 
97  float getMinFiringRate();
98 
100  SpikeMonMode getMode() { return mode_; }
101 
103  int getMonitorId() { return monitorId_; }
104 
106  float getNeuronMeanFiringRate(int neurId);
107 
109  int getNeuronNumSpikes(int neurId);
110 
112  int getNumNeuronsWithFiringRate(float min, float max);
113 
115  int getNumSilentNeurons();
116 
118  float getPercentNeuronsWithFiringRate(float min, float max);
119 
121  float getPercentSilentNeurons();
122 
124  bool getPersistentData() { return persistentData_; }
125 
127  float getPopMeanFiringRate();
128 
130  int getPopNumSpikes();
131 
133  float getPopStdFiringRate();
134 
136  long int getRecordingTotalTime() { return totalTime_; }
137 
139  long int getRecordingStartTime() { return startTime_; }
140 
142  long int getRecordingLastStartTime() { return startTimeLast_; }
143 
145  long int getRecordingStopTime() { return stopTime_; }
146 
148  std::vector<std::vector<int> > getSpikeVector2D();
149 
151  bool isRecording() { return recordSet_; }
152 
154  void print(bool printSpikeTimes);
155 
157  void pushAER(int time, int neurId);
158 
160  void setMode(SpikeMonMode mode) { mode_ = mode; }
161 
163  void setPersistentData(bool persistentData) { persistentData_ = persistentData; }
164 
166  void startRecording();
167 
169  void stopRecording();
170 
171 
172  // +++++ PUBLIC METHODS THAT SHOULD NOT BE EXPOSED TO INTERFACE +++++++++//
173 
175  void clear();
176 
178  FILE* getSpikeFileId() { return spikeFileId_; }
179 
181  void setSpikeFileId(FILE* spikeFileId);
182 
184  long int getLastUpdated() { return spkMonLastUpdated_; }
185 
187  void setLastUpdated(long int lastUpdate) { spkMonLastUpdated_ = lastUpdate; }
188 
190  bool isBufferBig();
191 
193  long int getBufferSize();
194 
196  long int getAccumTime();
197 
198 private:
200  void init();
201 
203  void calculateFiringRates();
204 
206  void sortFiringRates();
207 
209  void writeSpikeFileHeader();
210 
212  bool needToCalculateFiringRates_;
213 
215  bool needToSortFiringRates_;
216 
218  bool needToWriteFileHeader_;
219 
220  SNN* snn_;
221  int monitorId_;
222  int grpId_;
223  int nNeurons_;
224 
225  FILE* spikeFileId_;
226  int spikeFileSignature_;
227  float spikeFileVersion_;
228 
230  std::vector<std::vector<int> > spkVector_;
231 
232  std::vector<float> firingRates_;
233  std::vector<float> firingRatesSorted_;
234 
235  bool recordSet_;
236  long int startTime_;
237  long int startTimeLast_;
238  long int stopTime_;
239  long int totalTime_;
240  long int accumTime_;
241 
242  long int spkMonLastUpdated_;
243 
245  bool persistentData_;
246 
248  bool userHasBeenWarned_;
249  SpikeMonMode mode_;
250 
251  // file pointers for error logging
252  const FILE* fpInf_;
253  const FILE* fpErr_;
254  const FILE* fpDeb_;
255  const FILE* fpLog_;
256 };
257 
258 
259 #endif
SpikeMonitorCore::getAccumTime
long int getAccumTime()
returns the total accumulated time
Definition: spike_monitor_core.cpp:483
SpikeMonitorCore
Definition: spike_monitor_core.h:70
SpikeMonitorCore::getRecordingLastStartTime
long int getRecordingLastStartTime()
returns the timestamp of the last startRecording in ms
Definition: spike_monitor_core.h:142
SpikeMonitorCore::getRecordingStartTime
long int getRecordingStartTime()
retunrs the timestamp of the first startRecording in ms
Definition: spike_monitor_core.h:139
carlsim_datastructures.h
SpikeMonitorCore::getMinFiringRate
float getMinFiringRate()
returns the smallest recorded firing rate
Definition: spike_monitor_core.cpp:180
SpikeMonitorCore::~SpikeMonitorCore
~SpikeMonitorCore()
destructor, cleans up all the memory upon object deletion
Definition: spike_monitor_core.cpp:96
SpikeMonitorCore::pushAER
void pushAER(int time, int neurId)
inserts a (time,neurId) tupel into the 2D spike vector
Definition: spike_monitor_core.cpp:303
SpikeMonitorCore::print
void print(bool printSpikeTimes)
prints the AER vector in human-readable format
Definition: spike_monitor_core.cpp:257
SpikeMonitorCore::isRecording
bool isRecording()
returns recording status
Definition: spike_monitor_core.h:151
SpikeMonitorCore::getPopNumSpikes
int getPopNumSpikes()
returns the total number of recorded spikes in the group
Definition: spike_monitor_core.cpp:153
SpikeMonitorCore::getPersistentData
bool getPersistentData()
returns status of PersistentData mode
Definition: spike_monitor_core.h:124
SpikeMonitorCore::getPopStdFiringRate
float getPopStdFiringRate()
computes the standard deviation of firing rates in the group
Definition: spike_monitor_core.cpp:135
SpikeMonitorCore::setMode
void setMode(SpikeMonMode mode)
sets recording mode
Definition: spike_monitor_core.h:160
SpikeMonitorCore::getBufferSize
long int getBufferSize()
returns the approximate size of the spike vector in bytes
Definition: spike_monitor_core.cpp:457
SpikeMonitorCore::getGrpNumNeurons
int getGrpNumNeurons()
returns number of neurons in the group
Definition: spike_monitor_core.h:91
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:163
SpikeMonitorCore::getPopMeanFiringRate
float getPopMeanFiringRate()
returns the recorded mean firing rate of the group
Definition: spike_monitor_core.cpp:126
SpikeMonitorCore::getRecordingStopTime
long int getRecordingStopTime()
returns the timestamp of stopRecording
Definition: spike_monitor_core.h:145
SpikeMonitorCore::stopRecording
void stopRecording()
stops recording AER data
Definition: spike_monitor_core.cpp:342
SpikeMonitorCore::getRecordingTotalTime
long int getRecordingTotalTime()
returns the total recorded time in ms
Definition: spike_monitor_core.h:136
SpikeMonitorCore::SpikeMonitorCore
SpikeMonitorCore(SNN *snn, int monitorId, int grpId)
constructor (called by CARLsim::setSpikeMonitor)
Definition: spike_monitor_core.cpp:58
SpikeMonitorCore::getPercentSilentNeurons
float getPercentSilentNeurons()
returns percentage of neurons that didn't spike during recording
Definition: spike_monitor_core.cpp:244
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:212
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:203
SpikeMonitorCore::getNumSilentNeurons
int getNumSilentNeurons()
returns number of neurons that didn't spike while recording
Definition: spike_monitor_core.cpp:231
SpikeMonMode
SpikeMonMode
SpikeMonitor mode.
Definition: carlsim_datastructures.h:200
SpikeMonitorCore::setLastUpdated
void setLastUpdated(long int lastUpdate)
sets timestamp of last SpikeMonitor update
Definition: spike_monitor_core.h:187
SpikeMonitorCore::getSpikeFileId
FILE * getSpikeFileId()
returns a pointer to the spike file
Definition: spike_monitor_core.h:178
SpikeMonitorCore::isBufferBig
bool isBufferBig()
returns true if spike buffer is close to maxAllowedBufferSize
Definition: spike_monitor_core.cpp:467
SpikeMonitorCore::clear
void clear()
deletes data from the 2D spike vector
Definition: spike_monitor_core.cpp:105
SpikeMonitorCore::getMode
SpikeMonMode getMode()
returns recording mode
Definition: spike_monitor_core.h:100
SpikeMonitorCore::getGrpId
int getGrpId()
returns the group ID
Definition: spike_monitor_core.h:88
SpikeMonitorCore::getNeuronNumSpikes
int getNeuronNumSpikes(int neurId)
returns the number of recorded spikes of a specific neuron
Definition: spike_monitor_core.cpp:195
SpikeMonitorCore::setSpikeFileId
void setSpikeFileId(FILE *spikeFileId)
sets pointer to spike file
Definition: spike_monitor_core.cpp:359
SNN
Contains all of CARLsim's core functionality.
Definition: snn.h:114
SpikeMonitorCore::getNeuronMeanFiringRate
float getNeuronMeanFiringRate(int neurId)
returns the recorded mean firing rate for a specific neuron
Definition: spike_monitor_core.cpp:188
SpikeMonitorCore::getSpikeVector2D
std::vector< std::vector< int > > getSpikeVector2D()
returns the 2D AER vector
Definition: spike_monitor_core.cpp:250
SpikeMonitorCore::getLastUpdated
long int getLastUpdated()
returns timestamp of last SpikeMonitor update
Definition: spike_monitor_core.h:184
SpikeMonitorCore::getMonitorId
int getMonitorId()
returns the SpikeMonitor ID
Definition: spike_monitor_core.h:103
SpikeMonitorCore::getMaxFiringRate
float getMaxFiringRate()
returns the largest recorded firing rate
Definition: spike_monitor_core.cpp:172
SpikeMonitorCore::setPersistentData
void setPersistentData(bool persistentData)
sets status of PersistentData mode
Definition: spike_monitor_core.h:163
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:238
SpikeMonitorCore::startRecording
void startRecording()
starts recording AER data
Definition: spike_monitor_core.cpp:310