NEST main@caf0ae8
 
Loading...
Searching...
No Matches
spike_train_injector.h
Go to the documentation of this file.
1/*
2 * spike_train_injector.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_TRAIN_INJECTOR_H
24#define SPIKE_TRAIN_INJECTOR_H
25
26// C++ includes:
27#include <vector>
28
29// Includes from nestkernel:
30#include "connection.h"
31#include "device.h"
32#include "event.h"
33#include "nest_time.h"
34#include "nest_types.h"
35#include "node.h"
36
37namespace nest
38{
39
40/* BeginUserDocs: neuron, device, spike, generator
41
42Short description
43+++++++++++++++++
44
45Neuron that emits prescribed spike trains.
46
47Description
48+++++++++++
49
50The spike train injector neuron emits spikes at prescribed spike times
51which are given as an array. The neuron does not allow incoming connections
52and is thus not able to process incoming spikes or currents.
53
54.. note::
55
56 ``spike_train_injector`` is recommended if the spike trains have a similar
57 rate to regular neurons. For very high rates, use
58 :doc:`spike generator </models/spike_generator>`.
59
60Spike times are given in milliseconds as an array. The `spike_times` array
61must be sorted with the earliest spike first. All spike times must be strictly
62in the future. Trying to set a spike time in the past or at the current time
63step will cause a NEST error. Setting a spike time of 0.0 will also result
64in an error.
65
66Multiple occurrences of the same time indicate that more than one event is to
67be generated at this particular time.
68
69The spike generator supports spike times that do not coincide with a time
70step, that is, are not falling on the grid defined by the simulation resolution.
71Spike times that do not coincide with a step are handled with one of three
72options (see examples below):
73
74Option 1: ``precise_times`` default: false
75
76If false, spike times will be rounded to simulation steps, i.e., multiples
77of the resolution. The rounding is controlled by the two other flags. If true,
78spike times will not be rounded but represented exactly as a combination of
79step and offset. This should only be used if all neurons receiving the spike
80train can handle precise timing information. In this case, the other two
81options are ignored.
82
83Option 2: ``allow_offgrid_times`` default: false
84
85If false, spike times will be rounded to the nearest step if they are less
86than tic/2 from the step, otherwise NEST reports an error. If true, spike
87times are rounded to the nearest step if within tic/2 from the step, otherwise
88they are rounded up to the *end* of the step. This setting has no effect if
89``precise_times`` is `true`.
90
91Option 3: ``shift_now_spikes`` default: false
92
93This option is mainly for use by the PyNN-NEST interface. If false, spike
94times rounded down to the current point in time will be considered in the past
95and ignored. If true, spike times that are rounded down to the current time
96step are shifted one time step into the future.
97
98Note that ``GetStatus`` will report the spike times that the spike_generator
99will actually use, i.e., for grid-based simulation the spike times rounded
100to the appropriate point on the time grid. This means that ``GetStatus`` may
101return different `spike_times` values at different resolutions.
102
103Example:
104
105::
106
107 nest.Create("spike_train_injector",
108 params={"spike_times": [1.0, 2.0, 3.0]})
109
110Instructs the spike train injector neuron to emit events at 1.0, 2.0,
111and 3.0 milliseconds, relative to the timer origin.
112
113Example:
114
115Assume that NEST works with default resolution (step size) of 0.1 ms
116and default tic length of 0.001 ms. Then, spikes times not falling
117onto the grid will be handled as follows for different option settings:
118
119::
120
121 nest.Create("spike_train_injector",
122 params={"spike_times": [1.0, 1.9999, 3.0001]})
123
124---> spikes at steps 10 (==1.0 ms), 20 (==2.0 ms) and 30 (==3.0 ms)
125
126::
127
128 nest.Create("spike_train_injector",
129 params={"spike_times": [1.0, 1.05, 3.0001]})
130
131---> **Error!** Spike time 1.05 not within tic/2 of step
132
133
134::
135
136 nest.Create("spike_train_injector",
137 params={"spike_times": [1.0, 1.05, 3.0001],
138 "allow_offgrid_times": True})
139
140---> spikes at steps 10, 11 (mid-step time rounded up),
141 30 (time within tic/2 of step moved to step)
142
143::
144
145 nest.Create("spike_train_injector",
146 params={"spike_times": [1.0, 1.05, 3.0001],
147 "precise_times": True})
148
149---> spikes at step 10, offset 0.0; step 11, offset -0.05;
150 step 31, offset -0.0999
151
152Assume we have simulated 10.0 ms and simulation time is thus 10.0 (step
153100). Then, any spike times set at this time must be later than step 100.
154
155::
156
157 nest.Create("spike_train_injector",
158 params={"spike_times": [10.0001]})
159
160---> spike time is within tic/2 of step 100, rounded down to 100 thus
161 not in the future; **spike will not be emitted**
162
163::
164
165 nest.Create("spike_train_injector",
166 params={"spike_times": [10.0001],
167 "precise_times": True})
168
169---> spike at step 101, offset -0.0999 is in the future
170
171::
172
173 nest.Create("spike_train_injector",
174 params={"spike_times": [10.0001, 11.0001],
175 "shift_now_spikes": True})
176
177---> spike at step 101, spike shifted into the future, and spike at step
178 110, not shifted, since it is in the future anyways
179
180
181Parameters
182++++++++++
183
184origin
185 A positive floating point number (default : `0.0`) used as the
186 reference time in ms for `start` and `stop`.
187
188start
189 A positive floating point number (default: `0.0`) specifying the
190 activation time in ms, relative to `origin`.
191
192stop
193 A floating point number (default: `infinity`) specifying the
194 deactivation time in ms, relative to `origin`. The value of `stop`
195 must be greater than or equal to `start`.
196
197spike_times
198 List of spike times in ms.
199
200spike_multiplicities
201 List of multiplicities of spikes, same length as spike_times; mostly
202 for debugging.
203
204precise_times
205 See above.
206
207allow_offgrid_times
208 See above.
209
210shift_now_spikes
211 See above.
212
213Receives
214++++++++
215
216None
217
218Sends
219+++++
220
221SpikeEvent
222
223See also
224++++++++
225
226spike_generator
227
228Examples using this model
229+++++++++++++++++++++++++
230
231.. listexamples:: spike_train_injector
232
233EndUserDocs */
234
243void register_spike_train_injector( const std::string& name );
244
245class spike_train_injector : public Node, public Device
246{
247
248public:
251
252 size_t send_test_event( Node&, size_t, synindex, bool ) override;
253 void get_status( Dictionary& ) const override;
254 void set_status( const Dictionary& ) override;
255 bool is_active( const Time& ) const override;
256
257 bool
258 is_off_grid() const override
259 {
260 return P_.precise_times_;
261 }
262
263 void set_data( std::vector< double >& input_spikes );
264
265private:
266 void init_state_() override;
267 void init_buffers_() override;
268 void pre_run_hook() override;
269
270 void update( Time const&, const long, const long ) override;
271
275 struct State_
276 {
277 State_();
278 size_t position_;
279 };
280
285 {
287 std::vector< Time > spike_stamps_;
288
290 std::vector< double > spike_offsets_;
291
293 std::vector< long > spike_multiplicities_;
294
297
300
303
304 Parameters_();
305 Parameters_( const Parameters_& ) = default;
306 Parameters_& operator=( const Parameters_& ) = default;
307
308 void get( Dictionary& ) const;
309
316 void set( const Dictionary&, State_&, const Time&, const Time&, Node* node );
317
325 void assert_valid_spike_time_and_insert_( double, const Time&, const Time& );
326 };
327
330};
331
332
333inline size_t
334spike_train_injector::send_test_event( Node& target, size_t receptor_type, synindex, bool )
335{
336 SpikeEvent e;
337 e.set_sender( *this );
338 return target.handles_test_event( e, receptor_type );
339}
340
341
342inline void
344{
345 P_.get( d );
347}
348
349
350inline void
352{
353 Parameters_ ptmp = P_; // temporary copy in case of errors
354
355 // To detect "now" spikes and shift them, we need the origin. In case
356 // it is set in this call, we need to extract it explicitly here.
357 Time origin;
358 double v;
359 if ( d.update_value( names::origin, v ) )
360 {
361 origin = Time::ms( v );
362 }
363 else
364 {
365 origin = Device::get_origin();
366 }
367
368 // throws if BadProperty
369 ptmp.set( d, S_, origin, kernel().simulation_manager.get_time(), this );
370
371 // We now know that ptmp is consistent. We do not write it back
372 // to P_ before we are also sure that the properties to be set
373 // in the parent class are internally consistent.
375
376 // if we get here, temporary contains consistent set of properties
377 P_ = ptmp;
378}
379
380} // namespace
381
382#endif // SPIKE_TRAIN_INJECTOR_H
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Class implementing common interface and properties common for all devices.
Definition device.h:60
virtual void get_status(Dictionary &) const
Definition device.h:179
Time const & get_origin() const
Definition device.h:195
virtual void set_status(const Dictionary &)
Definition device.h:185
Base class for all NEST network objects.
Definition node.h:99
Event for spike information.
Definition event.h:418
Definition nest_time.h:135
Definition spike_train_injector.h:246
void pre_run_hook() override
Re-calculate dependent parameters of the node.
Definition spike_train_injector.cpp:291
void init_state_() override
Configure state variables depending on runtime information.
Definition spike_train_injector.cpp:280
size_t send_test_event(Node &, size_t, synindex, bool) override
Send an event to the receiving_node passed as an argument.
Definition spike_train_injector.h:334
void get_status(Dictionary &) const override
Export properties of the node by setting entries in the status dictionary.
Definition spike_train_injector.h:343
bool is_off_grid() const override
Returns true if the node sends/receives off-grid events.
Definition spike_train_injector.h:258
spike_train_injector()
Definition spike_train_injector.cpp:258
void init_buffers_() override
Configure persistent internal data structures.
Definition spike_train_injector.cpp:286
void update(Time const &, const long, const long) override
Advance the state of the node in time through the given interval.
Definition spike_train_injector.cpp:326
void set_status(const Dictionary &) override
Change properties of the node according to the entries in the dictionary.
Definition spike_train_injector.h:351
bool is_active(const Time &) const override
Returns true if the device is active at the given time stamp.
Definition spike_train_injector.cpp:319
void set_data(std::vector< double > &input_spikes)
State_ S_
Definition spike_train_injector.h:328
Parameters_ P_
Definition spike_train_injector.h:329
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_train_injector(const std::string &name)
Spike train injector node.
Definition spike_train_injector.cpp:39
size_t synindex
For enumerations of synapse types.
Definition nest_types.h:115
Declarations for base class Node.
Definition nest_time.h:255
Independent parameters of the model.
Definition spike_train_injector.h:285
std::vector< double > spike_offsets_
Spike time offset, if using precise_times_.
Definition spike_train_injector.h:290
Parameters_()
Sets default parameter values.
Definition spike_train_injector.cpp:49
bool precise_times_
Interpret spike times as precise, i.e. send as step and offset.
Definition spike_train_injector.h:296
void set(const Dictionary &, State_ &, const Time &, const Time &, Node *node)
Set values from dictionary.
Definition spike_train_injector.cpp:152
std::vector< long > spike_multiplicities_
Spike multiplicity.
Definition spike_train_injector.h:293
std::vector< Time > spike_stamps_
Spike time stamp as Time, rel to origin_.
Definition spike_train_injector.h:287
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_train_injector.cpp:87
bool shift_now_spikes_
Shift spike times at present to next step.
Definition spike_train_injector.h:302
void get(Dictionary &) const
Store current values in dictionary.
Definition spike_train_injector.cpp:65
Parameters_ & operator=(const Parameters_ &)=default
bool allow_offgrid_times_
Allow and round up spikes not on steps; irrelevant if precise_times_.
Definition spike_train_injector.h:299
Parameters_(const Parameters_ &)=default
State variables of the model.
Definition spike_train_injector.h:276
State_()
Definition spike_train_injector.cpp:248
size_t position_
index of next spike to deliver
Definition spike_train_injector.h:278