NEST  2.6.0,not_revisioned_source_dir@0
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 #include <vector>
28 #include <deque>
29 #include "nest.h"
30 #include "event.h"
31 #include "node.h"
33 
34 /* BeginDocumentation
35 
36  Name: correlomatrix_detector - Device for measuring the covariance matrix from several inputs
37 
38  Description: The correlomatrix_detector is a recording device. It is used to record spikes from
39  several pools of spike inputs and calculates the covariance matrix of inter-spike intervals
40  (raw auto and cross correlation) binned to bins of duration delta_tau. The histogram is only
41  recorded for non-negative time lags. The negative part can be obtained by the symmetry of the
42  covariance matrix C(t) = C^T(-t).
43  The result can be obtained via GetStatus under the key /count_covariance.
44  In parallel it records a weighted histogram, where the connection weight are used to weight every
45  count, which is available under the key /covariance.
46  Both are matrices of size N_channels x N_channels, with each entry C_ij being a vector of
47  size tau_max/delta_tau + 1 containing the (weighted) histogram for non-negative time lags.
48 
49  The bins are centered around the time difference they represent, and are left-closed
50  and right-open in the lower triangular part of the matrix. On the diagonal and in the upper
51  triangular part the intervals are left-open and right-closed. This ensures proper counting
52  of events at the border of bins, allowing consistent integration of a histogram over negative
53  and positive time lags by stacking two parts of the histogram (C(t)=[C[i][j][::-1],C[j][i][1:]]).
54  In this case one needs to exclude C[j][i][0] to avoid counting the zero-lag bin twice.
55 
56  The correlomatrix_detector has a variable number of inputs which can be set via SetStatus under
57  the key N_channels. All incoming connections to a specified receptor will be pooled.
58 
59  Parameters:
60  Tstart double - Time when to start counting events. This time should be set to at least
61  start + tau_max in order to avoid edge effects of the correlation counts.
62  Tstop double - Time when to stop counting events. This time should be set to at most
63  Tsim - tau_max, where Tsim is the duration of simulation,
64  in order to avoid edge effects of the correlation counts.
65  delta_tau double - bin width in ms. This has to be an odd multiple of the resolution, to allow
66  the symmetry between positive and negative time-lags.
67  tau_max double - one-sided width in ms. In the lower triagnular part events with differences in
68  [0, tau_max+delta_tau/2) are counted. On the diagonal and in
69  the upper triangular part events with differences in (0, tau_max+delta_tau/2]
70 
71  N_channels long - The number of pools. This defines the range of receptor_type. Default is 1.
72  Setting N_channels clears count_covariance, covariance and n_events.
73 
74  covariance matrix of double vectors, read-only - raw, weighted auto/cross correlation counts
75  count_covariance matrix of long vectors, read-only - raw, auto/cross correlation counts
76  n_events integer vector - number of events from all sources.
77 
78  Remarks: This recorder does not record to file, screen or memory in the usual sense.
79 
80  Example:
81  /s1 /spike_generator Create def
82  /s2 /spike_generator Create def
83  s1 << /spike_times [ 1.0 1.5 2.7 4.0 5.1 ] >> SetStatus
84  s2 << /spike_times [ 0.9 1.8 2.1 2.3 3.5 3.8 4.9 ] >> SetStatus
85  /cm /correlomatrix_detector Create def
86  cm << /N_channels 2 /delta_tau 0.5 /tau_max 2.5 >> SetStatus
87  s1 cm << /receptor_type 0 >> Connect
88  s2 cm << /receptor_type 1 >> Connect
89  10 Simulate
90  cm [/n_events] get == --> [# 5 7 #]
91  cm [/count_covariance] get == --> [[<# 5 1 2 2 0 2 #> <# 3 4 1 3 3 0 #>] [<# 3 2 6 1 2 2 #> <# 9 3 4 6 1 2 #>]]
92  cm << /N_channels 2 >> SetStatus
93  cm [/count_covariance] get == --> [[<# 0 0 0 0 0 0 #> <# 0 0 0 0 0 0 #>] [<# 0 0 0 0 0 0 #> <# 0 0 0 0 0 0 #>]]
94 
95  Receives: SpikeEvent
96 
97  Author: Dmytro Grytskyy
98  Jakob Jordan
99  FirstVersion: 2013/02/27
100  SeeAlso: correlation_detector, spike_detector, Device, PseudoRecordingDevice
101  Availability: NEST
102 */
103 
104 
105 namespace nest
106 {
107 
108  class Network;
109 
130  {
131 
132  public:
133 
136 
141  bool has_proxies() const {return true;}
142 
147  using Node::handle;
149 
150  void handle(SpikeEvent &);
151 
153 
154  void get_status(DictionaryDatum &) const;
155  void set_status(const DictionaryDatum &);
156 
157  private:
158 
159  void init_state_(Node const&);
160  void init_buffers_();
161  void calibrate();
162 
163  void update(Time const &, const long_t, const long_t);
164 
165  // ------------------------------------------------------------
166 
171  struct Spike_
172  {
176 
177  Spike_(long_t timestep, double_t weight, long_t receptorchannel)
178  : timestep_(timestep), weight_(weight), receptor_channel_(receptorchannel)
179  {}
180 
184  inline bool operator>(const Spike_ &second) const
185  {
186  return timestep_ > second.timestep_;
187  }
188  };
189 
190  typedef std::deque <Spike_> SpikelistType;
191 
192  // ------------------------------------------------------------
193 
194  struct State_;
195 
196  struct Parameters_ {
197 
203 
204  Parameters_();
205  Parameters_(const Parameters_&);
206 
207  void get(DictionaryDatum&) const;
208 
214  bool set(const DictionaryDatum&, const correlomatrix_detector&);
215  };
216 
217  // ------------------------------------------------------------
218 
228  struct State_ {
229 
230  std::vector<long_t> n_events_;
232 
235  std::vector<std::vector<std::vector<double_t> > > covariance_;
236 
239  std::vector<std::vector<std::vector<long_t> > > count_covariance_;
240 
241  State_();
242 
243  void get(DictionaryDatum&) const;
244 
248  void set(const DictionaryDatum&, const Parameters_&, bool);
249 
250  void reset(const Parameters_&);
251  };
252 
253  // ------------------------------------------------------------
254 
258  };
259 
260  inline
262  {
263  if (receptor_type < 0 || receptor_type > P_.N_channels_-1)
264  throw UnknownReceptorType(receptor_type, get_name());
265  return receptor_type;
266  }
267 
268  inline
270  {
271  device_.get_status(d);
272  P_.get(d);
273  S_.get(d);
274 
276  }
277 
278  inline
280  {
281  Parameters_ ptmp = P_;
282  const bool reset_required = ptmp.set(d, *this);
283 
284  device_.set_status(d);
285  P_ = ptmp;
286  if ( reset_required == true)
287  S_.reset(P_);
288  }
289 
290 } // namespace
291 
292 #endif /* #ifndef CORRELOMATRIX_DETECTOR_H */
double_t weight
Weight of a connection.
Definition: nest.h:170
const Name receptor_type("receptor_type")
Connection parameters.
Definition: nest_names.h:240
void init_buffers_()
Private function to initialize the buffers of a node.
Definition: correlomatrix_detector.cpp:233
Parameters_ P_
Definition: correlomatrix_detector.h:256
Definition: lockptrdatum.h:40
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
Declarations for base class Node.
std::deque< Spike_ > SpikelistType
Definition: correlomatrix_detector.h:190
correlomatrix_detector()
Definition: correlomatrix_detector.cpp:198
void set(const DictionaryDatum &, const Parameters_ &, bool)
Definition: correlomatrix_detector.cpp:164
Base class for all pseudo recording devices.
Definition: pseudo_recording_device.h:73
long_t timestep_
Definition: correlomatrix_detector.h:173
bool has_proxies() const
This device has proxies, so that it will receive spikes also from sources which live on other threads...
Definition: correlomatrix_detector.h:141
Time tau_max_
maximum time difference of events to detect
Definition: correlomatrix_detector.h:199
State_ S_
Definition: correlomatrix_detector.h:257
Definition: correlomatrix_detector.h:196
const Name element_type("element_type")
Node type.
Definition: nest_names.h:117
long_t rport
Connection port number to distinguish incoming connections, also called receiver port.
Definition: nest.h:147
long_t N_channels_
number of channels
Definition: correlomatrix_detector.h:202
const Name recorder("recorder")
Node type.
Definition: nest_names.h:245
void get_status(DictionaryDatum &) const
Definition: correlomatrix_detector.h:269
SpikelistType incoming_
incoming spikes, sorted
Definition: correlomatrix_detector.h:231
Definition: nest_time.h:130
Spike_(long_t timestep, double_t weight, long_t receptorchannel)
Definition: correlomatrix_detector.h:177
port handles_test_event(SpikeEvent &, rport)
Check if the node can handle a particular event and receptor type.
Definition: correlomatrix_detector.h:261
std::string get_name() const
Return class name.
Definition: node.cpp:83
Parameters_()
Sets default parameter values.
Definition: correlomatrix_detector.cpp:37
void reset(const Parameters_ &)
Definition: correlomatrix_detector.cpp:167
void calibrate()
Re-calculate dependent parameters of the node.
Definition: correlomatrix_detector.cpp:239
Exception to be thrown if the specified receptor type does not exist in the node. ...
Definition: exceptions.h:254
void handle(SpikeEvent &)
Handle incoming spike events.
Definition: correlomatrix_detector.cpp:252
Time delta_tau_
width of correlation histogram bins
Definition: correlomatrix_detector.h:198
State_()
initialize default state
Definition: correlomatrix_detector.cpp:64
long_t receptor_channel_
Definition: correlomatrix_detector.h:175
long_t port
Connection port number to distinguis outgoing connections.
Definition: nest.h:155
std::vector< std::vector< std::vector< double_t > > > covariance_
Weighted covariance matrix.
Definition: correlomatrix_detector.h:235
virtual void handle(SpikeEvent &e)
Handle incoming spike events.
Definition: node.cpp:198
Time Tstart_
start of recording
Definition: correlomatrix_detector.h:200
double double_t
Double precision floating point numbers.
Definition: nest.h:93
std::vector< std::vector< std::vector< long_t > > > count_covariance_
Unweighted covariance matrix.
Definition: correlomatrix_detector.h:239
bool operator>(const Spike_ &second) const
Greater operator needed for insertion sort.
Definition: correlomatrix_detector.h:184
virtual port handles_test_event(SpikeEvent &, rport receptor_type)
Check if the node can handle a particular event and receptor type.
Definition: node.cpp:203
Definition: namedatum.h:90
void set_status(const DictionaryDatum &)
Definition: correlomatrix_detector.h:279
std::vector< long_t > n_events_
spike counters
Definition: correlomatrix_detector.h:230
void init_state_(Node const &)
Private function to initialize the state of a node to model defaults.
Definition: correlomatrix_detector.cpp:224
Default types used by the NEST kernel.
Event for spike information.
Definition: event.h:320
Base class for all NEST network objects.
Definition: node.h:96
void update(Time const &, const long_t, const long_t)
Bring the node from state $t$ to $t+n*dt$.
Definition: correlomatrix_detector.cpp:249
Correlomatrixdetector class.
Definition: correlomatrix_detector.h:129
Definition: correlomatrix_detector.h:228
Time Tstop_
end of recording
Definition: correlomatrix_detector.h:201
long long_t
Integer number with at least 32 bit.
Definition: nest.h:96
bool set(const DictionaryDatum &, const correlomatrix_detector &)
Set values from dicitonary.
Definition: correlomatrix_detector.cpp:107
PseudoRecordingDevice device_
Definition: correlomatrix_detector.h:255
Spike structure to store in the deque of recently received events.
Definition: correlomatrix_detector.h:171
double_t weight_
Definition: correlomatrix_detector.h:174