/
iaf_psc_exp.cpp
392 lines (330 loc) · 11.4 KB
/
iaf_psc_exp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/*
* iaf_psc_exp.cpp
*
* This file is part of NEST.
*
* Copyright (C) 2004 The NEST Initiative
*
* NEST is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* NEST is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NEST. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "iaf_psc_exp.h"
// Includes from libnestutil:
#include "dict_util.h"
#include "iaf_propagator.h"
#include "numerics.h"
// Includes from nestkernel:
#include "exceptions.h"
#include "iaf_propagator.h"
#include "kernel_manager.h"
#include "nest_impl.h"
#include "numerics.h"
#include "ring_buffer_impl.h"
#include "universal_data_logger_impl.h"
// Includes from sli:
#include "dictutils.h"
/* ----------------------------------------------------------------
* Recordables map
* ---------------------------------------------------------------- */
nest::RecordablesMap< nest::iaf_psc_exp > nest::iaf_psc_exp::recordablesMap_;
namespace nest
{
void
register_iaf_psc_exp( const std::string& name )
{
register_node_model< iaf_psc_exp >( name );
}
// Override the create() method with one call to RecordablesMap::insert_()
// for each quantity to be recorded.
template <>
void
RecordablesMap< iaf_psc_exp >::create()
{
// use standard names wherever you can for consistency!
insert_( names::V_m, &iaf_psc_exp::get_V_m_ );
insert_( names::I_syn_ex, &iaf_psc_exp::get_I_syn_ex_ );
insert_( names::I_syn_in, &iaf_psc_exp::get_I_syn_in_ );
}
}
/* ----------------------------------------------------------------
* Default constructors defining default parameters and state
* ---------------------------------------------------------------- */
nest::iaf_psc_exp::Parameters_::Parameters_()
: Tau_( 10.0 ) // in ms
, C_( 250.0 ) // in pF
, t_ref_( 2.0 ) // in ms
, E_L_( -70.0 ) // in mV
, I_e_( 0.0 ) // in pA
, Theta_( -55.0 - E_L_ ) // relative E_L_
, V_reset_( -70.0 - E_L_ ) // in mV
, tau_ex_( 2.0 ) // in ms
, tau_in_( 2.0 ) // in ms
, rho_( 0.01 ) // in 1/s
, delta_( 0.0 ) // in mV
{
}
nest::iaf_psc_exp::State_::State_()
: i_0_( 0.0 )
, i_1_( 0.0 )
, i_syn_ex_( 0.0 )
, i_syn_in_( 0.0 )
, V_m_( 0.0 )
, r_ref_( 0 )
{
}
/* ----------------------------------------------------------------
* Parameter and state extractions and manipulation functions
* ---------------------------------------------------------------- */
void
nest::iaf_psc_exp::Parameters_::get( DictionaryDatum& d ) const
{
def< double >( d, names::E_L, E_L_ ); // resting potential
def< double >( d, names::I_e, I_e_ );
def< double >( d, names::V_th, Theta_ + E_L_ ); // threshold value
def< double >( d, names::V_reset, V_reset_ + E_L_ );
def< double >( d, names::C_m, C_ );
def< double >( d, names::tau_m, Tau_ );
def< double >( d, names::tau_syn_ex, tau_ex_ );
def< double >( d, names::tau_syn_in, tau_in_ );
def< double >( d, names::t_ref, t_ref_ );
def< double >( d, names::rho, rho_ );
def< double >( d, names::delta, delta_ );
}
double
nest::iaf_psc_exp::Parameters_::set( const DictionaryDatum& d, Node* node )
{
// if E_L_ is changed, we need to adjust all variables defined relative to
// E_L_
const double ELold = E_L_;
updateValueParam< double >( d, names::E_L, E_L_, node );
const double delta_EL = E_L_ - ELold;
if ( updateValueParam< double >( d, names::V_reset, V_reset_, node ) )
{
V_reset_ -= E_L_;
}
else
{
V_reset_ -= delta_EL;
}
if ( updateValueParam< double >( d, names::V_th, Theta_, node ) )
{
Theta_ -= E_L_;
}
else
{
Theta_ -= delta_EL;
}
updateValueParam< double >( d, names::I_e, I_e_, node );
updateValueParam< double >( d, names::C_m, C_, node );
updateValueParam< double >( d, names::tau_m, Tau_, node );
updateValueParam< double >( d, names::tau_syn_ex, tau_ex_, node );
updateValueParam< double >( d, names::tau_syn_in, tau_in_, node );
updateValueParam< double >( d, names::t_ref, t_ref_, node );
if ( V_reset_ >= Theta_ )
{
throw BadProperty( "Reset potential must be smaller than threshold." );
}
if ( C_ <= 0 )
{
throw BadProperty( "Capacitance must be strictly positive." );
}
if ( Tau_ <= 0 or tau_ex_ <= 0 or tau_in_ <= 0 )
{
throw BadProperty( "Membrane and synapse time constants must be strictly positive." );
}
if ( t_ref_ < 0 )
{
throw BadProperty( "Refractory time must not be negative." );
}
updateValue< double >( d, "rho", rho_ );
if ( rho_ < 0 )
{
throw BadProperty( "Stochastic firing intensity must not be negative." );
}
updateValue< double >( d, "delta", delta_ );
if ( delta_ < 0 )
{
throw BadProperty( "Width of threshold region must not be negative." );
}
return delta_EL;
}
void
nest::iaf_psc_exp::State_::get( DictionaryDatum& d, const Parameters_& p ) const
{
def< double >( d, names::V_m, V_m_ + p.E_L_ ); // Membrane potential
}
void
nest::iaf_psc_exp::State_::set( const DictionaryDatum& d, const Parameters_& p, double delta_EL, Node* node )
{
if ( updateValueParam< double >( d, names::V_m, V_m_, node ) )
{
V_m_ -= p.E_L_;
}
else
{
V_m_ -= delta_EL;
}
}
nest::iaf_psc_exp::Buffers_::Buffers_( iaf_psc_exp& n )
: logger_( n )
{
}
nest::iaf_psc_exp::Buffers_::Buffers_( const Buffers_&, iaf_psc_exp& n )
: logger_( n )
{
}
/* ----------------------------------------------------------------
* Default and copy constructor for node
* ---------------------------------------------------------------- */
nest::iaf_psc_exp::iaf_psc_exp()
: ArchivingNode()
, P_()
, S_()
, B_( *this )
{
recordablesMap_.create();
}
nest::iaf_psc_exp::iaf_psc_exp( const iaf_psc_exp& n )
: ArchivingNode( n )
, P_( n.P_ )
, S_( n.S_ )
, B_( n.B_, *this )
{
}
/* ----------------------------------------------------------------
* Node initialization functions
* ---------------------------------------------------------------- */
void
nest::iaf_psc_exp::init_buffers_()
{
B_.input_buffer_.clear(); // includes resize
B_.logger_.reset();
ArchivingNode::clear_history();
}
void
nest::iaf_psc_exp::pre_run_hook()
{
// ensures initialization in case mm connected after Simulate
B_.logger_.init();
const double h = Time::get_resolution().get_ms();
// these P are independent
V_.P11ex_ = std::exp( -h / P_.tau_ex_ );
V_.P11in_ = std::exp( -h / P_.tau_in_ );
V_.P22_ = std::exp( -h / P_.Tau_ );
// these are determined according to a numeric stability criterion
V_.P21ex_ = IAFPropagatorExp( P_.tau_ex_, P_.Tau_, P_.C_ ).evaluate( h );
V_.P21in_ = IAFPropagatorExp( P_.tau_in_, P_.Tau_, P_.C_ ).evaluate( h );
V_.P20_ = P_.Tau_ / P_.C_ * ( 1.0 - V_.P22_ );
// t_ref_ specifies the length of the absolute refractory period as
// a double in ms. The grid based iaf_psc_exp can only handle refractory
// periods that are integer multiples of the computation step size (h).
// To ensure consistency with the overall simulation scheme such conversion
// should be carried out via objects of class nest::Time. The conversion
// requires 2 steps:
// 1. A time object r is constructed, defining representation of
// t_ref_ in tics. This representation is then converted to computation
// time steps again by a strategy defined by class nest::Time.
// 2. The refractory time in units of steps is read out get_steps(), a
// member function of class nest::Time.
//
// Choosing a t_ref_ that is not an integer multiple of the computation time
// step h will lead to accurate (up to the resolution h) and self-consistent
// results. However, a neuron model capable of operating with real valued
// spike time may exhibit a different effective refractory time.
V_.RefractoryCounts_ = Time( Time::ms( P_.t_ref_ ) ).get_steps();
// since t_ref_ >= 0, this can only fail in error
assert( V_.RefractoryCounts_ >= 0 );
V_.rng_ = get_vp_specific_rng( get_thread() );
}
void
nest::iaf_psc_exp::update( const Time& origin, const long from, const long to )
{
const double h = Time::get_resolution().get_ms();
// evolve from timestep 'from' to timestep 'to' with steps of h each
for ( long lag = from; lag < to; ++lag )
{
if ( S_.r_ref_ == 0 ) // neuron not refractory, so evolve V
{
S_.V_m_ =
S_.V_m_ * V_.P22_ + S_.i_syn_ex_ * V_.P21ex_ + S_.i_syn_in_ * V_.P21in_ + ( P_.I_e_ + S_.i_0_ ) * V_.P20_;
}
else
{
// neuron is absolute refractory
--S_.r_ref_;
}
// exponential decaying PSCs
S_.i_syn_ex_ *= V_.P11ex_;
S_.i_syn_in_ *= V_.P11in_;
// add evolution of presynaptic input current
S_.i_syn_ex_ += ( 1. - V_.P11ex_ ) * S_.i_1_;
// get read access to the correct input-buffer slot
const size_t input_buffer_slot = kernel().event_delivery_manager.get_modulo( lag );
auto& input = B_.input_buffer_.get_values_all_channels( input_buffer_slot );
// the spikes arriving at T+1 have an immediate effect on the state of the
// neuron
V_.weighted_spikes_ex_ = input[ Buffers_::SYN_EX ];
V_.weighted_spikes_in_ = input[ Buffers_::SYN_IN ];
S_.i_syn_ex_ += V_.weighted_spikes_ex_;
S_.i_syn_in_ += V_.weighted_spikes_in_;
if ( ( P_.delta_ < 1e-10 and S_.V_m_ >= P_.Theta_ ) // deterministic threshold crossing
or ( P_.delta_ > 1e-10 and V_.rng_->drand() < phi_() * h * 1e-3 ) ) // stochastic threshold crossing
{
S_.r_ref_ = V_.RefractoryCounts_;
S_.V_m_ = P_.V_reset_;
set_spiketime( Time::step( origin.get_steps() + lag + 1 ) );
SpikeEvent se;
kernel().event_delivery_manager.send( *this, se, lag );
}
// set new input current
S_.i_0_ = input[ Buffers_::I0 ];
S_.i_1_ = input[ Buffers_::I1 ];
// reset all values in the currently processed input-buffer slot
B_.input_buffer_.reset_values_all_channels( input_buffer_slot );
// log state data
B_.logger_.record_data( origin.get_steps() + lag );
}
}
void
nest::iaf_psc_exp::handle( SpikeEvent& e )
{
assert( e.get_delay_steps() > 0 );
const size_t input_buffer_slot = kernel().event_delivery_manager.get_modulo(
e.get_rel_delivery_steps( kernel().simulation_manager.get_slice_origin() ) );
const double s = e.get_weight() * e.get_multiplicity();
// separate buffer channels for excitatory and inhibitory inputs
B_.input_buffer_.add_value( input_buffer_slot, s > 0 ? Buffers_::SYN_EX : Buffers_::SYN_IN, s );
}
void
nest::iaf_psc_exp::handle( CurrentEvent& e )
{
assert( e.get_delay_steps() > 0 );
const double c = e.get_current();
const double w = e.get_weight();
const size_t input_buffer_slot = kernel().event_delivery_manager.get_modulo(
e.get_rel_delivery_steps( kernel().simulation_manager.get_slice_origin() ) );
if ( 0 == e.get_rport() )
{
B_.input_buffer_.add_value( input_buffer_slot, Buffers_::I0, w * c );
}
if ( 1 == e.get_rport() )
{
B_.input_buffer_.add_value( input_buffer_slot, Buffers_::I1, w * c );
}
}
void
nest::iaf_psc_exp::handle( DataLoggingRequest& e )
{
B_.logger_.handle( e );
}