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