NEST main@caf0ae8
 
Loading...
Searching...
No Matches
step_rate_generator.h
Go to the documentation of this file.
1/*
2 * step_rate_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
24#ifndef STEP_RATE_GENERATOR_H
25#define STEP_RATE_GENERATOR_H
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_types.h"
35#include "ring_buffer.h"
36#include "stimulation_device.h"
38
39namespace nest
40{
41
42/* BeginUserDocs: device, generator, rate
43
44Short description
45+++++++++++++++++
46
47Provide a piecewise constant input rate
48
49Description
50+++++++++++
51
52The ``rate_generator`` provides a piecewise constant rate input to the
53connected rate unit(s). Please note that this input is handled in the same
54way as input from any other rate unit, that is, it is processed by the input
55function of the receiving rate unit. The amplitude of the rate is changed
56at the specified times. The unit of the rate is spks/s.
57
58If ``allow_offgrid_times`` is false, times will be rounded to the nearest
59grid point if they are less than tic/2 from the grid point, otherwise
60NEST reports an error. If true, times are rounded to the nearest grid
61point if within tic/2 from the grid point, otherwise they are rounded
62up to the *end* of the grid point.
63
64Times of amplitude changes must be strictly increasing after conversion
65to simulation time steps. The option ``allow_offgrid_times`` may be
66useful, for example, if you are using randomized times for rate changes
67which typically would not fall onto simulation time steps.
68
69.. include:: ../models/stimulation_device.rst
70
71amplitude_times
72 Times at which current changes (list of ms)
73
74amplitude_values
75 Amplitudes of step current current (list of pA)
76
77allow_offgrid_times
78 Default false
79
80Set parameters from a stimulation backend
81~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82
83The parameters in this stimulation device can be updated with input
84coming from a stimulation backend.
85
86The data structure used for the update holds pairs of values in the form
87
88 [ (amplitude_times, amplitude_values), (amplitude_times, amplitude_values), ... ].
89
90Thus, the size of the data for the step_rate_generator needs to be even.
91
92Sends
93+++++
94
95DelayedRateConnectionEvent
96
97See also
98++++++++
99
100step_current_generator
101
102Examples using this model
103+++++++++++++++++++++++++
104
105.. listexamples:: step_rate_generator
106
107EndUserDocs */
108
109void register_step_rate_generator( const std::string& name );
110
112{
113
114public:
117
118 // port send_test_event( Node&, rport, synindex, bool );
120
121 using Node::handle;
124
125 void handle( DataLoggingRequest& ) override;
126
127 size_t send_test_event( Node&, size_t, synindex, bool ) override;
128
129 size_t handles_test_event( DataLoggingRequest&, size_t ) override;
130
131 void get_status( Dictionary& ) const override;
132 void set_status( const Dictionary& ) override;
133
135 bool local_receiver() const override;
136
137 StimulationDevice::Type get_type() const override;
138 void set_data_from_stimulation_backend( std::vector< double >& input_param ) override;
139
140private:
141 void init_state_() override;
142 void init_buffers_() override;
143 void pre_run_hook() override;
144
145 void update( Time const&, const long, const long ) override;
146
147 struct Buffers_;
148
153 {
155 std::vector< Time > amp_time_stamps_;
156
158 std::vector< double > amp_values_;
159
162
163 Parameters_();
165 Parameters_( const Parameters_& );
166 Parameters_& operator=( const Parameters_& p );
167
168 void get( Dictionary& ) const;
170 void set( const Dictionary&, Buffers_&, Node* );
171
178 Time validate_time_( double, const Time& );
179 };
180
181 // ------------------------------------------------------------
182
183 struct State_
184 {
185 double rate_;
186
187 State_();
188 };
189
190 // ------------------------------------------------------------
191
192 // The next two classes need to be friends to access the State_ class/member
193 friend class RecordablesMap< step_rate_generator >;
194 friend class UniversalDataLogger< step_rate_generator >;
195
196 // ------------------------------------------------------------
197
207
208 // ------------------------------------------------------------
209
210 double
211 get_rate_() const
212 {
213 return S_.rate_;
214 }
215
216 // ------------------------------------------------------------
217
222};
223
224inline size_t
225step_rate_generator::send_test_event( Node& target, size_t receptor_type, synindex syn_id, bool )
226{
228
230 e.set_sender( *this );
231
232 return target.handles_test_event( e, receptor_type );
233}
234
235inline size_t
237{
238 if ( receptor_type != 0 )
239 {
240 throw UnknownReceptorType( receptor_type, get_name() );
241 }
242 return B_.logger_.connect_logging_device( dlr, recordablesMap_ );
243}
244
245inline void
247{
248 P_.get( d );
250
251 d[ names::recordables ] = recordablesMap_.get_list();
252}
253
254inline void
256{
257 Parameters_ ptmp = P_; // temporary copy in case of errors
258 ptmp.set( d, B_, this ); // throws if BadProperty
259
260 // We now know that ptmp is consistent. We do not write it back
261 // to P_ before we are also sure that the properties to be set
262 // in the parent class are internally consistent.
264
265 // if we get here, temporaries contain consistent set of properties
266 P_ = ptmp;
267}
268
270inline bool
272{
273 return true;
274}
275
281
282} // namespace
283
284#endif /* #ifndef STEP_RATE_GENERATOR_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Request data to be logged/logged data to be sent.
Definition event.h:636
Event for rate model connections with delay.
Definition secondary_event.h:331
Base class for all NEST network objects.
Definition node.h:99
std::string get_name() const
Return class name.
Definition node.cpp:105
Map names of recordables to data access functions.
Definition recordables_map.h:61
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
@ DELAYED_RATE_CONNECTION_GENERATOR
Definition stimulation_device.h:191
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
Exception to be thrown if the specified receptor type does not exist in the node.
Definition exceptions.h:417
Definition step_rate_generator.h:112
static RecordablesMap< step_rate_generator > recordablesMap_
Definition step_rate_generator.h:218
void set_data_from_stimulation_backend(std::vector< double > &input_param) override
Definition step_rate_generator.cpp:339
void init_buffers_() override
Configure persistent internal data structures.
Definition step_rate_generator.cpp:253
void update(Time const &, const long, const long) override
Advance the state of the node in time through the given interval.
Definition step_rate_generator.cpp:276
Parameters_ P_
Definition step_rate_generator.h:219
void init_state_() override
Configure state variables depending on runtime information.
Definition step_rate_generator.cpp:247
void pre_run_hook() override
Re-calculate dependent parameters of the node.
Definition step_rate_generator.cpp:263
size_t send_test_event(Node &, size_t, synindex, bool) override
Send an event to the receiving_node passed as an argument.
Definition step_rate_generator.h:225
void set_status(const Dictionary &) override
Change properties of the node according to the entries in the dictionary.
Definition step_rate_generator.h:255
double get_rate_() const
Definition step_rate_generator.h:211
friend class UniversalDataLogger< step_rate_generator >
Definition step_rate_generator.h:194
bool local_receiver() const override
Allow multimeter to connect to local instances.
Definition step_rate_generator.h:271
void handle(DataLoggingRequest &) override
Handler for universal data logging request.
Definition step_rate_generator.cpp:330
StimulationDevice::Type get_type() const override
Definition step_rate_generator.h:277
Buffers_ B_
Definition step_rate_generator.h:221
void get_status(Dictionary &) const override
Export properties of the node by setting entries in the status dictionary.
Definition step_rate_generator.h:246
size_t handles_test_event(DataLoggingRequest &, size_t) override
Definition step_rate_generator.h:236
void sends_secondary_event(DelayedRateConnectionEvent &) override
Required to check, if source neuron may send a SecondaryEvent.
Definition step_rate_generator.h:119
State_ S_
Definition step_rate_generator.h:220
step_rate_generator()
Definition step_rate_generator.cpp:224
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 sends_secondary_event(GapJunctionEvent &ge)
Required to check, if source neuron may send a SecondaryEvent.
Definition node.cpp:381
virtual void handle(SpikeEvent &e)
Handle incoming spike events.
Definition node.cpp:265
const std::string recordables("recordables")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
void register_step_rate_generator(const std::string &name)
Definition step_rate_generator.cpp:35
size_t synindex
For enumerations of synapse types.
Definition nest_types.h:115
Definition step_rate_generator.h:199
size_t idx_
index of current amplitude
Definition step_rate_generator.h:200
double amp_
current amplitude
Definition step_rate_generator.h:201
UniversalDataLogger< step_rate_generator > logger_
Definition step_rate_generator.h:205
Store independent parameters of the model.
Definition step_rate_generator.h:153
std::vector< Time > amp_time_stamps_
Times of amplitude changes.
Definition step_rate_generator.h:155
std::vector< double > amp_values_
Amplitude values activated at given times.
Definition step_rate_generator.h:158
Parameters_()
Sets default parameter values.
Definition step_rate_generator.cpp:53
bool allow_offgrid_amp_times_
Allow and round up amplitude times not on steps.
Definition step_rate_generator.h:161
void set(const Dictionary &, Buffers_ &, Node *)
Set values from dictionary.
Definition step_rate_generator.cpp:164
Parameters_ & operator=(const Parameters_ &p)
Definition step_rate_generator.cpp:68
Time validate_time_(double, const Time &)
Return time as Time object if valid, otherwise throw BadProperty.
Definition step_rate_generator.cpp:120
void get(Dictionary &) const
Store current values in dictionary.
Definition step_rate_generator.cpp:106
Parameters_(const Parameters_ &, Buffers_ &)
Definition step_rate_generator.h:184
State_()
Sets default parameter values.
Definition step_rate_generator.cpp:82
double rate_
Instantaneous rate value; used for recording current.
Definition step_rate_generator.h:185