NEST main@caf0ae8
 
Loading...
Searching...
No Matches
stdp_nn_symm_synapse.h
Go to the documentation of this file.
1/*
2 * stdp_nn_symm_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_NN_SYMM_SYNAPSE_H
24#define STDP_NN_SYMM_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, stdp
40
41Short description
42+++++++++++++++++
43
44Synapse type for spike-timing dependent plasticity with symmetric nearest-neighbour spike pairing scheme
45
46Description
47+++++++++++
48
49``stdp_nn_symm_synapse`` is a connector to create synapses with spike time
50dependent plasticity with the symmetric nearest-neighbour spike pairing
51scheme :footcite:p:`Morrison2007c`.
52
53When a presynaptic spike occurs, it is taken into account in the depression
54part of the STDP weight change rule with the nearest preceding postsynaptic
55one, and when a postsynaptic spike occurs, it is accounted in the
56facilitation rule with the nearest preceding presynaptic one (instead of
57pairing with all spikes, like in ``stdp_synapse``). For a clear illustration of
58this scheme see fig. 7A in :footcite:p:`Morrison2008`.
59
60The pairs exactly coinciding (so that ``presynaptic_spike == postsynaptic_spike
61+ dendritic_delay``), leading to zero ``delta_t``, are discarded. In this case the
62concerned pre/postsynaptic spike is paired with the second latest preceding
63post/presynaptic one (for example, ``pre=={10 ms; 20 ms}`` and ``post=={20 ms}`` will
64result in a potentiation pair 20-to-10).
65
66The implementation involves two additional variables - presynaptic and
67postsynaptic traces :footcite:p:`Morrison2008`. The presynaptic trace decays exponentially over
68time with the time constant ``tau_plus`` and increases to 1 on a pre-spike
69occurrence. The postsynaptic trace (implemented on the postsynaptic neuron
70side) decays with the time constant ``tau_minus`` and increases to 1 on a
71post-spike occurrence.
72
73.. warning::
74
75 This synaptic plasticity rule does not take
76 :ref:`precise spike timing <sim_precise_spike_times>` into
77 account. When calculating the weight update, the precise spike time part
78 of the timestamp is ignored.
79
80Parameters
81++++++++++
82
83========= ======= ======================================================
84 tau_plus ms Time constant of STDP window, potentiation
85 (tau_minus defined in postsynaptic neuron)
86 lambda real Step size
87 alpha real Asymmetry parameter (scales depressing increments as
88 alpha*lambda)
89 mu_plus real Weight dependence exponent, potentiation
90 mu_minus real Weight dependence exponent, depression
91 Wmax real Maximum allowed weight
92========= ======= ======================================================
93
94Transmits
95+++++++++
96
97SpikeEvent
98
99References
100++++++++++
101
102.. footbibliography::
103
104See also
105++++++++
106
107stdp_synapse
108
109Examples using this model
110+++++++++++++++++++++++++
111
112.. listexamples:: stdp_nn_symm_synapse
113
114EndUserDocs */
115
116// connections are templates of target identifier type (used for pointer /
117// target index addressing) derived from generic connection template
118
119void register_stdp_nn_symm_synapse( const std::string& name );
120
121template < typename targetidentifierT >
122class stdp_nn_symm_synapse : public Connection< targetidentifierT >
123{
124
125public:
128
132
138
139
146
147 // Explicitly declare all methods inherited from the dependent base
148 // ConnectionBase. This avoids explicit name prefixes in all places these
149 // functions are used. Since ConnectionBase depends on the template parameter,
150 // they are not automatically found in the base class.
155
159 void get_status( Dictionary& d ) const;
160
164 void set_status( const Dictionary& d, ConnectorModel& cm );
165
171 bool send( Event& e, size_t t, const CommonSynapseProperties& cp );
172
173
175 {
176 public:
177 // Ensure proper overriding of overloaded virtual functions.
178 // Return values from functions are ignored.
180 size_t
181 handles_test_event( SpikeEvent&, size_t ) override
182 {
183 return invalid_port;
184 }
185 };
186
187 void
188 check_connection( Node& s, Node& t, size_t receptor_type, const CommonPropertiesType& )
189 {
190 ConnTestDummyNode dummy_target;
191
192 ConnectionBase::check_connection_( dummy_target, s, t, receptor_type );
193
195 }
196
197 void
198 set_weight( double w )
199 {
200 weight_ = w;
201 }
202
203private:
204 double
205 facilitate_( double w, double kplus )
206 {
207 double norm_w = ( w / Wmax_ ) + ( lambda_ * std::pow( 1.0 - ( w / Wmax_ ), mu_plus_ ) * kplus );
208 return norm_w < 1.0 ? norm_w * Wmax_ : Wmax_;
209 }
210
211 double
212 depress_( double w, double kminus )
213 {
214 double norm_w = ( w / Wmax_ ) - ( alpha_ * lambda_ * std::pow( w / Wmax_, mu_minus_ ) * kminus );
215 return norm_w > 0.0 ? norm_w * Wmax_ : 0.0;
216 }
217
218 // data members of each connection
219 double weight_;
220 double tau_plus_;
221 double lambda_;
222 double alpha_;
223 double mu_plus_;
224 double mu_minus_;
225 double Wmax_;
226
228};
229
230template < typename targetidentifierT >
232
239template < typename targetidentifierT >
240inline bool
242{
243 // synapse STDP depressing/facilitation dynamics
244 double t_spike = e.get_stamp().get_ms();
245
246 // use accessor functions (inherited from Connection< >) to obtain delay and
247 // target
248 Node* target = get_target( t );
249 double dendritic_delay = get_delay();
250
251 // get spike history in relevant range (t1, t2] from postsynaptic neuron
252 std::deque< histentry >::iterator start;
253 std::deque< histentry >::iterator finish;
254
255 // For a new synapse, t_lastspike_ contains the point in time of the last
256 // spike. So we initially read the
257 // history(t_last_spike - dendritic_delay, ..., T_spike-dendritic_delay]
258 // which increases the access counter for these entries.
259 // At registration, all entries' access counters of
260 // history[0, ..., t_last_spike - dendritic_delay] have been
261 // incremented by ArchivingNode::register_stdp_connection(). See bug #218 for
262 // details.
263 target->get_history( t_lastspike_ - dendritic_delay, t_spike - dendritic_delay, &start, &finish );
264 // facilitation due to postsynaptic spikes since the last pre-synaptic spike
265 double minus_dt;
266 while ( start != finish )
267 {
268 minus_dt = t_lastspike_ - ( start->t_ + dendritic_delay );
269 ++start;
270
271 // get_history() should make sure that
272 // start->t_ > t_lastspike_ - dendritic_delay, i.e. minus_dt < 0
273 assert( minus_dt < -1.0 * kernel().connection_manager.get_stdp_eps() );
274
275 weight_ = facilitate_( weight_, std::exp( minus_dt / tau_plus_ ) );
276 }
277
278 // depression due to the new pre-synaptic spike
279 double nearest_neighbor_Kminus;
280 double value_to_throw_away; // discard Kminus and Kminus_triplet here
281 target->get_K_values( t_spike - dendritic_delay, value_to_throw_away, nearest_neighbor_Kminus, value_to_throw_away );
282 weight_ = depress_( weight_, nearest_neighbor_Kminus );
283
284 e.set_receiver( *target );
285 e.set_weight( weight_ );
286 // use accessor functions (inherited from Connection< >) to obtain delay in
287 // steps and rport
288 e.set_delay_steps( get_delay_steps() );
289 e.set_rport( get_rport() );
290 e();
291
292 t_lastspike_ = t_spike;
293
294 return true;
295}
296
297
298template < typename targetidentifierT >
301 , weight_( 1.0 )
302 , tau_plus_( 20.0 )
303 , lambda_( 0.01 )
304 , alpha_( 1.0 )
305 , mu_plus_( 1.0 )
306 , mu_minus_( 1.0 )
307 , Wmax_( 100.0 )
308 , t_lastspike_( 0.0 )
309{
310}
311
312template < typename targetidentifierT >
313void
315{
316 ConnectionBase::get_status( d );
317 d[ names::weight ] = weight_;
318 d[ names::tau_plus ] = tau_plus_;
319 d[ names::lambda ] = lambda_;
320 d[ names::alpha ] = alpha_;
321 d[ names::mu_plus ] = mu_plus_;
322 d[ names::mu_minus ] = mu_minus_;
323 d[ names::Wmax ] = Wmax_;
324 d[ names::size_of ] = static_cast< long >( sizeof( *this ) );
325}
326
327template < typename targetidentifierT >
328void
330{
331 ConnectionBase::set_status( d, cm );
332 d.update_value( names::weight, weight_ );
333 d.update_value( names::tau_plus, tau_plus_ );
334 d.update_value( names::lambda, lambda_ );
335 d.update_value( names::alpha, alpha_ );
336 d.update_value( names::mu_plus, mu_plus_ );
337 d.update_value( names::mu_minus, mu_minus_ );
338 d.update_value( names::Wmax, Wmax_ );
339
340 // check if weight_ and Wmax_ have the same sign
341 if ( std::signbit( weight_ ) != std::signbit( Wmax_ ) )
342 {
343 throw BadProperty( "Weight and Wmax must have same sign." );
344 }
345}
346
347} // of namespace nest
348
349#endif // of #ifndef STDP_NN_SYMM_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_nn_symm_synapse.h:175
size_t handles_test_event(SpikeEvent &, size_t) override
Check if the node can handle a particular event and receptor type.
Definition stdp_nn_symm_synapse.h:181
Definition stdp_nn_symm_synapse.h:123
stdp_nn_symm_synapse()
Default Constructor.
Definition stdp_nn_symm_synapse.h:299
double Wmax_
Definition stdp_nn_symm_synapse.h:225
double facilitate_(double w, double kplus)
Definition stdp_nn_symm_synapse.h:205
void check_connection(Node &s, Node &t, size_t receptor_type, const CommonPropertiesType &)
Definition stdp_nn_symm_synapse.h:188
void set_status(const Dictionary &d, ConnectorModel &cm)
Set properties of this connection from the values given in dictionary.
Definition stdp_nn_symm_synapse.h:329
double alpha_
Definition stdp_nn_symm_synapse.h:222
void set_weight(double w)
Definition stdp_nn_symm_synapse.h:198
double t_lastspike_
Definition stdp_nn_symm_synapse.h:227
void get_status(Dictionary &d) const
Get all properties of this connection and put them into a dictionary.
Definition stdp_nn_symm_synapse.h:314
Connection< targetidentifierT > ConnectionBase
Definition stdp_nn_symm_synapse.h:127
double weight_
Definition stdp_nn_symm_synapse.h:219
double depress_(double w, double kminus)
Definition stdp_nn_symm_synapse.h:212
stdp_nn_symm_synapse(const stdp_nn_symm_synapse &)=default
Copy constructor.
double lambda_
Definition stdp_nn_symm_synapse.h:221
double mu_plus_
Definition stdp_nn_symm_synapse.h:223
static constexpr ConnectionModelProperties properties
Definition stdp_nn_symm_synapse.h:129
double mu_minus_
Definition stdp_nn_symm_synapse.h:224
double get_delay() const
Return the delay of the connection in ms.
Definition connection.h:172
bool send(Event &e, size_t t, const CommonSynapseProperties &cp)
Send an event to the receiver of this connection.
Definition stdp_nn_symm_synapse.h:241
CommonSynapseProperties CommonPropertiesType
Definition stdp_nn_symm_synapse.h:126
stdp_nn_symm_synapse & operator=(const stdp_nn_symm_synapse &)=default
double tau_plus_
Definition stdp_nn_symm_synapse.h:220
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 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_nn_symm_synapse(const std::string &name)
Definition stdp_nn_symm_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