NEST main@caf0ae8
 
Loading...
Searching...
No Matches
correlomatrix_detector.h
Go to the documentation of this file.
1/*
2 * correlomatrix_detector.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef CORRELOMATRIX_DETECTOR_H
24#define CORRELOMATRIX_DETECTOR_H
25
26
27// C++ includes:
28#include <deque>
29#include <vector>
30
31// Includes from nestkernel:
32#include "event.h"
33#include "nest_timeconverter.h"
34#include "nest_types.h"
35#include "node.h"
37
38
39namespace nest
40{
41
42/* BeginUserDocs: device, detector
43
44Short description
45+++++++++++++++++
46
47Device for measuring the covariance matrix from several inputs
48
49Description
50+++++++++++
51
52The ``correlomatrix_detector`` is a device that receives spikes from several pools
53of spike inputs and calculates the covariance matrix of inter-spike intervals
54(raw auto and cross correlation) binned to bins of duration ``delta_tau``, which
55defaults to 5 times the simulation resolution. The histogram is only recorded for
56non-negative time lags. The negative part can be obtained by the symmetry of
57the covariance matrix :math:` C(t) = C^T(-t)`.
58
59The result can be obtained from the node's status dictionary under the key
60``count_covariance``.
61
62In parallel it records a weighted histogram, where the connection weight are
63used to weight every count, which is available under the key ``/covariance``.
64Both are matrices of size ``N_channels x N_channels``, with each entry :math:`C_{ij}` being
65a vector of size :math:`\tau_{max}/\delta_\tau + 1` containing the (weighted) histogram
66for non-negative time lags.
67
68The bins are centered around the time difference they represent, and are
69left-closed and right-open in the lower triangular part of the matrix. On the
70diagonal and in the upper triangular part the intervals are left-open and
71right-closed. This ensures proper counting of events at the border of bins,
72allowing consistent integration of a histogram over negative and positive
73time lags by stacking two parts of the histogram
74
75.. math::
76
77 (C(t)=[C[i][j][::-1],C[j][i][1:]]).
78
79In this case one needs to exclude :math:`C[j][i][0]` to avoid counting the zero-lag
80bin twice.
81
82The ``correlomatrix_detector`` has a variable number of inputs which can be set
83via ``SetStatus`` under the key ``N_channels``. All incoming connections to a
84specified receptor will be pooled.
85
86Correlomatrix detectors ignore any connection delays.
87
88Parameters
89++++++++++
90
91================ ========= ====================================================
92Tstart real Time when to start counting events. This time should
93 be set to at least start + tau_max in order to avoid
94 edge effects of the correlation counts.
95Tstop real Time when to stop counting events. This time should
96 be set to at most Tsim - tau_max, where Tsim is the
97 duration of simulation, in order to avoid edge
98 effects of the correlation counts.
99delta_tau ms Bin width. This has to be an odd multiple of
100 the resolution, to allow the symmetry between
101 positive and negative time-lags. Defaults to 5 times
102 the simulation resolution.
103tau_max ms One-sided width. In the lower triagnular part
104 events with differences in [0, tau_max+delta_tau/2)
105 are counted. On the diagonal and in the upper
106 triangular part events with differences in
107 (0, tau_max+delta_tau/2]. Defaults to 10 times the
108 value of delta_tau.
109N_channels integer The number of pools. This defines the range of
110 receptor_type. Default is 1.
111 Setting N_channels clears count_covariance,
112 covariance and n_events.
113covariance 3D matrix of read-only -raw, weighted, auto/cross
114 matrix of correlation
115 integers
116count_covariance 3D matrix of read-only -raw, auto/cross correlation
117 matrix of counts
118 integers
119n_events list of number of events from all sources
120 integers
121================ ========= ====================================================
122
123Receives
124++++++++
125
126SpikeEvent
127
128See also
129++++++++
130
131correlation_detector, spike_recorder
132
133Examples using this model
134+++++++++++++++++++++++++
135
136.. listexamples:: correlomatrix_detector
137
138EndUserDocs */
139
155void register_correlomatrix_detector( const std::string& name );
156
158{
159
160public:
163
168 bool
169 has_proxies() const override
170 {
171 return true;
172 }
173
174 std::string
175 get_element_type() const override
176 {
177 return names::recorder;
178 }
179
185 using Node::handle;
187
188 void handle( SpikeEvent& ) override;
189
190 size_t handles_test_event( SpikeEvent&, size_t ) override;
191
192 void get_status( Dictionary& ) const override;
193 void set_status( const Dictionary& ) override;
194
195 void calibrate_time( const TimeConverter& tc ) override;
196
197private:
198 void init_state_() override;
199 void init_buffers_() override;
200 void pre_run_hook() override;
201
202 void update( Time const&, const long, const long ) override;
203
204 // ------------------------------------------------------------
205
210 struct Spike_
211 {
213 double weight_;
215
216 Spike_( long timestep, double weight, long receptorchannel )
217 : timestep_( timestep )
218 , weight_( weight )
219 , receptor_channel_( receptorchannel )
220 {
221 }
222
226 inline bool
227 operator>( const Spike_& second ) const
228 {
229 return timestep_ > second.timestep_;
230 }
231 };
232
233 typedef std::deque< Spike_ > SpikelistType;
234
235 // ------------------------------------------------------------
236
237 struct State_;
238
240 {
245 size_t N_channels_;
246
247 Parameters_();
248 Parameters_( const Parameters_& );
249
251
252 void get( Dictionary& ) const;
253
259 bool set( const Dictionary&, const correlomatrix_detector&, Node* node );
260
262 };
263
264 // ------------------------------------------------------------
265
275 struct State_
276 {
277 std::vector< long > n_events_;
282 std::vector< std::vector< std::vector< double > > > covariance_;
283
286 std::vector< std::vector< std::vector< long > > > count_covariance_;
287
288 State_();
289
290 void get( Dictionary& ) const;
291
295 void set( const Dictionary&, const Parameters_&, bool, Node* node );
296
297 void reset( const Parameters_& );
298 };
299
300 // ------------------------------------------------------------
301
305};
306
307inline size_t
309{
310 if ( receptor_type > P_.N_channels_ - 1 )
311 {
312 throw UnknownReceptorType( receptor_type, get_name() );
313 }
314 return receptor_type;
315}
316
317inline void
319{
320 device_.get_status( d );
321 P_.get( d );
322 S_.get( d );
323}
324
325inline void
327{
328 Parameters_ ptmp = P_;
329 const bool reset_required = ptmp.set( d, *this, this );
330
331 device_.set_status( d );
332 P_ = ptmp;
333 if ( reset_required )
334 {
335 S_.reset( P_ );
336 }
337}
338
339inline Time
344
345} // namespace
346
347#endif /* #ifndef CORRELOMATRIX_DETECTOR_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
virtual void get_status(Dictionary &) const
Definition device.h:179
virtual void set_status(const Dictionary &)
Definition device.h:185
Base class for all NEST network objects.
Definition node.h:99
std::string get_name() const
Return class name.
Definition node.cpp:105
Common properties of all pseudo-recording devices.
Definition pseudo_recording_device.h:72
Event for spike information.
Definition event.h:418
Class to convert times from one representation to another.
Definition nest_timeconverter.h:42
Definition nest_time.h:135
static Time get_resolution()
Definition nest_time.h:325
Exception to be thrown if the specified receptor type does not exist in the node.
Definition exceptions.h:417
Definition correlomatrix_detector.h:158
size_t handles_test_event(SpikeEvent &, size_t) override
Check if the node can handle a particular event and receptor type.
Definition correlomatrix_detector.h:308
Parameters_ P_
Definition correlomatrix_detector.h:303
PseudoRecordingDevice device_
Definition correlomatrix_detector.h:302
void init_state_() override
Configure state variables depending on runtime information.
Definition correlomatrix_detector.cpp:252
void calibrate_time(const TimeConverter &tc) override
Re-calculate time-based properties of the node.
Definition correlomatrix_detector.cpp:386
void init_buffers_() override
Configure persistent internal data structures.
Definition correlomatrix_detector.cpp:258
void pre_run_hook() override
Re-calculate dependent parameters of the node.
Definition correlomatrix_detector.cpp:265
void set_status(const Dictionary &) override
Change properties of the node according to the entries in the dictionary.
Definition correlomatrix_detector.h:326
void update(Time const &, const long, const long) override
Advance the state of the node in time through the given interval.
Definition correlomatrix_detector.cpp:276
std::deque< Spike_ > SpikelistType
Definition correlomatrix_detector.h:233
correlomatrix_detector()
Definition correlomatrix_detector.cpp:230
void handle(SpikeEvent &) override
Handle incoming spike events.
Definition correlomatrix_detector.cpp:281
bool has_proxies() const override
This device has proxies, so that it will receive spikes also from sources which live on other threads...
Definition correlomatrix_detector.h:169
State_ S_
Definition correlomatrix_detector.h:304
void get_status(Dictionary &) const override
Export properties of the node by setting entries in the status dictionary.
Definition correlomatrix_detector.h:318
std::string get_element_type() const override
Return the element type of the node.
Definition correlomatrix_detector.h:175
virtual size_t handles_test_event(SpikeEvent &, size_t receptor_type)
Check if the node can handle a particular event and receptor type.
Definition node.cpp:271
virtual void handle(SpikeEvent &e)
Handle incoming spike events.
Definition node.cpp:265
const std::string recorder("recorder")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
void register_correlomatrix_detector(const std::string &name)
Definition correlomatrix_detector.cpp:43
Declarations for base class Node.
Definition correlomatrix_detector.h:240
Time delta_tau_
width of correlation histogram bins
Definition correlomatrix_detector.h:241
Parameters_()
Sets default parameter values.
Definition correlomatrix_detector.cpp:53
Parameters_ & operator=(const Parameters_ &)
Definition correlomatrix_detector.cpp:84
void get(Dictionary &) const
Store current values in dictionary.
Definition correlomatrix_detector.cpp:114
Time get_default_delta_tau()
Definition correlomatrix_detector.h:340
size_t N_channels_
number of channels
Definition correlomatrix_detector.h:245
Time tau_max_
maximum time difference of events to detect
Definition correlomatrix_detector.h:242
Time Tstart_
start of recording
Definition correlomatrix_detector.h:243
bool set(const Dictionary &, const correlomatrix_detector &, Node *node)
Set values from dictionary.
Definition correlomatrix_detector.cpp:132
Time Tstop_
end of recording //!< end of recording
Definition correlomatrix_detector.h:244
Spike structure to store in the deque of recently received events.
Definition correlomatrix_detector.h:211
long receptor_channel_
Definition correlomatrix_detector.h:214
Spike_(long timestep, double weight, long receptorchannel)
Definition correlomatrix_detector.h:216
bool operator>(const Spike_ &second) const
Greater operator needed for insertion sort.
Definition correlomatrix_detector.h:227
double weight_
Definition correlomatrix_detector.h:213
long timestep_
Definition correlomatrix_detector.h:212
Definition correlomatrix_detector.h:276
std::vector< std::vector< std::vector< double > > > covariance_
Weighted covariance matrix.
Definition correlomatrix_detector.h:282
std::vector< long > n_events_
spike counters
Definition correlomatrix_detector.h:277
SpikelistType incoming_
incoming spikes, sorted
Definition correlomatrix_detector.h:278
State_()
initialize default state
Definition correlomatrix_detector.cpp:100
std::vector< std::vector< std::vector< long > > > count_covariance_
Unweighted covariance matrix.
Definition correlomatrix_detector.h:286
void get(Dictionary &) const
Definition correlomatrix_detector.cpp:124
void set(const Dictionary &, const Parameters_ &, bool, Node *node)
Definition correlomatrix_detector.cpp:194
void reset(const Parameters_ &)
Definition correlomatrix_detector.cpp:199