NEST main@caf0ae8
 
Loading...
Searching...
No Matches
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// C++ includes:
28#include <vector>
29
30// Includes from nestkernel:
31#include "connection.h"
32#include "device_node.h"
33#include "event.h"
34#include "nest_time.h"
35#include "nest_types.h"
36#include "stimulation_device.h"
37
38namespace nest
39{
40
41/* BeginUserDocs: device, spike, generator
42
43Short description
44+++++++++++++++++
45
46Generate spikes from an array with spike-times
47
48Description
49+++++++++++
50
51A spike generator can be used to generate spikes at specific times
52which are given to the spike generator as an array.
53
54.. note::
55
56 If the spike trains have a very high rate, we recommend using the
57 ``spike_generator``. For rates similar to regular neurons, use
58 :doc:`spike train injector </models/spike_train_injector>`.
59
60
61
62Spike times are given in milliseconds as an array. The `spike_times`
63array must be sorted with the earliest spike first. All spike times
64must be strictly in the future. Trying to set a spike time in the
65past or at the current time step will cause a NEST error. Setting a
66spike time of 0.0 will also result in an error.
67
68Multiple occurrences of the same time indicate that more than one
69event is to be generated at this particular time.
70
71Additionally, `spike_weights` can be set. This is an array as well.
72It contains one weight value per spike time. If set, the spikes
73are delivered with the respective weight multiplied with the
74weight of the connection. To disable this functionality, the
75spike_weights array can be set to an empty array.
76
77The spike generator supports spike times that do not coincide with a time
78step, that is, are not falling on the grid defined by the simulation resolution.
79There are three options that control how spike times that do not coincide
80with a step are handled (see also examples below):
81
82Option 1: ``precise_times`` default: false
83
84If false, spike times will be rounded to simulation steps, i.e., multiples
85of the resolution. The rounding is controlled by the two other flags.
86If true, spike times will not be rounded but represented exactly as a
87combination of step and offset. This should only be used if all neurons
88receiving the spike train can handle precise timing information. In this
89case, the other two options are ignored.
90
91Option 2: ``allow_offgrid_times`` default: false
92
93If false, spike times will be rounded to the nearest step if they are
94less than tic/2 from the step, otherwise NEST reports an error.
95If true, spike times are rounded to the nearest step if within tic/2
96from the step, otherwise they are rounded up to the *end* of the step.
97This setting has no effect if ``precise_times`` is `true`.
98
99Option 3: ``shift_now_spikes`` default: false
100
101This option is mainly for use by the PyNN-NEST interface.
102If false, spike times rounded down to the current point in time will
103be considered in the past and ignored.
104If true, spike times that are rounded down to the current time step
105are shifted one time step into the future.
106
107Note that ``GetStatus`` will report the spike times that the spike_generator
108will actually use, i.e., for grid-based simulation the spike times rounded
109to the appropriate point on the time grid. This means that ``GetStatus`` may
110return different `spike_times` values at different resolutions.
111
112Example:
113
114::
115
116 nest.Create("spike_generator",
117 params={"spike_times": [1.0, 2.0, 3.0]})
118
119Instructs the spike generator to generate events at 1.0, 2.0, and
1203.0 milliseconds, relative to the device-timer origin.
121
122Example:
123
124Assume that NEST works with default resolution (step size) of 0.1 ms
125and default tic length of 0.001 ms. Then, spikes times not falling
126onto the grid will be handled as follows for different option settings:
127
128::
129
130 nest.Create("spike_generator",
131 params={"spike_times": [1.0, 1.9999, 3.0001]})
132
133---> spikes at steps 10 (==1.0 ms), 20 (==2.0 ms) and 30 (==3.0 ms)
134
135::
136
137 nest.Create("spike_generator",
138 params={"spike_times": [1.0, 1.05, 3.0001]})
139
140---> **Error!** Spike time 1.05 not within tic/2 of step
141
142
143::
144
145 nest.Create("spike_generator",
146 params={"spike_times": [1.0, 1.05, 3.0001],
147 "allow_offgrid_times": True})
148
149---> spikes at steps 10, 11 (mid-step time rounded up),
150 30 (time within tic/2 of step moved to step)
151
152::
153
154 nest.Create("spike_generator",
155 params={"spike_times": [1.0, 1.05, 3.0001],
156 "precise_times": True})
157
158---> spikes at step 10, offset 0.0; step 11, offset -0.05;
159 step 31, offset -0.0999
160
161Assume we have simulated 10.0 ms and simulation time is thus 10.0 (step
162100). Then, any spike times set at this time must be later than step 100.
163
164::
165
166 nest.Create("spike_generator",
167 params={"spike_times": [10.0001]})
168
169---> spike time is within tic/2 of step 100, rounded down to 100 thus
170 not in the future; **spike will not be emitted**
171
172::
173
174 nest.Create("spike_generator",
175 params={"spike_times": [10.0001],
176 "precise_times": True})
177
178---> spike at step 101, offset -0.0999 is in the future
179
180::
181
182 nest.Create("spike_generator",
183 params={"spike_times": [10.0001, 11.0001],
184 "shift_now_spikes": True})
185
186---> spike at step 101, spike shifted into the future, and spike at step
187 110, not shifted, since it is in the future anyways
188
189.. include:: ../models/stimulation_device.rst
190
191spike_times
192 List of spike times in ms.
193
194spike_weights
195 List of corresponding spike weights, the unit depends on the receiver.
196 (e.g., nS for conductance-based neurons or pA for current based ones)
197
198spike_multiplicities
199 List of multiplicities of spikes, same length as spike_times; mostly
200 for debugging.
201
202precise_times
203 See above.
204
205allow_offgrid_times
206 See above.
207
208shift_now_spikes
209 See above.
210
211Set spike times from a stimulation backend
212~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213
214The spike times for this stimulation device can be updated with input
215coming from a stimulation backend. The data structure used for the
216update holds just an array of spike times in ms.
217
218Sends
219+++++
220
221SpikeEvent
222
223See also
224++++++++
225
226poisson_generator, spike_train_injector
227
228
229Examples using this model
230+++++++++++++++++++++++++
231
232.. listexamples:: spike_generator
233
234EndUserDocs
235*/
236void register_spike_generator( const std::string& name );
237
239{
240
241public:
244
245 size_t send_test_event( Node&, size_t, synindex, bool ) override;
246 void get_status( Dictionary& ) const override;
247 void set_status( const Dictionary& ) override;
248
249 StimulationDevice::Type get_type() const override;
250 void set_data_from_stimulation_backend( std::vector< double >& input_spikes ) override;
251
252
258 using Node::event_hook;
259 using Node::sends_signal;
260
261 void event_hook( DSSpikeEvent& ) override;
262
264 sends_signal() const override
265 {
266 return ALL;
267 }
268
269private:
270 void init_state_() override;
271 void init_buffers_() override;
272 void pre_run_hook() override;
273
274 void update( Time const&, const long, const long ) override;
275
276 // ------------------------------------------------------------
277
278 struct State_
279 {
280 State_();
281 size_t position_;
282 };
283
284 // ------------------------------------------------------------
285
287 {
289 std::vector< Time > spike_stamps_;
290
292 std::vector< double > spike_offsets_;
293
294 std::vector< double > spike_weights_;
295
296 std::vector< long > spike_multiplicities_;
297
300
303
306
307 Parameters_();
308 Parameters_( const Parameters_& ) = default;
309 Parameters_& operator=( const Parameters_& ) = default;
310
311 void get( Dictionary& ) const;
312
319 void set( const Dictionary&, State_&, const Time&, const Time&, Node* node );
320
328 void assert_valid_spike_time_and_insert_( double, const Time&, const Time& );
329 };
330
331 // ------------------------------------------------------------
332
335};
336
337inline size_t
338spike_generator::send_test_event( Node& target, size_t receptor_type, synindex syn_id, bool dummy_target )
339{
340 enforce_single_syn_type( syn_id );
341
342 if ( dummy_target )
343 {
344 DSSpikeEvent e;
345 e.set_sender( *this );
346 return target.handles_test_event( e, receptor_type );
347 }
348 else
349 {
350 SpikeEvent e;
351 e.set_sender( *this );
352 return target.handles_test_event( e, receptor_type );
353 }
354}
355
356inline void
362
363inline void
365{
366 Parameters_ ptmp = P_; // temporary copy in case of errors
367
368 // To detect "now" spikes and shift them, we need the origin. In case
369 // it is set in this call, we need to extract it explicitly here.
370 Time origin;
371 double v;
372 if ( d.update_value( names::origin, v ) )
373 {
374 origin = Time::ms( v );
375 }
376 else
377 {
379 }
380
381 // throws if BadProperty
382 ptmp.set( d, S_, origin, kernel().simulation_manager.get_time(), this );
383
384 // We now know that ptmp is consistent. We do not write it back
385 // to P_ before we are also sure that the properties to be set
386 // in the parent class are internally consistent.
388
389 // if we get here, temporary contains consistent set of properties
390 P_ = ptmp;
391}
392
398
399} // namespace nest
400
401#endif /* #ifndef SPIKE_GENERATOR_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
"Callback request event" for use in Device.
Definition event.h:521
Time const & get_origin() const
Definition device.h:195
Base class for all NEST network objects.
Definition node.h:99
virtual void event_hook(DSSpikeEvent &)
Modify Event object parameters during event delivery.
Definition node.cpp:586
virtual SignalType sends_signal() const
Definition node.h:963
Event for spike information.
Definition event.h:418
Base class for common properties of StimulationDevices.
Definition stimulation_device.h:154
void enforce_single_syn_type(synindex)
Throws IllegalConnection if synapse id differs from initial synapse id.
Definition stimulation_device.cpp:62
Type
Device type.
Definition stimulation_device.h:187
@ SPIKE_GENERATOR
Definition stimulation_device.h:189
void set_status(const Dictionary &) override
Change properties of the node according to the entries in the dictionary.
Definition stimulation_device.cpp:125
void get_status(Dictionary &d) const override
Export properties of the node by setting entries in the status dictionary.
Definition stimulation_device.cpp:168
Definition nest_time.h:135
Definition spike_generator.h:239
void update(Time const &, const long, const long) override
Advance the state of the node in time through the given interval.
Definition spike_generator.cpp:319
Parameters_ P_
Definition spike_generator.h:333
void pre_run_hook() override
Re-calculate dependent parameters of the node.
Definition spike_generator.cpp:309
spike_generator()
Definition spike_generator.cpp:277
void event_hook(DSSpikeEvent &) override
Modify Event object parameters during event delivery.
Definition spike_generator.cpp:389
void get_status(Dictionary &) const override
Export properties of the node by setting entries in the status dictionary.
Definition spike_generator.h:357
void init_state_() override
Configure state variables depending on runtime information.
Definition spike_generator.cpp:297
StimulationDevice::Type get_type() const override
Definition spike_generator.h:394
void set_status(const Dictionary &) override
Change properties of the node according to the entries in the dictionary.
Definition spike_generator.h:364
void init_buffers_() override
Configure persistent internal data structures.
Definition spike_generator.cpp:303
void set_data_from_stimulation_backend(std::vector< double > &input_spikes) override
Definition spike_generator.cpp:401
State_ S_
Definition spike_generator.h:334
SignalType sends_signal() const override
Definition spike_generator.h:264
size_t send_test_event(Node &, size_t, synindex, bool) override
Send an event to the receiving_node passed as an argument.
Definition spike_generator.h:338
const std::string origin("origin")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
KernelManager & kernel()
Definition kernel_manager.h:311
void register_spike_generator(const std::string &name)
Definition spike_generator.cpp:38
SignalType
enum type of signal conveyed by spike events of a node.
Definition nest_types.h:165
@ ALL
Definition nest_types.h:169
size_t synindex
For enumerations of synapse types.
Definition nest_types.h:115
Definition nest_time.h:255
Definition spike_generator.h:287
Parameters_()
Sets default parameter values.
Definition spike_generator.cpp:47
void get(Dictionary &) const
Store current values in dictionary.
Definition spike_generator.cpp:64
std::vector< long > spike_multiplicities_
Spike multiplicity.
Definition spike_generator.h:296
Parameters_(const Parameters_ &)=default
bool precise_times_
Interpret spike times as precise, i.e. send as step and offset.
Definition spike_generator.h:299
std::vector< Time > spike_stamps_
Spike time stamp as Time, rel to origin_.
Definition spike_generator.h:289
void set(const Dictionary &, State_ &, const Time &, const Time &, Node *node)
Set values from dictionary.
Definition spike_generator.cpp:152
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:87
std::vector< double > spike_weights_
Spike weights as double.
Definition spike_generator.h:294
Parameters_ & operator=(const Parameters_ &)=default
bool shift_now_spikes_
Shift spike times at present to next step.
Definition spike_generator.h:305
bool allow_offgrid_times_
Allow and round up spikes not on steps; irrelevant if precise_times_.
Definition spike_generator.h:302
std::vector< double > spike_offsets_
Spike time offset, if using precise_times_.
Definition spike_generator.h:292
Definition spike_generator.h:279
State_()
Definition spike_generator.cpp:267
size_t position_
index of next spike to deliver
Definition spike_generator.h:281