NEST main@caf0ae8
 
Loading...
Searching...
No Matches
correlospinmatrix_detector.h
Go to the documentation of this file.
1/*
2 * correlospinmatrix_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 CORRELOSPINMATRIX_DETECTOR_H
24#define CORRELOSPINMATRIX_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 ``correlospinmatrix_detector`` is a device that receives input from several
53binary neuron sources and calculates the raw auto and cross correlation binned
54to bins of duration delta_tau, which defaults to the simulation resolution.
55
56The result can be obtained from the node's status dictionary under the key
57``count_covariance`` in the format of a tensor of rank 3 of size
58``N_channels`` x ``N_channels``, with each entry :math:`C_{ij}` being a vector
59of size :math:`2\cdot\tau_{max}/\delta_{\tau} + 1` containing the histogram for
60the different time lags.
61
62The bins are centered around the time difference they represent, and are
63left-closed and right-open in the lower triangular part of the matrix. On the
64diagonal and in the upper triangular part the intervals are left-open and
65right-closed. This ensures proper counting of events at the border of bins.
66
67The ``correlospinmatrix_detector`` has a variable number of inputs which can be
68set via SetStatus under the key N_channels. All incoming connections to a
69specified receptor will be pooled.
70
71Setting either N_channels, Tstart, Tstop, tau_max or delta_tau clears
72count_covariance.
73
74Correlospinmatrix detectors ignore any connection delays.
75
76See :doc:`../auto_examples/correlospinmatrix_detector_two_neuron` for
77a script reproducing a setting studied in Fig 1 of Grinzburg &
78Sompolinsky (1994) PRE 50(4) p. 3171.
79
80Parameters
81++++++++++
82
83================ ========= ====================================================
84Tstart real Time when to start counting events. This time should
85 be set to at least start + tau_max in order to avoid
86 edge effects of the correlation counts.
87Tstop real Time when to stop counting events. This time should
88 be set to at most Tsim - tau_max, where Tsim is the
89 duration of simulation, in order to avoid edge
90 effects of the correlation counts.
91delta_tau ms Bin width. This has to be an odd multiple of
92 the resolution, to allow the symmetry between
93 positive and negative time-lags. Defaults to the
94 simulation resolution.
95tau_max ms One-sided width. In the lower triagnular part
96 events with differences in [0, tau_max+delta_tau/2)
97 are counted. On the diagonal and in the upper
98 triangular part events with differences in
99 (0, tau_max+delta_tau/2]. Defaults to 10 times the
100 value of delta_tau.
101N_channels integer The number of pools. This defines the range of
102 receptor_type. Default is 1.
103 Setting N_channels clears count_covariance,
104 covariance and n_events.
105covariance 3D matrix of read-only -raw, weighted, auto/cross
106 matrix of correlation
107 integers
108count_covariance 3D matrix of read-only -raw, auto/cross correlation
109 matrix of counts
110 integers
111================ ========= ====================================================
112
113Receives
114++++++++
115
116SpikeEvent
117
118See also
119++++++++
120
121correlation_detector, correlomatrix_detector, spike_recorder
122
123Examples using this model
124+++++++++++++++++++++++++
125
126.. listexamples:: correlospinmatrix_detector
127
128EndUserDocs */
129
136void register_correlospinmatrix_detector( const std::string& name );
137
139{
140
141public:
144
149 bool
150 has_proxies() const override
151 {
152 return true;
153 }
154
155 std::string
156 get_element_type() const override
157 {
158 return names::recorder;
159 }
160
166 using Node::handle;
169
170 void handle( SpikeEvent& ) override;
171
172 size_t handles_test_event( SpikeEvent&, size_t ) override;
173
174 SignalType receives_signal() const override;
175
176 void get_status( Dictionary& ) const override;
177 void set_status( const Dictionary& ) override;
178
179 void calibrate_time( const TimeConverter& tc ) override;
180
181private:
182 void init_state_() override;
183 void init_buffers_() override;
184 void pre_run_hook() override;
185
186 void update( Time const&, const long, const long ) override;
187
188 // ------------------------------------------------------------
189
195 {
196 long t_on_;
197 long t_off_;
199
200 BinaryPulse_( long timeon, long timeoff, long receptorchannel )
201 : t_on_( timeon )
202 , t_off_( timeoff )
203 , receptor_channel_( receptorchannel )
204 {
205 }
206
210 inline bool
211 operator>( const BinaryPulse_& second ) const
212 {
213 return t_off_ > second.t_off_;
214 }
215 };
216
217 typedef std::deque< BinaryPulse_ > BinaryPulselistType;
218
219 // ------------------------------------------------------------
220
221 struct State_;
222
224 {
229 size_t N_channels_;
230
231 Parameters_();
232 Parameters_( const Parameters_& );
233
235
236 void get( Dictionary& ) const;
237
243 bool set( const Dictionary&, const correlospinmatrix_detector&, Node* );
244
246 };
247
248 // ------------------------------------------------------------
249
259 struct State_
260 {
266 size_t last_i_;
271
274
275 std::vector< bool > curr_state_;
276
278 std::vector< long > last_change_;
279
282 std::vector< std::vector< std::vector< long > > > count_covariance_;
283
284 State_();
285
286 void get( Dictionary& ) const;
287
291 void set( const Dictionary&, const Parameters_&, bool, Node* );
292
293 void reset( const Parameters_& );
294 };
295
296 // ------------------------------------------------------------
297
301};
302
303inline size_t
305{
306 if ( receptor_type > P_.N_channels_ - 1 )
307 {
308 throw UnknownReceptorType( receptor_type, get_name() );
309 }
310 return receptor_type;
311}
312
313inline void
315{
316 device_.get_status( d );
317 P_.get( d );
318 S_.get( d );
319}
320
321inline void
323{
324 Parameters_ ptmp = P_;
325 const bool reset_required = ptmp.set( d, *this, this );
326
327 device_.set_status( d );
328 P_ = ptmp;
329 if ( reset_required )
330 {
331 S_.reset( P_ );
332 }
333}
334
335
336inline SignalType
341
342inline Time
347
348} // namespace
349
350#endif /* #ifndef CORRELOSPINMATRIX_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
virtual SignalType receives_signal() const
Definition node.h:974
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 correlospinmatrix_detector.h:139
void handle(SpikeEvent &) override
Handle incoming spike events.
Definition correlospinmatrix_detector.cpp:292
void calibrate_time(const TimeConverter &tc) override
Re-calculate time-based properties of the node.
Definition correlospinmatrix_detector.cpp:476
void init_buffers_() override
Configure persistent internal data structures.
Definition correlospinmatrix_detector.cpp:269
void pre_run_hook() override
Re-calculate dependent parameters of the node.
Definition correlospinmatrix_detector.cpp:276
void set_status(const Dictionary &) override
Change properties of the node according to the entries in the dictionary.
Definition correlospinmatrix_detector.h:322
size_t handles_test_event(SpikeEvent &, size_t) override
Check if the node can handle a particular event and receptor type.
Definition correlospinmatrix_detector.h:304
SignalType receives_signal() const override
Definition correlospinmatrix_detector.h:337
PseudoRecordingDevice device_
Definition correlospinmatrix_detector.h:298
Parameters_ P_
Definition correlospinmatrix_detector.h:299
void init_state_() override
Configure state variables depending on runtime information.
Definition correlospinmatrix_detector.cpp:263
State_ S_
Definition correlospinmatrix_detector.h:300
void get_status(Dictionary &) const override
Export properties of the node by setting entries in the status dictionary.
Definition correlospinmatrix_detector.h:314
bool has_proxies() const override
This device has proxies, so that it will receive spikes also from sources which live on other threads...
Definition correlospinmatrix_detector.h:150
correlospinmatrix_detector()
Definition correlospinmatrix_detector.cpp:241
std::string get_element_type() const override
Return the element type of the node.
Definition correlospinmatrix_detector.h:156
std::deque< BinaryPulse_ > BinaryPulselistType
Definition correlospinmatrix_detector.h:217
void update(Time const &, const long, const long) override
Advance the state of the node in time through the given interval.
Definition correlospinmatrix_detector.cpp:287
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_correlospinmatrix_detector(const std::string &name)
Correlospinmatrix detector breaks with the persistence scheme as follows: the internal buffers for st...
Definition correlospinmatrix_detector.cpp:43
SignalType
enum type of signal conveyed by spike events of a node.
Definition nest_types.h:165
@ BINARY
Definition nest_types.h:168
Declarations for base class Node.
Structure to store in the deque of recently received events marked by beginning and end of the binary...
Definition correlospinmatrix_detector.h:195
long t_on_
Definition correlospinmatrix_detector.h:196
bool operator>(const BinaryPulse_ &second) const
Greater operator needed for insertion sort.
Definition correlospinmatrix_detector.h:211
BinaryPulse_(long timeon, long timeoff, long receptorchannel)
Definition correlospinmatrix_detector.h:200
long t_off_
Definition correlospinmatrix_detector.h:197
long receptor_channel_
Definition correlospinmatrix_detector.h:198
Definition correlospinmatrix_detector.h:224
Parameters_ & operator=(const Parameters_ &)
Definition correlospinmatrix_detector.cpp:84
bool set(const Dictionary &, const correlospinmatrix_detector &, Node *)
Set values from dictionary.
Definition correlospinmatrix_detector.cpp:131
Time get_default_delta_tau()
Definition correlospinmatrix_detector.h:343
void get(Dictionary &) const
Store current values in dictionary.
Definition correlospinmatrix_detector.cpp:115
Time Tstop_
end of recording
Definition correlospinmatrix_detector.h:228
Time Tstart_
start of recording
Definition correlospinmatrix_detector.h:227
size_t N_channels_
number of channels
Definition correlospinmatrix_detector.h:229
Time tau_max_
maximum time difference of events to detect
Definition correlospinmatrix_detector.h:226
Time delta_tau_
width of correlation histogram bins
Definition correlospinmatrix_detector.h:225
Parameters_()
Sets default parameter values.
Definition correlospinmatrix_detector.cpp:52
Definition correlospinmatrix_detector.h:260
void reset(const Parameters_ &)
Definition correlospinmatrix_detector.cpp:208
BinaryPulselistType incoming_
incoming binary pulses, sorted
Definition correlospinmatrix_detector.h:261
std::vector< long > last_change_
last time pointof change of neuron i
Definition correlospinmatrix_detector.h:278
State_()
initialize default state
Definition correlospinmatrix_detector.cpp:101
void get(Dictionary &) const
Definition correlospinmatrix_detector.cpp:125
size_t last_i_
rport of last event coming in (needed for decoding logic of binary events)
Definition correlospinmatrix_detector.h:266
bool tentative_down_
potentially a down transition (single spike received)
Definition correlospinmatrix_detector.h:273
void set(const Dictionary &, const Parameters_ &, bool, Node *)
Definition correlospinmatrix_detector.cpp:203
std::vector< bool > curr_state_
current state of neuron i
Definition correlospinmatrix_detector.h:275
Time t_last_in_spike_
time of last event coming in (needed for decoding logic of binary events)
Definition correlospinmatrix_detector.h:270
std::vector< std::vector< std::vector< long > > > count_covariance_
Unweighted covariance matrix.
Definition correlospinmatrix_detector.h:282