NEST main@caf0ae8
 
Loading...
Searching...
No Matches
noise_generator.h
Go to the documentation of this file.
1/*
2 * noise_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 NOISE_GENERATOR_H
24#define NOISE_GENERATOR_H
25
26// C++ includes:
27#include <vector>
28
29// Includes from nestkernel:
30#include "connection.h"
31#include "device_node.h"
32#include "event.h"
33#include "nest_timeconverter.h"
34#include "nest_types.h"
35#include "random_generators.h"
36#include "stimulation_device.h"
38
39namespace nest
40{
41
42/* BeginUserDocs: device, generator
43
44Short description
45+++++++++++++++++
46
47Generate a Gaussian white noise current
48
49Description
50+++++++++++
51
52The `noise_generator` can be used to inject a Gaussian "white" noise current into a node.
53
54The current is not truly white, but a piecewise constant current with a Gaussian distributed
55amplitude with mean :math:`\mu` and standard deviation :math:`\sigma`. The current changes at
56a user-defined interval :math:`\delta` and is given by
57
58.. math::
59
60 I(t) = \mu + N_j \sigma \quad \text{for} \quad t_0 + j \delta < t \leq t_0 + (j+1) \delta \;,
61
62where :math:`N_j` are Gaussian random numbers with unit standard deviation and :math:`t_0` is
63the device onset time.
64
65Additionally a sinusodially modulated term can be added to the standard
66deviation of the noise:
67
68.. math::
69
70 I(t) = \mu + N_j \sqrt{\sigma^2 + \sigma_{\text{mod}}^2 \sin(\omega t + \phi)}
71 \quad \text{for} \quad t_0 + j \delta < t \leq t_0 + (j+1) \delta \;.
72
73The effect of the noise current on a neuron depends on the switching interval :math:`\delta`.
74For a leaky integrate-and-fire neuron with time constant :math:`\tau_m` and capacitance
75:math:`C_m`, the variance of the membrane potential is given by
76
77.. math::
78
79 \Sigma^2 = \frac{\delta \tau_m \sigma^2}{2 C_m^2}
80
81for :math:`\delta \ll \tau_m`. For details, see the `noise generator notebook
82<../model_details/noise_generator.ipynb>`_.
83
84All targets of a noise generator receive different currents, but the currents for all
85targets change at the same points in time. The interval :math:`\delta` between
86changes must be a multiple of the time step.
87
88.. admonition:: Recording the generated current
89
90 You can use a :doc:`multimeter <multimeter>` to record the average current sent to all targets for each time step
91 if simulating on a single thread; multiple MPI processes with one thread each also work. In this case,
92 the recording interval of the multimeter should be equal to the simulation resolution to avoid confusing effects
93 due to offset or drift between the recording times of the multimeter and the switching times of the
94 noise generator. In multi-threaded mode, recording of noise currents is prohibited for technical reasons.
95
96
97.. include:: ../models/stimulation_device.rst
98
99mean
100 The mean value :math:`\mu` of the noise current (pA)
101
102std
103 The standard deviation :math:`\sigma` of the noise current (pA)
104
105dt
106 The interval :math:`\delta` between changes in current (ms; default: 10 * resolution)
107
108std_mod
109 The modulation :math:`\sigma_{\text{mod}}` of the standard deviation of the noise current (pA)
110
111frequency
112 The frequency of the sine modulation (Hz)
113
114phase
115 The phase of sine modulation (0–360 deg)
116
117
118Setting parameters from a stimulation backend
119~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120
121The parameters in this stimulation device can be updated with input
122coming from a stimulation backend. The data structure used for the
123update holds one value for each of the parameters mentioned above.
124The indexing is as follows:
125
126 0. mean
127 1. std
128 2. std_mod
129 3. frequency
130 4. phase
131
132Sends
133+++++
134
135CurrentEvent
136
137See also
138++++++++
139
140step_current_generator
141
142Examples using this model
143+++++++++++++++++++++++++
144
145.. listexamples:: noise_generator
146
147EndUserDocs */
148
149void register_noise_generator( const std::string& name );
150
152{
153
154public:
157
158
160 bool local_receiver() const override;
161
167 using Node::event_hook;
168 using Node::handle;
170 using Node::sends_signal;
171
172 size_t send_test_event( Node&, size_t, synindex, bool ) override;
173
174 SignalType sends_signal() const override;
175
176 void handle( DataLoggingRequest& ) override;
177
178 size_t handles_test_event( DataLoggingRequest&, size_t ) override;
179
180 void get_status( Dictionary& ) const override;
181 void set_status( const Dictionary& ) override;
182
183 void calibrate_time( const TimeConverter& tc ) override;
184
185 StimulationDevice::Type get_type() const override;
186 void set_data_from_stimulation_backend( std::vector< double >& input_param ) override;
187
188private:
189 void init_state_() override;
190 void init_buffers_() override;
191
196 void pre_run_hook() override;
197
198 void update( Time const&, const long, const long ) override;
199 void event_hook( DSCurrentEvent& ) override;
200
201 // ------------------------------------------------------------
202
203 typedef std::vector< double > AmpVec_;
204
209 {
210 double mean_;
211 double std_;
212 double std_mod_;
213 double freq_;
214 double phi_deg_;
216
224
225 Parameters_();
226 Parameters_( const Parameters_& );
227 Parameters_& operator=( const Parameters_& p );
228
229 void get( Dictionary& ) const;
231 void set( const Dictionary&, const noise_generator&, Node* node );
232
234 };
235
236 // ------------------------------------------------------------
237
238 struct State_
239 {
240 double y_0_;
241 double y_1_;
242 double I_avg_;
244
245 State_();
246
247 void get( Dictionary& ) const;
248 };
249
250 // ------------------------------------------------------------
251
252 // The next two classes need to be friends to access the State_ class/member
253 friend class RecordablesMap< noise_generator >;
254 friend class UniversalDataLogger< noise_generator >;
255
256 // ------------------------------------------------------------
257
266
267 // ------------------------------------------------------------
268
270 {
272
274 double omega_;
275 double phi_rad_;
276
277 // The exact integration matrix
278 double A_00_;
279 double A_01_;
280 double A_10_;
281 double A_11_;
282 };
283
284 double
286 {
287 return S_.I_avg_;
288 }
289
290 // ------------------------------------------------------------
291
293
298};
299
300inline size_t
302{
303 if ( kernel().vp_manager.get_num_threads() > 1 )
304 {
305 throw KernelException( "Recording from a noise_generator is only possible in single-threaded mode." );
306 }
307
308 if ( receptor_type != 0 )
309 {
310 throw UnknownReceptorType( receptor_type, get_name() );
311 }
312 return B_.logger_.connect_logging_device( dlr, recordablesMap_ );
313}
314
315inline void
317{
318 P_.get( d );
319 S_.get( d );
321
322 d[ names::recordables ] = recordablesMap_.get_list();
323}
324
325inline void
327{
328 Parameters_ ptmp = P_; // temporary copy in case of errors
329 ptmp.num_targets_ = P_.num_targets_; // Copy Constr. does not copy connections
330 ptmp.set( d, *this, this ); // throws if BadProperty
331
332 // We now know that ptmp is consistent. We do not write it back
333 // to P_ before we are also sure that the properties to be set
334 // in the parent class are internally consistent.
336
337 // if we get here, temporaries contain consistent set of properties
338 P_ = ptmp;
340}
341
342inline SignalType
344{
345 return ALL;
346}
347
348inline bool
350{
351 return true;
352}
353
359
360inline Time
365
366} // namespace
367
368#endif // NOISE_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:615
Request data to be logged/logged data to be sent.
Definition event.h:636
Base class for all Kernel exceptions.
Definition exceptions.h:65
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
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
Type
Device type.
Definition stimulation_device.h:187
@ CURRENT_GENERATOR
Definition stimulation_device.h:188
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
Class to convert times from one representation to another.
Definition nest_timeconverter.h:42
Definition nest_time.h:135
static Time get_resolution()
Definition nest_time.h:325
Exception to be thrown if the specified receptor type does not exist in the node.
Definition exceptions.h:417
Definition noise_generator.h:152
void handle(DataLoggingRequest &) override
Handler for universal data logging request.
Definition noise_generator.cpp:357
StimulationDevice::Type get_type() const override
Definition noise_generator.h:355
Buffers_ B_
Definition noise_generator.h:296
noise_generator()
Definition noise_generator.cpp:187
friend class UniversalDataLogger< noise_generator >
Definition noise_generator.h:254
bool local_receiver() const override
Allow multimeter to connect to local instances.
Definition noise_generator.h:349
void update(Time const &, const long, const long) override
Advance the state of the node in time through the given interval.
Definition noise_generator.cpp:293
void init_buffers_() override
Configure persistent internal data structures.
Definition noise_generator.cpp:216
void get_status(Dictionary &) const override
Export properties of the node by setting entries in the status dictionary.
Definition noise_generator.h:316
void set_data_from_stimulation_backend(std::vector< double > &input_param) override
Definition noise_generator.cpp:367
void init_state_() override
Configure state variables depending on runtime information.
Definition noise_generator.cpp:210
size_t handles_test_event(DataLoggingRequest &, size_t) override
Definition noise_generator.h:301
Parameters_ P_
Definition noise_generator.h:294
void set_status(const Dictionary &) override
Change properties of the node according to the entries in the dictionary.
Definition noise_generator.h:326
void calibrate_time(const TimeConverter &tc) override
Re-calculate time-based properties of the node.
Definition noise_generator.cpp:395
void pre_run_hook() override
Recalculates parameters and forces reinitialization of amplitudes if number of targets has changed.
Definition noise_generator.cpp:227
State_ S_
Definition noise_generator.h:295
static RecordablesMap< noise_generator > recordablesMap_
Definition noise_generator.h:292
std::vector< double > AmpVec_
Definition noise_generator.h:203
double get_I_avg_() const
Definition noise_generator.h:285
Variables_ V_
Definition noise_generator.h:297
void event_hook(DSCurrentEvent &) override
Definition noise_generator.cpp:344
SignalType sends_signal() const override
Definition noise_generator.h:343
size_t send_test_event(Node &, size_t, synindex, bool) override
Send an event to the receiving_node passed as an argument.
Definition noise_generator.cpp:266
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 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_noise_generator(const std::string &name)
Definition noise_generator.cpp:41
KernelManager & kernel()
Definition kernel_manager.h:311
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 noise_generator.h:259
long next_step_
time step of next change in current
Definition noise_generator.h:260
AmpVec_ amps_
amplitudes, one per target
Definition noise_generator.h:261
UniversalDataLogger< noise_generator > logger_
Definition noise_generator.h:264
Store independent parameters of the model.
Definition noise_generator.h:209
double mean_
mean current, in pA
Definition noise_generator.h:210
double std_
standard deviation of current, in pA
Definition noise_generator.h:211
double std_mod_
standard deviation of current modulation, in pA
Definition noise_generator.h:212
Time get_default_dt()
Definition noise_generator.h:361
void get(Dictionary &) const
Store current values in dictionary.
Definition noise_generator.cpp:131
Parameters_()
Sets default parameter values.
Definition noise_generator.cpp:59
double freq_
Standard frequency in Hz.
Definition noise_generator.h:213
size_t num_targets_
Number of targets.
Definition noise_generator.h:223
Time dt_
time interval between updates
Definition noise_generator.h:215
double phi_deg_
Phase of sinusodial noise modulation (0-360 deg)
Definition noise_generator.h:214
Parameters_ & operator=(const Parameters_ &p)
Definition noise_generator.cpp:90
void set(const Dictionary &, const noise_generator &, Node *node)
Set values from dictionary.
Definition noise_generator.cpp:149
Definition noise_generator.h:239
double I_avg_
Average of instantaneous currents computed Used for recording current.
Definition noise_generator.h:242
double y_1_
Definition noise_generator.h:241
double y_0_
Definition noise_generator.h:240
void get(Dictionary &) const
Store current values in dictionary.
Definition noise_generator.cpp:142
State_()
Sets default parameter values.
Definition noise_generator.cpp:107
Definition noise_generator.h:270
double A_11_
Definition noise_generator.h:281
double A_10_
Definition noise_generator.h:280
double A_00_
Definition noise_generator.h:278
double phi_rad_
phase of sine current (0-2Pi rad)
Definition noise_generator.h:275
double A_01_
Definition noise_generator.h:279
double omega_
frequency [radian/s]
Definition noise_generator.h:274
normal_distribution normal_dist_
normal distribution
Definition noise_generator.h:271
long dt_steps_
update interval in steps
Definition noise_generator.h:273