NEST main@d22e9b2
 
Loading...
Searching...
No Matches
ou_noise_generator.h
Go to the documentation of this file.
1/*
2 * ou_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 OU_NOISE_GENERATOR_H
24#define OU_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
47Generates a temporally correlated noise current based on an Ornstein-Uhlenbeck process.
48
49Description
50+++++++++++
51
52The `ou_noise_generator` can be used to inject a temporally correlated noise current into a node.
53The current I(t) follows an Ornstein-Uhlenbeck (OU) process, which is described by the following stochastic differential
54equation:
55
56.. math::
57
58 dI = \frac{1}{\tau}(\mu - I)dt + \sigma_{stat} \sqrt{\frac{2}{\tau}} dW
59
60where:
61 - :math:`\mu` is the long-term mean of the process (`mean` parameter).
62 - :math:`\tau` is the time constant of the correlation (`tau` parameter).
63 - :math:`\sigma_{stat}` is the stationary standard deviation of the process (`std` parameter).
64 - :math:`dW` is a Wiener process (Gaussian white noise).
65
66The generator integrates this process at a user-defined interval `dt` and delivers the resulting current to its targets.
67A larger time constant :math:`\tau` results in a more slowly varying noise signal.
68
69All targets of a noise generator receive different, independent noise currents, but the currents for all targets are
70updated at the same points in time. The interval `dt` between updates must be a multiple of the simulation time step.
71
72.. admonition:: Recording the generated current
73
74 You can use a :doc:`multimeter <multimeter>` to record the average current sent to all targets for each time step if
75 simulating on a single thread; multiple MPI processes with one thread each also work. In this case, the recording
76 interval of the multimeter should be equal to the `dt` of the generator to avoid aliasing effects. In multi-threaded
77 mode, recording of noise currents is prohibited for technical reasons.
78
79
80.. include:: ../models/stimulation_device.rst
81
82mean
83 The mean value :math:`\mu` to which the process reverts (pA).
84
85std
86 The stationary standard deviation :math:`\sigma_{stat}` of the process (pA).
87
88tau
89 The correlation time constant :math:`\tau` of the process (ms).
90
91dt
92 The time interval between updates of the noise current (ms).
93
94
95Setting parameters from a stimulation backend
96~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97
98The parameters in this stimulation device can be updated with input
99coming from a stimulation backend. The data structure used for the
100update holds one value for each of the parameters mentioned above.
101The indexing is as follows:
102
103 0. mean
104 1. std
105 2. tau
106
107
108EndUserDocs */
109
110void register_ou_noise_generator( const std::string& name );
111
113{
114
115public:
118
120 bool local_receiver() const override;
121
127 using Node::event_hook;
128 using Node::handle;
130 using Node::sends_signal;
131
132 size_t send_test_event( Node&, size_t, synindex, bool ) override;
133
134 SignalType sends_signal() const override;
135
136 void handle( DataLoggingRequest& ) override;
137
138 size_t handles_test_event( DataLoggingRequest&, size_t ) override;
139
140 void get_status( Dictionary& ) const override;
141 void set_status( const Dictionary& ) override;
142
143 void calibrate_time( const TimeConverter& tc ) override;
144
145 StimulationDevice::Type get_type() const override;
146 void set_data_from_stimulation_backend( std::vector< double >& input_param ) override;
147
148private:
149 void init_state_() override;
150 void init_buffers_() override;
151
156 void pre_run_hook() override;
157
158 void update( Time const&, const long, const long ) override;
159 void event_hook( DSCurrentEvent& ) override;
160
161 // ------------------------------------------------------------
162
163 typedef std::vector< double > AmpVec_;
164
169 {
170 double mean_;
171 double std_;
172 double tau_;
174
182
183 Parameters_();
184 Parameters_( const Parameters_& );
185 Parameters_& operator=( const Parameters_& p );
186
187 void get( Dictionary& ) const;
189 void set( const Dictionary&, const ou_noise_generator&, Node* node );
190
192 };
193
194 // ------------------------------------------------------------
195
196 struct State_
197 {
198 double I_avg_;
200
201 State_();
202 };
203
204 // ------------------------------------------------------------
205
206 // The next two classes need to be friends to access the State_ class/member
207 friend class RecordablesMap< ou_noise_generator >;
208 friend class UniversalDataLogger< ou_noise_generator >;
209
210 // ------------------------------------------------------------
211
220
221 // ------------------------------------------------------------
222
233
234 double
236 {
237 return S_.I_avg_;
238 }
239
240 // ------------------------------------------------------------
241
243
248};
249
250inline size_t
252{
253 if ( kernel().vp_manager.get_num_threads() > 1 )
254 {
255 throw KernelException( "Recording from a ou_noise_generator is only possible in single-threaded mode." );
256 }
257
258 if ( receptor_type != 0 )
259 {
260 throw UnknownReceptorType( receptor_type, get_name() );
261 }
262 return B_.logger_.connect_logging_device( dlr, recordablesMap_ );
263}
264
265inline void
267{
268 P_.get( d );
270
271 d[ names::recordables ] = recordablesMap_.get_list();
272}
273
274inline void
276{
277 Parameters_ ptmp = P_; // temporary copy in case of errors
278 ptmp.num_targets_ = P_.num_targets_; // Copy Constr. does not copy connections
279 ptmp.set( d, *this, this ); // throws if BadProperty
280
281 // We now know that ptmp is consistent. We do not write it back
282 // to P_ before we are also sure that the properties to be set
283 // in the parent class are internally consistent.
285
286 // if we get here, temporaries contain consistent set of properties
287 P_ = ptmp;
289}
290
291inline SignalType
293{
294 return ALL;
295}
296
297inline bool
299{
300 return true;
301}
302
308
309inline Time
314
315} // namespace
316
317#endif // OU_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:192
@ CURRENT_GENERATOR
Definition stimulation_device.h:193
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 ou_noise_generator.h:113
std::vector< double > AmpVec_
Definition ou_noise_generator.h:163
State_ S_
Definition ou_noise_generator.h:245
void update(Time const &, const long, const long) override
Advance the state of the node in time through the given interval.
Definition ou_noise_generator.cpp:271
static RecordablesMap< ou_noise_generator > recordablesMap_
Definition ou_noise_generator.h:242
Parameters_ P_
Definition ou_noise_generator.h:244
void calibrate_time(const TimeConverter &tc) override
Re-calculate time-based properties of the node.
Definition ou_noise_generator.cpp:376
void get_status(Dictionary &) const override
Export properties of the node by setting entries in the status dictionary.
Definition ou_noise_generator.h:266
size_t handles_test_event(DataLoggingRequest &, size_t) override
Definition ou_noise_generator.h:251
SignalType sends_signal() const override
Definition ou_noise_generator.h:292
double get_I_avg_() const
Definition ou_noise_generator.h:235
void set_status(const Dictionary &) override
Change properties of the node according to the entries in the dictionary.
Definition ou_noise_generator.h:275
void init_buffers_() override
Configure persistent internal data structures.
Definition ou_noise_generator.cpp:194
Variables_ V_
Definition ou_noise_generator.h:247
ou_noise_generator()
Definition ou_noise_generator.cpp:165
size_t send_test_event(Node &, size_t, synindex, bool) override
Send an event to the receiving_node passed as an argument.
Definition ou_noise_generator.cpp:244
void pre_run_hook() override
Recalculates parameters and forces reinitialization of amplitudes if number of targets has changed.
Definition ou_noise_generator.cpp:206
Buffers_ B_
Definition ou_noise_generator.h:246
void handle(DataLoggingRequest &) override
Handler for universal data logging request.
Definition ou_noise_generator.cpp:341
void set_data_from_stimulation_backend(std::vector< double > &input_param) override
Definition ou_noise_generator.cpp:351
bool local_receiver() const override
Allow multimeter to connect to local instances.
Definition ou_noise_generator.h:298
void event_hook(DSCurrentEvent &) override
Definition ou_noise_generator.cpp:328
void init_state_() override
Configure state variables depending on runtime information.
Definition ou_noise_generator.cpp:188
StimulationDevice::Type get_type() const override
Definition ou_noise_generator.h:304
friend class UniversalDataLogger< ou_noise_generator >
Definition ou_noise_generator.h:208
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
KernelManager & kernel()
Definition kernel_manager.h:311
void register_ou_noise_generator(const std::string &name)
Definition ou_noise_generator.cpp:43
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 ou_noise_generator.h:213
UniversalDataLogger< ou_noise_generator > logger_
Definition ou_noise_generator.h:218
long next_step_
time step of next change in current
Definition ou_noise_generator.h:214
AmpVec_ amps_
amplitudes, one per target
Definition ou_noise_generator.h:215
Store independent parameters of the model.
Definition ou_noise_generator.h:169
double mean_
mean current, in pA
Definition ou_noise_generator.h:170
Time get_default_dt()
Definition ou_noise_generator.h:310
size_t num_targets_
Number of targets.
Definition ou_noise_generator.h:181
double std_
standard deviation of current, in pA
Definition ou_noise_generator.h:171
Time dt_
time interval between updates
Definition ou_noise_generator.h:173
void get(Dictionary &) const
Store current values in dictionary.
Definition ou_noise_generator.cpp:126
Parameters_()
Sets default parameter values.
Definition ou_noise_generator.cpp:62
void set(const Dictionary &, const ou_noise_generator &, Node *node)
Set values from dictionary.
Definition ou_noise_generator.cpp:135
double tau_
OU time constant, in ms.
Definition ou_noise_generator.h:172
Parameters_ & operator=(const Parameters_ &p)
Definition ou_noise_generator.cpp:89
Definition ou_noise_generator.h:197
double I_avg_
Average of instantaneous currents computed Used for recording current.
Definition ou_noise_generator.h:198
State_()
Sets default parameter values.
Definition ou_noise_generator.cpp:104
Definition ou_noise_generator.h:224
long dt_steps_
update interval in steps
Definition ou_noise_generator.h:227
normal_distribution normal_dist_
normal distribution
Definition ou_noise_generator.h:225
double prop_
propagator exp(-dt/tau)
Definition ou_noise_generator.h:228
double mean_weight_
weight for mean contribution
Definition ou_noise_generator.h:230
double noise_amp_
noise amplitude for one update, in pA
Definition ou_noise_generator.h:229
double mean_incr_
precomputed mean contribution per step
Definition ou_noise_generator.h:231