NEST main@caf0ae8
 
Loading...
Searching...
No Matches
stdp_synapse.h
Go to the documentation of this file.
1/*
2 * stdp_synapse.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 STDP_SYNAPSE_H
24#define STDP_SYNAPSE_H
25
26// C++ includes:
27#include <cmath>
28
29// Includes from nestkernel:
31#include "connection.h"
32#include "connector_model.h"
33#include "event.h"
34
35
36namespace nest
37{
38
39/* BeginUserDocs: synapse, chemical, functional, stdp
40
41Short description
42+++++++++++++++++
43
44Synapse type for spike-timing dependent plasticity
45
46Description
47+++++++++++
48
49``stdp_synapse`` is a connector to create synapses with spike time
50dependent plasticity (as defined in :footcite:p:`Guetig2003`). Here the weight dependence
51exponent can be set separately for potentiation and depression.
52
53.. warning::
54
55 This synaptic plasticity rule does not take
56 :ref:`precise spike timing <sim_precise_spike_times>` into
57 account. When calculating the weight update, the precise spike time part
58 of the timestamp is ignored.
59
60See also :footcite:p:`Rubin2001`, :footcite:p:`Song2000`, :footcite:p:`vanRossum2000`.
61
62Parameters
63++++++++++
64
65========= ======= ======================================================
66 tau_plus ms Time constant of STDP window, potentiation
67 (tau_minus defined in postsynaptic neuron)
68 lambda real Step size
69 alpha real Asymmetry parameter (scales depressing increments as
70 alpha*lambda)
71 mu_plus real Weight dependence exponent, potentiation
72 mu_minus real Weight dependence exponent, depression
73 Wmax real Maximum allowed weight
74========= ======= ======================================================
75
76Transmits
77+++++++++
78
79SpikeEvent
80
81References
82++++++++++
83
84.. footbibliography::
85
86See also
87++++++++
88
89tsodyks_synapse, static_synapse
90
91Examples using this model
92+++++++++++++++++++++++++
93
94.. listexamples:: stdp_synapse
95
96EndUserDocs */
97
98// connections are templates of target identifier type (used for pointer /
99// target index addressing) derived from generic connection template
100
101void register_stdp_synapse( const std::string& name );
102
103template < typename targetidentifierT >
104class stdp_synapse : public Connection< targetidentifierT >
105{
106
107public:
110
114
119 stdp_synapse();
120
121
126 stdp_synapse( const stdp_synapse& ) = default;
127 stdp_synapse& operator=( const stdp_synapse& ) = default;
128
129 // Explicitly declare all methods inherited from the dependent base
130 // ConnectionBase. This avoids explicit name prefixes in all places these
131 // functions are used. Since ConnectionBase depends on the template parameter,
132 // they are not automatically found in the base class.
137
141 void get_status( Dictionary& d ) const;
142
146 void set_status( const Dictionary& d, ConnectorModel& cm );
147
153 bool send( Event& e, size_t t, const CommonSynapseProperties& cp );
154
155
157 {
158 public:
159 // Ensure proper overriding of overloaded virtual functions.
160 // Return values from functions are ignored.
162 size_t
163 handles_test_event( SpikeEvent&, size_t ) override
164 {
165 return invalid_port;
166 }
167 };
168
169 void
170 check_connection( Node& s, Node& t, size_t receptor_type, const CommonPropertiesType& )
171 {
172 ConnTestDummyNode dummy_target;
173
174 ConnectionBase::check_connection_( dummy_target, s, t, receptor_type );
175
177 }
178
179 void
180 set_weight( double w )
181 {
182 weight_ = w;
183 }
184
185private:
186 double
187 facilitate_( double w, double kplus )
188 {
189 double norm_w = ( w / Wmax_ ) + ( lambda_ * std::pow( 1.0 - ( w / Wmax_ ), mu_plus_ ) * kplus );
190 return norm_w < 1.0 ? norm_w * Wmax_ : Wmax_;
191 }
192
193 double
194 depress_( double w, double kminus )
195 {
196 double norm_w = ( w / Wmax_ ) - ( alpha_ * lambda_ * std::pow( w / Wmax_, mu_minus_ ) * kminus );
197 return norm_w > 0.0 ? norm_w * Wmax_ : 0.0;
198 }
199
200 // data members of each connection
201 double weight_;
202 double tau_plus_;
203 double lambda_;
204 double alpha_;
205 double mu_plus_;
206 double mu_minus_;
207 double Wmax_;
208 double Kplus_;
209
211};
212
213template < typename targetidentifierT >
215
222template < typename targetidentifierT >
223inline bool
225{
226 // synapse STDP depressing/facilitation dynamics
227 const double t_spike = e.get_stamp().get_ms();
228
229 // use accessor functions (inherited from Connection< >) to obtain delay and
230 // target
231 Node* target = get_target( t );
232 double dendritic_delay = get_delay();
233
234 // get spike history in relevant range (t1, t2] from postsynaptic neuron
235 std::deque< histentry >::iterator start;
236 std::deque< histentry >::iterator finish;
237
238 // For a new synapse, t_lastspike_ contains the point in time of the last
239 // spike. So we initially read the
240 // history(t_last_spike - dendritic_delay, ..., T_spike-dendritic_delay]
241 // which increases the access counter for these entries.
242 // At registration, all entries' access counters of
243 // history[0, ..., t_last_spike - dendritic_delay] have been
244 // incremented by ArchivingNode::register_stdp_connection(). See bug #218 for
245 // details.
246 target->get_history( t_lastspike_ - dendritic_delay, t_spike - dendritic_delay, &start, &finish );
247 // facilitation due to postsynaptic spikes since last pre-synaptic spike
248 double minus_dt;
249 while ( start != finish )
250 {
251 minus_dt = t_lastspike_ - ( start->t_ + dendritic_delay );
252 ++start;
253 // get_history() should make sure that
254 // start->t_ > t_lastspike - dendritic_delay, i.e. minus_dt < 0
255 assert( minus_dt < -1.0 * kernel().connection_manager.get_stdp_eps() );
256 weight_ = facilitate_( weight_, Kplus_ * std::exp( minus_dt / tau_plus_ ) );
257 }
258
259 const double _K_value = target->get_K_value( t_spike - dendritic_delay );
260 weight_ = depress_( weight_, _K_value );
261
262 e.set_receiver( *target );
263 e.set_weight( weight_ );
264 // use accessor functions (inherited from Connection< >) to obtain delay in
265 // steps and rport
266 e.set_delay_steps( get_delay_steps() );
267 e.set_rport( get_rport() );
268 e();
269
270 Kplus_ = Kplus_ * std::exp( ( t_lastspike_ - t_spike ) / tau_plus_ ) + 1.0;
271
272 t_lastspike_ = t_spike;
273
274 return true;
275}
276
277
278template < typename targetidentifierT >
281 , weight_( 1.0 )
282 , tau_plus_( 20.0 )
283 , lambda_( 0.01 )
284 , alpha_( 1.0 )
285 , mu_plus_( 1.0 )
286 , mu_minus_( 1.0 )
287 , Wmax_( 100.0 )
288 , Kplus_( 0.0 )
289 , t_lastspike_( 0.0 )
290{
291}
292
293template < typename targetidentifierT >
294void
296{
297 ConnectionBase::get_status( d );
298 d[ names::weight ] = weight_;
299 d[ names::tau_plus ] = tau_plus_;
300 d[ names::lambda ] = lambda_;
301 d[ names::alpha ] = alpha_;
302 d[ names::mu_plus ] = mu_plus_;
303 d[ names::mu_minus ] = mu_minus_;
304 d[ names::Wmax ] = Wmax_;
305 d[ names::Kplus ] = Kplus_;
306 d[ names::size_of ] = static_cast< long >( sizeof( *this ) );
307}
308
309template < typename targetidentifierT >
310void
312{
313 ConnectionBase::set_status( d, cm );
314 d.update_value( names::weight, weight_ );
315 d.update_value( names::tau_plus, tau_plus_ );
316 d.update_value( names::lambda, lambda_ );
317 d.update_value( names::alpha, alpha_ );
318 d.update_value( names::mu_plus, mu_plus_ );
319 d.update_value( names::mu_minus, mu_minus_ );
320 d.update_value( names::Wmax, Wmax_ );
321 d.update_value( names::Kplus, Kplus_ );
322
323 // check if weight_ and Wmax_ has the same sign
324 if ( not( ( ( weight_ >= 0 ) - ( weight_ < 0 ) ) == ( ( Wmax_ >= 0 ) - ( Wmax_ < 0 ) ) ) )
325 {
326 throw BadProperty( "Weight and Wmax must have same sign." );
327 }
328
329 if ( Kplus_ < 0 )
330 {
331 throw BadProperty( "Kplus must be non-negative." );
332 }
333}
334
335} // of namespace nest
336
337#endif // of #ifndef STDP_SYNAPSE_H
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition exceptions.h:680
Class containing the common properties for all connections of a certain type.
Definition common_synapse_properties.h:50
Base class for dummy nodes used in connection testing.
Definition connection.h:67
Base class for representing connections.
Definition connection.h:110
void check_connection_(Node &dummy_target, Node &source, Node &target, const size_t receptor_type)
This function calls check_connection() on the sender to check if the receiver accepts the event type ...
Definition connection.h:319
long get_delay_steps() const
Return the delay of the connection in steps.
Definition connection.h:181
Node * get_target(const size_t tid) const
Definition connection.h:239
size_t get_rport() const
Definition connection.h:244
double get_delay() const
Return the delay of the connection in ms.
Definition connection.h:172
Definition connector_model.h:69
Encapsulate information sent between nodes.
Definition event.h:103
Base class for all NEST network objects.
Definition node.h:99
virtual void register_stdp_connection(double, double)
Register a STDP connection.
Definition node.cpp:211
Event for spike information.
Definition event.h:418
Definition stdp_synapse.h:157
size_t handles_test_event(SpikeEvent &, size_t) override
Check if the node can handle a particular event and receptor type.
Definition stdp_synapse.h:163
Definition stdp_synapse.h:105
stdp_synapse(const stdp_synapse &)=default
Copy constructor.
bool send(Event &e, size_t t, const CommonSynapseProperties &cp)
Send an event to the receiver of this connection.
Definition stdp_synapse.h:224
double Kplus_
Definition stdp_synapse.h:208
double alpha_
Definition stdp_synapse.h:204
double tau_plus_
Definition stdp_synapse.h:202
double weight_
Definition stdp_synapse.h:201
stdp_synapse & operator=(const stdp_synapse &)=default
stdp_synapse()
Default Constructor.
Definition stdp_synapse.h:279
double Wmax_
Definition stdp_synapse.h:207
double mu_minus_
Definition stdp_synapse.h:206
void set_weight(double w)
Definition stdp_synapse.h:180
double get_delay() const
Return the delay of the connection in ms.
Definition connection.h:172
void check_connection(Node &s, Node &t, size_t receptor_type, const CommonPropertiesType &)
Definition stdp_synapse.h:170
static constexpr ConnectionModelProperties properties
Definition stdp_synapse.h:111
double t_lastspike_
Definition stdp_synapse.h:210
CommonSynapseProperties CommonPropertiesType
Definition stdp_synapse.h:108
double depress_(double w, double kminus)
Definition stdp_synapse.h:194
double mu_plus_
Definition stdp_synapse.h:205
double facilitate_(double w, double kplus)
Definition stdp_synapse.h:187
double lambda_
Definition stdp_synapse.h:203
void get_status(Dictionary &d) const
Get all properties of this connection and put them into a dictionary.
Definition stdp_synapse.h:295
Connection< targetidentifierT > ConnectionBase
Definition stdp_synapse.h:109
void set_status(const Dictionary &d, ConnectorModel &cm)
Set properties of this connection from the values given in dictionary.
Definition stdp_synapse.h:311
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
const std::string mu_plus("mu_plus")
const std::string mu_minus("mu_minus")
const std::string lambda("lambda")
const std::string alpha("alpha")
const std::string Kplus("Kplus")
const std::string tau_plus("tau_plus")
const std::string weight("weight")
const std::string size_of("sizeof")
const std::string Wmax("Wmax")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
KernelManager & kernel()
Definition kernel_manager.h:311
void register_stdp_synapse(const std::string &name)
Definition stdp_synapse.cpp:32
ConnectionModelProperties
Definition connector_model.h:49
constexpr size_t invalid_port
Value for invalid connection port number.
Definition nest_types.h:141