NEST  2.6.0,not_revisioned_source_dir@0
spike_generator.h
Go to the documentation of this file.
1 /*
2  * spike_generator.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 SPIKE_GENERATOR_H
24 #define SPIKE_GENERATOR_H
25 
26 
27 #include <vector>
28 #include "nest.h"
29 #include "event.h"
30 #include "node.h"
31 #include "scheduler.h"
32 #include "stimulating_device.h"
33 #include "connection.h"
34 #include "nest_time.h"
35 #include "network.h"
36 
37 namespace nest
38 {
39  /*BeginDocumentation
40  Name: spike_generator - A device which generates spikes from an array with spike-times.
41 
42  Synopsis: spike_generator Create -> gid
43 
44  Description:
45  A spike generator can be used to generate spikes at specific times
46  which are given to the spike generator as an array.
47 
48  Spike times are given in milliseconds, and must be sorted with the
49  earliest spike first. All spike times must be strictly in the future.
50  Trying to set a spike time in the past or at the current time step,
51  will cause a NEST error. Setting a spike time of 0.0 will also result
52  in an error.
53 
54  Spike times may not coincide with a time step, i.e., are not a multiple
55  of the simulation resolution. Three options control how spike times that
56  do not coincide with a step are handled (see examples below):
57 
58  Multiple occurences of the same time indicate that more than one
59  event is to be generated at this particular time.
60 
61  Additionally, spike_weights can be set. This also is an array,
62  which contains one weight value per spike time. If set, the spikes
63  are delivered with the respective weight multiplied with the
64  weight of the connection. To disable this functionality, the
65  spike_weights array can be set to an empty array.
66 
67  /precise_times default: false
68  If false, spike times will be rounded to simulation steps, i.e., multiples
69  of the resolution. The rounding is controlled by the two other flags.
70  If true, spike times will not be rounded but represented exactly as a
71  combination of step and offset. This should only be used if all neurons
72  receiving the spike train can handle precise timing information. In this
73  case, the other two options are ignored.
74 
75  /allow_offgrid_times default: false
76  If false, spike times will be rounded to the nearest step if they are
77  less than tic/2 from the step, otherwise NEST reports an error.
78  If true, spike times are rounded to the nearest step if within tic/2
79  from the step, otherwise they are rounded up to the *end* of the step.
80 
81  /shift_now_spikes default: false
82  This option is mainly for use by the PyNN-NEST interface.
83  If false, spike times rounded down to the current point in time will
84  be considered in the past and ignored.
85  If true, spike times that are rounded down to the current time step
86  are shifted one time step into the future.
87 
88  Note that GetStatus will report the spike times that the spike_generator
89  will actually use, i.e., for grid-based simulation the spike times rounded
90  to the appropriate point on the time grid. This means that GetStatus may
91  return different /spike_times values at different resolutions.
92 
93  Example:
94  spikegenerator << /spike_times [1.0 2.0 3.0] >> SetStatus
95 
96  Instructs the spike generator to generate events at 1.0, 2.0, and
97  3.0 milliseconds, relative to the device-timer origin.
98 
99  Example:
100  Assume that NEST works with default resolution (step size) of 0.1ms
101  and default tic length of 0.001ms. Then, spikes times not falling
102  onto the grid will be handled as follows for different option settings:
103 
104  /spike_generator << /spike_times [1.0 1.9999 3.0001] >> Create
105  ---> spikes at steps 10 (==1.0ms), 20 (==2.0ms) and 30 (==3.0ms)
106 
107  /spike_generator << /spike_times [1.0 1.05 3.0001] >> Create
108  ---> error, spike time 1.05 not within tic/2 of step
109 
110  /spike_generator << /spike_times [1.0 1.05 3.0001]
111  /allow_offgrid_times true >> Create
112  ---> spikes at steps 10, 11 (mid-step time rounded up),
113  30 (time within tic/2 of step moved to step)
114 
115  /spike_generator << /spike_times [1.0 1.05 3.0001]
116  /precise_times true >> Create
117  ---> spikes at step 10, offset 0.0; step 11, offset -0.05;
118  step 31, offset -0.0999
119 
120  Assume we have simulated 10.0ms and simulation times is thus 10.0 (step 100).
121  Then, any spike times set, at this time, must be later than step 100.
122 
123  /spike_generator << /spike_times [10.0001] >> Create
124  ---> spike time is within tic/2 of step 100, rounded down to 100 thus
125  not in the future, spike will not be emitted
126 
127  /spike_generator << /spike_times [10.0001] /precise_times true >> Create
128  ---> spike at step 101, offset -0.0999 is in the future
129 
130  /spike_generator << /spike_times [10.0001 11.0001] /shift_now_spikes true >> Create
131  ---> spike at step 101, spike shifted into the future, and spike at step 110,
132  not shifted, since it is in the future anyways
133 
134 
135  Example:
136  spikegenerator << /spike_times [1.0 2.0] /spike_weights [5.0 -8.0] >> SetStatus
137 
138  Instructs the spike generator to generate an event with weight 5.0
139  at 1.0 ms, and an event with weight -8.0 at 2.0 ms, relative to
140  the device-timer origin.
141 
142  spikegenerator << /spike_weights [] >> SetStatus
143 
144  Instructs the spike generator to generate events at 1.0, 2.0, and
145  3.0 milliseconds, and use the weight of the connection.
146 
147  Parameters:
148  The following properties can be set in the status dictionary.
149 
150  origin double - Time origin for device timer in ms
151  start double - earliest possible time stamp of a spike to be emitted in ms
152  stop double - earliest time stamp of a potential spike event that is not emitted in ms
153  spike_times double array - spike-times in ms
154  spike_weights double array - corrsponding spike-weights, the unit depends on the receiver
155  precise_times bool - see above
156  allow_offgrid_spikes bool - see above
157  shift_now_spikes bool - see above
158 
159  Sends: SpikeEvent
160 
161  Author: Gewaltig, Diesmann, Eppler
162 
163  SeeAlso: Device, StimulatingDevice, testsuite::test_spike_generator
164  */
165 
173  class spike_generator : public Node
174  {
175 
176  public:
177  spike_generator();
179 
180  bool has_proxies() const {return false;}
181 
183  void get_status(DictionaryDatum &) const;
184  void set_status(const DictionaryDatum &);
185 
190  using Node::event_hook;
191  void event_hook(DSSpikeEvent&);
192 
193  private:
194 
195  void init_state_(const Node&);
196  void init_buffers_();
197  void calibrate();
198 
199  void update(Time const &, const long_t, const long_t);
200 
201  // ------------------------------------------------------------
202 
203  struct State_ {
204  size_t position_;
205 
206  State_();
207  };
208 
209  // ------------------------------------------------------------
210 
211  struct Parameters_ {
212 
213  std::vector<Time> spike_stamps_;
214  std::vector<double> spike_offsets_;
215 
216  std::vector<double> spike_weights_;
217 
220 
223 
226 
227  Parameters_();
228  Parameters_(const Parameters_&);
229 
230  void get(DictionaryDatum&) const;
231 
238  void set(const DictionaryDatum&, State_&, const Time&, const Time&);
239 
247  void assert_valid_spike_time_and_insert_(double, const Time&, const Time&);
248  };
249 
250  // ------------------------------------------------------------
251 
253 
256  };
257 
258 inline
260 {
261  device_.enforce_single_syn_type(syn_id);
262 
263  if ( dummy_target )
264  {
265  DSSpikeEvent e;
266  e.set_sender(*this);
267  return target.handles_test_event(e, receptor_type);
268  }
269  else
270  {
271  SpikeEvent e;
272  e.set_sender(*this);
273  return target.handles_test_event(e, receptor_type);
274  }
275 }
276 
277 inline
279 {
280  P_.get(d);
281  device_.get_status(d);
282 }
283 
284 inline
286 {
287  Parameters_ ptmp = P_; // temporary copy in case of errors
288 
289  // To detect "now" spikes and shift them, we need the origin. In case
290  // it is set in this call, we need to extract it explicitly here.
291  Time origin;
292  double_t v;
293  if ( updateValue<double_t>(d, names::origin, v) )
294  origin = Time::ms(v);
295  else
296  origin = device_.get_origin();
297  ptmp.set(d, S_, origin, network()->get_time()); // throws if BadProperty
298 
299  // We now know that ptmp is consistent. We do not write it back
300  // to P_ before we are also sure that the properties to be set
301  // in the parent class are internally consistent.
302  device_.set_status(d);
303 
304  // if we get here, temporary contains consistent set of properties
305  P_ = ptmp;
306 }
307 
308 
309 } // namespace
310 
311 #endif /* #ifndef SPIKE_GENERATOR_H */
spike_generator()
Definition: spike_generator.cpp:220
bool shift_now_spikes_
Shift spike times at present to next step.
Definition: spike_generator.h:225
const Name receptor_type("receptor_type")
Connection parameters.
Definition: nest_names.h:240
StimulatingDevice< SpikeEvent > device_
Definition: spike_generator.h:252
Definition: spike_generator.h:211
Definition: lockptrdatum.h:40
void calibrate()
Re-calculate dependent parameters of the node.
Definition: spike_generator.cpp:252
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
Declarations for base class Node.
State_ S_
Definition: spike_generator.h:255
"Callback request event" for use in Device.
Definition: event.h:374
void set_status(const DictionaryDatum &)
Definition: spike_generator.h:285
Base class for common properties of Stimulating Devices.
Definition: stimulating_device.h:117
std::vector< double > spike_offsets_
Spike time offset, if using precise_times_.
Definition: spike_generator.h:214
void set_sender(Node &)
Change pointer to sending Node.
Definition: event.h:714
void init_buffers_()
Private function to initialize the buffers of a node.
Definition: spike_generator.cpp:247
port send_test_event(Node &, rport, synindex, bool)
Send an event to the receiving_node passed as an argument.
Definition: spike_generator.h:259
std::vector< double > spike_weights_
Spike weights as double.
Definition: spike_generator.h:216
void event_hook(DSSpikeEvent &)
Modify Event object parameters during event delivery.
Definition: spike_generator.cpp:318
long_t rport
Connection port number to distinguish incoming connections, also called receiver port.
Definition: nest.h:147
void get(DictionaryDatum &) const
Store current values in dictionary.
Definition: spike_generator.cpp:65
Definition: nest_time.h:130
void set(const DictionaryDatum &, State_ &, const Time &, const Time &)
Set values from dicitonary.
Definition: spike_generator.cpp:149
const Name target("target")
Connection parameters.
Definition: nest_names.h:282
Declarations for class Network.
bool allow_offgrid_spikes_
Allow and round up spikes not on steps; irrelevant if precise_times_.
Definition: spike_generator.h:222
Parameters_ P_
Definition: spike_generator.h:254
const Name origin("origin")
Device parameters.
Definition: nest_names.h:215
void get_status(DictionaryDatum &) const
Definition: spike_generator.h:278
long_t port
Connection port number to distinguis outgoing connections.
Definition: nest.h:155
void update(Time const &, const long_t, const long_t)
Bring the node from state $t$ to $t+n*dt$.
Definition: spike_generator.cpp:262
double double_t
Double precision floating point numbers.
Definition: nest.h:93
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
friend struct ms
Definition: nest_time.h:173
Parameters_()
Sets default parameter values.
Definition: spike_generator.cpp:38
static Network * network()
Return pointer to network driver class.
Definition: node.h:813
unsigned char synindex
Unsigned char type for enumerations of synapse types.
Definition: nest.h:115
void assert_valid_spike_time_and_insert_(double, const Time &, const Time &)
Insert spike time to arrays, throw BadProperty for invalid spike times.
Definition: spike_generator.cpp:90
void init_state_(const Node &)
Private function to initialize the state of a node to model defaults.
Definition: spike_generator.cpp:239
bool has_proxies() const
Returns true if the node has proxies on remote threads.
Definition: spike_generator.h:180
Default types used by the NEST kernel.
Definition: spike_generator.h:203
Event for spike information.
Definition: event.h:320
Emit spikes at given times.
Definition: spike_generator.h:173
Base class for all NEST network objects.
Definition: node.h:96
std::vector< Time > spike_stamps_
Spike time stamp as Time, rel to origin_.
Definition: spike_generator.h:213
size_t position_
index of next spike to deliver
Definition: spike_generator.h:204
virtual void event_hook(DSSpikeEvent &)
Modify Event object parameters during event delivery.
Definition: node.cpp:301
long long_t
Integer number with at least 32 bit.
Definition: nest.h:96
const double e
Definition: numerics.cpp:62
bool precise_times_
Interpret spike times as precise, i.e. send as step and offset.
Definition: spike_generator.h:219
State_()
Sets default state value.
Definition: spike_generator.cpp:56