-
Notifications
You must be signed in to change notification settings - Fork 358
/
stdp_pl_synapse_hom.h
319 lines (256 loc) · 8.82 KB
/
stdp_pl_synapse_hom.h
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
/*
* stdp_pl_synapse_hom.h
*
* 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/>.
*
*/
#ifndef STDP_PL_SYNAPSE_HOM_H
#define STDP_PL_SYNAPSE_HOM_H
// C++ includes:
#include <cmath>
// Includes from nestkernel:
#include "connection.h"
namespace nest
{
/* BeginUserDocs: synapse, spike-timing-dependent plasticity
Short description
+++++++++++++++++
Synapse type for spike-timing dependent plasticity with power law
Description
+++++++++++
stdp_pl_synapse is a connector to create synapses with spike time
dependent plasticity using homoegeneous parameters (as defined in [1]_).
Parameters
++++++++++
========= ====== ====================================================
tau_plus ms Time constant of STDP window, potentiation
(tau_minus defined in postsynaptic neuron)
lambda real Learning rate
alpha real Asymmetry parameter (scales depressing increments as
alpha*lambda)
mu real Weight dependence exponent, potentiation
========= ====== ====================================================
Remarks:
The parameters can only be set by SetDefaults and apply to all synapses of
the model.
References
++++++++++
.. [1] Morrison A, Aertsen A, Diesmann M. (2007) Spike-timing dependent
plasticity in balanced random netrks. Neural Computation,
19(6):1437-1467. DOI: https://doi.org/10.1162/neco.2007.19.6.1437
Transmits
+++++++++
SpikeEvent
See also
++++++++
stdp_synapse, tsodyks_synapse, static_synapse
EndUserDocs */
/**
* Class containing the common properties for all synapses of type
* stdp_pl_synapse_hom.
*/
class STDPPLHomCommonProperties : public CommonSynapseProperties
{
public:
/**
* Default constructor.
* Sets all property values to defaults.
*/
STDPPLHomCommonProperties();
/**
* Get all properties and put them into a dictionary.
*/
void get_status( DictionaryDatum& d ) const;
/**
* Set properties from the values given in dictionary.
*/
void set_status( const DictionaryDatum& d, ConnectorModel& cm );
// data members common to all connections
double tau_plus_;
double tau_plus_inv_; //!< 1 / tau_plus for efficiency
double lambda_;
double alpha_;
double mu_;
};
/**
* Class representing an STDP connection with homogeneous parameters, i.e.
* parameters are the same for all synapses.
*/
template < typename targetidentifierT >
class stdp_pl_synapse_hom : public Connection< targetidentifierT >
{
public:
typedef STDPPLHomCommonProperties CommonPropertiesType;
typedef Connection< targetidentifierT > ConnectionBase;
/**
* Default Constructor.
* Sets default values for all parameters. Needed by GenericConnectorModel.
*/
stdp_pl_synapse_hom();
/**
* Copy constructor from a property object.
* Needs to be defined properly in order for GenericConnector to work.
*/
stdp_pl_synapse_hom( const stdp_pl_synapse_hom& ) = default;
// Explicitly declare all methods inherited from the dependent base
// ConnectionBase. This avoids explicit name prefixes in all places these
// functions are used. Since ConnectionBase depends on the template parameter,
// they are not automatically found in the base class.
using ConnectionBase::get_delay;
using ConnectionBase::get_delay_steps;
using ConnectionBase::get_rport;
using ConnectionBase::get_target;
/**
* Get all properties of this connection and put them into a dictionary.
*/
void get_status( DictionaryDatum& d ) const;
/**
* Set properties of this connection from the values given in dictionary.
*/
void set_status( const DictionaryDatum& d, ConnectorModel& cm );
/**
* Send an event to the receiver of this connection.
* \param e The event to send
*/
void send( Event& e, thread t, const STDPPLHomCommonProperties& );
class ConnTestDummyNode : public ConnTestDummyNodeBase
{
public:
// Ensure proper overriding of overloaded virtual functions.
// Return values from functions are ignored.
using ConnTestDummyNodeBase::handles_test_event;
port
handles_test_event( SpikeEvent&, rport )
{
return invalid_port_;
}
};
/*
* This function calls check_connection on the sender and checks if the
* receiver accepts the event type and receptor type requested by the sender.
* Node::check_connection() will either confirm the receiver port by returning
* true or false if the connection should be ignored.
* We have to override the base class' implementation, since for STDP
* connections we have to call register_stdp_pl_connection on the target
* neuron to inform the Archiver to collect spikes for this connection.
*
* \param s The source node
* \param r The target node
* \param receptor_type The ID of the requested receptor type
*/
void
check_connection( Node& s, Node& t, rport receptor_type, const CommonPropertiesType& )
{
ConnTestDummyNode dummy_target;
ConnectionBase::check_connection_( dummy_target, s, t, receptor_type );
t.register_stdp_connection( t_lastspike_ - get_delay(), get_delay() );
}
void
set_weight( double w )
{
weight_ = w;
}
private:
double
facilitate_( double w, double kplus, const STDPPLHomCommonProperties& cp )
{
return w + ( cp.lambda_ * std::pow( w, cp.mu_ ) * kplus );
}
double
depress_( double w, double kminus, const STDPPLHomCommonProperties& cp )
{
double new_w = w - ( cp.lambda_ * cp.alpha_ * w * kminus );
return new_w > 0.0 ? new_w : 0.0;
}
// data members of each connection
double weight_;
double Kplus_;
double t_lastspike_;
};
//
// Implementation of class stdp_pl_synapse_hom.
//
/**
* Send an event to the receiver of this connection.
* \param e The event to send
* \param p The port under which this connection is stored in the Connector.
*/
template < typename targetidentifierT >
inline void
stdp_pl_synapse_hom< targetidentifierT >::send( Event& e, thread t, const STDPPLHomCommonProperties& cp )
{
// synapse STDP depressing/facilitation dynamics
const double t_spike = e.get_stamp().get_ms();
// t_lastspike_ = 0 initially
Node* target = get_target( t );
double dendritic_delay = get_delay();
// get spike history in relevant range (t1, t2] from postsynaptic neuron
std::deque< histentry >::iterator start;
std::deque< histentry >::iterator finish;
target->get_history( t_lastspike_ - dendritic_delay, t_spike - dendritic_delay, &start, &finish );
// facilitation due to postsynaptic spikes since last pre-synaptic spike
double minus_dt;
while ( start != finish )
{
minus_dt = t_lastspike_ - ( start->t_ + dendritic_delay );
start++;
// get_history() should make sure that
// start->t_ > t_lastspike - dendritic_delay, i.e. minus_dt < 0
assert( minus_dt < -1.0 * kernel().connection_manager.get_stdp_eps() );
weight_ = facilitate_( weight_, Kplus_ * std::exp( minus_dt * cp.tau_plus_inv_ ), cp );
}
// depression due to new pre-synaptic spike
weight_ = depress_( weight_, target->get_K_value( t_spike - dendritic_delay ), cp );
e.set_receiver( *target );
e.set_weight( weight_ );
e.set_delay_steps( get_delay_steps() );
e.set_rport( get_rport() );
e();
Kplus_ = Kplus_ * std::exp( ( t_lastspike_ - t_spike ) * cp.tau_plus_inv_ ) + 1.0;
t_lastspike_ = t_spike;
}
template < typename targetidentifierT >
stdp_pl_synapse_hom< targetidentifierT >::stdp_pl_synapse_hom()
: ConnectionBase()
, weight_( 1.0 )
, Kplus_( 0.0 )
, t_lastspike_( 0.0 )
{
}
template < typename targetidentifierT >
void
stdp_pl_synapse_hom< targetidentifierT >::get_status( DictionaryDatum& d ) const
{
// base class properties, different for individual synapse
ConnectionBase::get_status( d );
def< double >( d, names::weight, weight_ );
// own properties, different for individual synapse
def< double >( d, names::Kplus, Kplus_ );
def< long >( d, names::size_of, sizeof( *this ) );
}
template < typename targetidentifierT >
void
stdp_pl_synapse_hom< targetidentifierT >::set_status( const DictionaryDatum& d, ConnectorModel& cm )
{
// base class properties
ConnectionBase::set_status( d, cm );
updateValue< double >( d, names::weight, weight_ );
updateValue< double >( d, names::Kplus, Kplus_ );
}
} // of namespace nest
#endif // of #ifndef STDP_PL_SYNAPSE_HOM_H